Added fl_filename_relative which uses an additional parameter instead of the current working directory. Now we can find a relative path without changing the cwd.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.3@8064 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
This commit is contained in:
parent
9092dccab8
commit
22953ccb02
@ -63,6 +63,7 @@ FL_EXPORT char *fl_filename_setext(char *to, int tolen, const char *ext);
|
||||
FL_EXPORT int fl_filename_expand(char *to, int tolen, const char *from);
|
||||
FL_EXPORT int fl_filename_absolute(char *to, int tolen, const char *from);
|
||||
FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from);
|
||||
FL_EXPORT int fl_filename_relative(char *to, int tolen, const char *from, const char *cwd);
|
||||
FL_EXPORT int fl_filename_match(const char *name, const char *pattern);
|
||||
FL_EXPORT int fl_filename_isdir(const char *name);
|
||||
|
||||
|
@ -136,13 +136,34 @@ 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__)
|
||||
if (from[0] == '\0' ||
|
||||
@ -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, '\\'))
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user