diff options
| author | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-11-26 00:15:06 +0000 |
|---|---|---|
| committer | Michael R Sweet <michael.r.sweet@gmail.com> | 2001-11-26 00:15:06 +0000 |
| commit | eba128dcc01aae25f688a05683436ab4d508aef6 (patch) | |
| tree | 7215180cb738dee1dd1c4bc33f8156b0f332f9ad /src/filename_expand.cxx | |
| parent | 2b826b0f318e8df5176d3a5fa2edba4b1811e78d (diff) | |
New filename_relative() function, and use it from fl_file_chooser() and
fl_dir_chooser(), so that apps like FLUID won't get absolute paths all
the time...
Update filename_xyz() functions to take a destination size, and provide
inline methods for the old FL_PATH_MAX convention.
git-svn-id: file:///fltk/svn/fltk/branches/branch-1.1@1731 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Diffstat (limited to 'src/filename_expand.cxx')
| -rw-r--r-- | src/filename_expand.cxx | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/src/filename_expand.cxx b/src/filename_expand.cxx index 146c0d742..06d76721f 100644 --- a/src/filename_expand.cxx +++ b/src/filename_expand.cxx @@ -1,5 +1,5 @@ // -// "$Id: filename_expand.cxx,v 1.4.2.4 2001/01/22 15:13:40 easysw Exp $" +// "$Id: filename_expand.cxx,v 1.4.2.4.2.1 2001/11/26 00:15:06 easysw Exp $" // // Filename expansion routines for the Fast Light Tool Kit (FLTK). // @@ -43,12 +43,13 @@ static inline int isdirsep(char c) {return c=='/' || c=='\\';} #define isdirsep(c) ((c)=='/') #endif -int filename_expand(char *to,const char *from) { +int filename_expand(char *to,int tolen, const char *from) { - char temp[FL_PATH_MAX]; - strcpy(temp,from); - const char *start = temp; - const char *end = temp+strlen(temp); + char *temp = new char[tolen]; + strncpy(temp,from, tolen); + temp[tolen - 1] = '\0'; + char *start = temp; + char *end = temp+strlen(temp); int ret = 0; @@ -81,8 +82,10 @@ int filename_expand(char *to,const char *from) { if (value[0] && value[1]==':') start = a; #endif int t = strlen(value); if (isdirsep(value[t-1])) t--; + if ((end+1-e+t) >= tolen) end += tolen - (end+1-e+t); memmove(a+t, e, end+1-e); end = a+t+(end-e); + *end = '\0'; memcpy(a, value, t); ret++; } else { @@ -92,10 +95,16 @@ int filename_expand(char *to,const char *from) { #endif } } - strcpy(to,start); + + strncpy(to, start, tolen - 1); + to[tolen - 1] = '\0'; + + delete[] temp; + return ret; } + // -// End of "$Id: filename_expand.cxx,v 1.4.2.4 2001/01/22 15:13:40 easysw Exp $". +// End of "$Id: filename_expand.cxx,v 1.4.2.4.2.1 2001/11/26 00:15:06 easysw Exp $". // |
