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