]> git.ipfire.org Git - thirdparty/glibc.git/blame - time/ialloc.c
Update.
[thirdparty/glibc.git] / time / ialloc.c
CommitLineData
28f540f4
RM
1#ifndef lint
2#ifndef NOID
4cca6b86 3static char elsieid[] = "@(#)ialloc.c 8.29";
28f540f4
RM
4#endif /* !defined NOID */
5#endif /* !defined lint */
6
7/*LINTLIBRARY*/
8
9#include "private.h"
10
28f540f4
RM
11#define nonzero(n) (((n) == 0) ? 1 : (n))
12
28f540f4
RM
13char *
14imalloc(n)
15const int n;
16{
6c2f0507 17 return malloc((size_t) nonzero(n));
28f540f4
RM
18}
19
20char *
21icalloc(nelem, elsize)
22int nelem;
23int elsize;
24{
25 if (nelem == 0 || elsize == 0)
26 nelem = elsize = 1;
6c2f0507 27 return calloc((size_t) nelem, (size_t) elsize);
28f540f4
RM
28}
29
30void *
31irealloc(pointer, size)
32void * const pointer;
33const int size;
34{
6c2f0507 35 if (pointer == NULL)
28f540f4 36 return imalloc(size);
6c2f0507 37 return realloc((void *) pointer, (size_t) nonzero(size));
28f540f4
RM
38}
39
40char *
41icatalloc(old, new)
42char * const old;
43const char * const new;
44{
45 register char * result;
46 register int oldsize, newsize;
47
6c2f0507
RM
48 newsize = (new == NULL) ? 0 : strlen(new);
49 if (old == NULL)
28f540f4
RM
50 oldsize = 0;
51 else if (newsize == 0)
52 return old;
53 else oldsize = strlen(old);
54 if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
6c2f0507 55 if (new != NULL)
28f540f4
RM
56 (void) strcpy(result + oldsize, new);
57 return result;
58}
59
60char *
61icpyalloc(string)
62const char * const string;
63{
64 return icatalloc((char *) NULL, string);
65}
66
67void
68ifree(p)
69char * const p;
70{
6c2f0507 71 if (p != NULL)
28f540f4
RM
72 (void) free(p);
73}
74
75void
76icfree(p)
77char * const p;
78{
6c2f0507 79 if (p != NULL)
28f540f4
RM
80 (void) free(p);
81}