Cleaned out the "exists" nonsense in the stat() API.
This commit is contained in:
parent
ada24e9c5d
commit
7824a093fb
|
@ -43,10 +43,9 @@ static void *DIR_openArchive(PHYSFS_Io *io, const char *name, int forWriting)
|
||||||
char *retval = NULL;
|
char *retval = NULL;
|
||||||
const size_t namelen = strlen(name);
|
const size_t namelen = strlen(name);
|
||||||
const size_t seplen = 1;
|
const size_t seplen = 1;
|
||||||
int exists = 0;
|
|
||||||
|
|
||||||
assert(io == NULL); /* shouldn't create an Io for these. */
|
assert(io == NULL); /* shouldn't create an Io for these. */
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &exists, &st), ERRPASS, NULL);
|
BAIL_IF_MACRO(!__PHYSFS_platformStat(name, &st), ERRPASS, NULL);
|
||||||
if (st.filetype != PHYSFS_FILETYPE_DIRECTORY)
|
if (st.filetype != PHYSFS_FILETYPE_DIRECTORY)
|
||||||
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
|
BAIL_MACRO(PHYSFS_ERR_UNSUPPORTED, NULL);
|
||||||
|
|
||||||
|
@ -81,31 +80,22 @@ static void DIR_enumerateFiles(void *opaque, const char *dname,
|
||||||
} /* DIR_enumerateFiles */
|
} /* DIR_enumerateFiles */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_Io *doOpen(void *opaque, const char *name,
|
static PHYSFS_Io *doOpen(void *opaque, const char *name, const int mode)
|
||||||
const int mode, int *fileExists)
|
|
||||||
{
|
{
|
||||||
char *f;
|
|
||||||
PHYSFS_Io *io = NULL;
|
PHYSFS_Io *io = NULL;
|
||||||
int existtmp = 0;
|
char *f = NULL;
|
||||||
|
|
||||||
CVT_TO_DEPENDENT(f, opaque, name);
|
CVT_TO_DEPENDENT(f, opaque, name);
|
||||||
BAIL_IF_MACRO(!f, ERRPASS, NULL);
|
BAIL_IF_MACRO(!f, ERRPASS, NULL);
|
||||||
|
|
||||||
if (fileExists == NULL)
|
|
||||||
fileExists = &existtmp;
|
|
||||||
|
|
||||||
io = __PHYSFS_createNativeIo(f, mode);
|
io = __PHYSFS_createNativeIo(f, mode);
|
||||||
if (io == NULL)
|
if (io == NULL)
|
||||||
{
|
{
|
||||||
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
|
const PHYSFS_ErrorCode err = PHYSFS_getLastErrorCode();
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
__PHYSFS_platformStat(f, fileExists, &statbuf);
|
__PHYSFS_platformStat(f, &statbuf);
|
||||||
__PHYSFS_setError(err);
|
__PHYSFS_setError(err);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
|
||||||
{
|
|
||||||
*fileExists = 1;
|
|
||||||
} /* else */
|
|
||||||
|
|
||||||
__PHYSFS_smallFree(f);
|
__PHYSFS_smallFree(f);
|
||||||
|
|
||||||
|
@ -113,21 +103,22 @@ static PHYSFS_Io *doOpen(void *opaque, const char *name,
|
||||||
} /* doOpen */
|
} /* doOpen */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_Io *DIR_openRead(void *opaque, const char *fnm, int *exist)
|
static PHYSFS_Io *DIR_openRead(void *opaque, const char *filename, int *exists)
|
||||||
{
|
{
|
||||||
return doOpen(opaque, fnm, 'r', exist);
|
// !!! FIXME: exists
|
||||||
|
return doOpen(opaque, filename, 'r');
|
||||||
} /* DIR_openRead */
|
} /* DIR_openRead */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_Io *DIR_openWrite(void *opaque, const char *filename)
|
static PHYSFS_Io *DIR_openWrite(void *opaque, const char *filename)
|
||||||
{
|
{
|
||||||
return doOpen(opaque, filename, 'w', NULL);
|
return doOpen(opaque, filename, 'w');
|
||||||
} /* DIR_openWrite */
|
} /* DIR_openWrite */
|
||||||
|
|
||||||
|
|
||||||
static PHYSFS_Io *DIR_openAppend(void *opaque, const char *filename)
|
static PHYSFS_Io *DIR_openAppend(void *opaque, const char *filename)
|
||||||
{
|
{
|
||||||
return doOpen(opaque, filename, 'a', NULL);
|
return doOpen(opaque, filename, 'a');
|
||||||
} /* DIR_openAppend */
|
} /* DIR_openAppend */
|
||||||
|
|
||||||
|
|
||||||
|
@ -163,15 +154,14 @@ static void DIR_closeArchive(void *opaque)
|
||||||
} /* DIR_closeArchive */
|
} /* DIR_closeArchive */
|
||||||
|
|
||||||
|
|
||||||
static int DIR_stat(void *opaque, const char *name,
|
static int DIR_stat(void *opaque, const char *name, PHYSFS_Stat *stat)
|
||||||
int *exists, PHYSFS_Stat *stat)
|
|
||||||
{
|
{
|
||||||
int retval = 0;
|
int retval = 0;
|
||||||
char *d;
|
char *d;
|
||||||
|
|
||||||
CVT_TO_DEPENDENT(d, opaque, name);
|
CVT_TO_DEPENDENT(d, opaque, name);
|
||||||
BAIL_IF_MACRO(!d, ERRPASS, 0);
|
BAIL_IF_MACRO(!d, ERRPASS, 0);
|
||||||
retval = __PHYSFS_platformStat(d, exists, stat);
|
retval = __PHYSFS_platformStat(d, stat);
|
||||||
__PHYSFS_smallFree(d);
|
__PHYSFS_smallFree(d);
|
||||||
return retval;
|
return retval;
|
||||||
} /* DIR_stat */
|
} /* DIR_stat */
|
||||||
|
|
|
@ -398,7 +398,7 @@ static void iso_extractsubpath(char *path, char **subpath)
|
||||||
* a file needs to branch to the directory extent sooner or later.
|
* a file needs to branch to the directory extent sooner or later.
|
||||||
*/
|
*/
|
||||||
static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
|
static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
|
||||||
ISO9660FileDescriptor *descriptor, int *exists)
|
ISO9660FileDescriptor *descriptor)
|
||||||
{
|
{
|
||||||
char *subpath = 0;
|
char *subpath = 0;
|
||||||
PHYSFS_uint64 readpos, end_of_dir;
|
PHYSFS_uint64 readpos, end_of_dir;
|
||||||
|
@ -409,7 +409,6 @@ static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
|
||||||
|
|
||||||
strcpy(pathcopy, path);
|
strcpy(pathcopy, path);
|
||||||
mypath = pathcopy;
|
mypath = pathcopy;
|
||||||
*exists = 0;
|
|
||||||
|
|
||||||
readpos = handle->rootdirstart;
|
readpos = handle->rootdirstart;
|
||||||
end_of_dir = handle->rootdirstart + handle->rootdirsize;
|
end_of_dir = handle->rootdirstart + handle->rootdirsize;
|
||||||
|
@ -442,10 +441,7 @@ static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
|
||||||
if (strcmp(filename, mypath) == 0)
|
if (strcmp(filename, mypath) == 0)
|
||||||
{
|
{
|
||||||
if ( (subpath == 0) || (subpath[0] == 0) )
|
if ( (subpath == 0) || (subpath[0] == 0) )
|
||||||
{
|
|
||||||
*exists = 1;
|
|
||||||
return 0; /* no subpaths left and we found the entry */
|
return 0; /* no subpaths left and we found the entry */
|
||||||
} /* if */
|
|
||||||
|
|
||||||
if (descriptor->flags.directory)
|
if (descriptor->flags.directory)
|
||||||
{
|
{
|
||||||
|
@ -458,12 +454,14 @@ static int iso_find_dir_entry(ISO9660Handle *handle,const char *path,
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* !!! FIXME: set PHYSFS_ERR_NOT_FOUND? */
|
||||||
/* we're at a file but have a remaining subpath -> no match */
|
/* we're at a file but have a remaining subpath -> no match */
|
||||||
return 0;
|
return 0;
|
||||||
} /* else */
|
} /* else */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
|
/* !!! FIXME: set PHYSFS_ERR_NOT_FOUND? */
|
||||||
return 0;
|
return 0;
|
||||||
} /* iso_find_dir_entry */
|
} /* iso_find_dir_entry */
|
||||||
|
|
||||||
|
@ -783,9 +781,8 @@ static PHYSFS_Io *ISO9660_openRead(void *opaque, const char *filename,
|
||||||
GOTO_IF_MACRO(retval == 0, PHYSFS_ERR_OUT_OF_MEMORY, errorhandling);
|
GOTO_IF_MACRO(retval == 0, PHYSFS_ERR_OUT_OF_MEMORY, errorhandling);
|
||||||
|
|
||||||
/* find file descriptor */
|
/* find file descriptor */
|
||||||
rc = iso_find_dir_entry(handle, filename, &descriptor, exists);
|
rc = iso_find_dir_entry(handle, filename, &descriptor);
|
||||||
GOTO_IF_MACRO(rc, ERRPASS, errorhandling);
|
GOTO_IF_MACRO(rc, ERRPASS, errorhandling);
|
||||||
GOTO_IF_MACRO(!*exists, PHYSFS_ERR_NOT_FOUND, errorhandling);
|
|
||||||
|
|
||||||
fhandle->startblock = descriptor.extentpos + descriptor.extattributelen;
|
fhandle->startblock = descriptor.extentpos + descriptor.extattributelen;
|
||||||
fhandle->filesize = descriptor.datalen;
|
fhandle->filesize = descriptor.datalen;
|
||||||
|
@ -835,9 +832,7 @@ static void ISO9660_enumerateFiles(void *opaque, const char *dname,
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("pfad %s\n",dname);
|
printf("pfad %s\n",dname);
|
||||||
int exists = 0;
|
BAIL_IF_MACRO(iso_find_dir_entry(handle,dname, &descriptor), ERRPASS,);
|
||||||
BAIL_IF_MACRO(iso_find_dir_entry(handle,dname, &descriptor, &exists), ERRPASS,);
|
|
||||||
BAIL_IF_MACRO(!exists, ERRPASS, );
|
|
||||||
BAIL_IF_MACRO(!descriptor.flags.directory, ERRPASS,);
|
BAIL_IF_MACRO(!descriptor.flags.directory, ERRPASS,);
|
||||||
|
|
||||||
readpos = descriptor.extentpos * 2048;
|
readpos = descriptor.extentpos * 2048;
|
||||||
|
@ -872,15 +867,12 @@ static void ISO9660_enumerateFiles(void *opaque, const char *dname,
|
||||||
} /* ISO9660_enumerateFiles */
|
} /* ISO9660_enumerateFiles */
|
||||||
|
|
||||||
|
|
||||||
static int ISO9660_stat(void *opaque, const char *name, int *exists,
|
static int ISO9660_stat(void *opaque, const char *name, PHYSFS_Stat *stat)
|
||||||
PHYSFS_Stat *stat)
|
|
||||||
{
|
{
|
||||||
ISO9660Handle *handle = (ISO9660Handle*) opaque;
|
ISO9660Handle *handle = (ISO9660Handle*) opaque;
|
||||||
ISO9660FileDescriptor descriptor;
|
ISO9660FileDescriptor descriptor;
|
||||||
ISO9660ExtAttributeRec extattr;
|
ISO9660ExtAttributeRec extattr;
|
||||||
BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor, exists), ERRPASS, -1);
|
BAIL_IF_MACRO(iso_find_dir_entry(handle, name, &descriptor), ERRPASS, -1);
|
||||||
if (!*exists)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
stat->readonly = 1;
|
stat->readonly = 1;
|
||||||
|
|
||||||
|
|
|
@ -639,13 +639,11 @@ static int LZMA_mkdir(void *opaque, const char *name)
|
||||||
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
|
BAIL_MACRO(PHYSFS_ERR_READ_ONLY, 0);
|
||||||
} /* LZMA_mkdir */
|
} /* LZMA_mkdir */
|
||||||
|
|
||||||
static int LZMA_stat(void *opaque, const char *filename,
|
static int LZMA_stat(void *opaque, const char *filename, PHYSFS_Stat *stat)
|
||||||
int *exists, PHYSFS_Stat *stat)
|
|
||||||
{
|
{
|
||||||
const LZMAarchive *archive = (const LZMAarchive *) opaque;
|
const LZMAarchive *archive = (const LZMAarchive *) opaque;
|
||||||
const LZMAfile *file = lzma_find_file(archive, filename);
|
const LZMAfile *file = lzma_find_file(archive, filename);
|
||||||
|
|
||||||
*exists = (file != 0);
|
|
||||||
if (!file)
|
if (!file)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
@ -699,5 +697,5 @@ const PHYSFS_Archiver __PHYSFS_Archiver_LZMA =
|
||||||
|
|
||||||
#endif /* defined PHYSFS_SUPPORTS_7Z */
|
#endif /* defined PHYSFS_SUPPORTS_7Z */
|
||||||
|
|
||||||
/* end of lzma.c ... */
|
/* end of archiver_lzma.c ... */
|
||||||
|
|
||||||
|
|
|
@ -414,8 +414,7 @@ int UNPK_mkdir(void *opaque, const char *name)
|
||||||
} /* UNPK_mkdir */
|
} /* UNPK_mkdir */
|
||||||
|
|
||||||
|
|
||||||
int UNPK_stat(void *opaque, const char *filename,
|
int UNPK_stat(void *opaque, const char *filename, PHYSFS_Stat *stat)
|
||||||
int *exists, PHYSFS_Stat *stat)
|
|
||||||
{
|
{
|
||||||
int isDir = 0;
|
int isDir = 0;
|
||||||
const UNPKinfo *info = (const UNPKinfo *) opaque;
|
const UNPKinfo *info = (const UNPKinfo *) opaque;
|
||||||
|
@ -423,19 +422,16 @@ int UNPK_stat(void *opaque, const char *filename,
|
||||||
|
|
||||||
if (isDir)
|
if (isDir)
|
||||||
{
|
{
|
||||||
*exists = 1;
|
|
||||||
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
||||||
stat->filesize = 0;
|
stat->filesize = 0;
|
||||||
} /* if */
|
} /* if */
|
||||||
else if (entry != NULL)
|
else if (entry != NULL)
|
||||||
{
|
{
|
||||||
*exists = 1;
|
|
||||||
stat->filetype = PHYSFS_FILETYPE_REGULAR;
|
stat->filetype = PHYSFS_FILETYPE_REGULAR;
|
||||||
stat->filesize = entry->size;
|
stat->filesize = entry->size;
|
||||||
} /* else if */
|
} /* else if */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
*exists = 0;
|
|
||||||
return 0;
|
return 0;
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
|
|
|
@ -1649,8 +1649,7 @@ static int ZIP_mkdir(void *opaque, const char *name)
|
||||||
} /* ZIP_mkdir */
|
} /* ZIP_mkdir */
|
||||||
|
|
||||||
|
|
||||||
static int ZIP_stat(void *opaque, const char *filename, int *exists,
|
static int ZIP_stat(void *opaque, const char *filename, PHYSFS_Stat *stat)
|
||||||
PHYSFS_Stat *stat)
|
|
||||||
{
|
{
|
||||||
int isDir = 0;
|
int isDir = 0;
|
||||||
const ZIPinfo *info = (const ZIPinfo *) opaque;
|
const ZIPinfo *info = (const ZIPinfo *) opaque;
|
||||||
|
@ -1658,11 +1657,10 @@ static int ZIP_stat(void *opaque, const char *filename, int *exists,
|
||||||
|
|
||||||
/* !!! FIXME: does this need to resolve entries here? */
|
/* !!! FIXME: does this need to resolve entries here? */
|
||||||
|
|
||||||
*exists = isDir || (entry != 0);
|
if ((!isDir) && (entry == NULL))
|
||||||
if (!*exists)
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if (isDir)
|
else if (isDir)
|
||||||
{
|
{
|
||||||
stat->filesize = 0;
|
stat->filesize = 0;
|
||||||
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
||||||
|
|
31
src/physfs.c
31
src/physfs.c
|
@ -728,6 +728,14 @@ void __PHYSFS_setError(const PHYSFS_ErrorCode errcode)
|
||||||
} /* __PHYSFS_setError */
|
} /* __PHYSFS_setError */
|
||||||
|
|
||||||
|
|
||||||
|
/* this doesn't reset the error state. */
|
||||||
|
static inline PHYSFS_ErrorCode currentErrorCode(void)
|
||||||
|
{
|
||||||
|
const ErrState *err = findErrorForCurrentThread();
|
||||||
|
return err ? err->code : PHYSFS_ERR_OK;
|
||||||
|
} /* currentErrorCode */
|
||||||
|
|
||||||
|
|
||||||
PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
|
PHYSFS_ErrorCode PHYSFS_getLastErrorCode(void)
|
||||||
{
|
{
|
||||||
ErrState *err = findErrorForCurrentThread();
|
ErrState *err = findErrorForCurrentThread();
|
||||||
|
@ -1537,7 +1545,6 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
char *endstr = NULL;
|
char *endstr = NULL;
|
||||||
int exists = 0;
|
|
||||||
|
|
||||||
BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0);
|
BAIL_IF_MACRO(!initialized, PHYSFS_ERR_NOT_INITIALIZED, 0);
|
||||||
BAIL_IF_MACRO(!org, PHYSFS_ERR_INVALID_ARGUMENT, NULL);
|
BAIL_IF_MACRO(!org, PHYSFS_ERR_INVALID_ARGUMENT, NULL);
|
||||||
|
@ -1554,7 +1561,7 @@ const char *PHYSFS_getPrefDir(const char *org, const char *app)
|
||||||
assert(*endstr == dirsep);
|
assert(*endstr == dirsep);
|
||||||
*endstr = '\0'; /* mask out the final dirsep for now. */
|
*endstr = '\0'; /* mask out the final dirsep for now. */
|
||||||
|
|
||||||
if (!__PHYSFS_platformStat(prefDir, &exists, &statbuf))
|
if (!__PHYSFS_platformStat(prefDir, &statbuf))
|
||||||
{
|
{
|
||||||
for (ptr = strchr(prefDir, dirsep); ptr; ptr = strchr(ptr+1, dirsep))
|
for (ptr = strchr(prefDir, dirsep); ptr; ptr = strchr(ptr+1, dirsep))
|
||||||
{
|
{
|
||||||
|
@ -1968,9 +1975,12 @@ static int verifyPath(DirHandle *h, char **_fname, int allowMissing)
|
||||||
end = strchr(start, '/');
|
end = strchr(start, '/');
|
||||||
|
|
||||||
if (end != NULL) *end = '\0';
|
if (end != NULL) *end = '\0';
|
||||||
rc = h->funcs->stat(h->opaque, fname, &retval, &statbuf);
|
rc = h->funcs->stat(h->opaque, fname, &statbuf);
|
||||||
if (rc)
|
if (rc)
|
||||||
rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK);
|
rc = (statbuf.filetype == PHYSFS_FILETYPE_SYMLINK);
|
||||||
|
else if (currentErrorCode() == PHYSFS_ERR_NOT_FOUND)
|
||||||
|
retval = 0;
|
||||||
|
|
||||||
if (end != NULL) *end = '/';
|
if (end != NULL) *end = '/';
|
||||||
|
|
||||||
/* insecure path (has a disallowed symlink in it)? */
|
/* insecure path (has a disallowed symlink in it)? */
|
||||||
|
@ -2026,7 +2036,9 @@ static int doMkdir(const char *_dname, char *dname)
|
||||||
if (exists)
|
if (exists)
|
||||||
{
|
{
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
const int rc = h->funcs->stat(h->opaque, dname, &exists, &statbuf);
|
const int rc = h->funcs->stat(h->opaque, dname, &statbuf);
|
||||||
|
if ((!rc) && (currentErrorCode() == PHYSFS_ERR_NOT_FOUND))
|
||||||
|
exists = 0;
|
||||||
retval = ((rc) && (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY));
|
retval = ((rc) && (statbuf.filetype == PHYSFS_FILETYPE_DIRECTORY));
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -2123,10 +2135,8 @@ const char *PHYSFS_getRealDir(const char *_fname)
|
||||||
else if (verifyPath(i, &arcfname, 0))
|
else if (verifyPath(i, &arcfname, 0))
|
||||||
{
|
{
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
int exists = 0;
|
if (i->funcs->stat(i->opaque, arcfname, &statbuf))
|
||||||
if (i->funcs->stat(i->opaque, arcfname, &exists, &statbuf))
|
|
||||||
{
|
{
|
||||||
if (exists)
|
|
||||||
retval = i->dirName;
|
retval = i->dirName;
|
||||||
break;
|
break;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -2265,10 +2275,9 @@ static void enumCallbackFilterSymLinks(void *_data, const char *origdir,
|
||||||
SymlinkFilterData *data = (SymlinkFilterData *) _data;
|
SymlinkFilterData *data = (SymlinkFilterData *) _data;
|
||||||
const DirHandle *dh = data->dirhandle;
|
const DirHandle *dh = data->dirhandle;
|
||||||
PHYSFS_Stat statbuf;
|
PHYSFS_Stat statbuf;
|
||||||
int exists = 0;
|
|
||||||
|
|
||||||
sprintf(path, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
|
sprintf(path, "%s%s%s", trimmedDir, *trimmedDir ? "/" : "", fname);
|
||||||
if (dh->funcs->stat(dh->opaque, path, &exists, &statbuf))
|
if (dh->funcs->stat(dh->opaque, path, &statbuf))
|
||||||
{
|
{
|
||||||
/* Pass it on to the application if it's not a symlink. */
|
/* Pass it on to the application if it's not a symlink. */
|
||||||
if (statbuf.filetype != PHYSFS_FILETYPE_SYMLINK)
|
if (statbuf.filetype != PHYSFS_FILETYPE_SYMLINK)
|
||||||
|
@ -2871,7 +2880,9 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
|
||||||
/* !!! FIXME: this test is wrong and should be elsewhere. */
|
/* !!! FIXME: this test is wrong and should be elsewhere. */
|
||||||
stat->readonly = !(writeDir &&
|
stat->readonly = !(writeDir &&
|
||||||
(strcmp(writeDir->dirName, i->dirName) == 0));
|
(strcmp(writeDir->dirName, i->dirName) == 0));
|
||||||
retval = i->funcs->stat(i->opaque, arcfname, &exists, stat);
|
retval = i->funcs->stat(i->opaque, arcfname, stat);
|
||||||
|
if ((retval) || (currentErrorCode() != PHYSFS_ERR_NOT_FOUND))
|
||||||
|
exists = 1;
|
||||||
} /* else if */
|
} /* else if */
|
||||||
} /* for */
|
} /* for */
|
||||||
__PHYSFS_platformReleaseMutex(stateLock);
|
__PHYSFS_platformReleaseMutex(stateLock);
|
||||||
|
|
|
@ -3496,8 +3496,7 @@ typedef struct PHYSFS_Archiver
|
||||||
* Returns non-zero on success, zero on failure.
|
* Returns non-zero on success, zero on failure.
|
||||||
* On failure, call PHYSFS_setErrorCode().
|
* On failure, call PHYSFS_setErrorCode().
|
||||||
*/
|
*/
|
||||||
// !!! FIXME: remove this exists nonsense (check error code instead)
|
int (*stat)(void *opaque, const char *fn, PHYSFS_Stat *stat);
|
||||||
int (*stat)(void *opaque, const char *fn, int *exists, PHYSFS_Stat *stat);
|
|
||||||
} PHYSFS_Archiver;
|
} PHYSFS_Archiver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -308,7 +308,7 @@ PHYSFS_Io *UNPK_openWrite(void *opaque, const char *name);
|
||||||
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name);
|
PHYSFS_Io *UNPK_openAppend(void *opaque, const char *name);
|
||||||
int UNPK_remove(void *opaque, const char *name);
|
int UNPK_remove(void *opaque, const char *name);
|
||||||
int UNPK_mkdir(void *opaque, const char *name);
|
int UNPK_mkdir(void *opaque, const char *name);
|
||||||
int UNPK_stat(void *opaque, const char *fn, int *exist, PHYSFS_Stat *st);
|
int UNPK_stat(void *opaque, const char *fn, PHYSFS_Stat *st);
|
||||||
|
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
@ -474,7 +474,7 @@ PHYSFS_sint64 __PHYSFS_platformFileLength(void *handle);
|
||||||
/*
|
/*
|
||||||
* !!! FIXME: comment me.
|
* !!! FIXME: comment me.
|
||||||
*/
|
*/
|
||||||
int __PHYSFS_platformStat(const char *fn, int *exists, PHYSFS_Stat *stat);
|
int __PHYSFS_platformStat(const char *fn, PHYSFS_Stat *stat);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Flush any pending writes to disk. (opaque) should be cast to whatever data
|
* Flush any pending writes to disk. (opaque) should be cast to whatever data
|
||||||
|
|
|
@ -299,17 +299,11 @@ int __PHYSFS_platformDelete(const char *path)
|
||||||
} /* __PHYSFS_platformDelete */
|
} /* __PHYSFS_platformDelete */
|
||||||
|
|
||||||
|
|
||||||
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *st)
|
int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st)
|
||||||
{
|
{
|
||||||
struct stat statbuf;
|
struct stat statbuf;
|
||||||
|
|
||||||
if (lstat(filename, &statbuf) == -1)
|
BAIL_IF_MACRO(lstat(filename, &statbuf) == -1, errcodeFromErrno(), 0);
|
||||||
{
|
|
||||||
*exists = (errno != ENOENT);
|
|
||||||
BAIL_MACRO(errcodeFromErrno(), 0);
|
|
||||||
} /* if */
|
|
||||||
|
|
||||||
*exists = 1;
|
|
||||||
|
|
||||||
if (S_ISREG(statbuf.st_mode))
|
if (S_ISREG(statbuf.st_mode))
|
||||||
{
|
{
|
||||||
|
|
|
@ -873,7 +873,8 @@ static PHYSFS_sint64 FileTimeToPhysfsTime(const FILETIME *ft)
|
||||||
return retval;
|
return retval;
|
||||||
} /* FileTimeToPhysfsTime */
|
} /* FileTimeToPhysfsTime */
|
||||||
|
|
||||||
int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
|
|
||||||
|
int __PHYSFS_platformStat(const char *filename, PHYSFS_Stat *st)
|
||||||
{
|
{
|
||||||
WIN32_FILE_ATTRIBUTE_DATA winstat;
|
WIN32_FILE_ATTRIBUTE_DATA winstat;
|
||||||
WCHAR *wstr = NULL;
|
WCHAR *wstr = NULL;
|
||||||
|
@ -884,37 +885,36 @@ int __PHYSFS_platformStat(const char *filename, int *exists, PHYSFS_Stat *stat)
|
||||||
BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(!wstr, PHYSFS_ERR_OUT_OF_MEMORY, 0);
|
||||||
rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
|
rc = GetFileAttributesExW(wstr, GetFileExInfoStandard, &winstat);
|
||||||
err = (!rc) ? GetLastError() : 0;
|
err = (!rc) ? GetLastError() : 0;
|
||||||
*exists = ((err != ERROR_FILE_NOT_FOUND) && (err != ERROR_PATH_NOT_FOUND));
|
|
||||||
__PHYSFS_smallFree(wstr);
|
__PHYSFS_smallFree(wstr);
|
||||||
BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0);
|
BAIL_IF_MACRO(!rc, errcodeFromWinApiError(err), 0);
|
||||||
|
|
||||||
stat->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
|
st->modtime = FileTimeToPhysfsTime(&winstat.ftLastWriteTime);
|
||||||
stat->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
|
st->accesstime = FileTimeToPhysfsTime(&winstat.ftLastAccessTime);
|
||||||
stat->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
|
st->createtime = FileTimeToPhysfsTime(&winstat.ftCreationTime);
|
||||||
|
|
||||||
if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
if(winstat.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
stat->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
st->filetype = PHYSFS_FILETYPE_DIRECTORY;
|
||||||
stat->filesize = 0;
|
st->filesize = 0;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
else if(winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
|
else if(winstat.dwFileAttributes & (FILE_ATTRIBUTE_OFFLINE | FILE_ATTRIBUTE_DEVICE))
|
||||||
{
|
{
|
||||||
/* !!! FIXME: what are reparse points? */
|
/* !!! FIXME: what are reparse points? */
|
||||||
stat->filetype = PHYSFS_FILETYPE_OTHER;
|
st->filetype = PHYSFS_FILETYPE_OTHER;
|
||||||
/* !!! FIXME: don't rely on this */
|
/* !!! FIXME: don't rely on this */
|
||||||
stat->filesize = 0;
|
st->filesize = 0;
|
||||||
} /* else if */
|
} /* else if */
|
||||||
|
|
||||||
/* !!! FIXME: check for symlinks on Vista. */
|
/* !!! FIXME: check for symlinks on Vista. */
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stat->filetype = PHYSFS_FILETYPE_REGULAR;
|
st->filetype = PHYSFS_FILETYPE_REGULAR;
|
||||||
stat->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
|
st->filesize = (((PHYSFS_uint64) winstat.nFileSizeHigh) << 32) | winstat.nFileSizeLow;
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
stat->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
|
st->readonly = ((winstat.dwFileAttributes & FILE_ATTRIBUTE_READONLY) != 0);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
} /* __PHYSFS_platformStat */
|
} /* __PHYSFS_platformStat */
|
||||||
|
|
Loading…
Reference in New Issue