Abstracted file deletion, so we don't rely on C library for it anymore.
--- a/archivers/dir.c Mon Mar 25 05:01:29 2002 +0000
+++ b/archivers/dir.c Mon Mar 25 05:02:12 2002 +0000
@@ -299,13 +299,7 @@
int retval;
BAIL_IF_MACRO(f == NULL, NULL, 0);
-
- /* !!! FIXME: Abstract in platform drivers. */
- errno = 0;
- retval = (remove(f) == 0);
- if (!retval)
- __PHYSFS_setError(strerror(errno));
-
+ retval = __PHYSFS_platformDelete(f);
free(f);
return(retval);
} /* DIR_remove */
--- a/physfs.h Mon Mar 25 05:01:29 2002 +0000
+++ b/physfs.h Mon Mar 25 05:02:12 2002 +0000
@@ -596,6 +596,9 @@
*
* A directory must be empty before this call can delete it.
*
+ * Deleting a symlink will remove the link, not what it points to, regardless
+ * of whether you "permitSymLinks" or not.
+ *
* So if you've got the write dir set to "C:\mygame\writedir" and call
* PHYSFS_delete("downloads/maps/level1.map") then the file
* "C:\mygame\writedir\downloads\maps\level1.map" is removed from the
@@ -606,6 +609,10 @@
* actual file won't be removed until all processes that have an open
* filehandle to it (including your program) close their handles.
*
+ * Chances are, the bits that make up the file still exist, they are just
+ * made available to be written over at a later point. Don't consider this
+ * a security method or anything. :)
+ *
* @param filename Filename to delete.
* @return nonzero on success, zero on error. Specifics of the error can be
* gleaned from PHYSFS_getLastError().
--- a/physfs_internal.h Mon Mar 25 05:01:29 2002 +0000
+++ b/physfs_internal.h Mon Mar 25 05:02:12 2002 +0000
@@ -619,6 +619,20 @@
*/
int __PHYSFS_platformMkDir(const char *path);
+/*
+ * Remove a file or directory entry in the actual filesystem. (path) is
+ * specified in platform-dependent notation. Note that this deletes files
+ * _and_ directories, so you might need to do some determination.
+ * Non-empty directories should report an error and not delete themselves
+ * or their contents.
+ *
+ * Deleting a symlink should remove the link, not what it points to.
+ *
+ * On error, return zero and set the error message. Return non-zero on success.
+ */
+int __PHYSFS_platformDelete(const char *path);
+
+
#ifdef __cplusplus
}
#endif
--- a/platform/unix.c Mon Mar 25 05:01:29 2002 +0000
+++ b/platform/unix.c Mon Mar 25 05:02:12 2002 +0000
@@ -639,19 +639,26 @@
int __PHYSFS_platformFlush(void *opaque)
{
- int rc = fflush((FILE *) opaque);
- BAIL_IF_MACRO(rc == EOF, strerror(errno), 0);
+ errno = 0;
+ BAIL_IF_MACRO(fflush((FILE *) opaque) == EOF, strerror(errno), 0);
return(1);
} /* __PHYSFS_platformFlush */
int __PHYSFS_platformClose(void *opaque)
{
- int rc = fclose((FILE *) opaque);
- BAIL_IF_MACRO(rc == EOF, strerror(errno), 0);
+ errno = 0;
+ BAIL_IF_MACRO(fclose((FILE *) opaque) == EOF, strerror(errno), 0);
return(1);
} /* __PHYSFS_platformClose */
+int __PHYSFS_platformDelete(const char *path)
+{
+ errno = 0;
+ BAIL_IF_MACRO(remove(path) == -1, strerror(errno), 0);
+ return(1);
+} /* __PHYSFS_platformDelete */
+
/* end of unix.c ... */