Skip to content
Permalink
Browse files
Abstracted file deletion, so we don't rely on C library for it anymore.
  • Loading branch information
icculus committed Mar 25, 2002
1 parent 255322c commit f6b15061c86a1ff8faf94fb5f4d3b4dccd8c6646
Showing with 33 additions and 11 deletions.
  1. +1 −7 archivers/dir.c
  2. +7 −0 physfs.h
  3. +14 −0 physfs_internal.h
  4. +11 −4 platform/unix.c
@@ -299,13 +299,7 @@ static int DIR_remove(DirHandle *h, const char *name)
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 */
@@ -596,6 +596,9 @@ __EXPORT__ int PHYSFS_mkdir(const char *dirName);
*
* 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 @@ __EXPORT__ int PHYSFS_mkdir(const char *dirName);
* 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().
@@ -619,6 +619,20 @@ char *__PHYSFS_platformRealPath(const char *path);
*/
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
@@ -639,19 +639,26 @@ int __PHYSFS_platformEOF(void *opaque)

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 ... */

0 comments on commit f6b1506

Please sign in to comment.