summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/filename_absolute.cxx45
-rw-r--r--src/numericsort.c2
2 files changed, 36 insertions, 11 deletions
diff --git a/src/filename_absolute.cxx b/src/filename_absolute.cxx
index 4381a2dbe..9dea51817 100644
--- a/src/filename_absolute.cxx
+++ b/src/filename_absolute.cxx
@@ -136,12 +136,33 @@ int fl_filename_absolute(char *to, int tolen, const char *from) {
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
- char *newslash; // Directory separator
- const char *slash; // Directory separator
- char cwd_buf[FL_PATH_MAX]; // Current directory
- char *cwd = cwd_buf;
+ const char *from) // I - Absolute filename
+{
+ char cwd_buf[FL_PATH_MAX]; // Current directory
+ // get the current directory and return if we can't
+ if (!fl_getcwd(cwd_buf, sizeof(cwd_buf))) {
+ strlcpy(to, from, tolen);
+ return 0;
+ }
+ return fl_filename_relative(to, tolen, from, cwd_buf);
+}
+
+/** Makes a filename relative to any other directory.
+ \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
+ \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 *newslash; // Directory separator
+ const char *slash; // Directory separator
// return if "from" is not an absolute path
#if defined(WIN32) || defined(__EMX__)
@@ -154,13 +175,19 @@ fl_filename_relative(char *to, // O - Relative filename
strlcpy(to, from, tolen);
return 0;
}
-
- // get the current directory and return if we can't
- if (!fl_getcwd(cwd_buf, sizeof(cwd_buf))) {
+
+ // return if "cwd" is not an absolute path
+#if defined(WIN32) || defined(__EMX__)
+ if (!cwd || cwd[0] == '\0' ||
+ (!isdirsep(*cwd) && !isalpha(*cwd) && cwd[1] != ':' &&
+ !isdirsep(cwd[2]))) {
+#else
+ if (!cwd || cwd[0] == '\0' || !isdirsep(*cwd)) {
+#endif // WIN32 || __EMX__
strlcpy(to, from, tolen);
return 0;
}
-
+
#if defined(WIN32) || defined(__EMX__)
// convert all backslashes into forward slashes
for (newslash = strchr(cwd, '\\'); newslash; newslash = strchr(newslash + 1, '\\'))
diff --git a/src/numericsort.c b/src/numericsort.c
index 7c8618e3e..be1b518ff 100644
--- a/src/numericsort.c
+++ b/src/numericsort.c
@@ -33,8 +33,6 @@
#include <stdlib.h>
#include <sys/types.h>
-#include <FL/filename.H>
-
#if !defined(WIN32) || defined(__CYGWIN__)
# ifdef HAVE_DIRENT_H
# include <dirent.h>