replaced Sys_FileTime() with Sys_FileType() from uhexen2 project.

This commit is contained in:
Ozkan Sezer 2022-10-25 10:35:20 +03:00
parent 5e589597c2
commit c3ef90eb36
6 changed files with 35 additions and 26 deletions

View file

@ -1604,7 +1604,7 @@ static int COM_FindFile (const char *filename, int *handle, FILE **file,
searchpath_t *search; searchpath_t *search;
char netpath[MAX_OSPATH]; char netpath[MAX_OSPATH];
pack_t *pak; pack_t *pak;
int i, findtime; int i;
if (file && handle) if (file && handle)
Sys_Error ("COM_FindFile: both handle and file set"); 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); q_snprintf (netpath, sizeof(netpath), "%s/%s",search->filename, filename);
findtime = Sys_FileTime (netpath); if (! (Sys_FileType(netpath) & FS_ENT_FILE))
if (findtime == -1)
continue; continue;
if (path_id) if (path_id)

View file

@ -345,6 +345,11 @@ const char *COM_ParseFloatNewline(const char *buffer, float *value);
// newline. Returns advanced buffer position. // newline. Returns advanced buffer position.
const char *COM_ParseStringNewline(const char *buffer); 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 /* The following FS_*() stdio replacements are necessary if one is
* to perform non-sequential reads on files reopened on pak files * to perform non-sequential reads on files reopened on pak files
* because we need the bookkeeping about file start/end positions. * because we need the bookkeeping about file start/end positions.

View file

@ -794,7 +794,7 @@ void SCR_ScreenShot_f (void)
{ {
q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext); // "fitz%04i.tga" q_snprintf (imagename, sizeof(imagename), "spasm%04i.%s", i, ext); // "fitz%04i.tga"
q_snprintf (checkname, sizeof(checkname), "%s/%s", com_gamedir, imagename); 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 break; // file doesn't exist
} }
if (i == 10000) if (i == 10000)

View file

@ -39,9 +39,12 @@ void Sys_FileClose (int handle);
void Sys_FileSeek (int handle, int position); void Sys_FileSeek (int handle, int position);
int Sys_FileRead (int handle, void *dest, int count); int Sys_FileRead (int handle, void *dest, int count);
int Sys_FileWrite (int handle,const void *data, int count); int Sys_FileWrite (int handle,const void *data, int count);
int Sys_FileTime (const char *path);
void Sys_mkdir (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 // system IO
// //

View file

@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h> #include <sys/time.h>
#include <fcntl.h> #include <fcntl.h>
#include <time.h>
#ifdef DO_USERDIRS #ifdef DO_USERDIRS
#include <pwd.h> #include <pwd.h>
#endif #endif
@ -140,19 +139,22 @@ int Sys_FileWrite (int handle, const void *data, int count)
return fwrite (data, 1, count, sys_handles[handle]); 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) return FS_ENT_NONE;
{
fclose(f);
return 1;
}
return -1;
} }

View file

@ -139,19 +139,19 @@ int Sys_FileWrite (int handle, const void *data, int count)
return fwrite (data, 1, count, sys_handles[handle]); 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) return FS_ENT_FILE;
{
fclose(f);
return 1;
}
return -1;
} }
static char cwd[1024]; static char cwd[1024];