fix bug in envp handling in main(); always put trailing dot on
[unix-history] / usr / src / share / zoneinfo / ialloc.c
CommitLineData
6b4c1ff3
KB
1/*-
2 * Copyright (c) 1991 The Regents of the University of California.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Arthur David Olson of the National Cancer Institute.
7 *
8 * %sccs.include.redist.c%
9 */
10
98200606 11#ifndef lint
6b4c1ff3
KB
12static char sccsid[] = "@(#)ialloc.c 5.3 (Berkeley) %G%";
13#endif /* not lint */
14
15#ifdef notdef
98200606 16static char elsieid[] = "@(#)ialloc.c 8.18";
6b4c1ff3 17#endif
98200606
KB
18
19/*LINTLIBRARY*/
20
256a180c
KB
21#include <string.h>
22#include <stdlib.h>
98200606
KB
23
24#ifdef MAL
25#define NULLMAL(x) ((x) == NULL || (x) == MAL)
26#else /* !defined MAL */
27#define NULLMAL(x) ((x) == NULL)
28#endif /* !defined MAL */
29
30#define nonzero(n) (((n) == 0) ? 1 : (n))
31
256a180c
KB
32char * icalloc __P((int nelem, int elsize));
33char * icatalloc __P((char * old, const char * new));
34char * icpyalloc __P((const char * string));
35char * imalloc __P((int n));
36char * irealloc __P((char * pointer, int size));
37void ifree __P((char * pointer));
98200606
KB
38
39char *
40imalloc(n)
41const int n;
42{
43#ifdef MAL
44 register char * result;
45
256a180c 46 result = malloc((size_t) nonzero(n));
98200606
KB
47 return NULLMAL(result) ? NULL : result;
48#else /* !defined MAL */
256a180c 49 return malloc((size_t) nonzero(n));
98200606
KB
50#endif /* !defined MAL */
51}
52
53char *
54icalloc(nelem, elsize)
55int nelem;
56int elsize;
57{
58 if (nelem == 0 || elsize == 0)
59 nelem = elsize = 1;
256a180c 60 return calloc((size_t) nelem, (size_t) elsize);
98200606
KB
61}
62
63char *
64irealloc(pointer, size)
65char * const pointer;
66const int size;
67{
68 if (NULLMAL(pointer))
69 return imalloc(size);
256a180c 70 return realloc((void *) pointer, (size_t) nonzero(size));
98200606
KB
71}
72
73char *
74icatalloc(old, new)
75char * const old;
76const char * const new;
77{
78 register char * result;
79 register oldsize, newsize;
80
81 newsize = NULLMAL(new) ? 0 : strlen(new);
82 if (NULLMAL(old))
83 oldsize = 0;
84 else if (newsize == 0)
85 return old;
86 else oldsize = strlen(old);
87 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
88 if (!NULLMAL(new))
89 (void) strcpy(result + oldsize, new);
90 return result;
91}
92
93char *
94icpyalloc(string)
95const char * const string;
96{
97 return icatalloc((char *) NULL, string);
98}
99
100void
101ifree(p)
102char * const p;
103{
104 if (!NULLMAL(p))
105 (void) free(p);
106}
107
108void
109icfree(p)
110char * const p;
111{
112 if (!NULLMAL(p))
113 (void) free(p);
114}