home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mmdf / libz / ialloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-10  |  1.4 KB  |  93 lines

  1. #
  2.  
  3. /*LINTLIBRARY*/
  4.  
  5. #include "stdio.h"
  6.  
  7. #ifndef lint
  8. #ifndef NOID
  9. static char    sccsid[] = "@(#)ialloc.c    7.13";
  10. #endif /* !NOID */
  11. #endif /* !lint */
  12.  
  13. #ifndef alloc_t
  14. #define alloc_t    unsigned
  15. #endif /* !alloc_t */
  16.  
  17. #ifdef MAL
  18. #define NULLMAL(x)    ((x) == NULL || (x) == MAL)
  19. #else /* !MAL */
  20. #define NULLMAL(x)    ((x) == NULL)
  21. #endif /* !MAL */
  22.  
  23. extern char *    calloc();
  24. extern char *    malloc();
  25. extern char *    realloc();
  26. extern char *    strcpy();
  27.  
  28. char *
  29. imalloc(n)
  30. {
  31. #ifdef MAL
  32.     register char *    result;
  33.  
  34.     if (n == 0)
  35.         n = 1;
  36.     result = malloc((alloc_t) n);
  37.     return (result == MAL) ? NULL : result;
  38. #else /* !MAL */
  39.     if (n == 0)
  40.         n = 1;
  41.     return malloc((alloc_t) n);
  42. #endif /* !MAL */
  43. }
  44.  
  45. char *
  46. icalloc(nelem, elsize)
  47. {
  48.     if (nelem == 0 || elsize == 0)
  49.         nelem = elsize = 1;
  50.     return calloc((alloc_t) nelem, (alloc_t) elsize);
  51. }
  52.  
  53. char *
  54. irealloc(pointer, size)
  55. char *    pointer;
  56. {
  57.     if (NULLMAL(pointer))
  58.         return imalloc(size);
  59.     if (size == 0)
  60.         size = 1;
  61.     return realloc(pointer, (alloc_t) size);
  62. }
  63.  
  64. char *
  65. icatalloc(old, new)
  66. char *    old;
  67. char *    new;
  68. {
  69.     register char *    result;
  70.     register    oldsize, newsize;
  71.  
  72.     oldsize = NULLMAL(old) ? 0 : strlen(old);
  73.     newsize = NULLMAL(new) ? 0 : strlen(new);
  74.     if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
  75.         if (!NULLMAL(new))
  76.             (void) strcpy(result + oldsize, new);
  77.     return result;
  78. }
  79.  
  80. char *
  81. icpyalloc(string)
  82. char *    string;
  83. {
  84.     return icatalloc((char *) NULL, string);
  85. }
  86.  
  87. ifree(p)
  88. char *    p;
  89. {
  90.     if (!NULLMAL(p))
  91.         free(p);
  92. }
  93.