FLTK logo

[Library] r5762 - in branches/fctrunk: fltk src

FLTK matrix user chat room
(using Element browser app)   FLTK gitter user chat room   GitHub FLTK Project   FLTK News RSS Feed  
  FLTK Apps      FLTK Library      Forums      Links     Login 
 All Forums  |  Back to fltk.commit  ]
 
Previous Message ]Next Message ]

[Library] r5762 - in branches/fctrunk: fltk src fltk-dev Apr 05, 2007  
 
Author: fabien
Date: 2007-04-05 11:58:57 -0400 (Thu, 05 Apr 2007)
New Revision: 5762
Log:
+ fixing some more regressions ...
PLEASE DON'T make the assumption that an absolute path starts by '/' !!!

+ added a correct guess of absolute filenames
  in filename.h
  this new api is named fltk:: filename_isabsolute() 


Modified:
   branches/fctrunk/fltk/filename.h
   branches/fctrunk/src/SharedImage.cxx
   branches/fctrunk/src/filename_isdir.cxx
   branches/fctrunk/src/gifImage.cxx

Modified: branches/fctrunk/fltk/filename.h
===================================================================
--- branches/fctrunk/fltk/filename.h	2007-04-05 14:30:37 UTC (rev 5761)
+++ branches/fctrunk/fltk/filename.h	2007-04-05 15:58:57 UTC (rev 5762)
@@ -96,6 +96,7 @@
 FL_API bool filename_match(const char *, const char *pattern); // glob match
 FL_API bool filename_exist(const char*);
 FL_API bool filename_isdir(const char*);
+FL_API bool filename_isabsolute(const char *fname);
 FL_API double filename_size(const char *); // return size of file
 FL_API long int filename_mtime(const char *); // return modification time
 FL_API void filename_setext(char * fname, size_t maxsize, const char* ext); // add or replace a new extension to a file 
@@ -107,7 +108,6 @@
 FL_API int numericsort(const dirent*const*, const dirent*const*);
 FL_API int filename_list(const char *d, dirent ***list, File_Sort_F *sort);
 FL_API int filename_list(const char *d, dirent ***list); // uses numericsort
-
 }
 
 #endif

Modified: branches/fctrunk/src/SharedImage.cxx
===================================================================
--- branches/fctrunk/src/SharedImage.cxx	2007-04-05 14:30:37 UTC (rev 5761)
+++ branches/fctrunk/src/SharedImage.cxx	2007-04-05 15:58:57 UTC (rev 5762)
@@ -30,6 +30,7 @@
 #include <ctype.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <fltk/filename.h>
 
 using namespace fltk;
 
@@ -124,16 +125,20 @@
   would return for a SharedImage with this name. */
 const char* SharedImage::get_filename(const char* name)
 {
-  if (name[0] == '/' || !shared_image_root || !*shared_image_root)
-    return name;
+	if (fltk::filename_isabsolute(name) || !shared_image_root || !*shared_image_root)
+		return name; // please dont use '/' to test if a file path  is absolute !!! 
   int m = strlen(shared_image_root);
   int n = strlen(name) + m + 2;
-  static char *s;
+  static char *t=0;
+  char *  s=t;
   delete[] s;
   s = new char[n+1];
-  strcpy(s, shared_image_root);
-  if (s[m-1] != '/') s[m++] = '/';
-  strcpy(s+m, name);
+  strlcpy(s, shared_image_root,m+1);
+  if (s[m-1] != '/') { 
+	  s[m++] = '/';
+	  s[m] = '\0'; // don't forget to terminate the str under windows
+  }
+  strlcat(s, name,n+1); // don't concatenate with an absolute filename !
   return s;
 }
 

Modified: branches/fctrunk/src/filename_isdir.cxx
===================================================================
--- branches/fctrunk/src/filename_isdir.cxx	2007-04-05 14:30:37 UTC (rev 5761)
+++ branches/fctrunk/src/filename_isdir.cxx	2007-04-05 15:58:57 UTC (rev 5762)
@@ -92,7 +92,16 @@
   if (last_stat.st_atime) return (long) last_stat.st_atime;
   return (long) last_stat.st_ctime;
 }
+/**
+	filename_isabsolute return true if the path starts with / or x: or \\
+*/
+FL_API bool fltk::filename_isabsolute(const char *fname) {
+	if (!fname || *fname=='\0') return false;
+	if (fname[0]=='/' || fname[1]==':' || (fname[0]=='\\' && fname[1]=='\\') )
+		return true; // if / on Unixes, or x: or unc on win32
+	return false;
 
+}
 //
 // End of "$Id$".
 //

Modified: branches/fctrunk/src/gifImage.cxx
===================================================================
--- branches/fctrunk/src/gifImage.cxx	2007-04-05 14:30:37 UTC (rev 5761)
+++ branches/fctrunk/src/gifImage.cxx	2007-04-05 15:58:57 UTC (rev 5762)
@@ -74,7 +74,7 @@
     char b[6];
     if (!GifFile || fread(b,1,6,GifFile) < 6 ||
 	b[0]!='G' || b[1]!='I' || b[2] != 'F') {
-      fclose(GifFile);
+      if (GifFile) fclose(GifFile); // don't gen. a last chance exception under vc6
       return false;
     }
   }

Direct Link to Message ]
 
     
Previous Message ]Next Message ]
 
 

Comments are owned by the poster. All other content is copyright 1998-2024 by Bill Spitzak and others. This project is hosted by The FLTK Team. Please report site problems to 'erco@seriss.com'.