Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
authorRyan C. Gordon <icculus@icculus.org>
Sat, 21 Aug 2010 19:10:42 -0400
changeset 1106 94c3669d0311
parent 1105 a81d0326300f
child 1107 b3d42c9117ec
Fixed PHYSFS_stat()'s return value to match rest of PhysicsFS API.
src/archiver_grp.c
src/archiver_hog.c
src/archiver_iso9660.c
src/archiver_lzma.c
src/archiver_mvl.c
src/archiver_qpak.c
src/archiver_wad.c
src/archiver_zip.c
src/physfs.c
src/physfs.h
src/platform_os2.c
src/platform_pocketpc.c
src/platform_posix.c
src/platform_windows.c
test/test_physfs.c
--- a/src/archiver_grp.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_grp.c	Sat Aug 21 19:10:42 2010 -0400
@@ -450,7 +450,7 @@
     stat->accesstime = -1;
     stat->readonly = 1;
 
-    return 0;
+    return 1;
 } /* GRP_stat */
 
 
--- a/src/archiver_hog.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_hog.c	Sat Aug 21 19:10:42 2010 -0400
@@ -485,7 +485,7 @@
     stat->accesstime = -1;
     stat->readonly = 1;
 
-    return 0;
+    return 1;
 } /* HOG_stat */
 
 
--- a/src/archiver_iso9660.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_iso9660.c	Sat Aug 21 19:10:42 2010 -0400
@@ -920,7 +920,7 @@
         stat->filetype = PHYSFS_FILETYPE_REGULAR;
     } /* else */
 
-    return 0;
+    return 1;
 } /* ISO9660_stat */
 
 
--- a/src/archiver_lzma.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_lzma.c	Sat Aug 21 19:10:42 2010 -0400
@@ -721,7 +721,7 @@
 
     stat->readonly = 1;  /* 7zips are always read only */
 
-    return 0;
+    return 1;
 } /* LZMA_stat */
 
 
--- a/src/archiver_mvl.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_mvl.c	Sat Aug 21 19:10:42 2010 -0400
@@ -445,7 +445,7 @@
     stat->accesstime = 0;
     stat->readonly = 1;
 
-    return 0;
+    return 1;
 } /* MVL_stat */
 
 
--- a/src/archiver_qpak.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_qpak.c	Sat Aug 21 19:10:42 2010 -0400
@@ -608,7 +608,7 @@
     stat->accesstime = 0;
     stat->readonly = 1;
 
-    return 0;
+    return 1;
 } /* QPAK_stat */
 
 
--- a/src/archiver_wad.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_wad.c	Sat Aug 21 19:10:42 2010 -0400
@@ -504,7 +504,7 @@
     stat->createtime = ((WADinfo *) opaque)->last_mod_time;
     stat->readonly = 1; /* WADs are always readonly */
 
-    return 0;
+    return 1;
 } /* WAD_stat */
 
 
--- a/src/archiver_zip.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/archiver_zip.c	Sat Aug 21 19:10:42 2010 -0400
@@ -1433,7 +1433,7 @@
     stat->accesstime = 0;
     stat->readonly = 1; /* .zip files are always read only */
 
-    return 0;
+    return 1;
 } /* ZIP_stat */
 
 
--- a/src/physfs.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/physfs.c	Sat Aug 21 19:10:42 2010 -0400
@@ -1630,7 +1630,7 @@
 PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname)
 {
     PHYSFS_Stat statbuf;
-    BAIL_IF_MACRO(PHYSFS_stat(fname, &statbuf) != 0, NULL, -1);
+    BAIL_IF_MACRO(!PHYSFS_stat(fname, &statbuf), NULL, -1);
     return statbuf.modtime;
 } /* PHYSFS_getLastModTime */
 
@@ -2172,8 +2172,13 @@
     fname = (char *) __PHYSFS_smallAlloc(len);
     BAIL_IF_MACRO(fname == NULL, ERR_OUT_OF_MEMORY, -1);
 
