Header And Logo

PostgreSQL
| The world's most advanced open source database.

ialloc.c

Go to the documentation of this file.
00001 /*
00002  * This file is in the public domain, so clarified as of
00003  * 2006-07-17 by Arthur David Olson.
00004  *
00005  * IDENTIFICATION
00006  *    src/timezone/ialloc.c
00007  */
00008 
00009 #include "postgres_fe.h"
00010 
00011 #include "private.h"
00012 
00013 
00014 #define nonzero(n)  (((n) == 0) ? 1 : (n))
00015 
00016 char *
00017 imalloc(int n)
00018 {
00019     return malloc((size_t) nonzero(n));
00020 }
00021 
00022 char *
00023 icalloc(int nelem, int elsize)
00024 {
00025     if (nelem == 0 || elsize == 0)
00026         nelem = elsize = 1;
00027     return calloc((size_t) nelem, (size_t) elsize);
00028 }
00029 
00030 void *
00031 irealloc(void *pointer, int size)
00032 {
00033     if (pointer == NULL)
00034         return imalloc(size);
00035     return realloc((void *) pointer, (size_t) nonzero(size));
00036 }
00037 
00038 char *
00039 icatalloc(char *old, const char *new)
00040 {
00041     char       *result;
00042     int         oldsize,
00043                 newsize;
00044 
00045     newsize = (new == NULL) ? 0 : strlen(new);
00046     if (old == NULL)
00047         oldsize = 0;
00048     else if (newsize == 0)
00049         return old;
00050     else
00051         oldsize = strlen(old);
00052     if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
00053         if (new != NULL)
00054             (void) strcpy(result + oldsize, new);
00055     return result;
00056 }
00057 
00058 char *
00059 icpyalloc(const char *string)
00060 {
00061     return icatalloc((char *) NULL, string);
00062 }
00063 
00064 void
00065 ifree(char *p)
00066 {
00067     if (p != NULL)
00068         (void) free(p);
00069 }
00070 
00071 void
00072 icfree(char *p)
00073 {
00074     if (p != NULL)
00075         (void) free(p);
00076 }