All memory management now goes through allocation hooks instead of directly to
C runtime malloc/realloc/free...
This commit is contained in:
parent
4787894ffa
commit
d840403c1c
|
@ -91,7 +91,7 @@ static void *DIR_openArchive(const char *name, int forWriting)
|
||||||
BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
|
BAIL_IF_MACRO(!DIR_isArchive(name, forWriting),
|
||||||
ERR_UNSUPPORTED_ARCHIVE, 0);
|
ERR_UNSUPPORTED_ARCHIVE, 0);
|
||||||
|
|
||||||
retval = malloc(namelen + seplen + 1);
|
retval = allocator.Malloc(namelen + seplen + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
/* make sure there's a dir separator at the end of the string */
|
/* make sure there's a dir separator at the end of the string */
|
||||||
|
@ -111,7 +111,7 @@ static void DIR_enumerateFiles(dvoid *opaque, const char *dname,
|
||||||
if (d != NULL)
|
if (d != NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata);
|
__PHYSFS_platformEnumerateFiles(d, omitSymLinks, cb, callbackdata);
|
||||||
free(d);
|
allocator.Free(d);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* DIR_enumerateFiles */
|
} /* DIR_enumerateFiles */
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ static int DIR_exists(dvoid *opaque, const char *name)
|
||||||
|
|
||||||
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
||||||
retval = __PHYSFS_platformExists(f);
|
retval = __PHYSFS_platformExists(f);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_exists */
|
} /* DIR_exists */
|
||||||
|
|
||||||
|
@ -137,7 +137,7 @@ static int DIR_isDirectory(dvoid *opaque, const char *name, int *fileExists)
|
||||||
*fileExists = __PHYSFS_platformExists(d);
|
*fileExists = __PHYSFS_platformExists(d);
|
||||||
if (*fileExists)
|
if (*fileExists)
|
||||||
retval = __PHYSFS_platformIsDirectory(d);
|
retval = __PHYSFS_platformIsDirectory(d);
|
||||||
free(d);
|
allocator.Free(d);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_isDirectory */
|
} /* DIR_isDirectory */
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ static int DIR_isSymLink(dvoid *opaque, const char *name, int *fileExists)
|
||||||
*fileExists = __PHYSFS_platformExists(f);
|
*fileExists = __PHYSFS_platformExists(f);
|
||||||
if (*fileExists)
|
if (*fileExists)
|
||||||
retval = __PHYSFS_platformIsSymLink(f);
|
retval = __PHYSFS_platformIsSymLink(f);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_isSymLink */
|
} /* DIR_isSymLink */
|
||||||
|
|
||||||
|
@ -167,7 +167,7 @@ static PHYSFS_sint64 DIR_getLastModTime(dvoid *opaque,
|
||||||
*fileExists = __PHYSFS_platformExists(d);
|
*fileExists = __PHYSFS_platformExists(d);
|
||||||
if (*fileExists)
|
if (*fileExists)
|
||||||
retval = __PHYSFS_platformGetLastModTime(d);
|
retval = __PHYSFS_platformGetLastModTime(d);
|
||||||
free(d);
|
allocator.Free(d);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_getLastModTime */
|
} /* DIR_getLastModTime */
|
||||||
|
|
||||||
|
@ -186,13 +186,13 @@ static fvoid *doOpen(dvoid *opaque, const char *name,
|
||||||
*fileExists = __PHYSFS_platformExists(f);
|
*fileExists = __PHYSFS_platformExists(f);
|
||||||
if (!(*fileExists))
|
if (!(*fileExists))
|
||||||
{
|
{
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
rc = openFunc(f);
|
rc = openFunc(f);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
|
|
||||||
return((fvoid *) rc);
|
return((fvoid *) rc);
|
||||||
} /* doOpen */
|
} /* doOpen */
|
||||||
|
@ -223,7 +223,7 @@ static int DIR_remove(dvoid *opaque, const char *name)
|
||||||
|
|
||||||
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
||||||
retval = __PHYSFS_platformDelete(f);
|
retval = __PHYSFS_platformDelete(f);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_remove */
|
} /* DIR_remove */
|
||||||
|
|
||||||
|
@ -235,14 +235,14 @@ static int DIR_mkdir(dvoid *opaque, const char *name)
|
||||||
|
|
||||||
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
BAIL_IF_MACRO(f == NULL, NULL, 0);
|
||||||
retval = __PHYSFS_platformMkDir(f);
|
retval = __PHYSFS_platformMkDir(f);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* DIR_mkdir */
|
} /* DIR_mkdir */
|
||||||
|
|
||||||
|
|
||||||
static void DIR_dirClose(dvoid *opaque)
|
static void DIR_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
free(opaque);
|
allocator.Free(opaque);
|
||||||
} /* DIR_dirClose */
|
} /* DIR_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -64,9 +64,9 @@ typedef struct
|
||||||
static void GRP_dirClose(dvoid *opaque)
|
static void GRP_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
GRPinfo *info = ((GRPinfo *) opaque);
|
GRPinfo *info = ((GRPinfo *) opaque);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* GRP_dirClose */
|
} /* GRP_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -138,7 +138,7 @@ static int GRP_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
GRPfileinfo *finfo = (GRPfileinfo *) opaque;
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* GRP_fileClose */
|
} /* GRP_fileClose */
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ static int grp_load_entries(const char *name, int forWriting, GRPinfo *info)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!grp_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
BAIL_IF_MACRO(!grp_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
||||||
info->entryCount = fileCount;
|
info->entryCount = fileCount;
|
||||||
info->entries = (GRPentry *) malloc(sizeof (GRPentry) * fileCount);
|
info->entries = (GRPentry *) allocator.Malloc(sizeof(GRPentry)*fileCount);
|
||||||
if (info->entries == NULL)
|
if (info->entries == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(fh);
|
__PHYSFS_platformClose(fh);
|
||||||
|
@ -264,12 +264,12 @@ static int grp_load_entries(const char *name, int forWriting, GRPinfo *info)
|
||||||
static void *GRP_openArchive(const char *name, int forWriting)
|
static void *GRP_openArchive(const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
||||||
GRPinfo *info = malloc(sizeof (GRPinfo));
|
GRPinfo *info = (GRPinfo *) allocator.Malloc(sizeof (GRPinfo));
|
||||||
|
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
memset(info, '\0', sizeof (GRPinfo));
|
memset(info, '\0', sizeof (GRPinfo));
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, GRP_openArchive_failed);
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, GRP_openArchive_failed);
|
||||||
|
|
||||||
if (!grp_load_entries(name, forWriting, info))
|
if (!grp_load_entries(name, forWriting, info))
|
||||||
|
@ -284,10 +284,10 @@ GRP_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entries != NULL)
|
if (info->entries != NULL)
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -390,14 +390,14 @@ static fvoid *GRP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
*fileExists = (entry != NULL);
|
*fileExists = (entry != NULL);
|
||||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||||
|
|
||||||
finfo = (GRPfileinfo *) malloc(sizeof (GRPfileinfo));
|
finfo = (GRPfileinfo *) allocator.Malloc(sizeof (GRPfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if ( (finfo->handle == NULL) ||
|
if ( (finfo->handle == NULL) ||
|
||||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -78,9 +78,9 @@ typedef struct
|
||||||
static void HOG_dirClose(dvoid *opaque)
|
static void HOG_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
HOGinfo *info = ((HOGinfo *) opaque);
|
HOGinfo *info = ((HOGinfo *) opaque);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* HOG_dirClose */
|
} /* HOG_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -152,7 +152,7 @@ static int HOG_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
HOGfileinfo *finfo = (HOGfileinfo *) opaque;
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* HOG_fileClose */
|
} /* HOG_fileClose */
|
||||||
|
|
||||||
|
@ -256,7 +256,7 @@ static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
BAIL_IF_MACRO(!hog_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
||||||
info->entryCount = fileCount;
|
info->entryCount = fileCount;
|
||||||
info->entries = (HOGentry *) malloc(sizeof (HOGentry) * fileCount);
|
info->entries = (HOGentry *) allocator.Malloc(sizeof(HOGentry)*fileCount);
|
||||||
if (info->entries == NULL)
|
if (info->entries == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(fh);
|
__PHYSFS_platformClose(fh);
|
||||||
|
@ -304,11 +304,11 @@ static int hog_load_entries(const char *name, int forWriting, HOGinfo *info)
|
||||||
static void *HOG_openArchive(const char *name, int forWriting)
|
static void *HOG_openArchive(const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
||||||
HOGinfo *info = malloc(sizeof (HOGinfo));
|
HOGinfo *info = (HOGinfo *) allocator.Malloc(sizeof (HOGinfo));
|
||||||
|
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
memset(info, '\0', sizeof (HOGinfo));
|
memset(info, '\0', sizeof (HOGinfo));
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, HOG_openArchive_failed);
|
||||||
|
|
||||||
if (!hog_load_entries(name, forWriting, info))
|
if (!hog_load_entries(name, forWriting, info))
|
||||||
|
@ -323,10 +323,10 @@ HOG_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entries != NULL)
|
if (info->entries != NULL)
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -429,14 +429,14 @@ static fvoid *HOG_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
*fileExists = (entry != NULL);
|
*fileExists = (entry != NULL);
|
||||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||||
|
|
||||||
finfo = (HOGfileinfo *) malloc(sizeof (HOGfileinfo));
|
finfo = (HOGfileinfo *) allocator.Malloc(sizeof (HOGfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if ( (finfo->handle == NULL) ||
|
if ( (finfo->handle == NULL) ||
|
||||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -116,8 +116,8 @@ static PHYSFS_uint32 MIX_hash(const char *name)
|
||||||
static void MIX_dirClose(dvoid *opaque)
|
static void MIX_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
MIXinfo *info = ((MIXinfo *) opaque);
|
MIXinfo *info = ((MIXinfo *) opaque);
|
||||||
free(info->entry);
|
allocator.Free(info->entry);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
} /* MIX_dirClose */
|
} /* MIX_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -186,7 +186,7 @@ static int MIX_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
MIXfileinfo *finfo = (MIXfileinfo *) opaque;
|
MIXfileinfo *finfo = (MIXfileinfo *) opaque;
|
||||||
__PHYSFS_platformClose(finfo->handle);
|
__PHYSFS_platformClose(finfo->handle);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* MIX_fileClose */
|
} /* MIX_fileClose */
|
||||||
|
|
||||||
|
@ -231,11 +231,11 @@ static void *MIX_openArchive(const char *name, int forWriting)
|
||||||
MIXinfo *info = NULL;
|
MIXinfo *info = NULL;
|
||||||
void *handle = NULL;
|
void *handle = NULL;
|
||||||
|
|
||||||
info = (MIXinfo *) malloc(sizeof (MIXinfo));
|
info = (MIXinfo *) allocator.Malloc(sizeof (MIXinfo));
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
memset(info, '\0', sizeof (MIXinfo));
|
memset(info, '\0', sizeof (MIXinfo));
|
||||||
|
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);
|
||||||
|
|
||||||
/* store filename */
|
/* store filename */
|
||||||
|
@ -254,7 +254,7 @@ static void *MIX_openArchive(const char *name, int forWriting)
|
||||||
info->delta = 6 + (info->header.num_files * 12);
|
info->delta = 6 + (info->header.num_files * 12);
|
||||||
|
|
||||||
/* allocate space for the entries and read the entries */
|
/* allocate space for the entries and read the entries */
|
||||||
info->entry = malloc(sizeof (MIXentry) * info->header.num_files);
|
info->entry = allocator.Malloc(sizeof (MIXentry) * info->header.num_files);
|
||||||
GOTO_IF_MACRO(!info->entry, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);
|
GOTO_IF_MACRO(!info->entry, ERR_OUT_OF_MEMORY, MIX_openArchive_failed);
|
||||||
|
|
||||||
/* read the directory list */
|
/* read the directory list */
|
||||||
|
@ -274,10 +274,10 @@ MIX_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entry != NULL)
|
if (info->entry != NULL)
|
||||||
free(info->entry);
|
allocator.Free(info->entry);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (handle != NULL)
|
if (handle != NULL)
|
||||||
|
@ -367,14 +367,14 @@ static fvoid *MIX_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
|
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
|
||||||
|
|
||||||
/* allocate a MIX handle */
|
/* allocate a MIX handle */
|
||||||
finfo = (MIXfileinfo *) malloc(sizeof (MIXfileinfo));
|
finfo = (MIXfileinfo *) allocator.Malloc(sizeof (MIXfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
/* open the archive */
|
/* open the archive */
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if(!finfo->handle)
|
if(!finfo->handle)
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -67,9 +67,9 @@ typedef struct
|
||||||
static void MVL_dirClose(dvoid *opaque)
|
static void MVL_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
MVLinfo *info = ((MVLinfo *) opaque);
|
MVLinfo *info = ((MVLinfo *) opaque);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* MVL_dirClose */
|
} /* MVL_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ static int MVL_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
MVLfileinfo *finfo = (MVLfileinfo *) opaque;
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* MVL_fileClose */
|
} /* MVL_fileClose */
|
||||||
|
|
||||||
|
@ -223,7 +223,7 @@ static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!mvl_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
BAIL_IF_MACRO(!mvl_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
||||||
info->entryCount = fileCount;
|
info->entryCount = fileCount;
|
||||||
info->entries = (MVLentry *) malloc(sizeof (MVLentry) * fileCount);
|
info->entries = (MVLentry *) allocator.Malloc(sizeof(MVLentry)*fileCount);
|
||||||
if (info->entries == NULL)
|
if (info->entries == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(fh);
|
__PHYSFS_platformClose(fh);
|
||||||
|
@ -262,12 +262,12 @@ static int mvl_load_entries(const char *name, int forWriting, MVLinfo *info)
|
||||||
static void *MVL_openArchive(const char *name, int forWriting)
|
static void *MVL_openArchive(const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
||||||
MVLinfo *info = malloc(sizeof (MVLinfo));
|
MVLinfo *info = (MVLinfo *) allocator.Malloc(sizeof (MVLinfo));
|
||||||
|
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
memset(info, '\0', sizeof (MVLinfo));
|
memset(info, '\0', sizeof (MVLinfo));
|
||||||
|
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MVL_openArchive_failed);
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, MVL_openArchive_failed);
|
||||||
if (!mvl_load_entries(name, forWriting, info))
|
if (!mvl_load_entries(name, forWriting, info))
|
||||||
goto MVL_openArchive_failed;
|
goto MVL_openArchive_failed;
|
||||||
|
@ -280,10 +280,10 @@ MVL_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entries != NULL)
|
if (info->entries != NULL)
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -386,14 +386,14 @@ static fvoid *MVL_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
*fileExists = (entry != NULL);
|
*fileExists = (entry != NULL);
|
||||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||||
|
|
||||||
finfo = (MVLfileinfo *) malloc(sizeof (MVLfileinfo));
|
finfo = (MVLfileinfo *) allocator.Malloc(sizeof (MVLfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if ( (finfo->handle == NULL) ||
|
if ( (finfo->handle == NULL) ||
|
||||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -81,9 +81,9 @@ typedef struct
|
||||||
static void QPAK_dirClose(dvoid *opaque)
|
static void QPAK_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
QPAKinfo *info = ((QPAKinfo *) opaque);
|
QPAKinfo *info = ((QPAKinfo *) opaque);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* QPAK_dirClose */
|
} /* QPAK_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ static int QPAK_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
QPAKfileinfo *finfo = (QPAKfileinfo *) opaque;
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* QPAK_fileClose */
|
} /* QPAK_fileClose */
|
||||||
|
|
||||||
|
@ -245,7 +245,7 @@ static int qpak_load_entries(const char *name, int forWriting, QPAKinfo *info)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
BAIL_IF_MACRO(!qpak_open(name, forWriting, &fh, &fileCount), NULL, 0);
|
||||||
info->entryCount = fileCount;
|
info->entryCount = fileCount;
|
||||||
info->entries = (QPAKentry *) malloc(sizeof (QPAKentry) * fileCount);
|
info->entries = (QPAKentry*) allocator.Malloc(sizeof(QPAKentry)*fileCount);
|
||||||
if (info->entries == NULL)
|
if (info->entries == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(fh);
|
__PHYSFS_platformClose(fh);
|
||||||
|
@ -288,13 +288,13 @@ static int qpak_load_entries(const char *name, int forWriting, QPAKinfo *info)
|
||||||
|
|
||||||
static void *QPAK_openArchive(const char *name, int forWriting)
|
static void *QPAK_openArchive(const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
QPAKinfo *info = malloc(sizeof (QPAKinfo));
|
QPAKinfo *info = (QPAKinfo *) allocator.Malloc(sizeof (QPAKinfo));
|
||||||
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
||||||
|
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
memset(info, '\0', sizeof (QPAKinfo));
|
memset(info, '\0', sizeof (QPAKinfo));
|
||||||
|
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
if (info->filename == NULL)
|
if (info->filename == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
||||||
|
@ -312,10 +312,10 @@ QPAK_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entries != NULL)
|
if (info->entries != NULL)
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -544,14 +544,14 @@ static fvoid *QPAK_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
|
BAIL_IF_MACRO(isDir, ERR_NOT_A_FILE, NULL);
|
||||||
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
|
BAIL_IF_MACRO(entry == NULL, ERR_NO_SUCH_FILE, NULL);
|
||||||
|
|
||||||
finfo = (QPAKfileinfo *) malloc(sizeof (QPAKfileinfo));
|
finfo = (QPAKfileinfo *) allocator.Malloc(sizeof (QPAKfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if ( (finfo->handle == NULL) ||
|
if ( (finfo->handle == NULL) ||
|
||||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -83,9 +83,9 @@ typedef struct
|
||||||
static void WAD_dirClose(dvoid *opaque)
|
static void WAD_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
WADinfo *info = ((WADinfo *) opaque);
|
WADinfo *info = ((WADinfo *) opaque);
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* WAD_dirClose */
|
} /* WAD_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ static int WAD_fileClose(fvoid *opaque)
|
||||||
{
|
{
|
||||||
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
WADfileinfo *finfo = (WADfileinfo *) opaque;
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformClose(finfo->handle), NULL, 0);
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* WAD_fileClose */
|
} /* WAD_fileClose */
|
||||||
|
|
||||||
|
@ -247,7 +247,7 @@ static int wad_load_entries(const char *name, int forWriting, WADinfo *info)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0);
|
BAIL_IF_MACRO(!wad_open(name, forWriting, &fh, &fileCount,&directoryOffset), NULL, 0);
|
||||||
info->entryCount = fileCount;
|
info->entryCount = fileCount;
|
||||||
info->entries = (WADentry *) malloc(sizeof (WADentry) * fileCount);
|
info->entries = (WADentry *) allocator.Malloc(sizeof(WADentry)*fileCount);
|
||||||
if (info->entries == NULL)
|
if (info->entries == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(fh);
|
__PHYSFS_platformClose(fh);
|
||||||
|
@ -292,12 +292,12 @@ static int wad_load_entries(const char *name, int forWriting, WADinfo *info)
|
||||||
static void *WAD_openArchive(const char *name, int forWriting)
|
static void *WAD_openArchive(const char *name, int forWriting)
|
||||||
{
|
{
|
||||||
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
PHYSFS_sint64 modtime = __PHYSFS_platformGetLastModTime(name);
|
||||||
WADinfo *info = malloc(sizeof (WADinfo));
|
WADinfo *info = (WADinfo *) allocator.Malloc(sizeof (WADinfo));
|
||||||
|
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
memset(info, '\0', sizeof (WADinfo));
|
memset(info, '\0', sizeof (WADinfo));
|
||||||
|
|
||||||
info->filename = (char *) malloc(strlen(name) + 1);
|
info->filename = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, WAD_openArchive_failed);
|
GOTO_IF_MACRO(!info->filename, ERR_OUT_OF_MEMORY, WAD_openArchive_failed);
|
||||||
|
|
||||||
if (!wad_load_entries(name, forWriting, info))
|
if (!wad_load_entries(name, forWriting, info))
|
||||||
|
@ -311,10 +311,10 @@ WAD_openArchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->filename != NULL)
|
if (info->filename != NULL)
|
||||||
free(info->filename);
|
allocator.Free(info->filename);
|
||||||
if (info->entries != NULL)
|
if (info->entries != NULL)
|
||||||
free(info->entries);
|
allocator.Free(info->entries);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -449,14 +449,14 @@ static fvoid *WAD_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
*fileExists = (entry != NULL);
|
*fileExists = (entry != NULL);
|
||||||
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
BAIL_IF_MACRO(entry == NULL, NULL, NULL);
|
||||||
|
|
||||||
finfo = (WADfileinfo *) malloc(sizeof (WADfileinfo));
|
finfo = (WADfileinfo *) allocator.Malloc(sizeof (WADfileinfo));
|
||||||
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(finfo == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
finfo->handle = __PHYSFS_platformOpenRead(info->filename);
|
||||||
if ( (finfo->handle == NULL) ||
|
if ( (finfo->handle == NULL) ||
|
||||||
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
(!__PHYSFS_platformSeek(finfo->handle, entry->startPos)) )
|
||||||
{
|
{
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
|
|
@ -27,8 +27,8 @@
|
||||||
#include "physfs_internal.h"
|
#include "physfs_internal.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A buffer of ZIP_READBUFSIZE is malloc() for each compressed file opened,
|
* A buffer of ZIP_READBUFSIZE is allocated for each compressed file opened,
|
||||||
* and is free()'d when you close the file; compressed data is read into
|
* and is freed when you close the file; compressed data is read into
|
||||||
* this buffer, and then is decompressed into the buffer passed to
|
* this buffer, and then is decompressed into the buffer passed to
|
||||||
* PHYSFS_read().
|
* PHYSFS_read().
|
||||||
*
|
*
|
||||||
|
@ -121,7 +121,7 @@ typedef struct
|
||||||
*/
|
*/
|
||||||
static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
|
static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
return(((PHYSFS_Allocator *) opaque)->malloc(items * size));
|
return(((PHYSFS_Allocator *) opaque)->Malloc(items * size));
|
||||||
} /* zlibPhysfsAlloc */
|
} /* zlibPhysfsAlloc */
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -129,7 +129,7 @@ static voidpf zlibPhysfsAlloc(voidpf opaque, uInt items, uInt size)
|
||||||
*/
|
*/
|
||||||
static void zlibPhysfsFree(voidpf opaque, voidpf address)
|
static void zlibPhysfsFree(voidpf opaque, voidpf address)
|
||||||
{
|
{
|
||||||
((PHYSFS_Allocator *) opaque)->free(address);
|
((PHYSFS_Allocator *) opaque)->Free(address);
|
||||||
} /* zlibPhysfsFree */
|
} /* zlibPhysfsFree */
|
||||||
|
|
||||||
|
|
||||||
|
@ -141,7 +141,7 @@ static void initializeZStream(z_stream *pstr)
|
||||||
memset(pstr, '\0', sizeof (z_stream));
|
memset(pstr, '\0', sizeof (z_stream));
|
||||||
pstr->zalloc = zlibPhysfsAlloc;
|
pstr->zalloc = zlibPhysfsAlloc;
|
||||||
pstr->zfree = zlibPhysfsFree;
|
pstr->zfree = zlibPhysfsFree;
|
||||||
pstr->opaque = __PHYSFS_getAllocator();
|
pstr->opaque = &allocator;
|
||||||
} /* initializeZStream */
|
} /* initializeZStream */
|
||||||
|
|
||||||
|
|
||||||
|
@ -369,9 +369,9 @@ static int ZIP_fileClose(fvoid *opaque)
|
||||||
inflateEnd(&finfo->stream);
|
inflateEnd(&finfo->stream);
|
||||||
|
|
||||||
if (finfo->buffer != NULL)
|
if (finfo->buffer != NULL)
|
||||||
free(finfo->buffer);
|
allocator.Free(finfo->buffer);
|
||||||
|
|
||||||
free(finfo);
|
allocator.Free(finfo);
|
||||||
return(1);
|
return(1);
|
||||||
} /* ZIP_fileClose */
|
} /* ZIP_fileClose */
|
||||||
|
|
||||||
|
@ -388,7 +388,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(void *in, PHYSFS_sint64 *len)
|
||||||
PHYSFS_uint32 extra = 0;
|
PHYSFS_uint32 extra = 0;
|
||||||
|
|
||||||
filelen = __PHYSFS_platformFileLength(in);
|
filelen = __PHYSFS_platformFileLength(in);
|
||||||
BAIL_IF_MACRO(filelen == -1, NULL, 0);
|
BAIL_IF_MACRO(filelen == -1, NULL, 0); /* !!! FIXME: unlocalized string */
|
||||||
BAIL_IF_MACRO(filelen > 0xFFFFFFFF, "ZIP bigger than 2 gigs?!", 0);
|
BAIL_IF_MACRO(filelen > 0xFFFFFFFF, "ZIP bigger than 2 gigs?!", 0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -501,10 +501,10 @@ static void zip_free_entries(ZIPentry *entries, PHYSFS_uint32 max)
|
||||||
{
|
{
|
||||||
ZIPentry *entry = &entries[i];
|
ZIPentry *entry = &entries[i];
|
||||||
if (entry->name != NULL)
|
if (entry->name != NULL)
|
||||||
free(entry->name);
|
allocator.Free(entry->name);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
free(entries);
|
allocator.Free(entries);
|
||||||
} /* zip_free_entries */
|
} /* zip_free_entries */
|
||||||
|
|
||||||
|
|
||||||
|
@ -658,7 +658,7 @@ static ZIPentry *zip_follow_symlink(void *in, ZIPinfo *info, char *path)
|
||||||
} /* else */
|
} /* else */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
free(path);
|
allocator.Free(path);
|
||||||
return(entry);
|
return(entry);
|
||||||
} /* zip_follow_symlink */
|
} /* zip_follow_symlink */
|
||||||
|
|
||||||
|
@ -677,7 +677,7 @@ static int zip_resolve_symlink(void *in, ZIPinfo *info, ZIPentry *entry)
|
||||||
|
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, entry->offset), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, entry->offset), NULL, 0);
|
||||||
|
|
||||||
path = (char *) malloc(size + 1);
|
path = (char *) allocator.Malloc(size + 1);
|
||||||
BAIL_IF_MACRO(path == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(path == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
if (entry->compression_method == COMPMETH_NONE)
|
if (entry->compression_method == COMPMETH_NONE)
|
||||||
|
@ -687,7 +687,7 @@ static int zip_resolve_symlink(void *in, ZIPinfo *info, ZIPentry *entry)
|
||||||
{
|
{
|
||||||
z_stream stream;
|
z_stream stream;
|
||||||
PHYSFS_uint32 compsize = entry->compressed_size;
|
PHYSFS_uint32 compsize = entry->compressed_size;
|
||||||
PHYSFS_uint8 *compressed = (PHYSFS_uint8 *) malloc(compsize);
|
PHYSFS_uint8 *compressed = (PHYSFS_uint8 *) allocator.Malloc(compsize);
|
||||||
if (compressed != NULL)
|
if (compressed != NULL)
|
||||||
{
|
{
|
||||||
if (__PHYSFS_platformRead(in, compressed, compsize, 1) == 1)
|
if (__PHYSFS_platformRead(in, compressed, compsize, 1) == 1)
|
||||||
|
@ -706,12 +706,12 @@ static int zip_resolve_symlink(void *in, ZIPinfo *info, ZIPentry *entry)
|
||||||
rc = ((rc == Z_OK) || (rc == Z_STREAM_END));
|
rc = ((rc == Z_OK) || (rc == Z_STREAM_END));
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
free(compressed);
|
allocator.Free(compressed);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
if (!rc)
|
if (!rc)
|
||||||
free(path);
|
allocator.Free(path);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
path[entry->uncompressed_size] = '\0'; /* null-terminate it. */
|
path[entry->uncompressed_size] = '\0'; /* null-terminate it. */
|
||||||
|
@ -928,7 +928,7 @@ static int zip_load_entry(void *in, ZIPentry *entry, PHYSFS_uint32 ofs_fixup)
|
||||||
entry->resolved = (zip_has_symlink_attr(entry, external_attr)) ?
|
entry->resolved = (zip_has_symlink_attr(entry, external_attr)) ?
|
||||||
ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE;
|
ZIP_UNRESOLVED_SYMLINK : ZIP_UNRESOLVED_FILE;
|
||||||
|
|
||||||
entry->name = (char *) malloc(fnamelen + 1);
|
entry->name = (char *) allocator.Malloc(fnamelen + 1);
|
||||||
BAIL_IF_MACRO(entry->name == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(entry->name == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
if (__PHYSFS_platformRead(in, entry->name, fnamelen, 1) != 1)
|
if (__PHYSFS_platformRead(in, entry->name, fnamelen, 1) != 1)
|
||||||
goto zip_load_entry_puked;
|
goto zip_load_entry_puked;
|
||||||
|
@ -947,7 +947,7 @@ static int zip_load_entry(void *in, ZIPentry *entry, PHYSFS_uint32 ofs_fixup)
|
||||||
return(1); /* success. */
|
return(1); /* success. */
|
||||||
|
|
||||||
zip_load_entry_puked:
|
zip_load_entry_puked:
|
||||||
free(entry->name);
|
allocator.Free(entry->name);
|
||||||
return(0); /* failure. */
|
return(0); /* failure. */
|
||||||
} /* zip_load_entry */
|
} /* zip_load_entry */
|
||||||
|
|
||||||
|
@ -978,7 +978,7 @@ static int zip_load_entries(void *in, ZIPinfo *info,
|
||||||
|
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, central_ofs), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformSeek(in, central_ofs), NULL, 0);
|
||||||
|
|
||||||
info->entries = (ZIPentry *) malloc(sizeof (ZIPentry) * max);
|
info->entries = (ZIPentry *) allocator.Malloc(sizeof (ZIPentry) * max);
|
||||||
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(info->entries == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
|
|
||||||
for (i = 0; i < max; i++)
|
for (i = 0; i < max; i++)
|
||||||
|
@ -1065,14 +1065,14 @@ static int zip_parse_end_of_central_dir(void *in, ZIPinfo *info,
|
||||||
static ZIPinfo *zip_create_zipinfo(const char *name)
|
static ZIPinfo *zip_create_zipinfo(const char *name)
|
||||||
{
|
{
|
||||||
char *ptr;
|
char *ptr;
|
||||||
ZIPinfo *info = (ZIPinfo *) malloc(sizeof (ZIPinfo));
|
ZIPinfo *info = (ZIPinfo *) allocator.Malloc(sizeof (ZIPinfo));
|
||||||
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(info == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
memset(info, '\0', sizeof (ZIPinfo));
|
memset(info, '\0', sizeof (ZIPinfo));
|
||||||
|
|
||||||
ptr = (char *) malloc(strlen(name) + 1);
|
ptr = (char *) allocator.Malloc(strlen(name) + 1);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -1110,8 +1110,8 @@ zip_openarchive_failed:
|
||||||
if (info != NULL)
|
if (info != NULL)
|
||||||
{
|
{
|
||||||
if (info->archiveName != NULL)
|
if (info->archiveName != NULL)
|
||||||
free(info->archiveName);
|
allocator.Free(info->archiveName);
|
||||||
free(info);
|
allocator.Free(info);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (in != NULL)
|
if (in != NULL)
|
||||||
|
@ -1340,7 +1340,7 @@ static fvoid *ZIP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
in = zip_get_file_handle(info->archiveName, info, entry);
|
in = zip_get_file_handle(info->archiveName, info, entry);
|
||||||
BAIL_IF_MACRO(in == NULL, NULL, NULL);
|
BAIL_IF_MACRO(in == NULL, NULL, NULL);
|
||||||
|
|
||||||
finfo = (ZIPfileinfo *) malloc(sizeof (ZIPfileinfo));
|
finfo = (ZIPfileinfo *) allocator.Malloc(sizeof (ZIPfileinfo));
|
||||||
if (finfo == NULL)
|
if (finfo == NULL)
|
||||||
{
|
{
|
||||||
__PHYSFS_platformClose(in);
|
__PHYSFS_platformClose(in);
|
||||||
|
@ -1359,7 +1359,7 @@ static fvoid *ZIP_openRead(dvoid *opaque, const char *fnm, int *fileExists)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
finfo->buffer = (PHYSFS_uint8 *) malloc(ZIP_READBUFSIZE);
|
finfo->buffer = (PHYSFS_uint8 *) allocator.Malloc(ZIP_READBUFSIZE);
|
||||||
if (finfo->buffer == NULL)
|
if (finfo->buffer == NULL)
|
||||||
{
|
{
|
||||||
ZIP_fileClose(finfo);
|
ZIP_fileClose(finfo);
|
||||||
|
@ -1387,8 +1387,8 @@ static void ZIP_dirClose(dvoid *opaque)
|
||||||
{
|
{
|
||||||
ZIPinfo *zi = (ZIPinfo *) (opaque);
|
ZIPinfo *zi = (ZIPinfo *) (opaque);
|
||||||
zip_free_entries(zi->entries, zi->entryCount);
|
zip_free_entries(zi->entries, zi->entryCount);
|
||||||
free(zi->archiveName);
|
allocator.Free(zi->archiveName);
|
||||||
free(zi);
|
allocator.Free(zi);
|
||||||
} /* ZIP_dirClose */
|
} /* ZIP_dirClose */
|
||||||
|
|
||||||
|
|
||||||
|
|
120
physfs.c
120
physfs.c
|
@ -180,7 +180,7 @@ static void *stateLock = NULL; /* protects other PhysFS static state. */
|
||||||
|
|
||||||
/* allocator ... */
|
/* allocator ... */
|
||||||
static int externalAllocator = 0;
|
static int externalAllocator = 0;
|
||||||
static PHYSFS_Allocator allocator;
|
PHYSFS_Allocator allocator;
|
||||||
|
|
||||||
|
|
||||||
/* functions ... */
|
/* functions ... */
|
||||||
|
@ -201,8 +201,8 @@ static void enumStringListCallback(void *data, const char *str)
|
||||||
if (pecd->errorstr)
|
if (pecd->errorstr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ptr = realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
|
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
|
||||||
newstr = malloc(strlen(str) + 1);
|
newstr = (char *) allocator.Malloc(strlen(str) + 1);
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
pecd->list = (char **) ptr;
|
pecd->list = (char **) ptr;
|
||||||
|
|
||||||
|
@ -224,7 +224,7 @@ static char **doEnumStringList(void (*func)(PHYSFS_StringCallback, void *))
|
||||||
{
|
{
|
||||||
EnumStringListCallbackData ecd;
|
EnumStringListCallbackData ecd;
|
||||||
memset(&ecd, '\0', sizeof (ecd));
|
memset(&ecd, '\0', sizeof (ecd));
|
||||||
ecd.list = (char **) malloc(sizeof (char *));
|
ecd.list = (char **) allocator.Malloc(sizeof (char *));
|
||||||
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
func(enumStringListCallback, &ecd);
|
func(enumStringListCallback, &ecd);
|
||||||
BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL);
|
BAIL_IF_MACRO(ecd.errorstr != NULL, ecd.errorstr, NULL);
|
||||||
|
@ -345,7 +345,7 @@ void __PHYSFS_setError(const char *str)
|
||||||
|
|
||||||
if (err == NULL)
|
if (err == NULL)
|
||||||
{
|
{
|
||||||
err = (ErrMsg *) malloc(sizeof (ErrMsg));
|
err = (ErrMsg *) allocator.Malloc(sizeof (ErrMsg));
|
||||||
if (err == NULL)
|
if (err == NULL)
|
||||||
return; /* uhh...? */
|
return; /* uhh...? */
|
||||||
|
|
||||||
|
@ -389,7 +389,7 @@ static void freeErrorMessages(void)
|
||||||
for (i = errorMessages; i != NULL; i = next)
|
for (i = errorMessages; i != NULL; i = next)
|
||||||
{
|
{
|
||||||
next = i->next;
|
next = i->next;
|
||||||
free(i);
|
allocator.Free(i);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
errorMessages = NULL;
|
errorMessages = NULL;
|
||||||
|
@ -435,7 +435,7 @@ static DirHandle *tryOpenDir(const PHYSFS_Archiver *funcs,
|
||||||
void *opaque = funcs->openArchive(d, forWriting);
|
void *opaque = funcs->openArchive(d, forWriting);
|
||||||
if (opaque != NULL)
|
if (opaque != NULL)
|
||||||
{
|
{
|
||||||
retval = (DirHandle *) allocator.malloc(sizeof (DirHandle));
|
retval = (DirHandle *) allocator.Malloc(sizeof (DirHandle));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
funcs->dirClose(opaque);
|
funcs->dirClose(opaque);
|
||||||
else
|
else
|
||||||
|
@ -592,13 +592,13 @@ static DirHandle *createDirHandle(const char *newDir,
|
||||||
dirHandle = openDirectory(newDir, forWriting);
|
dirHandle = openDirectory(newDir, forWriting);
|
||||||
GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle);
|
GOTO_IF_MACRO(!dirHandle, NULL, badDirHandle);
|
||||||
|
|
||||||
dirHandle->dirName = (char *) malloc(strlen(newDir) + 1);
|
dirHandle->dirName = (char *) allocator.Malloc(strlen(newDir) + 1);
|
||||||
GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle);
|
GOTO_IF_MACRO(!dirHandle->dirName, ERR_OUT_OF_MEMORY, badDirHandle);
|
||||||
strcpy(dirHandle->dirName, newDir);
|
strcpy(dirHandle->dirName, newDir);
|
||||||
|
|
||||||
if ((mountPoint != NULL) && (*mountPoint != '\0'))
|
if ((mountPoint != NULL) && (*mountPoint != '\0'))
|
||||||
{
|
{
|
||||||
dirHandle->mountPoint = (char *) malloc(strlen(mountPoint) + 2);
|
dirHandle->mountPoint = (char *)allocator.Malloc(strlen(mountPoint)+2);
|
||||||
GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle);
|
GOTO_IF_MACRO(!dirHandle->mountPoint, ERR_OUT_OF_MEMORY, badDirHandle);
|
||||||
strcpy(dirHandle->mountPoint, mountPoint);
|
strcpy(dirHandle->mountPoint, mountPoint);
|
||||||
strcat(dirHandle->mountPoint, "/");
|
strcat(dirHandle->mountPoint, "/");
|
||||||
|
@ -610,9 +610,9 @@ badDirHandle:
|
||||||
if (dirHandle != NULL)
|
if (dirHandle != NULL)
|
||||||
{
|
{
|
||||||
dirHandle->funcs->dirClose(dirHandle->opaque);
|
dirHandle->funcs->dirClose(dirHandle->opaque);
|
||||||
free(dirHandle->dirName);
|
allocator.Free(dirHandle->dirName);
|
||||||
free(dirHandle->mountPoint);
|
allocator.Free(dirHandle->mountPoint);
|
||||||
free(dirHandle);
|
allocator.Free(dirHandle);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -631,9 +631,9 @@ static int freeDirHandle(DirHandle *dh, FileHandle *openList)
|
||||||
BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0);
|
BAIL_IF_MACRO(i->dirHandle == dh, ERR_FILES_STILL_OPEN, 0);
|
||||||
|
|
||||||
dh->funcs->dirClose(dh->opaque);
|
dh->funcs->dirClose(dh->opaque);
|
||||||
free(dh->dirName);
|
allocator.Free(dh->dirName);
|
||||||
free(dh->mountPoint);
|
allocator.Free(dh->mountPoint);
|
||||||
free(dh);
|
allocator.Free(dh);
|
||||||
return(1);
|
return(1);
|
||||||
} /* freeDirHandle */
|
} /* freeDirHandle */
|
||||||
|
|
||||||
|
@ -652,8 +652,8 @@ static char *calculateUserDir(void)
|
||||||
const char *uname = __PHYSFS_platformGetUserName();
|
const char *uname = __PHYSFS_platformGetUserName();
|
||||||
|
|
||||||
str = (uname != NULL) ? uname : "default";
|
str = (uname != NULL) ? uname : "default";
|
||||||
retval = (char *) malloc(strlen(baseDir) + strlen(str) +
|
retval = (char *) allocator.Malloc(strlen(baseDir) + strlen(str) +
|
||||||
strlen(dirsep) + 6);
|
strlen(dirsep) + 6);
|
||||||
|
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
__PHYSFS_setError(ERR_OUT_OF_MEMORY);
|
||||||
|
@ -661,7 +661,7 @@ static char *calculateUserDir(void)
|
||||||
sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
|
sprintf(retval, "%susers%s%s", baseDir, dirsep, str);
|
||||||
|
|
||||||
if (uname != NULL)
|
if (uname != NULL)
|
||||||
free((void *) uname);
|
allocator.Free((void *) uname);
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
return(retval);
|
return(retval);
|
||||||
|
@ -676,10 +676,10 @@ static int appendDirSep(char **dir)
|
||||||
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
|
if (strcmp((*dir + strlen(*dir)) - strlen(dirsep), dirsep) == 0)
|
||||||
return(1);
|
return(1);
|
||||||
|
|
||||||
ptr = realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
|
ptr = (char *) allocator.Realloc(*dir, strlen(*dir) + strlen(dirsep) + 1);
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
{
|
{
|
||||||
free(*dir);
|
allocator.Free(*dir);
|
||||||
return(0);
|
return(0);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -717,7 +717,7 @@ static char *calculateBaseDir(const char *argv0)
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
size = (size_t) (ptr - argv0);
|
size = (size_t) (ptr - argv0);
|
||||||
retval = (char *) malloc(size + 1);
|
retval = (char *) allocator.Malloc(size + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
memcpy(retval, argv0, size);
|
memcpy(retval, argv0, size);
|
||||||
retval[size] = '\0';
|
retval[size] = '\0';
|
||||||
|
@ -736,7 +736,7 @@ static char *calculateBaseDir(const char *argv0)
|
||||||
* Not a good alternative, but it only happens if the current
|
* Not a good alternative, but it only happens if the current
|
||||||
* directory was deleted from under the program.
|
* directory was deleted from under the program.
|
||||||
*/
|
*/
|
||||||
retval = (char *) malloc(strlen(dirsep) + 1);
|
retval = (char *) allocator.Malloc(strlen(dirsep) + 1);
|
||||||
strcpy(retval, dirsep);
|
strcpy(retval, dirsep);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* calculateBaseDir */
|
} /* calculateBaseDir */
|
||||||
|
@ -777,7 +777,7 @@ int PHYSFS_init(const char *argv0)
|
||||||
if (!externalAllocator)
|
if (!externalAllocator)
|
||||||
setDefaultAllocator();
|
setDefaultAllocator();
|
||||||
|
|
||||||
BAIL_IF_MACRO(!allocator.init(), NULL, 0);
|
BAIL_IF_MACRO(!allocator.Init(), NULL, 0);
|
||||||
|
|
||||||
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
|
BAIL_IF_MACRO(!__PHYSFS_platformInit(), NULL, 0);
|
||||||
|
|
||||||
|
@ -787,7 +787,7 @@ int PHYSFS_init(const char *argv0)
|
||||||
BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
|
BAIL_IF_MACRO(baseDir == NULL, NULL, 0);
|
||||||
|
|
||||||
ptr = __PHYSFS_platformRealPath(baseDir);
|
ptr = __PHYSFS_platformRealPath(baseDir);
|
||||||
free(baseDir);
|
allocator.Free(baseDir);
|
||||||
BAIL_IF_MACRO(ptr == NULL, NULL, 0);
|
BAIL_IF_MACRO(ptr == NULL, NULL, 0);
|
||||||
baseDir = ptr;
|
baseDir = ptr;
|
||||||
|
|
||||||
|
@ -797,13 +797,13 @@ int PHYSFS_init(const char *argv0)
|
||||||
if (userDir != NULL)
|
if (userDir != NULL)
|
||||||
{
|
{
|
||||||
ptr = __PHYSFS_platformRealPath(userDir);
|
ptr = __PHYSFS_platformRealPath(userDir);
|
||||||
free(userDir);
|
allocator.Free(userDir);
|
||||||
userDir = ptr;
|
userDir = ptr;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if ((userDir == NULL) || (!appendDirSep(&userDir)))
|
if ((userDir == NULL) || (!appendDirSep(&userDir)))
|
||||||
{
|
{
|
||||||
free(baseDir);
|
allocator.Free(baseDir);
|
||||||
baseDir = NULL;
|
baseDir = NULL;
|
||||||
return(0);
|
return(0);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -832,7 +832,7 @@ static int closeFileHandleList(FileHandle **list)
|
||||||
return(0);
|
return(0);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
free(i);
|
allocator.Free(i);
|
||||||
} /* for */
|
} /* for */
|
||||||
|
|
||||||
*list = NULL;
|
*list = NULL;
|
||||||
|
@ -873,13 +873,13 @@ int PHYSFS_deinit(void)
|
||||||
|
|
||||||
if (baseDir != NULL)
|
if (baseDir != NULL)
|
||||||
{
|
{
|
||||||
free(baseDir);
|
allocator.Free(baseDir);
|
||||||
baseDir = NULL;
|
baseDir = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
if (userDir != NULL)
|
if (userDir != NULL)
|
||||||
{
|
{
|
||||||
free(userDir);
|
allocator.Free(userDir);
|
||||||
userDir = NULL;
|
userDir = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -889,7 +889,7 @@ int PHYSFS_deinit(void)
|
||||||
__PHYSFS_platformDestroyMutex(errorLock);
|
__PHYSFS_platformDestroyMutex(errorLock);
|
||||||
__PHYSFS_platformDestroyMutex(stateLock);
|
__PHYSFS_platformDestroyMutex(stateLock);
|
||||||
|
|
||||||
allocator.deinit();
|
allocator.Deinit();
|
||||||
|
|
||||||
errorLock = stateLock = NULL;
|
errorLock = stateLock = NULL;
|
||||||
return(1);
|
return(1);
|
||||||
|
@ -906,9 +906,9 @@ void PHYSFS_freeList(void *list)
|
||||||
{
|
{
|
||||||
void **i;
|
void **i;
|
||||||
for (i = (void **) list; *i != NULL; i++)
|
for (i = (void **) list; *i != NULL; i++)
|
||||||
free(*i);
|
allocator.Free(*i);
|
||||||
|
|
||||||
free(list);
|
allocator.Free(list);
|
||||||
} /* PHYSFS_freeList */
|
} /* PHYSFS_freeList */
|
||||||
|
|
||||||
|
|
||||||
|
@ -1106,8 +1106,10 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
|
||||||
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
|
BAIL_IF_MACRO(!initialized, ERR_NOT_INITIALIZED, 0);
|
||||||
|
|
||||||
/* set write dir... */
|
/* set write dir... */
|
||||||
str = malloc(strlen(userdir) + (strlen(organization) * 2) +
|
str = (char *) allocator.Malloc(
|
||||||
(strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
|
strlen(userdir) + (strlen(organization) * 2) +
|
||||||
|
(strlen(appName) * 2) + (strlen(dirsep) * 3) + 2);
|
||||||
|
|
||||||
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
|
sprintf(str, "%s.%s%s%s", userdir, organization, dirsep, appName);
|
||||||
|
|
||||||
|
@ -1130,14 +1132,14 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
|
||||||
if (no_write)
|
if (no_write)
|
||||||
{
|
{
|
||||||
PHYSFS_setWriteDir(NULL); /* just in case. */
|
PHYSFS_setWriteDir(NULL); /* just in case. */
|
||||||
free(str);
|
allocator.Free(str);
|
||||||
BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0);
|
BAIL_MACRO(ERR_CANT_SET_WRITE_DIR, 0);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* Put write dir first in search path... */
|
/* Put write dir first in search path... */
|
||||||
PHYSFS_addToSearchPath(str, 0);
|
PHYSFS_addToSearchPath(str, 0);
|
||||||
free(str);
|
allocator.Free(str);
|
||||||
|
|
||||||
/* Put base path on search path... */
|
/* Put base path on search path... */
|
||||||
PHYSFS_addToSearchPath(basedir, 1);
|
PHYSFS_addToSearchPath(basedir, 1);
|
||||||
|
@ -1170,12 +1172,13 @@ int PHYSFS_setSaneConfig(const char *organization, const char *appName,
|
||||||
if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
|
if (__PHYSFS_platformStricmp(ext, archiveExt) == 0)
|
||||||
{
|
{
|
||||||
const char *d = PHYSFS_getRealDir(*i);
|
const char *d = PHYSFS_getRealDir(*i);
|
||||||
str = malloc(strlen(d) + strlen(dirsep) + l + 1);
|
size_t allocsize = strlen(d) + strlen(dirsep) + l + 1;
|
||||||
|
str = (char *) allocator.Malloc(allocsize);
|
||||||
if (str != NULL)
|
if (str != NULL)
|
||||||
{
|
{
|
||||||
sprintf(str, "%s%s%s", d, dirsep, *i);
|
sprintf(str, "%s%s%s", d, dirsep, *i);
|
||||||
PHYSFS_addToSearchPath(str, archivesFirst == 0);
|
PHYSFS_addToSearchPath(str, archivesFirst == 0);
|
||||||
free(str);
|
allocator.Free(str);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -1195,9 +1198,9 @@ void PHYSFS_permitSymbolicLinks(int allow)
|
||||||
|
|
||||||
|
|
||||||
/* string manipulation in C makes my ass itch. */
|
/* string manipulation in C makes my ass itch. */
|
||||||
char * __PHYSFS_convertToDependent(const char *prepend,
|
char *__PHYSFS_convertToDependent(const char *prepend,
|
||||||
const char *dirName,
|
const char *dirName,
|
||||||
const char *append)
|
const char *append)
|
||||||
{
|
{
|
||||||
const char *dirsep = __PHYSFS_platformDirSeparator;
|
const char *dirsep = __PHYSFS_platformDirSeparator;
|
||||||
size_t sepsize = strlen(dirsep);
|
size_t sepsize = strlen(dirsep);
|
||||||
|
@ -1206,7 +1209,7 @@ char * __PHYSFS_convertToDependent(const char *prepend,
|
||||||
char *i2;
|
char *i2;
|
||||||
size_t allocSize;
|
size_t allocSize;
|
||||||
|
|
||||||
while (*dirName == '/')
|
while (*dirName == '/') /* !!! FIXME: pass through sanitize function. */
|
||||||
dirName++;
|
dirName++;
|
||||||
|
|
||||||
allocSize = strlen(dirName) + 1;
|
allocSize = strlen(dirName) + 1;
|
||||||
|
@ -1230,7 +1233,7 @@ char * __PHYSFS_convertToDependent(const char *prepend,
|
||||||
} while (str != NULL);
|
} while (str != NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
str = (char *) malloc(allocSize);
|
str = (char *) allocator.Malloc(allocSize);
|
||||||
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(str == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
if (prepend == NULL)
|
if (prepend == NULL)
|
||||||
|
@ -1504,8 +1507,8 @@ static void enumFilesCallback(void *data, const char *str)
|
||||||
return; /* already in the list. */
|
return; /* already in the list. */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
ptr = realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
|
ptr = allocator.Realloc(pecd->list, (pecd->size + 2) * sizeof (char *));
|
||||||
newstr = malloc(strlen(str) + 1);
|
newstr = (char *) allocator.Malloc(strlen(str) + 1);
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
pecd->list = (char **) ptr;
|
pecd->list = (char **) ptr;
|
||||||
|
|
||||||
|
@ -1529,7 +1532,7 @@ char **PHYSFS_enumerateFiles(const char *path)
|
||||||
{
|
{
|
||||||
EnumStringListCallbackData ecd;
|
EnumStringListCallbackData ecd;
|
||||||
memset(&ecd, '\0', sizeof (ecd));
|
memset(&ecd, '\0', sizeof (ecd));
|
||||||
ecd.list = (char **) malloc(sizeof (char *));
|
ecd.list = (char **) allocator.Malloc(sizeof (char *));
|
||||||
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(ecd.list == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
PHYSFS_enumerateFilesCallback(path, enumFilesCallback, &ecd);
|
PHYSFS_enumerateFilesCallback(path, enumFilesCallback, &ecd);
|
||||||
ecd.list[ecd.size] = NULL;
|
ecd.list[ecd.size] = NULL;
|
||||||
|
@ -1690,7 +1693,7 @@ static PHYSFS_File *doOpenWrite(const char *_fname, int appending)
|
||||||
|
|
||||||
BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
|
BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
|
||||||
|
|
||||||
fh = (FileHandle *) malloc(sizeof (FileHandle));
|
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
||||||
if (fh == NULL)
|
if (fh == NULL)
|
||||||
{
|
{
|
||||||
f->fileClose(opaque);
|
f->fileClose(opaque);
|
||||||
|
@ -1736,7 +1739,7 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname)
|
||||||
|
|
||||||
__PHYSFS_platformGrabMutex(stateLock);
|
__PHYSFS_platformGrabMutex(stateLock);
|
||||||
|
|
||||||
BAIL_IF_MACRO_MUTEX(!searchPath, ERR_PATH_NOT_FOUND, stateLock, NULL);
|
BAIL_IF_MACRO_MUTEX(!searchPath, ERR_NO_SUCH_PATH, stateLock, NULL);
|
||||||
|
|
||||||
/* !!! FIXME: Why aren't we using a for loop here? */
|
/* !!! FIXME: Why aren't we using a for loop here? */
|
||||||
i = searchPath;
|
i = searchPath;
|
||||||
|
@ -1755,7 +1758,7 @@ PHYSFS_File *PHYSFS_openRead(const char *_fname)
|
||||||
|
|
||||||
BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
|
BAIL_IF_MACRO_MUTEX(opaque == NULL, NULL, stateLock, NULL);
|
||||||
|
|
||||||
fh = (FileHandle *) malloc(sizeof (FileHandle));
|
fh = (FileHandle *) allocator.Malloc(sizeof (FileHandle));
|
||||||
if (fh == NULL)
|
if (fh == NULL)
|
||||||
{
|
{
|
||||||
i->funcs->fileClose(opaque);
|
i->funcs->fileClose(opaque);
|
||||||
|
@ -1793,14 +1796,14 @@ static int closeHandleInOpenList(FileHandle **list, FileHandle *handle)
|
||||||
return(-1);
|
return(-1);
|
||||||
|
|
||||||
if (tmp != NULL) /* free any associated buffer. */
|
if (tmp != NULL) /* free any associated buffer. */
|
||||||
free(tmp);
|
allocator.Free(tmp);
|
||||||
|
|
||||||
if (prev == NULL)
|
if (prev == NULL)
|
||||||
*list = handle->next;
|
*list = handle->next;
|
||||||
else
|
else
|
||||||
prev->next = handle->next;
|
prev->next = handle->next;
|
||||||
|
|
||||||
free(handle);
|
allocator.Free(handle);
|
||||||
return(1);
|
return(1);
|
||||||
} /* if */
|
} /* if */
|
||||||
prev = i;
|
prev = i;
|
||||||
|
@ -2005,14 +2008,15 @@ int PHYSFS_setBuffer(PHYSFS_File *handle, PHYSFS_uint64 _bufsize)
|
||||||
{
|
{
|
||||||
if (fh->buffer != NULL)
|
if (fh->buffer != NULL)
|
||||||
{
|
{
|
||||||
free(fh->buffer);
|
allocator.Free(fh->buffer);
|
||||||
fh->buffer = NULL;
|
fh->buffer = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
PHYSFS_uint8 *newbuf = realloc(fh->buffer, bufsize);
|
PHYSFS_uint8 *newbuf;
|
||||||
|
newbuf = (PHYSFS_uint8 *) allocator.Realloc(fh->buffer, bufsize);
|
||||||
BAIL_IF_MACRO(newbuf == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(newbuf == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
fh->buffer = newbuf;
|
fh->buffer = newbuf;
|
||||||
} /* else */
|
} /* else */
|
||||||
|
@ -2054,11 +2058,11 @@ int PHYSFS_setAllocator(PHYSFS_Allocator *a)
|
||||||
static void setDefaultAllocator(void)
|
static void setDefaultAllocator(void)
|
||||||
{
|
{
|
||||||
assert(!externalAllocator);
|
assert(!externalAllocator);
|
||||||
allocator.init = __PHYSFS_platformAllocatorInit;
|
allocator.Init = __PHYSFS_platformAllocatorInit;
|
||||||
allocator.deinit = __PHYSFS_platformAllocatorDeinit;
|
allocator.Deinit = __PHYSFS_platformAllocatorDeinit;
|
||||||
allocator.malloc = __PHYSFS_platformAllocatorMalloc;
|
allocator.Malloc = __PHYSFS_platformAllocatorMalloc;
|
||||||
allocator.realloc = __PHYSFS_platformAllocatorRealloc;
|
allocator.Realloc = __PHYSFS_platformAllocatorRealloc;
|
||||||
allocator.free = __PHYSFS_platformAllocatorFree;
|
allocator.Free = __PHYSFS_platformAllocatorFree;
|
||||||
} /* setDefaultAllocator */
|
} /* setDefaultAllocator */
|
||||||
|
|
||||||
|
|
||||||
|
|
12
physfs.h
12
physfs.h
|
@ -1861,11 +1861,11 @@ __EXPORT__ int PHYSFS_writeUBE64(PHYSFS_File *file, PHYSFS_uint64 val);
|
||||||
*/
|
*/
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int (*init)(void);
|
int (*Init)(void);
|
||||||
void (*deinit)(void);
|
void (*Deinit)(void);
|
||||||
void *(*malloc)(size_t);
|
void *(*Malloc)(size_t);
|
||||||
void *(*realloc)(void *, size_t);
|
void *(*Realloc)(void *, size_t);
|
||||||
void (*free)(void *);
|
void (*Free)(void *);
|
||||||
} PHYSFS_Allocator;
|
} PHYSFS_Allocator;
|
||||||
|
|
||||||
|
|
||||||
|
@ -1876,6 +1876,8 @@ typedef struct
|
||||||
* (This is for limited, hardcore use. If you don't immediately see a need
|
* (This is for limited, hardcore use. If you don't immediately see a need
|
||||||
* for it, you can probably ignore this forever.)
|
* for it, you can probably ignore this forever.)
|
||||||
*
|
*
|
||||||
|
* !!! FIXME: don't promise C runtime malloc.
|
||||||
|
*
|
||||||
* By default, PhysicsFS will use ANSI C malloc/realloc/calloc/free calls
|
* By default, PhysicsFS will use ANSI C malloc/realloc/calloc/free calls
|
||||||
* to manage dynamic memory, but in some uncommon cases, the app might want
|
* to manage dynamic memory, but in some uncommon cases, the app might want
|
||||||
* more control over the library's memory management. This lets you redirect
|
* more control over the library's memory management. This lets you redirect
|
||||||
|
|
|
@ -26,6 +26,11 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* Use the allocation hooks. */
|
||||||
|
#define malloc(x) Do not use malloc() directly.
|
||||||
|
#define realloc(x, y) Do not use realloc() directly.
|
||||||
|
#define free(x) Do not use free() directly.
|
||||||
|
|
||||||
|
|
||||||
/* The LANG section. */
|
/* The LANG section. */
|
||||||
/* please send questions/translations to Ryan: icculus@clutteredmind.org. */
|
/* please send questions/translations to Ryan: icculus@clutteredmind.org. */
|
||||||
|
@ -1241,10 +1246,12 @@ void __PHYSFS_sort(void *entries, PHYSFS_uint32 max,
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Get the current allocator. Not valid before PHYSFS_init is called!
|
* The current allocator. Not valid before PHYSFS_init is called!
|
||||||
*/
|
*/
|
||||||
PHYSFS_Allocator *__PHYSFS_getAllocator(void);
|
extern PHYSFS_Allocator __PHYSFS_AllocatorHooks;
|
||||||
|
|
||||||
|
/* convenience macro to make this less cumbersome internally... */
|
||||||
|
#define allocator __PHYSFS_AllocatorHooks
|
||||||
|
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
/*--------------------------------------------------------------------------*/
|
/*--------------------------------------------------------------------------*/
|
||||||
|
|
|
@ -19,6 +19,7 @@ EXTRA_DIST = \
|
||||||
skeleton.c \
|
skeleton.c \
|
||||||
macclassic.c \
|
macclassic.c \
|
||||||
win32.c \
|
win32.c \
|
||||||
|
pocketpc.c \
|
||||||
unix.c \
|
unix.c \
|
||||||
os2.c \
|
os2.c \
|
||||||
beos.cpp
|
beos.cpp
|
||||||
|
|
|
@ -241,7 +241,7 @@ static char *convFSSpecToPath(FSSpec *spec, int includeFile)
|
||||||
if (oserr(PBGetCatInfoSync(&infoPB)) != noErr)
|
if (oserr(PBGetCatInfoSync(&infoPB)) != noErr)
|
||||||
{
|
{
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -249,11 +249,11 @@ static char *convFSSpecToPath(FSSpec *spec, int includeFile)
|
||||||
|
|
||||||
/* allocate more space for the retval... */
|
/* allocate more space for the retval... */
|
||||||
retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
|
retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
|
||||||
ptr = (char *) malloc(retLength);
|
ptr = (char *) allocator.Malloc(retLength);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -264,7 +264,7 @@ static char *convFSSpecToPath(FSSpec *spec, int includeFile)
|
||||||
{
|
{
|
||||||
strcat(ptr, ":");
|
strcat(ptr, ":");
|
||||||
strcat(ptr, retval);
|
strcat(ptr, retval);
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
} /* if */
|
} /* if */
|
||||||
retval = ptr;
|
retval = ptr;
|
||||||
} while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
|
} while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
|
||||||
|
@ -297,7 +297,7 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
|
BAIL_IF_MACRO(strHandle == NULL, NULL, NULL);
|
||||||
|
|
||||||
HLock((Handle) strHandle);
|
HLock((Handle) strHandle);
|
||||||
retval = (char *) malloc((*strHandle)[0] + 1);
|
retval = (char *) allocator.Malloc((*strHandle)[0] + 1);
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
HUnlock((Handle) strHandle);
|
HUnlock((Handle) strHandle);
|
||||||
|
@ -533,7 +533,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
strlen(dirName) + 1;
|
strlen(dirName) + 1;
|
||||||
const char *src;
|
const char *src;
|
||||||
char *dst;
|
char *dst;
|
||||||
char *retval = malloc(len);
|
char *retval = (char *) allocator.Malloc(len);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
if (prepend != NULL)
|
if (prepend != NULL)
|
||||||
|
@ -691,7 +691,7 @@ static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
|
||||||
created = 1;
|
created = 1;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
retval = (SInt16 *) malloc(sizeof (SInt16));
|
retval = (SInt16 *) allocator.Malloc(sizeof (SInt16));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
if (created)
|
if (created)
|
||||||
|
@ -702,7 +702,7 @@ static SInt16 *macDoOpen(const char *fname, SInt8 perm, int createIfMissing)
|
||||||
err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
|
err = HOpenDF(spec.vRefNum, spec.parID, spec.name, perm, retval);
|
||||||
if (oserr(err) != noErr)
|
if (oserr(err) != noErr)
|
||||||
{
|
{
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
if (created)
|
if (created)
|
||||||
HDelete(spec.vRefNum, spec.parID, spec.name);
|
HDelete(spec.vRefNum, spec.parID, spec.name);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -866,7 +866,7 @@ int __PHYSFS_platformClose(void *opaque)
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
|
BAIL_IF_MACRO(oserr(FSClose(ref)) != noErr, NULL, 0);
|
||||||
free(opaque);
|
allocator.Free(opaque);
|
||||||
|
|
||||||
if (flushVol)
|
if (flushVol)
|
||||||
FlushVol(volName, vRefNum); /* update catalog info, etc. */
|
FlushVol(volName, vRefNum); /* update catalog info, etc. */
|
||||||
|
@ -936,5 +936,39 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
||||||
return((PHYSFS_sint64) modDate);
|
return((PHYSFS_sint64) modDate);
|
||||||
} /* __PHYSFS_platformGetLastModTime */
|
} /* __PHYSFS_platformGetLastModTime */
|
||||||
|
|
||||||
|
|
||||||
|
/* !!! FIXME: Don't use C runtime for allocators? */
|
||||||
|
int __PHYSFS_platformAllocatorInit(void)
|
||||||
|
{
|
||||||
|
return(1); /* always succeeds. */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorDeinit(void)
|
||||||
|
{
|
||||||
|
/* no-op */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
||||||
|
{
|
||||||
|
#undef malloc
|
||||||
|
return(malloc(s));
|
||||||
|
} /* __PHYSFS_platformMalloc */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
||||||
|
{
|
||||||
|
#undef realloc
|
||||||
|
return(realloc(ptr, s));
|
||||||
|
} /* __PHYSFS_platformRealloc */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorFree(void *ptr)
|
||||||
|
{
|
||||||
|
#undef free
|
||||||
|
free(ptr);
|
||||||
|
} /* __PHYSFS_platformAllocatorFree */
|
||||||
|
|
||||||
/* end of macclassic.c ... */
|
/* end of macclassic.c ... */
|
||||||
|
|
||||||
|
|
|
@ -199,7 +199,7 @@ int __PHYSFS_platformInit(void)
|
||||||
/* The string is capitalized! Figure out the REAL case... */
|
/* The string is capitalized! Figure out the REAL case... */
|
||||||
cvt_path_to_correct_case(buf);
|
cvt_path_to_correct_case(buf);
|
||||||
|
|
||||||
baseDir = (char *) malloc(len + 1);
|
baseDir = (char *) allocator.Malloc(len + 1);
|
||||||
BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
|
BAIL_IF_MACRO(baseDir == NULL, ERR_OUT_OF_MEMORY, 0);
|
||||||
strcpy(baseDir, buf);
|
strcpy(baseDir, buf);
|
||||||
return(1); /* success. */
|
return(1); /* success. */
|
||||||
|
@ -209,7 +209,7 @@ int __PHYSFS_platformInit(void)
|
||||||
int __PHYSFS_platformDeinit(void)
|
int __PHYSFS_platformDeinit(void)
|
||||||
{
|
{
|
||||||
assert(baseDir != NULL);
|
assert(baseDir != NULL);
|
||||||
free(baseDir);
|
allocator.Free(baseDir);
|
||||||
baseDir = NULL;
|
baseDir = NULL;
|
||||||
return(1); /* success. */
|
return(1); /* success. */
|
||||||
} /* __PHYSFS_platformDeinit */
|
} /* __PHYSFS_platformDeinit */
|
||||||
|
@ -279,7 +279,7 @@ void __PHYSFS_platformDetectAvailableCDs(PHYSFS_StringCallback cb, void *data)
|
||||||
|
|
||||||
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
{
|
{
|
||||||
char *retval = (char *) malloc(strlen(baseDir) + 1);
|
char *retval = (char *) allocator.Malloc(strlen(baseDir) + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
strcpy(retval, baseDir); /* calculated at init time. */
|
strcpy(retval, baseDir); /* calculated at init time. */
|
||||||
return(retval);
|
return(retval);
|
||||||
|
@ -365,6 +365,7 @@ int __PHYSFS_platformIsDirectory(const char *fname)
|
||||||
} /* __PHYSFS_platformIsDirectory */
|
} /* __PHYSFS_platformIsDirectory */
|
||||||
|
|
||||||
|
|
||||||
|
/* !!! FIXME: can we lose the malloc here? */
|
||||||
char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
const char *dirName,
|
const char *dirName,
|
||||||
const char *append)
|
const char *append)
|
||||||
|
@ -372,7 +373,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
int len = ((prepend) ? strlen(prepend) : 0) +
|
int len = ((prepend) ? strlen(prepend) : 0) +
|
||||||
((append) ? strlen(append) : 0) +
|
((append) ? strlen(append) : 0) +
|
||||||
strlen(dirName) + 1;
|
strlen(dirName) + 1;
|
||||||
char *retval = malloc(len);
|
char *retval = allocator.Malloc(len);
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
@ -441,14 +442,14 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
/* The first call just tells us how much space we need for the string. */
|
/* The first call just tells us how much space we need for the string. */
|
||||||
rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
|
rc = DosQueryCurrentDir(currentDisk, &byte, &pathSize);
|
||||||
pathSize++; /* Add space for null terminator. */
|
pathSize++; /* Add space for null terminator. */
|
||||||
retval = (char *) malloc(pathSize + 3); /* plus "x:\\" */
|
retval = (char *) allocator.Malloc(pathSize + 3); /* plus "x:\\" */
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
/* Actually get the string this time. */
|
/* Actually get the string this time. */
|
||||||
rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
|
rc = DosQueryCurrentDir(currentDisk, (PBYTE) (retval + 3), &pathSize);
|
||||||
if (os2err(rc) != NO_ERROR)
|
if (os2err(rc) != NO_ERROR)
|
||||||
{
|
{
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -465,7 +466,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
char *retval;
|
char *retval;
|
||||||
APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
|
APIRET rc = DosQueryPathInfo(path, FIL_QUERYFULLNAME, buf, sizeof (buf));
|
||||||
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
|
BAIL_IF_MACRO(os2err(rc) != NO_ERROR, NULL, NULL);
|
||||||
retval = (char *) malloc(strlen(buf) + 1);
|
retval = (char *) allocator.Malloc(strlen(buf) + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
strcpy(retval, buf);
|
strcpy(retval, buf);
|
||||||
return(retval);
|
return(retval);
|
||||||
|
|
|
@ -72,11 +72,11 @@ static char *UnicodeToAsc(const wchar_t *w_str)
|
||||||
if (w_str != NULL)
|
if (w_str != NULL)
|
||||||
{
|
{
|
||||||
int len = wcslen(w_str) + 1;
|
int len = wcslen(w_str) + 1;
|
||||||
str = (char *) malloc(len);
|
str = (char *) allocator.Malloc(len);
|
||||||
|
|
||||||
if (WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL) == 0)
|
if (WideCharToMultiByte(CP_ACP,0,w_str,-1,str,len,NULL,NULL) == 0)
|
||||||
{ /*Conversion failed */
|
{ /*Conversion failed */
|
||||||
free(str);
|
allocator.Free(str);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
|
@ -98,10 +98,10 @@ static wchar_t *AscToUnicode(const char *str)
|
||||||
if (str != NULL)
|
if (str != NULL)
|
||||||
{
|
{
|
||||||
int len = strlen(str) + 1;
|
int len = strlen(str) + 1;
|
||||||
w_str = (wchar_t *) malloc(sizeof (wchar_t) * len);
|
w_str = (wchar_t *) allocator.Malloc(sizeof (wchar_t) * len);
|
||||||
if (MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len) == 0)
|
if (MultiByteToWideChar(CP_ACP,0,str,-1,w_str,len) == 0)
|
||||||
{
|
{
|
||||||
free(w_str);
|
allocator.Free(w_str);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
|
@ -121,7 +121,7 @@ static char *getExePath()
|
||||||
DWORD buflen;
|
DWORD buflen;
|
||||||
int success = 0;
|
int success = 0;
|
||||||
TCHAR *ptr = NULL;
|
TCHAR *ptr = NULL;
|
||||||
TCHAR *retval = (TCHAR *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
TCHAR *retval = (TCHAR*) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
||||||
char *charretval;
|
char *charretval;
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
|
@ -145,17 +145,17 @@ static char *getExePath()
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
return(NULL); /* physfs error message will be set, above. */
|
return(NULL); /* physfs error message will be set, above. */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* free up the bytes we didn't actually use. */
|
/* free up the bytes we didn't actually use. */
|
||||||
ptr = (TCHAR *) realloc(retval, sizeof(TCHAR) * _tcslen(retval) + 1);
|
ptr = (TCHAR *) allocator.Realloc(retval, sizeof(TCHAR)*_tcslen(retval)+1);
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
retval = ptr;
|
retval = ptr;
|
||||||
|
|
||||||
charretval = UnicodeToAsc(retval);
|
charretval = UnicodeToAsc(retval);
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
if(charretval == NULL) {
|
if(charretval == NULL) {
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ int __PHYSFS_platformInit(void)
|
||||||
|
|
||||||
int __PHYSFS_platformDeinit(void)
|
int __PHYSFS_platformDeinit(void)
|
||||||
{
|
{
|
||||||
free(userDir);
|
allocator.Free(userDir);
|
||||||
return(1); /* always succeed. */
|
return(1); /* always succeed. */
|
||||||
} /* __PHYSFS_platformDeinit */
|
} /* __PHYSFS_platformDeinit */
|
||||||
|
|
||||||
|
@ -230,7 +230,7 @@ int __PHYSFS_platformExists(const char *fname)
|
||||||
if(w_fname!=NULL)
|
if(w_fname!=NULL)
|
||||||
{
|
{
|
||||||
retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
|
retval=(GetFileAttributes(w_fname) != INVALID_FILE_ATTRIBUTES);
|
||||||
free(w_fname);
|
allocator.Free(w_fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(retval);
|
return(retval);
|
||||||
|
@ -252,7 +252,7 @@ int __PHYSFS_platformIsDirectory(const char *fname)
|
||||||
if(w_fname!=NULL)
|
if(w_fname!=NULL)
|
||||||
{
|
{
|
||||||
retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
retval=((GetFileAttributes(w_fname) & FILE_ATTRIBUTE_DIRECTORY) != 0);
|
||||||
free(w_fname);
|
allocator.Free(w_fname);
|
||||||
}
|
}
|
||||||
|
|
||||||
return(retval);
|
return(retval);
|
||||||
|
@ -266,7 +266,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
int len = ((prepend) ? strlen(prepend) : 0) +
|
int len = ((prepend) ? strlen(prepend) : 0) +
|
||||||
((append) ? strlen(append) : 0) +
|
((append) ? strlen(append) : 0) +
|
||||||
strlen(dirName) + 1;
|
strlen(dirName) + 1;
|
||||||
char *retval = malloc(len);
|
char *retval = (char *) allocator.Malloc(len);
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
@ -325,8 +325,8 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
w_SearchPath=AscToUnicode(SearchPath);
|
w_SearchPath=AscToUnicode(SearchPath);
|
||||||
|
|
||||||
dir = FindFirstFile(w_SearchPath, &ent);
|
dir = FindFirstFile(w_SearchPath, &ent);
|
||||||
free(w_SearchPath);
|
allocator.Free(w_SearchPath);
|
||||||
free(SearchPath);
|
allocator.Free(SearchPath);
|
||||||
|
|
||||||
if (dir == INVALID_HANDLE_VALUE)
|
if (dir == INVALID_HANDLE_VALUE)
|
||||||
return;
|
return;
|
||||||
|
@ -347,7 +347,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
callback(callbackdata, str);
|
callback(callbackdata, str);
|
||||||
free(str);
|
allocator.Free(str);
|
||||||
} while (FindNextFile(dir, &ent) != 0);
|
} while (FindNextFile(dir, &ent) != 0);
|
||||||
|
|
||||||
FindClose(dir);
|
FindClose(dir);
|
||||||
|
@ -362,10 +362,8 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
|
|
||||||
char *__PHYSFS_platformRealPath(const char *path)
|
char *__PHYSFS_platformRealPath(const char *path)
|
||||||
{
|
{
|
||||||
char *retval=(char *)malloc(strlen(path)+1);
|
char *retval = (char *) allocator.Malloc(strlen(path) + 1);
|
||||||
|
|
||||||
strcpy(retval,path);
|
strcpy(retval,path);
|
||||||
|
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* __PHYSFS_platformRealPath */
|
} /* __PHYSFS_platformRealPath */
|
||||||
|
|
||||||
|
@ -376,7 +374,7 @@ int __PHYSFS_platformMkDir(const char *path)
|
||||||
if(w_path!=NULL)
|
if(w_path!=NULL)
|
||||||
{
|
{
|
||||||
DWORD rc = CreateDirectory(w_path, NULL);
|
DWORD rc = CreateDirectory(w_path, NULL);
|
||||||
free(w_path);
|
allocator.Free(w_path);
|
||||||
if(rc==0)
|
if(rc==0)
|
||||||
{
|
{
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -399,7 +397,7 @@ static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
||||||
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
|
fileHandle = CreateFile(w_fname, mode, FILE_SHARE_READ, NULL,
|
||||||
creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
creation, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||||
|
|
||||||
free(w_fname);
|
allocator.Free(w_fname);
|
||||||
|
|
||||||
if(fileHandle==INVALID_HANDLE_VALUE)
|
if(fileHandle==INVALID_HANDLE_VALUE)
|
||||||
{
|
{
|
||||||
|
@ -408,7 +406,7 @@ static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
||||||
|
|
||||||
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
BAIL_IF_MACRO(fileHandle == INVALID_HANDLE_VALUE, win32strerror(), NULL);
|
||||||
|
|
||||||
retval = malloc(sizeof (winCEfile));
|
retval = (winCEfile *) allocator.Malloc(sizeof (winCEfile));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(fileHandle);
|
CloseHandle(fileHandle);
|
||||||
|
@ -443,7 +441,7 @@ void *__PHYSFS_platformOpenAppend(const char *filename)
|
||||||
{
|
{
|
||||||
const char *err = win32strerror();
|
const char *err = win32strerror();
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(err, NULL);
|
BAIL_MACRO(err, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -604,7 +602,7 @@ int __PHYSFS_platformClose(void *opaque)
|
||||||
{
|
{
|
||||||
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
HANDLE Handle = ((winCEfile *) opaque)->handle;
|
||||||
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
|
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
|
||||||
free(opaque);
|
allocator.Free(opaque);
|
||||||
return(1);
|
return(1);
|
||||||
} /* __PHYSFS_platformClose */
|
} /* __PHYSFS_platformClose */
|
||||||
|
|
||||||
|
@ -617,13 +615,13 @@ int __PHYSFS_platformDelete(const char *path)
|
||||||
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
|
if (GetFileAttributes(w_path) == FILE_ATTRIBUTE_DIRECTORY)
|
||||||
{
|
{
|
||||||
int retval=!RemoveDirectory(w_path);
|
int retval=!RemoveDirectory(w_path);
|
||||||
free(w_path);
|
allocator.Free(w_path);
|
||||||
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
||||||
} /* if */
|
} /* if */
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
int retval=!DeleteFile(w_path);
|
int retval=!DeleteFile(w_path);
|
||||||
free(w_path);
|
allocator.Free(w_path);
|
||||||
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
BAIL_IF_MACRO(retval, win32strerror(), 0);
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
|
@ -660,5 +658,39 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
||||||
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
||||||
} /* __PHYSFS_platformGetLastModTime */
|
} /* __PHYSFS_platformGetLastModTime */
|
||||||
|
|
||||||
|
|
||||||
|
/* !!! FIXME: Don't use C runtime for allocators? */
|
||||||
|
int __PHYSFS_platformAllocatorInit(void)
|
||||||
|
{
|
||||||
|
return(1); /* always succeeds. */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorDeinit(void)
|
||||||
|
{
|
||||||
|
/* no-op */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
||||||
|
{
|
||||||
|
#undef malloc
|
||||||
|
return(malloc(s));
|
||||||
|
} /* __PHYSFS_platformMalloc */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
||||||
|
{
|
||||||
|
#undef realloc
|
||||||
|
return(realloc(ptr, s));
|
||||||
|
} /* __PHYSFS_platformRealloc */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorFree(void *ptr)
|
||||||
|
{
|
||||||
|
#undef free
|
||||||
|
free(ptr);
|
||||||
|
} /* __PHYSFS_platformAllocatorFree */
|
||||||
|
|
||||||
/* end of pocketpc.c ... */
|
/* end of pocketpc.c ... */
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname)
|
||||||
|
|
||||||
if (envr != NULL)
|
if (envr != NULL)
|
||||||
{
|
{
|
||||||
retval = (char *) malloc(strlen(envr) + 1);
|
retval = (char *) allocator.Malloc(strlen(envr) + 1);
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
strcpy(retval, envr);
|
strcpy(retval, envr);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -77,7 +77,7 @@ static char *getUserNameByUID(void)
|
||||||
pw = getpwuid(uid);
|
pw = getpwuid(uid);
|
||||||
if ((pw != NULL) && (pw->pw_name != NULL))
|
if ((pw != NULL) && (pw->pw_name != NULL))
|
||||||
{
|
{
|
||||||
retval = (char *) malloc(strlen(pw->pw_name) + 1);
|
retval = (char *) allocator.Malloc(strlen(pw->pw_name) + 1);
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
strcpy(retval, pw->pw_name);
|
strcpy(retval, pw->pw_name);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -95,7 +95,7 @@ static char *getUserDirByUID(void)
|
||||||
pw = getpwuid(uid);
|
pw = getpwuid(uid);
|
||||||
if ((pw != NULL) && (pw->pw_dir != NULL))
|
if ((pw != NULL) && (pw->pw_dir != NULL))
|
||||||
{
|
{
|
||||||
retval = (char *) malloc(strlen(pw->pw_dir) + 1);
|
retval = (char *) allocator.Malloc(strlen(pw->pw_dir) + 1);
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
strcpy(retval, pw->pw_dir);
|
strcpy(retval, pw->pw_dir);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -204,7 +204,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
int len = ((prepend) ? strlen(prepend) : 0) +
|
int len = ((prepend) ? strlen(prepend) : 0) +
|
||||||
((append) ? strlen(append) : 0) +
|
((append) ? strlen(append) : 0) +
|
||||||
strlen(dirName) + 1;
|
strlen(dirName) + 1;
|
||||||
char *retval = (char *) malloc(len);
|
char *retval = (char *) allocator.Malloc(len);
|
||||||
|
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
|
@ -240,7 +240,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
{
|
{
|
||||||
dlen = strlen(dirname);
|
dlen = strlen(dirname);
|
||||||
bufsize = dlen + 256;
|
bufsize = dlen + 256;
|
||||||
buf = (char *) malloc(bufsize);
|
buf = (char *) allocator.Malloc(bufsize);
|
||||||
if (buf == NULL)
|
if (buf == NULL)
|
||||||
return;
|
return;
|
||||||
strcpy(buf, dirname);
|
strcpy(buf, dirname);
|
||||||
|
@ -256,7 +256,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
if (dir == NULL)
|
if (dir == NULL)
|
||||||
{
|
{
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
free(buf);
|
allocator.Free(buf);
|
||||||
return;
|
return;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -274,7 +274,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
int len = strlen(ent->d_name) + dlen + 1;
|
int len = strlen(ent->d_name) + dlen + 1;
|
||||||
if (len > bufsize)
|
if (len > bufsize)
|
||||||
{
|
{
|
||||||
p = realloc(buf, len);
|
p = (char *) allocator.Realloc(buf, len);
|
||||||
if (p == NULL)
|
if (p == NULL)
|
||||||
continue;
|
continue;
|
||||||
buf = p;
|
buf = p;
|
||||||
|
@ -290,7 +290,7 @@ void __PHYSFS_platformEnumerateFiles(const char *dirname,
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
if (buf != NULL)
|
if (buf != NULL)
|
||||||
free(buf);
|
allocator.Free(buf);
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
} /* __PHYSFS_platformEnumerateFiles */
|
} /* __PHYSFS_platformEnumerateFiles */
|
||||||
|
@ -305,11 +305,11 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
allocSize += 100;
|
allocSize += 100;
|
||||||
ptr = (char *) realloc(retval, allocSize);
|
ptr = (char *) allocator.Realloc(retval, allocSize);
|
||||||
if (ptr == NULL)
|
if (ptr == NULL)
|
||||||
{
|
{
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -324,7 +324,7 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
* directory not existing.
|
* directory not existing.
|
||||||
*/
|
*/
|
||||||
if (retval != NULL)
|
if (retval != NULL)
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -352,7 +352,7 @@ static void *doOpen(const char *filename, int mode)
|
||||||
fd = open(filename, mode, S_IRUSR | S_IWUSR);
|
fd = open(filename, mode, S_IRUSR | S_IWUSR);
|
||||||
BAIL_IF_MACRO(fd < 0, strerror(errno), NULL);
|
BAIL_IF_MACRO(fd < 0, strerror(errno), NULL);
|
||||||
|
|
||||||
retval = (int *) malloc(sizeof (int));
|
retval = (int *) allocator.Malloc(sizeof (int));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
close(fd);
|
close(fd);
|
||||||
|
@ -482,7 +482,7 @@ int __PHYSFS_platformClose(void *opaque)
|
||||||
{
|
{
|
||||||
int fd = *((int *) opaque);
|
int fd = *((int *) opaque);
|
||||||
BAIL_IF_MACRO(close(fd) == -1, strerror(errno), 0);
|
BAIL_IF_MACRO(close(fd) == -1, strerror(errno), 0);
|
||||||
free(opaque);
|
allocator.Free(opaque);
|
||||||
return(1);
|
return(1);
|
||||||
} /* __PHYSFS_platformClose */
|
} /* __PHYSFS_platformClose */
|
||||||
|
|
||||||
|
@ -516,18 +516,21 @@ void __PHYSFS_platformAllocatorDeinit(void)
|
||||||
|
|
||||||
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
||||||
{
|
{
|
||||||
|
#undef malloc
|
||||||
return(malloc(s));
|
return(malloc(s));
|
||||||
} /* __PHYSFS_platformMalloc */
|
} /* __PHYSFS_platformMalloc */
|
||||||
|
|
||||||
|
|
||||||
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
||||||
{
|
{
|
||||||
|
#undef realloc
|
||||||
return(realloc(ptr, s));
|
return(realloc(ptr, s));
|
||||||
} /* __PHYSFS_platformRealloc */
|
} /* __PHYSFS_platformRealloc */
|
||||||
|
|
||||||
|
|
||||||
void __PHYSFS_platformAllocatorFree(void *ptr)
|
void __PHYSFS_platformAllocatorFree(void *ptr)
|
||||||
{
|
{
|
||||||
|
#undef free
|
||||||
free(ptr);
|
free(ptr);
|
||||||
} /* __PHYSFS_platformAllocatorFree */
|
} /* __PHYSFS_platformAllocatorFree */
|
||||||
|
|
||||||
|
|
|
@ -233,5 +233,38 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
||||||
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
BAIL_MACRO(ERR_NOT_IMPLEMENTED, -1);
|
||||||
} /* __PHYSFS_platformGetLastModTime */
|
} /* __PHYSFS_platformGetLastModTime */
|
||||||
|
|
||||||
|
|
||||||
|
int __PHYSFS_platformAllocatorInit(void)
|
||||||
|
{
|
||||||
|
return(1); /* always succeeds. */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorDeinit(void)
|
||||||
|
{
|
||||||
|
/* no-op */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
||||||
|
{
|
||||||
|
#undef malloc
|
||||||
|
return(malloc(s));
|
||||||
|
} /* __PHYSFS_platformMalloc */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
||||||
|
{
|
||||||
|
#undef realloc
|
||||||
|
return(realloc(ptr, s));
|
||||||
|
} /* __PHYSFS_platformRealloc */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorFree(void *ptr)
|
||||||
|
{
|
||||||
|
#undef free
|
||||||
|
free(ptr);
|
||||||
|
} /* __PHYSFS_platformAllocatorFree */
|
||||||
|
|
||||||
/* end of skeleton.c ... */
|
/* end of skeleton.c ... */
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,10 @@
|
||||||
#define __PHYSICSFS_INTERNAL__
|
#define __PHYSICSFS_INTERNAL__
|
||||||
#include "physfs_internal.h"
|
#include "physfs_internal.h"
|
||||||
|
|
||||||
|
/* Seems to get defined in some system header... */
|
||||||
|
#ifdef Free
|
||||||
|
#undef Free
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *__PHYSFS_platformDirSeparator = "/";
|
const char *__PHYSFS_platformDirSeparator = "/";
|
||||||
|
|
||||||
|
@ -250,7 +254,7 @@ extern char *__PHYSFS_platformCopyEnvironmentVariable(const char *varname);
|
||||||
* if it doesn't exist or there were other problems. PHYSFS_SetError() is
|
* if it doesn't exist or there were other problems. PHYSFS_SetError() is
|
||||||
* called if we have a problem.
|
* called if we have a problem.
|
||||||
*
|
*
|
||||||
* (envr) will be scribbled over, and you are expected to free() the
|
* (envr) will be scribbled over, and you are expected to allocator.Free() the
|
||||||
* return value when you're done with it.
|
* return value when you're done with it.
|
||||||
*/
|
*/
|
||||||
static char *findBinaryInPath(const char *bin, char *envr)
|
static char *findBinaryInPath(const char *bin, char *envr)
|
||||||
|
@ -273,11 +277,11 @@ static char *findBinaryInPath(const char *bin, char *envr)
|
||||||
size = strlen(start) + strlen(bin) + 2;
|
size = strlen(start) + strlen(bin) + 2;
|
||||||
if (size > alloc_size)
|
if (size > alloc_size)
|
||||||
{
|
{
|
||||||
char *x = (char *) realloc(exe, size);
|
char *x = (char *) allocator.Realloc(exe, size);
|
||||||
if (x == NULL)
|
if (x == NULL)
|
||||||
{
|
{
|
||||||
if (exe != NULL)
|
if (exe != NULL)
|
||||||
free(exe);
|
allocator.Free(exe);
|
||||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -301,7 +305,7 @@ static char *findBinaryInPath(const char *bin, char *envr)
|
||||||
} while (ptr != NULL);
|
} while (ptr != NULL);
|
||||||
|
|
||||||
if (exe != NULL)
|
if (exe != NULL)
|
||||||
free(exe);
|
allocator.Free(exe);
|
||||||
|
|
||||||
return(NULL); /* doesn't exist in path. */
|
return(NULL); /* doesn't exist in path. */
|
||||||
} /* findBinaryInPath */
|
} /* findBinaryInPath */
|
||||||
|
@ -320,7 +324,7 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
|
||||||
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
|
envr = __PHYSFS_platformCopyEnvironmentVariable("PATH");
|
||||||
BAIL_IF_MACRO(!envr, NULL, NULL);
|
BAIL_IF_MACRO(!envr, NULL, NULL);
|
||||||
retval = findBinaryInPath(argv0, envr);
|
retval = findBinaryInPath(argv0, envr);
|
||||||
free(envr);
|
allocator.Free(envr);
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* __PHYSFS_platformCalcBaseDir */
|
} /* __PHYSFS_platformCalcBaseDir */
|
||||||
|
|
||||||
|
@ -377,11 +381,14 @@ static void stripAppleBundle(char *path)
|
||||||
char *sub_str = "/contents/macos";
|
char *sub_str = "/contents/macos";
|
||||||
char *found_ptr = NULL;
|
char *found_ptr = NULL;
|
||||||
char *tempbuf = NULL;
|
char *tempbuf = NULL;
|
||||||
|
size_t len = strlen(path) + 1;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
/* Calloc will place the \0 character in the proper place for us */
|
|
||||||
/* !!! FIXME: Can we stack-allocate this? --ryan. */
|
/* !!! FIXME: Can we stack-allocate this? --ryan. */
|
||||||
tempbuf = (char*)calloc( (strlen(path)+1), sizeof(char) );
|
tempbuf = (char *) allocator.Malloc(len);
|
||||||
|
if (!tempbuf) return;
|
||||||
|
memset(tempbuf, '\0', len);
|
||||||
|
|
||||||
/* Unlike other Unix filesystems, HFS is case insensitive
|
/* Unlike other Unix filesystems, HFS is case insensitive
|
||||||
* It wouldn be nice to use strcasestr, but it doesn't seem
|
* It wouldn be nice to use strcasestr, but it doesn't seem
|
||||||
* to be available in the OSX gcc library right now.
|
* to be available in the OSX gcc library right now.
|
||||||
|
@ -399,7 +406,7 @@ static void stripAppleBundle(char *path)
|
||||||
{
|
{
|
||||||
/* It doesn't look like a bundle so we can keep the
|
/* It doesn't look like a bundle so we can keep the
|
||||||
* original path. Just return */
|
* original path. Just return */
|
||||||
free(tempbuf);
|
allocator.Free(tempbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
/* We have a bundle, so let's backstep character by character
|
/* We have a bundle, so let's backstep character by character
|
||||||
|
@ -424,7 +431,7 @@ static void stripAppleBundle(char *path)
|
||||||
/* Back up one more to remove trailing '/' and set the '\0' */
|
/* Back up one more to remove trailing '/' and set the '\0' */
|
||||||
path[i] = '\0';
|
path[i] = '\0';
|
||||||
}
|
}
|
||||||
free(tempbuf);
|
allocator.Free(tempbuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif /* defined __MACH__ && defined __APPLE__ */
|
#endif /* defined __MACH__ && defined __APPLE__ */
|
||||||
|
@ -437,7 +444,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
|
|
||||||
errno = 0;
|
errno = 0;
|
||||||
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
|
BAIL_IF_MACRO(!realpath(path, resolved_path), strerror(errno), NULL);
|
||||||
retval = (char *) malloc(strlen(resolved_path) + 1);
|
retval = (char *) allocator.Malloc(strlen(resolved_path) + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
strcpy(retval, resolved_path);
|
strcpy(retval, resolved_path);
|
||||||
|
|
||||||
|
@ -483,12 +490,13 @@ PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
|
||||||
void *__PHYSFS_platformCreateMutex(void)
|
void *__PHYSFS_platformCreateMutex(void)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
pthread_mutex_t *m = (pthread_mutex_t *) malloc(sizeof (pthread_mutex_t));
|
pthread_mutex_t *m;
|
||||||
|
m = (pthread_mutex_t *) allocator.Malloc(sizeof (pthread_mutex_t));
|
||||||
BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(m == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
rc = pthread_mutex_init(m, NULL);
|
rc = pthread_mutex_init(m, NULL);
|
||||||
if (rc != 0)
|
if (rc != 0)
|
||||||
{
|
{
|
||||||
free(m);
|
allocator.Free(m);
|
||||||
BAIL_MACRO(strerror(rc), NULL);
|
BAIL_MACRO(strerror(rc), NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -499,7 +507,7 @@ void *__PHYSFS_platformCreateMutex(void)
|
||||||
void __PHYSFS_platformDestroyMutex(void *mutex)
|
void __PHYSFS_platformDestroyMutex(void *mutex)
|
||||||
{
|
{
|
||||||
pthread_mutex_destroy((pthread_mutex_t *) mutex);
|
pthread_mutex_destroy((pthread_mutex_t *) mutex);
|
||||||
free(mutex);
|
allocator.Free(mutex);
|
||||||
} /* __PHYSFS_platformDestroyMutex */
|
} /* __PHYSFS_platformDestroyMutex */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -111,7 +111,7 @@ static char *getExePath(const char *argv0)
|
||||||
DWORD buflen;
|
DWORD buflen;
|
||||||
int success = 0;
|
int success = 0;
|
||||||
char *ptr = NULL;
|
char *ptr = NULL;
|
||||||
char *retval = (char *) malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
char *retval = (char *) allocator.Malloc(sizeof (TCHAR) * (MAX_PATH + 1));
|
||||||
|
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
|
@ -159,12 +159,12 @@ static char *getExePath(const char *argv0)
|
||||||
|
|
||||||
if (!success)
|
if (!success)
|
||||||
{
|
{
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
return(NULL); /* physfs error message will be set, above. */
|
return(NULL); /* physfs error message will be set, above. */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* free up the bytes we didn't actually use. */
|
/* free up the bytes we didn't actually use. */
|
||||||
ptr = (char *) realloc(retval, strlen(retval) + 1);
|
ptr = (char *) allocator.Realloc(retval, strlen(retval) + 1);
|
||||||
if (ptr != NULL)
|
if (ptr != NULL)
|
||||||
retval = ptr;
|
retval = ptr;
|
||||||
|
|
||||||
|
@ -221,12 +221,12 @@ static int determineUserDir(void)
|
||||||
assert(!rc); /* success?! */
|
assert(!rc); /* success?! */
|
||||||
|
|
||||||
/* Allocate memory for the profile directory */
|
/* Allocate memory for the profile directory */
|
||||||
userDir = (char *) malloc(psize);
|
userDir = (char *) allocator.Malloc(psize);
|
||||||
if (userDir != NULL)
|
if (userDir != NULL)
|
||||||
{
|
{
|
||||||
if (!GetUserProfileDirectory(accessToken, userDir, &psize))
|
if (!GetUserProfileDirectory(accessToken, userDir, &psize))
|
||||||
{
|
{
|
||||||
free(userDir);
|
allocator.Free(userDir);
|
||||||
userDir = NULL;
|
userDir = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* else */
|
} /* else */
|
||||||
|
@ -297,12 +297,12 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
|
|
||||||
if (GetUserName(NULL, &bufsize) == 0) /* This SHOULD fail. */
|
if (GetUserName(NULL, &bufsize) == 0) /* This SHOULD fail. */
|
||||||
{
|
{
|
||||||
retval = (LPTSTR) malloc(bufsize);
|
retval = (LPTSTR) allocator.Malloc(bufsize);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
if (GetUserName(retval, &bufsize) == 0) /* ?! */
|
if (GetUserName(retval, &bufsize) == 0) /* ?! */
|
||||||
{
|
{
|
||||||
__PHYSFS_setError(win32strerror());
|
__PHYSFS_setError(win32strerror());
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
retval = NULL;
|
retval = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -313,7 +313,7 @@ char *__PHYSFS_platformGetUserName(void)
|
||||||
|
|
||||||
char *__PHYSFS_platformGetUserDir(void)
|
char *__PHYSFS_platformGetUserDir(void)
|
||||||
{
|
{
|
||||||
char *retval = (char *) malloc(strlen(userDir) + 1);
|
char *retval = (char *) allocator.Malloc(strlen(userDir) + 1);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
strcpy(retval, userDir); /* calculated at init time. */
|
strcpy(retval, userDir); /* calculated at init time. */
|
||||||
return(retval);
|
return(retval);
|
||||||
|
@ -409,7 +409,7 @@ char *__PHYSFS_platformCvtToDependent(const char *prepend,
|
||||||
int len = ((prepend) ? strlen(prepend) : 0) +
|
int len = ((prepend) ? strlen(prepend) : 0) +
|
||||||
((append) ? strlen(append) : 0) +
|
((append) ? strlen(append) : 0) +
|
||||||
strlen(dirName) + 1;
|
strlen(dirName) + 1;
|
||||||
char *retval = malloc(len);
|
char *retval = (char *) allocator.Malloc(len);
|
||||||
char *p;
|
char *p;
|
||||||
|
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
@ -491,7 +491,7 @@ char *__PHYSFS_platformCurrentDir(void)
|
||||||
DWORD buflen = 0;
|
DWORD buflen = 0;
|
||||||
|
|
||||||
buflen = GetCurrentDirectory(buflen, NULL);
|
buflen = GetCurrentDirectory(buflen, NULL);
|
||||||
retval = (LPTSTR) malloc(sizeof (TCHAR) * (buflen + 2));
|
retval = (LPTSTR) allocator.Malloc(sizeof (TCHAR) * (buflen + 2));
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
GetCurrentDirectory(buflen, retval);
|
GetCurrentDirectory(buflen, retval);
|
||||||
|
|
||||||
|
@ -511,7 +511,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
|
BAIL_IF_MACRO(path == NULL, ERR_INVALID_ARGUMENT, NULL);
|
||||||
BAIL_IF_MACRO(*path == '\0', ERR_INVALID_ARGUMENT, NULL);
|
BAIL_IF_MACRO(*path == '\0', ERR_INVALID_ARGUMENT, NULL);
|
||||||
|
|
||||||
retval = (char *) malloc(MAX_PATH);
|
retval = (char *) allocator.Malloc(MAX_PATH);
|
||||||
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -526,7 +526,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
char *currentDir = __PHYSFS_platformCurrentDir();
|
char *currentDir = __PHYSFS_platformCurrentDir();
|
||||||
if (currentDir == NULL)
|
if (currentDir == NULL)
|
||||||
{
|
{
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -572,7 +572,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
} /* else */
|
} /* else */
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
free(currentDir);
|
allocator.Free(currentDir);
|
||||||
} /* else */
|
} /* else */
|
||||||
|
|
||||||
/* (whew.) Ok, now take out "." and ".." path entries... */
|
/* (whew.) Ok, now take out "." and ".." path entries... */
|
||||||
|
@ -615,7 +615,7 @@ char *__PHYSFS_platformRealPath(const char *path)
|
||||||
} /* while */
|
} /* while */
|
||||||
|
|
||||||
/* shrink the retval's memory block if possible... */
|
/* shrink the retval's memory block if possible... */
|
||||||
p = (char *) realloc(retval, strlen(retval) + 1);
|
p = (char *) allocator.Realloc(retval, strlen(retval) + 1);
|
||||||
if (p != NULL)
|
if (p != NULL)
|
||||||
retval = p;
|
retval = p;
|
||||||
|
|
||||||
|
@ -708,7 +708,7 @@ int __PHYSFS_platformDeinit(void)
|
||||||
{
|
{
|
||||||
if (userDir != NULL)
|
if (userDir != NULL)
|
||||||
{
|
{
|
||||||
free(userDir);
|
allocator.Free(userDir);
|
||||||
userDir = NULL;
|
userDir = NULL;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
|
@ -736,7 +736,7 @@ static void *doOpen(const char *fname, DWORD mode, DWORD creation, int rdonly)
|
||||||
win32strerror(), NULL
|
win32strerror(), NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
retval = malloc(sizeof (win32file));
|
retval = (win32file *) allocator.Malloc(sizeof (win32file));
|
||||||
if (retval == NULL)
|
if (retval == NULL)
|
||||||
{
|
{
|
||||||
CloseHandle(fileHandle);
|
CloseHandle(fileHandle);
|
||||||
|
@ -772,7 +772,7 @@ void *__PHYSFS_platformOpenAppend(const char *filename)
|
||||||
{
|
{
|
||||||
const char *err = win32strerror();
|
const char *err = win32strerror();
|
||||||
CloseHandle(h);
|
CloseHandle(h);
|
||||||
free(retval);
|
allocator.Free(retval);
|
||||||
BAIL_MACRO(err, NULL);
|
BAIL_MACRO(err, NULL);
|
||||||
} /* if */
|
} /* if */
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -946,7 +946,7 @@ int __PHYSFS_platformClose(void *opaque)
|
||||||
{
|
{
|
||||||
HANDLE Handle = ((win32file *) opaque)->handle;
|
HANDLE Handle = ((win32file *) opaque)->handle;
|
||||||
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
|
BAIL_IF_MACRO(!CloseHandle(Handle), win32strerror(), 0);
|
||||||
free(opaque);
|
allocator.Free(opaque);
|
||||||
return(1);
|
return(1);
|
||||||
} /* __PHYSFS_platformClose */
|
} /* __PHYSFS_platformClose */
|
||||||
|
|
||||||
|
@ -1100,7 +1100,7 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
||||||
rc = GetFileTime(f->handle, NULL, NULL, &ft);
|
rc = GetFileTime(f->handle, NULL, NULL, &ft);
|
||||||
err = win32strerror();
|
err = win32strerror();
|
||||||
CloseHandle(f->handle);
|
CloseHandle(f->handle);
|
||||||
free(f);
|
allocator.Free(f);
|
||||||
BAIL_IF_MACRO(!rc, err, -1);
|
BAIL_IF_MACRO(!rc, err, -1);
|
||||||
retval = FileTimeToPhysfsTime(&ft);
|
retval = FileTimeToPhysfsTime(&ft);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -1108,6 +1108,40 @@ PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname)
|
||||||
return(retval);
|
return(retval);
|
||||||
} /* __PHYSFS_platformGetLastModTime */
|
} /* __PHYSFS_platformGetLastModTime */
|
||||||
|
|
||||||
|
|
||||||
|
/* !!! FIXME: Don't use C runtime for allocators? */
|
||||||
|
int __PHYSFS_platformAllocatorInit(void)
|
||||||
|
{
|
||||||
|
return(1); /* always succeeds. */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorDeinit(void)
|
||||||
|
{
|
||||||
|
/* no-op */
|
||||||
|
} /* __PHYSFS_platformAllocatorInit */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorMalloc(size_t s)
|
||||||
|
{
|
||||||
|
#undef malloc
|
||||||
|
return(malloc(s));
|
||||||
|
} /* __PHYSFS_platformMalloc */
|
||||||
|
|
||||||
|
|
||||||
|
void *__PHYSFS_platformAllocatorRealloc(void *ptr, size_t s)
|
||||||
|
{
|
||||||
|
#undef realloc
|
||||||
|
return(realloc(ptr, s));
|
||||||
|
} /* __PHYSFS_platformRealloc */
|
||||||
|
|
||||||
|
|
||||||
|
void __PHYSFS_platformAllocatorFree(void *ptr)
|
||||||
|
{
|
||||||
|
#undef free
|
||||||
|
free(ptr);
|
||||||
|
} /* __PHYSFS_platformAllocatorFree */
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* end of win32.c ... */
|
/* end of win32.c ... */
|
||||||
|
|
Loading…
Reference in New Issue