Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Added PHYSFS_getLastModTime() API. (Thanks, John Hall!)
  • Loading branch information
icculus committed May 25, 2002
1 parent 4766a7d commit 5386a5c
Show file tree
Hide file tree
Showing 10 changed files with 117 additions and 0 deletions.
14 changes: 14 additions & 0 deletions archivers/dir.c
Expand Up @@ -38,6 +38,7 @@ static int DIR_exists(DirHandle *h, const char *name);
static int DIR_isDirectory(DirHandle *h, const char *name);
static int DIR_isSymLink(DirHandle *h, const char *name);
static FileHandle *DIR_openRead(DirHandle *h, const char *filename);
static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h, const char *name);
static FileHandle *DIR_openWrite(DirHandle *h, const char *filename);
static FileHandle *DIR_openAppend(DirHandle *h, const char *filename);
static int DIR_remove(DirHandle *h, const char *name);
Expand Down Expand Up @@ -77,6 +78,7 @@ const DirFunctions __PHYSFS_DirFunctions_DIR =
DIR_exists, /* exists() method */
DIR_isDirectory, /* isDirectory() method */
DIR_isSymLink, /* isSymLink() method */
DIR_getLastModTime, /* getLastModTime() method */
DIR_openRead, /* openRead() method */
DIR_openWrite, /* openWrite() method */
DIR_openAppend, /* openAppend() method */
Expand Down Expand Up @@ -241,6 +243,18 @@ static int DIR_isSymLink(DirHandle *h, const char *name)
} /* DIR_isSymLink */


static PHYSFS_sint64 DIR_getLastModTime(DirHandle *h, const char *name)
{
char *d = __PHYSFS_platformCvtToDependent((char *)(h->opaque), name, NULL);
PHYSFS_sint64 retval;

BAIL_IF_MACRO(d == NULL, NULL, 0);
retval = __PHYSFS_platformGetMtime(d);
free(d);
return(retval);
} /* DIR_getLastModTime */


static FileHandle *doOpen(DirHandle *h, const char *name,
void *(*openFunc)(const char *filename),
const FileFunctions *fileFuncs)
Expand Down
1 change: 1 addition & 0 deletions archivers/grp.c
Expand Up @@ -98,6 +98,7 @@ const DirFunctions __PHYSFS_DirFunctions_GRP =
GRP_exists, /* exists() method */
GRP_isDirectory, /* isDirectory() method */
GRP_isSymLink, /* isSymLink() method */
NULL, /* getLastModTime() method */
GRP_openRead, /* openRead() method */
NULL, /* openWrite() method */
NULL, /* openAppend() method */
Expand Down
1 change: 1 addition & 0 deletions archivers/zip.c
Expand Up @@ -99,6 +99,7 @@ const DirFunctions __PHYSFS_DirFunctions_ZIP =
ZIP_exists, /* exists() method */
ZIP_isDirectory, /* isDirectory() method */
ZIP_isSymLink, /* isSymLink() method */
NULL, /* getLastModTime() method */ /* !!! FIXME: This can be determined in a zipfile. */
ZIP_openRead, /* openRead() method */
NULL, /* openWrite() method */
NULL, /* openAppend() method */
Expand Down
32 changes: 32 additions & 0 deletions physfs.c
Expand Up @@ -1146,6 +1146,37 @@ int PHYSFS_exists(const char *fname)
} /* PHYSFS_exists */


PHYSFS_sint64 PHYSFS_getLastModTime(const char *fname)
{
PhysDirInfo *i;

BAIL_IF_MACRO(fname == NULL, ERR_INVALID_ARGUMENT, 0);
while (*fname == '/')
fname++;

if (*fname == '\0') /* eh...punt if it's the root dir. */
return(1);

__PHYSFS_platformGrabMutex(stateLock);
for (i = searchPath; i != NULL; i = i->next)
{
DirHandle *h = i->dirHandle;
if (__PHYSFS_verifySecurity(h, fname))
{
if (h->funcs->exists(h, fname))
{
PHYSFS_sint64 retval = h->funcs->getLastModTime(h, fname);
__PHYSFS_platformReleaseMutex(stateLock);
return(retval);
} /* if */
} /* if */
} /* for */
__PHYSFS_platformReleaseMutex(stateLock);

return(0);
} /* PHYSFS_getLastModTime */


int PHYSFS_isDirectory(const char *fname)
{
PhysDirInfo *i;
Expand Down Expand Up @@ -1405,6 +1436,7 @@ PHYSFS_sint64 PHYSFS_fileLength(PHYSFS_file *handle)
assert(h != NULL);
assert(h->funcs != NULL);
BAIL_IF_MACRO(h->funcs->fileLength == NULL, ERR_NOT_SUPPORTED, 0);

return(h->funcs->fileLength(h));
} /* PHYSFS_filelength */

Expand Down
13 changes: 13 additions & 0 deletions physfs.h
Expand Up @@ -783,6 +783,19 @@ __EXPORT__ PHYSFS_file *PHYSFS_openRead(const char *filename);
__EXPORT__ int PHYSFS_close(PHYSFS_file *handle);


/**
* Get the last modification time of a file. This is returned as a
* number of seconds since the epoch (Jan 1, 1970). The exact derivation
* and accuracy of this time depends on the particular archiver. If there
* is no reasonable way to obtain this information for a particular archiver,
* or there was some sort of error, this function returns (-1).
*
* @param filename filename to check.
* @return last modified time of the file. -1 if it can't be determined.
*/
__EXPORT__ PHYSFS_sint64 PHYSFS_getLastModTime(const char *filename);


