home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / glibc-1.06 / time / ialloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-15  |  1.8 KB  |  102 lines

  1. #ifndef lint
  2. #ifndef NOID
  3. static char    elsieid[] = "@(#)ialloc.c    8.20";
  4. #endif /* !defined NOID */
  5. #endif /* !defined lint */
  6.  
  7. /*LINTLIBRARY*/
  8.  
  9. #include "private.h"
  10.  
  11. #ifdef MAL
  12. #define NULLMAL(x)    ((x) == NULL || (x) == MAL)
  13. #else /* !defined MAL */
  14. #define NULLMAL(x)    ((x) == NULL)
  15. #endif /* !defined MAL */
  16.  
  17. #define nonzero(n)    (((n) == 0) ? 1 : (n))
  18.  
  19. char *    icalloc P((int nelem, int elsize));
  20. char *    icatalloc P((char * old, const char * new));
  21. char *    icpyalloc P((const char * string));
  22. char *    imalloc P((int n));
  23. char *    irealloc P((char * pointer, int size));
  24. void    ifree P((char * pointer));
  25.  
  26. char *
  27. imalloc(n)
  28. const int    n;
  29. {
  30. #ifdef MAL
  31.     register char *    result;
  32.  
  33.     result = malloc((alloc_size_t) nonzero(n));
  34.     return NULLMAL(result) ? NULL : result;
  35. #else /* !defined MAL */
  36.     return malloc((alloc_size_t) nonzero(n));
  37. #endif /* !defined MAL */
  38. }
  39.  
  40. char *
  41. icalloc(nelem, elsize)
  42. int    nelem;
  43. int    elsize;
  44. {
  45.     if (nelem == 0 || elsize == 0)
  46.         nelem = elsize = 1;
  47.     return calloc((alloc_size_t) nelem, (alloc_size_t) elsize);
  48. }
  49.  
  50. char *
  51. irealloc(pointer, size)
  52. char * const    pointer;
  53. const int    size;
  54. {
  55.     if (NULLMAL(pointer))
  56.         return imalloc(size);
  57.     return realloc((genericptr_t) pointer, (alloc_size_t) nonzero(size));
  58. }
  59.  
  60. char *
  61. icatalloc(old, new)
  62. char * const        old;
  63. const char * const    new;
  64. {
  65.     register char *    result;
  66.     register int    oldsize, newsize;
  67.  
  68.     newsize = NULLMAL(new) ? 0 : strlen(new);
  69.     if (NULLMAL(old))
  70.         oldsize = 0;
  71.     else if (newsize == 0)
  72.         return old;
  73.     else    oldsize = strlen(old);
  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. const char * const    string;
  83. {
  84.     return icatalloc((char *) NULL, string);
  85. }
  86.  
  87. void
  88. ifree(p)
  89. char * const    p;
  90. {
  91.     if (!NULLMAL(p))
  92.         (void) free(p);
  93. }
  94.  
  95. void
  96. icfree(p)
  97. char * const    p;
  98. {
  99.     if (!NULLMAL(p))
  100.         (void) free(p);
  101. }
  102.