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