/**
* Read data from a PhysicsFS filehandle. The file must be opened for reading.
*
Expand Down
29 changes: 29 additions & 0 deletions physfs_internal.h
Expand Up @@ -175,6 +175,14 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
*/
int (*isSymLink)(DirHandle *r, const char *name);

/*
* Retrieve the last modification time (mtime) of a file.
* Returns -1 on failure, or the file's mtime in seconds since
* the epoch (Jan 1, 1970) on success.
* This filename is in platform-independent notation.
*/
PHYSFS_sint64 (*getLastModTime)(DirHandle *r, const char *filename);

/*
* Open file for reading, and return a FileHandle.
* This filename is in platform-independent notation.
Expand Down Expand Up @@ -267,6 +275,7 @@ typedef struct __PHYSFS_DIRFUNCTIONS__
#define ERR_NOT_A_DIR "Not a directory"
#define ERR_FILE_NOT_FOUND "File not found"


/*
* Call this to set the message returned by PHYSFS_getLastError().
* Please only use the ERR_* constants above, or add new constants to the
Expand Down Expand Up @@ -343,6 +352,7 @@ extern const char *__PHYSFS_platformDirSeparator;
*/
int __PHYSFS_platformInit(void);


/*
* Deinitialize the platform. This is called when PHYSFS_deinit() is called
* from the application. You can use this to clean up anything you've
Expand All @@ -353,6 +363,7 @@ int __PHYSFS_platformInit(void);
*/
int __PHYSFS_platformDeinit(void);


/*
* Open a file for reading. (filename) is in platform-dependent notation. The
* file pointer should be positioned on the first byte of the file.
Expand All @@ -368,6 +379,7 @@ int __PHYSFS_platformDeinit(void);
*/
void *__PHYSFS_platformOpenRead(const char *filename);


/*
* Open a file for writing. (filename) is in platform-dependent notation. If
* the file exists, it should be truncated to zero bytes, and if it doesn't
Expand All @@ -384,6 +396,7 @@ void *__PHYSFS_platformOpenRead(const char *filename);
*/
void *__PHYSFS_platformOpenWrite(const char *filename);


/*
* Open a file for appending. (filename) is in platform-dependent notation. If
* the file exists, the file pointer should be place just past the end of the
Expand All @@ -401,6 +414,7 @@ void *__PHYSFS_platformOpenWrite(const char *filename);
*/
void *__PHYSFS_platformOpenAppend(const char *filename);


/*
* Read more data from a platform-specific file handle. (opaque) should be
* cast to whatever data type your platform uses. Read a maximum of (count)
Expand Down Expand Up @@ -441,6 +455,7 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer,
*/
int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);


/*
* Get the file pointer's position, in an 8-bit byte offset from the start of
* the file. (opaque) should be cast to whatever data type your platform
Expand All @@ -453,6 +468,7 @@ int __PHYSFS_platformSeek(void *opaque, PHYSFS_uint64 pos);
*/
PHYSFS_sint64 __PHYSFS_platformTell(void *opaque);


/*
* Determine the current size of a file, in 8-bit bytes, from an open file.
*
Expand Down Expand Up @@ -543,18 +559,29 @@ int __PHYSFS_platformStricmp(const char *str1, const char *str2);
*/
int __PHYSFS_platformExists(const char *fname);

/*
* Return the last modified time (in seconds since the epoch) of a file.
* Returns -1 on failure. (fname) is in platform-dependent notation.
* Symlinks should be followed; if what the symlink points to is missing,
* then the retval is -1.
*/
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname);


/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
*/
int __PHYSFS_platformIsSymLink(const char *fname);


/*
* Return non-zero if filename (in platform-dependent notation) is a symlink.
* Symlinks should be followed; if what the symlink points to is missing,
* or isn't a directory, then the retval is false.
*/
int __PHYSFS_platformIsDirectory(const char *fname);


/*
* Convert (dirName) to platform-dependent notation, then prepend (prepend)
* and append (append) to the converted string.
Expand All @@ -577,6 +604,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
const char *dirName,
const char *append);


/*
* Make the current thread give up a timeslice. This is called in a loop
* while waiting for various external forces to get back to us.
Expand Down Expand Up @@ -626,6 +654,7 @@ 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
Expand Down
6 changes: 6 additions & 0 deletions platform/macclassic.c
Expand Up @@ -805,5 +805,11 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
/* no mutexes on MacOS Classic. */
} /* __PHYSFS_platformReleaseMutex */


PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1); /* !!! FIXME! */
} /* __PHYSFS_platformGetLastModTime */

/* end of macclassic.c ... */

8 changes: 8 additions & 0 deletions platform/posix.c
Expand Up @@ -470,5 +470,13 @@ int __PHYSFS_platformDelete(const char *path)
return(1);
} /* __PHYSFS_platformDelete */


PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
struct stat statbuf;
BAIL_IF_MACRO(stat(fname, &statbuf) < 0, strerror(errno), -1);
return statbuf.st_mtime;
} /* __PHYSFS_platformGetLastModTime */

/* end of posix.c ... */

6 changes: 6 additions & 0 deletions platform/skeleton.c
Expand Up @@ -221,5 +221,11 @@ void __PHYSFS_platformReleaseMutex(void *mutex)
/* not implemented, but can't call __PHYSFS_setError! */
} /* __PHYSFS_platformReleaseMutex */


PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
} /* __PHYSFS_platformGetLastModTime */

/* end of skeleton.c ... */

7 changes: 7 additions & 0 deletions platform/win32.c
Expand Up @@ -886,5 +886,12 @@ static int doNTInit(void)
return 1;
}
#endif


PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
{
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1); /* !!! FIXME! */
} /* __PHYSFS_platformGetLastModTime */

/* end of win32.c ... */

0 comments on commit 5386a5c

Please sign in to comment.