summaryrefslogtreecommitdiff
path: root/src/filename_absolute.cxx
diff options
context:
space:
mode:
authorMatthias Melcher <fltk@matthiasm.com>2010-12-19 23:52:59 +0000
committerMatthias Melcher <fltk@matthiasm.com>2010-12-19 23:52:59 +0000
commit31f6505cb313c4448ccffef08e2d281ebe7c95d0 (patch)
tree11b4f9c82ff72a9483d44c3cebf1f38e970fb8df /src/filename_absolute.cxx
parent740d7e211fc5af5bbab84cc6554bf015cdc19f13 (diff)
Fixed fl_filename_relative access to const string.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8066 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/filename_absolute.cxx')
-rw-r--r--src/filename_absolute.cxx16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/filename_absolute.cxx b/src/filename_absolute.cxx
index 9dea51817..a3fea5bbe 100644
--- a/src/filename_absolute.cxx
+++ b/src/filename_absolute.cxx
@@ -152,18 +152,20 @@ fl_filename_relative(char *to, // O - Relative filename
\param[out] to resulting relative filename
\param[in] tolen size of the relative filename buffer
\param[in] from absolute filename
- \param[in] cwd relative to this absolute path
+ \param[in] base relative to this absolute path
\return 0 if no change, non zero otherwise
*/
int // O - 0 if no change, 1 if changed
fl_filename_relative(char *to, // O - Relative filename
int tolen, // I - Size of "to" buffer
const char *from, // I - Absolute filename
- const char *cwd) { // I - Find path relative to this path
+ const char *base) { // I - Find path relative to this path
- const char *newslash; // Directory separator
+ char *newslash; // Directory separator
const char *slash; // Directory separator
-
+ char *cwd = 0L;
+ if (base) cwd = strdup(base);
+
// return if "from" is not an absolute path
#if defined(WIN32) || defined(__EMX__)
if (from[0] == '\0' ||
@@ -173,6 +175,7 @@ fl_filename_relative(char *to, // O - Relative filename
if (from[0] == '\0' || !isdirsep(*from)) {
#endif // WIN32 || __EMX__
strlcpy(to, from, tolen);
+ if (cwd) free(cwd);
return 0;
}
@@ -185,6 +188,7 @@ fl_filename_relative(char *to, // O - Relative filename
if (!cwd || cwd[0] == '\0' || !isdirsep(*cwd)) {
#endif // WIN32 || __EMX__
strlcpy(to, from, tolen);
+ if (cwd) free(cwd);
return 0;
}
@@ -196,6 +200,7 @@ fl_filename_relative(char *to, // O - Relative filename
// test for the exact same string and return "." if so
if (!strcasecmp(from, cwd)) {
strlcpy(to, ".", tolen);
+ free(cwd);
return (1);
}
@@ -203,6 +208,7 @@ fl_filename_relative(char *to, // O - Relative filename
if (tolower(*from & 255) != tolower(*cwd & 255)) {
// Not the same drive...
strlcpy(to, from, tolen);
+ free(cwd);
return 0;
}
@@ -212,6 +218,7 @@ fl_filename_relative(char *to, // O - Relative filename
// test for the exact same string and return "." if so
if (!strcmp(from, cwd)) {
strlcpy(to, ".", tolen);
+ free(cwd);
return (1);
}
#endif // WIN32 || __EMX__
@@ -255,6 +262,7 @@ fl_filename_relative(char *to, // O - Relative filename
// finally add the differing path from "from"
strlcat(to, slash, tolen);
+ free(cwd);
return 1;
}