Annotation of 43BSDTahoe/etc/tzone/ialloc.c, revision 1.1

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

unix.superglobalmegacorp.com

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