-    /* !!! FIXME: what should this be set to if we fail completely? */
-    memset(stat, '\0', sizeof (PHYSFS_Stat));
+    /* set some sane defaults... */
+    stat->filesize = -1;
+    stat->modtime = -1;
+    stat->createtime = -1;
+    stat->accesstime = -1;
+    stat->filetype = PHYSFS_FILETYPE_OTHER;
+    stat->readonly = 1;  /* !!! FIXME */
 
     if (sanitizePlatformIndependentPath(_fname, fname))
     {
@@ -2181,7 +2186,7 @@
         {
             stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
             stat->readonly = !writeDir; /* Writeable if we have a writeDir */
-            retval = 0;
+            retval = 1;
         } /* if */
         else
         {
@@ -2193,9 +2198,14 @@
                 char *arcfname = fname;
                 exists = partOfMountPoint(i, arcfname);
                 if (exists)
-                    retval = 1; /* !!! FIXME: What's the right value? */
+                {
+                    stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
+                    stat->readonly = 1;  /* !!! FIXME */
+                    retval = 1;
+                } /* if */
                 else if (verifyPath(i, &arcfname, 0))
                 {
+                    /* !!! FIXME: this test is wrong and should be elsewhere. */
                     stat->readonly = !(writeDir &&
                                  (strcmp(writeDir->dirName, i->dirName) == 0));
                     retval = i->funcs->stat(i->opaque, arcfname, &exists, stat);
--- a/src/physfs.h	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/physfs.h	Sat Aug 21 19:10:42 2010 -0400
@@ -2562,7 +2562,8 @@
  *
  *    \param fname filename to check, in platform-indepedent notation.
  *    \param stat pointer to structure to fill in with data about (fname).
- *   \return 0 on success, non-zero on error.  // !!! FIXME: arg, that's backwards from everything else in PhysicsFS!
+ *   \return non-zero on success, zero on failure. On failure, (stat)'s
+ *           contents are undefined.
  *
  * \sa PHYSFS_Stat
  */
--- a/src/platform_os2.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/platform_os2.c	Sat Aug 21 19:10:42 2010 -0400
@@ -657,7 +657,7 @@
             *exists = 0;
             return 0;
         } /* if */
-        BAIL_MACRO(get_os2_error_string(rc), -1);
+        BAIL_MACRO(get_os2_error_string(rc), 0);
     } /* if */
 
     *exists = 1;
@@ -687,7 +687,7 @@
 
     stat->readonly = ((fs.attrFile & FILE_READONLY) == FILE_READONLY);
 
-    return 0;
+    return 1;
 } /* __PHYSFS_platformStat */
 
 
--- a/src/platform_pocketpc.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/platform_pocketpc.c	Sat Aug 21 19:10:42 2010 -0400
@@ -609,7 +609,7 @@
             *exists = 0;
             return 0;
         } /* if */
-        BAIL_MACRO(win32strerror, -1);
+        BAIL_MACRO(win32strerror, 0);
     } /* if */
 
     FindClose(searchhandle);  /* close handle, not needed anymore */
@@ -631,7 +631,7 @@
     stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
     stat->readonly = ((winstat.dwFileAttributes & (FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_INROM)) != 0);
 
-    return 0;
+    return 1;
 } /* __PHYSFS_platformStat */
 
 
--- a/src/platform_posix.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/platform_posix.c	Sat Aug 21 19:10:42 2010 -0400
@@ -429,10 +429,8 @@
             *exists = 0;
             return 0;
         } /* if */
-        else
-        {
-            BAIL_MACRO(strerror(errno), -1);
-        } /* else */
+
+        BAIL_MACRO(strerror(errno), 0);
     } /* if */
 
     if (S_ISREG(statbuf.st_mode))
@@ -459,7 +457,7 @@
 
     /* !!! FIXME: maybe we should just report full permissions? */
     st->readonly = access(filename, W_OK);
-    return 0;
+    return 1;
 } /* __PHYSFS_platformStat */
 
 #endif  /* PHYSFS_PLATFORM_POSIX */
--- a/src/platform_windows.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/src/platform_windows.c	Sat Aug 21 19:10:42 2010 -0400
@@ -1381,7 +1381,7 @@
             *exists = 0;
             return 0;
         } /* if */
-        BAIL_MACRO(strerror(errno), -1);
+        BAIL_MACRO(strerror(errno), 0);
     } /* if */
 
     FindClose(searchhandle); /* close handle, not needed anymore */
@@ -1403,7 +1403,7 @@
     stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
     stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
 
-    return 0;
+    return 1;
 } /* __PHYSFS_platformStatOldWay */
 
 
@@ -1442,7 +1442,7 @@
         } /* if */
         else
         {
-            BAIL_MACRO(strerror(errno), -1);
+            BAIL_MACRO(strerror(errno), 0);
         } /* else */
     } /* if */
 
@@ -1476,7 +1476,7 @@
 
     stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
 
-    return 0;
+    return 1;
 } /* __PHYSFS_platformStatNewWay */
 
 
--- a/test/test_physfs.c	Sat Aug 21 17:34:00 2010 -0400
+++ b/test/test_physfs.c	Sat Aug 21 19:10:42 2010 -0400
@@ -931,7 +931,7 @@
 static int cmd_getlastmodtime(char *args)
 {
     PHYSFS_Stat statbuf;
-    if (PHYSFS_stat(args, &statbuf) != 0)  // !!! FIXME: backwards, api will change later.
+    if (!PHYSFS_stat(args, &statbuf))
         printf("Failed to determine. Reason: [%s].\n", PHYSFS_getLastError());
     else
     {
@@ -954,7 +954,7 @@
         args[strlen(args) - 1] = '\0';
     } /* if */
 
-    if(PHYSFS_stat(args, &stat))
+    if(!PHYSFS_stat(args, &stat))
     {
         printf("failed to stat. Reason [%s].\n", PHYSFS_getLastError());
         return 1;