Annotation of 43BSDReno/share/zoneinfo/ialloc.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.