Commit ec4b5ab1 authored by rswindell's avatar rswindell
Browse files

Optimized fdate(), fcdate(), flength(), fnameexist() functions:

There's no reason to call access() before stat() since stat() will fail
(return -1) if the file does not exist.
parent 477b2cfd
......@@ -84,6 +84,10 @@
#include "genwrap.h" /* strupr/strlwr */
#include "dirwrap.h" /* DLLCALL */
#if !defined(S_ISDIR)
#define S_ISDIR(x) ((x)&S_IFDIR)
#endif
/****************************************************************************/
/* Return the filename portion of a full pathname */
/****************************************************************************/
......@@ -396,9 +400,6 @@ time_t DLLCALL fcdate(const char* filename)
{
struct stat st;
if(access(filename, 0) < 0)
return -1;
if(stat(filename, &st) != 0)
return -1;
......@@ -412,9 +413,6 @@ time_t DLLCALL fdate(const char* filename)
{
struct stat st;
if(access(filename,0)==-1)
return(-1);
if(stat(filename, &st)!=0)
return(-1);
......@@ -447,9 +445,6 @@ off_t DLLCALL flength(const char *filename)
long handle;
struct _finddata_t f;
if(access((char*)filename,0)==-1)
return(-1);
if((handle=_findfirst((char*)filename,&f))==-1)
return(-1);
......@@ -461,9 +456,6 @@ off_t DLLCALL flength(const char *filename)
struct stat st;
if(access(filename,0)==-1)
return(-1);
if(stat(filename, &st)!=0)
return(-1);
......@@ -474,17 +466,21 @@ off_t DLLCALL flength(const char *filename)
/****************************************************************************/
/* Checks the file system for the existence of one or more files. */
/* Checks the file system for the existence of a file. */
/* Returns TRUE if it exists, FALSE if it doesn't. */
/* 'filespec' may *NOT* contain wildcards! */
/* 'filename' may *NOT* contain wildcards! */
/****************************************************************************/
static BOOL fnameexist(const char *filename)
{
if(access(filename,0)==-1)
return(FALSE);
if(!isdir(filename))
return(TRUE);
return(FALSE);
struct stat st;
if(stat(filename, &st) != 0)
return FALSE;
if(S_ISDIR(st.st_mode))
return FALSE;
return TRUE;
}
/****************************************************************************/
......@@ -561,7 +557,7 @@ BOOL DLLCALL fexistcase(char *path)
long handle;
struct _finddata_t f;
if(access(path,0)==-1 && !strchr(path,'*') && !strchr(path,'?'))
if(access(path, F_OK)==-1 && !strchr(path,'*') && !strchr(path,'?'))
return(FALSE);
if((handle=_findfirst((char*)path,&f))==-1)
......@@ -631,10 +627,6 @@ BOOL DLLCALL fexistcase(char *path)
#endif
}
#if !defined(S_ISDIR)
#define S_ISDIR(x) ((x)&S_IFDIR)
#endif
/****************************************************************************/
/* Returns TRUE if the filename specified is a directory */
/****************************************************************************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment