diff --git a/Quake/common.c b/Quake/common.c index a3461d57..702eb2c9 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -1604,7 +1604,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file, searchpath_t *search; char netpath[MAX_OSPATH]; pack_t *pak; - int i, findtime; + int i; if (file && handle) Sys_Error ("COM_FindFile: both handle and file set"); @@ -1656,8 +1656,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file, } q_snprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename); - findtime = Sys_FileTime (netpath); - if (findtime == -1) + if (! (Sys_FileType(netpath) & FS_ENT_FILE)) continue; if (path_id) diff --git a/Quake/common.h b/Quake/common.h index bb414045..9e9ca809 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -345,6 +345,11 @@ const char *COM_ParseFloatNewline(const char *buffer, float *value); // newline. Returns advanced buffer position. const char *COM_ParseStringNewline(const char *buffer); + +#define FS_ENT_NONE (0) +#define FS_ENT_FILE (1 << 0) +#define FS_ENT_DIRECTORY (1 << 1) + /* The following FS_*() stdio replacements are necessary if one is * to perform non-sequential reads on files reopened on pak files * because we need the bookkeeping about file start/end positions. diff --git a/Quake/gl_screen.c b/Quake/gl_screen.c index 962c0ebb..614d1074 100644 --- a/Quake/gl_screen.c +++ b/Quake/gl_screen.c @@ -794,7 +794,7 @@ void SCR_ScreenShot_f (void) { q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext); // "fitz%04i.tga" q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, imagename); - if (Sys_FileTime(checkname) == -1) + if (Sys_FileType(checkname) == FS_ENT_NONE) break; // file doesn't exist } if (i == 10000) diff --git a/Quake/sys.h b/Quake/sys.h index dd023638..05d1055c 100644 --- a/Quake/sys.h +++ b/Quake/sys.h @@ -39,9 +39,12 @@ void Sys_FileClose (int handle); void Sys_FileSeek (int handle, int position); int Sys_FileRead (int handle, void *dest, int count); int Sys_FileWrite (int handle,const void *data, int count); -int Sys_FileTime (const char *path); void Sys_mkdir (const char *path); +int Sys_FileType (const char *path); +/* returns an FS entity type, i.e. FS_ENT_FILE or FS_ENT_DIRECTORY. + * returns FS_ENT_NONE (0) if no such file or directory is present. */ + // // system IO // diff --git a/Quake/sys_sdl_unix.c b/Quake/sys_sdl_unix.c index d2036778..8820dc58 100644 --- a/Quake/sys_sdl_unix.c +++ b/Quake/sys_sdl_unix.c @@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include -#include #ifdef DO_USERDIRS #include #endif @@ -140,19 +139,22 @@ int Sys_FileWrite (int handle, const void *data, int count) return fwrite (data, 1, count, sys_handles[handle]); } -int Sys_FileTime (const char *path) +int Sys_FileType (const char *path) { - FILE *f; + /* + if (access(path, R_OK) == -1) + return 0; + */ + struct stat st; - f = fopen(path, "rb"); + if (stat(path, &st) != 0) + return FS_ENT_NONE; + if (S_ISDIR(st.st_mode)) + return FS_ENT_DIRECTORY; + if (S_ISREG(st.st_mode)) + return FS_ENT_FILE; - if (f) - { - fclose(f); - return 1; - } - - return -1; + return FS_ENT_NONE; } diff --git a/Quake/sys_sdl_win.c b/Quake/sys_sdl_win.c index 039c0e38..2f6f7367 100644 --- a/Quake/sys_sdl_win.c +++ b/Quake/sys_sdl_win.c @@ -139,19 +139,19 @@ int Sys_FileWrite (int handle, const void *data, int count) return fwrite (data, 1, count, sys_handles[handle]); } -int Sys_FileTime (const char *path) +#ifndef INVALID_FILE_ATTRIBUTES +#define INVALID_FILE_ATTRIBUTES ((DWORD)-1) +#endif +int Sys_FileType (const char *path) { - FILE *f; + DWORD result = GetFileAttributes(path); - f = fopen(path, "rb"); + if (result == INVALID_FILE_ATTRIBUTES) + return FS_ENT_NONE; + if (result & FILE_ATTRIBUTE_DIRECTORY) + return FS_ENT_DIRECTORY; - if (f) - { - fclose(f); - return 1; - } - - return -1; + return FS_ENT_FILE; } static char cwd[1024];