added my_popen()
[fw/sdcc] / support / Util / newalloc.h
index e27957fa38be8f34a163d4903caf9dd9835df281..9e583c9d591e1980f09257ae8e6c082b9f46015c 100644 (file)
@@ -10,19 +10,19 @@ functions.
    under the terms of the GNU General Public License as published by the
    Free Software Foundation; either version 2, or (at your option) any
    later version.
-   
+
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
-   
+
    In other words, you are welcome to use, share and improve this program.
    You are forbidden to forbid anyone else to use, share and improve
-   what you give them.   Help stamp out software-hoarding!  
+   what you give them.   Help stamp out software-hoarding!
 
 ===============================================================================
 */
@@ -33,9 +33,16 @@ functions.
 
 #include <memory.h>
 
+typedef struct _allocTrace
+{
+  int num;
+  int max;
+  void **palloced;
+} allocTrace;
+
 /*
 -------------------------------------------------------------------------------
-Clear_realloc - Reallocate a memory block and clear any memory added with 
+Clear_realloc - Reallocate a memory block and clear any memory added with
 out of memory error detection
 
 -------------------------------------------------------------------------------
@@ -60,7 +67,7 @@ all data to zero and checking for out or memory errors.
 -------------------------------------------------------------------------------
 */
 
-void *Safe_calloc(size_t Size) ;
+void *Safe_calloc(size_t Elements,size_t Size) ;
 
 /*
 -------------------------------------------------------------------------------
@@ -72,4 +79,25 @@ and checking for out or memory errors.
 
 void *Safe_malloc(size_t Size) ;
 
+/** Replacement for Safe_malloc that also zeros memory.  To make it interchangable.
+ */
+void *Safe_alloc(size_t Size) ;
+
+/** Function to make the replacements complete.
+ */
+void Safe_free(void *p);
+
+/** Creates a copy of a string in a safe way.
+ */
+char *Safe_strdup(const char *sz);
+
+/** Logs the allocated memory 'p' in the given trace for batch freeing
+    later using freeTrace.
+*/
+void *traceAlloc(allocTrace *ptrace, void *p);
+
+/** Frees all the memory logged in the trace and resets the trace.
+ */
+void freeTrace(allocTrace *ptrace);
+
 #endif