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;
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)

View file

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

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

View file

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

View file

@ -33,7 +33,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <sys/stat.h>
#include <sys/time.h>
#include <fcntl.h>
#include <time.h>
#ifdef DO_USERDIRS
#include <pwd.h>
#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;
}

View file

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