Skip to content
Permalink
Browse files
Moved some functions around.
We want the #undef malloc, etc, lines as close to the end of the file as
 possible, and __PHYSFS_readAll() not in the middle of the allocator code.
  • Loading branch information
icculus committed Mar 25, 2012
1 parent 107f07d commit a7383c295fef2141359e161de1c2291fcc152ad0
Showing with 38 additions and 38 deletions.
  1. +38 −38 src/physfs.c
@@ -2644,6 +2644,44 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat)
} /* PHYSFS_stat */


int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
{
return (io->read(io, buf, len) == len);
} /* __PHYSFS_readAll */


void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len)
{
void *useHeap = ((ptr == NULL) ? ((void *) 1) : ((void *) 0));
if (useHeap) /* too large for stack allocation or alloca() failed. */
ptr = allocator.Malloc(len+sizeof (void *));

if (ptr != NULL)
{
void **retval = (void **) ptr;
/*printf("%s alloc'd (%d) bytes at (%p).\n",
useHeap ? "heap" : "stack", (int) len, ptr);*/
*retval = useHeap;
return retval + 1;
} /* if */

return NULL; /* allocation failed. */
} /* __PHYSFS_initSmallAlloc */


void __PHYSFS_smallFree(void *ptr)
{
if (ptr != NULL)
{
void **block = ((void **) ptr) - 1;
const int useHeap = (*block != 0);
if (useHeap)
allocator.Free(block);
/*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/
} /* if */
} /* __PHYSFS_smallFree */


int PHYSFS_setAllocator(const PHYSFS_Allocator *a)
{
BAIL_IF_MACRO(initialized, PHYSFS_ERR_IS_INITIALIZED, 0);
@@ -2700,43 +2738,5 @@ static void setDefaultAllocator(void)
} /* if */
} /* setDefaultAllocator */


void *__PHYSFS_initSmallAlloc(void *ptr, PHYSFS_uint64 len)
{
void *useHeap = ((ptr == NULL) ? ((void *) 1) : ((void *) 0));
if (useHeap) /* too large for stack allocation or alloca() failed. */
ptr = allocator.Malloc(len+sizeof (void *));

if (ptr != NULL)
{
void **retval = (void **) ptr;
/*printf("%s alloc'd (%d) bytes at (%p).\n",
useHeap ? "heap" : "stack", (int) len, ptr);*/
*retval = useHeap;
return retval + 1;
} /* if */

return NULL; /* allocation failed. */
} /* __PHYSFS_initSmallAlloc */


void __PHYSFS_smallFree(void *ptr)
{
if (ptr != NULL)
{
void **block = ((void **) ptr) - 1;
const int useHeap = (*block != 0);
if (useHeap)
allocator.Free(block);
/*printf("%s free'd (%p).\n", useHeap ? "heap" : "stack", block);*/
} /* if */
} /* __PHYSFS_smallFree */


int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const PHYSFS_uint64 len)
{
return (io->read(io, buf, len) == len);
} /* __PHYSFS_readAll */

/* end of physfs.c ... */

0 comments on commit a7383c2

Please sign in to comment.