Abstracted file deletion, so we don't rely on C library for it anymore.

This commit is contained in:
Ryan C. Gordon 2002-03-25 05:02:12 +00:00
parent 255322c2fa
commit f6b15061c8
4 changed files with 33 additions and 11 deletions

View File

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

View File

@ -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().

View File

@ -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

View File

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