Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. /*=============================================================================
  3.    GNU UnRTF, a command-line program to convert RTF documents to other formats.
  4.    Copyright (C) 2000,2001 Zachary Thayer Smith
  5.  
  6.    This program is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2 of the License, or
  9.    (at your option) any later version.
  10.  
  11.    This program is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with this program; if not, write to the Free Software
  18.    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  19.  
  20.    The author is reachable by electronic mail at tuorfa@yahoo.com.
  21. =============================================================================*/
  22.  
  23.  
  24. /*----------------------------------------------------------------------
  25.  * Module name:    malloc
  26.  * Author name:    Zach Smith
  27.  * Create date:    01 Aug 01
  28.  * Purpose:        Memory management. Allows us to keep track of how
  29.  *                 much memory is being used.
  30.  *----------------------------------------------------------------------
  31.  * Changes:
  32.  * 14 Aug 01, tuorfa@yahoo.com: added Turbo C support.
  33.  * 16 Aug 01, Lars Unger <l.unger@tu-bs.de>: added Amiga/GCC support.
  34.  * 22 Sep 01, tuorfa@yahoo.com: added function-level comment blocks
  35.  * 28 Sep 01, tuorfa@yahoo.com: removed Turbo C support.
  36.  *--------------------------------------------------------------------*/
  37.  
  38.  
  39. #include <stdio.h>
  40. #include <string.h>
  41.  
  42. #if AMIGA
  43. #include <stdlib.h>
  44. #else
  45. #include <malloc.h>
  46. #endif
  47.  
  48. #include "error.h"
  49.  
  50.  
  51. static unsigned long count=0;
  52.  
  53.  
  54.  
  55. /*========================================================================
  56.  * Name:        my_malloc
  57.  * Purpose:     Internal version of malloc necessary for record keeping.
  58.  * Args:        Amount.
  59.  * Returns:     Pointer.
  60.  *=======================================================================*/
  61.  
  62. char *
  63. my_malloc (unsigned long size) {
  64.         char *ptr;
  65.  
  66.         ptr = malloc (size);
  67.         if (ptr)
  68.                 count += size;
  69.  
  70.         return ptr;
  71. }
  72.  
  73. /*========================================================================
  74.  * Name:        my_free
  75.  * Purpose:     Internal version of free necessary for record keeping.
  76.  * Args:        Pointer.
  77.  * Returns:     None.
  78.  *=======================================================================*/
  79.  
  80. void
  81. my_free (char* ptr) {
  82.         CHECK_PARAM_NOT_NULL(ptr);
  83.  
  84.         free (ptr);
  85. }
  86.  
  87.  
  88.  
  89. /*========================================================================
  90.  * Name:        total_malloced
  91.  * Purpose:     Returns total amount of memory thus far allocated.
  92.  * Args:        None.
  93.  * Returns:     Amount.
  94.  *=======================================================================*/
  95.  
  96. unsigned long
  97. total_malloced (void) {
  98.         return count;
  99. }
  100.  
  101.  
  102.  
  103. /*========================================================================
  104.  * Name:        my_strdup
  105.  * Purpose:     Internal version of strdup necessary for record keeping.
  106.  * Args:        String.
  107.  * Returns:     String.
  108.  *=======================================================================*/
  109.  
  110. char *
  111. my_strdup (char *src) {
  112.         unsigned long len;
  113.         char *ptr;
  114.  
  115.         CHECK_PARAM_NOT_NULL(src);
  116.  
  117.         len = strlen(src);
  118.         ptr = my_malloc (len+1);
  119.         if (!ptr)
  120.                 error_handler ("out of memory in strdup()");
  121.  
  122.         strcpy (ptr, src);
  123.         return ptr;
  124. }
  125.  
  126.