Skip to content

Commit

Permalink
Abstracted file deletion, so we don't rely on C library for it anymore.
Browse files Browse the repository at this point in the history
  • Loading branch information
icculus committed Mar 25, 2002
1 parent 255322c commit f6b1506
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 11 deletions.
8 changes: 1 addition & 7 deletions archivers/dir.c
Expand Up @@ -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 */
Expand Down
7 changes: 7 additions & 0 deletions physfs.h
Expand Up @@ -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
Expand All @@ -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().
Expand Down
14 changes: 14 additions & 0 deletions physfs_internal.h
Expand Up @@ -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
Expand Down
15 changes: 11 additions & 4 deletions platform/unix.c
Expand Up @@ -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.