platform/posix.c
changeset 691 71d9affe0d8a
parent 657 dad3b5c307a9
child 717 ae8bc9888553
--- a/platform/posix.c	Mon Mar 14 11:48:29 2005 +0000
+++ b/platform/posix.c	Mon Mar 14 11:49:30 2005 +0000
@@ -59,7 +59,7 @@
 
     if (envr != NULL)
     {
-        retval = (char *) malloc(strlen(envr) + 1);
+        retval = (char *) allocator.Malloc(strlen(envr) + 1);
         if (retval != NULL)
             strcpy(retval, envr);
     } /* if */
@@ -77,7 +77,7 @@
     pw = getpwuid(uid);
     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)
             strcpy(retval, pw->pw_name);
     } /* if */
@@ -95,7 +95,7 @@
     pw = getpwuid(uid);
     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)
             strcpy(retval, pw->pw_dir);
     } /* if */
@@ -204,7 +204,7 @@
     int len = ((prepend) ? strlen(prepend) : 0) +
               ((append) ? strlen(append) : 0) +
               strlen(dirName) + 1;
-    char *retval = (char *) malloc(len);
+    char *retval = (char *) allocator.Malloc(len);
 
     BAIL_IF_MACRO(retval == NULL, ERR_OUT_OF_MEMORY, NULL);
 
@@ -240,7 +240,7 @@
     {
         dlen = strlen(dirname);
         bufsize = dlen + 256;
-        buf = (char *) malloc(bufsize);
+        buf = (char *) allocator.Malloc(bufsize);
         if (buf == NULL)
             return;
         strcpy(buf, dirname);
@@ -256,7 +256,7 @@
     if (dir == NULL)
     {
         if (buf != NULL)
-            free(buf);
+            allocator.Free(buf);
         return;
     } /* if */
 
@@ -274,7 +274,7 @@
             int len = strlen(ent->d_name) + dlen + 1;
             if (len > bufsize)
             {
-                p = realloc(buf, len);
+                p = (char *) allocator.Realloc(buf, len);
                 if (p == NULL)
                     continue;
                 buf = p;
@@ -290,7 +290,7 @@
     } /* while */
 
     if (buf != NULL)
-        free(buf);
+        allocator.Free(buf);
 
     closedir(dir);
 } /* __PHYSFS_platformEnumerateFiles */
@@ -305,11 +305,11 @@
     do
     {
         allocSize += 100;
-        ptr = (char *) realloc(retval, allocSize);
+        ptr = (char *) allocator.Realloc(retval, allocSize);
         if (ptr == NULL)
         {
             if (retval != NULL)
-                free(retval);
+                allocator.Free(retval);
             BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL);
         } /* if */
 
@@ -324,7 +324,7 @@
              * directory not existing.
              */
         if (retval != NULL)
-            free(retval);
+            allocator.Free(retval);
         BAIL_MACRO(ERR_NO_SUCH_FILE, NULL);
     } /* if */
 
@@ -352,7 +352,7 @@
     fd = open(filename, mode, S_IRUSR | S_IWUSR);
     BAIL_IF_MACRO(fd < 0, strerror(errno), NULL);
 
-    retval = (int *) malloc(sizeof (int));
+    retval = (int *) allocator.Malloc(sizeof (int));
     if (retval == NULL)
     {
         close(fd);
@@ -482,7 +482,7 @@
 {
     int fd = *((int *) opaque);
     BAIL_IF_MACRO(close(fd) == -1, strerror(errno), 0);
-    free(opaque);
+    allocator.Free(opaque);
     return(1);
 } /* __PHYSFS_platformClose */
 
@@ -516,18 +516,21 @@
 
 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 */