[AD] file.c # patch

[ Thread Index | Date Index | More lists.liballeg.org/allegro-developers Archives ]


This patch should hopefully take care of the #-in-filenames problem. It also removes some undocumented functionality, most noteably that datafile objectnames were treated as seperate filenames, and that # is treated as both a path seperator and an extension seperator. Since there was no mention of these things in the docs, I can only imagine they'd cause unexpected behavior, and thusly problems for people using them. Also, removing that functionality was the only way I could fix it so files and directories with # could be handled properly.

- Kitty Cat
Index: src/file.c
===================================================================
RCS file: /cvsroot/alleg/allegro/src/file.c,v
retrieving revision 1.49
diff -u -r1.49 file.c
--- src/file.c	2 Jul 2004 16:25:40 -0000	1.49
+++ src/file.c	26 Jul 2004 22:08:46 -0000
@@ -505,7 +505,7 @@
 
    while (pos>0) {
       c = ugetat(path, pos-1);
-      if ((c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR) || (c == '#'))
+      if ((c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR))
 	 break;
       pos--;
    }
@@ -537,7 +537,7 @@
 
    while (pos>0) {
       c = ugetat(filename, pos-1);
-      if ((c == '.') || (c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR) || (c == '#'))
+      if ((c == '.') || (c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR))
 	 break;
       pos--;
    }
@@ -574,7 +574,7 @@
    if ((pos > 0) && (uoffset(tmp, pos) < ((int)sizeof(tmp) - ucwidth(OTHER_PATH_SEPARATOR) - ucwidth(0)))) {
       c = ugetat(tmp, pos-1);
 
-      if ((c != '/') && (c != OTHER_PATH_SEPARATOR) && (c != DEVICE_SEPARATOR) && (c != '#')) {
+      if ((c != '/') && (c != OTHER_PATH_SEPARATOR) && (c != DEVICE_SEPARATOR)) {
 	 pos = uoffset(tmp, pos);
 	 pos += usetc(tmp+pos, OTHER_PATH_SEPARATOR);
 	 usetc(tmp+pos, 0);
@@ -606,7 +606,7 @@
    for (;;) {
       c = ugetxc(&ptr);
       if (!c) break;
-      if ((c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR) || (c == '#'))
+      if ((c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR))
          ret = (char*)ptr;
    }
    return (char*)ret;
@@ -627,7 +627,7 @@
 
    while (pos>0) {
       c = ugetat(filename, pos-1);
-      if ((c == '.') || (c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR) || (c == '#'))
+      if ((c == '.') || (c == '/') || (c == OTHER_PATH_SEPARATOR) || (c == DEVICE_SEPARATOR))
 	 break;
       pos--;
    }
@@ -825,7 +825,7 @@
       else {
 	 /* read object from a regular datafile */
 	 ustrzcpy(fname,  sizeof(fname), filename);
-	 p = ustrchr(fname, '#');
+	 p = ustrrchr(fname, '#');
 	 usetat(p, 0, 0);
 	 ustrzcpy(objname, sizeof(objname), p+uwidth(p));
       }
@@ -868,8 +868,6 @@
 	    *aret = FA_DAT_FLAGS;
 	 return ((attrib & FA_DAT_FLAGS) == FA_DAT_FLAGS) ? TRUE : FALSE;
       }
-      else
-	 return FALSE;
    }
 
    if (!_al_file_isok(filename))
@@ -919,8 +917,6 @@
 	 pack_fclose(f);
 	 return ret;
       }
-      else
-	 return 0;
    }
 
    if (!_al_file_isok(filename))
@@ -939,10 +935,6 @@
 time_t file_time(AL_CONST char *filename)
 {
    ASSERT(filename);
-   if (ustrchr(filename, '#')) {
-      *allegro_errno = EPERM;
-      return 0;
-   }
 
    if (!_al_file_isok(filename))
       return 0;
@@ -960,11 +952,6 @@
    char tmp[1024];
    ASSERT(filename);
 
-   if (ustrchr(filename, '#')) {
-      *allegro_errno = EROFS;
-      return -1;
-   }
-
    if (!_al_file_isok(filename))
       return -1;
 
@@ -997,11 +984,6 @@
    int c = 0;
    ASSERT(name);
 
-   if (ustrchr(name, '#')) {
-      *allegro_errno = ENOTDIR;
-      return 0;
-   }
-
    if (!_al_file_isok(name))
       return 0;
 
@@ -1056,11 +1038,6 @@
    int ret, c = 0;
    ASSERT(name);
 
-   if (ustrchr(name, '#')) {
-      *allegro_errno = ENOTDIR;
-      return 0;
-   }
-
    if (!_al_file_isok(name))
       return 0;
 
@@ -1693,8 +1670,11 @@
 
    _packfile_type = 0;
 
-   if (ustrchr(filename, '#'))
-      return pack_fopen_special_file(filename, mode);
+   if (ustrchr(filename, '#')) {
+      PACKFILE *special = pack_fopen_special_file(filename, mode);
+      if (special)
+	 return special;
+   }
 
    if (!_al_file_isok(filename))
       return NULL;


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/