Header And Logo

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

Defines | Functions

ialloc.c File Reference

#include "postgres_fe.h"
#include "private.h"
Include dependency graph for ialloc.c:

Go to the source code of this file.

Defines

#define nonzero(n)   (((n) == 0) ? 1 : (n))

Functions

char * imalloc (int n)
char * icalloc (int nelem, int elsize)
void * irealloc (void *pointer, int size)
char * icatalloc (char *old, const char *new)
char * icpyalloc (const char *string)
void ifree (char *p)
void icfree (char *p)

Define Documentation

#define nonzero (   n  )     (((n) == 0) ? 1 : (n))

Definition at line 14 of file ialloc.c.

Referenced by imalloc(), and irealloc().


Function Documentation

char* icalloc ( int  nelem,
int  elsize 
)

Definition at line 23 of file ialloc.c.

References calloc.

{
    if (nelem == 0 || elsize == 0)
        nelem = elsize = 1;
    return calloc((size_t) nelem, (size_t) elsize);
}

char* icatalloc ( char *  old,
const char *  new 
)

Definition at line 39 of file ialloc.c.

References irealloc(), and NULL.

Referenced by icpyalloc().

{
    char       *result;
    int         oldsize,
                newsize;

    newsize = (new == NULL) ? 0 : strlen(new);
    if (old == NULL)
        oldsize = 0;
    else if (newsize == 0)
        return old;
    else
        oldsize = strlen(old);
    if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
        if (new != NULL)
            (void) strcpy(result + oldsize, new);
    return result;
}

void icfree ( char *  p  ) 

Definition at line 72 of file ialloc.c.

References free, and NULL.

{
    if (p != NULL)
        (void) free(p);
}

char* icpyalloc ( const char *  string  ) 

Definition at line 59 of file ialloc.c.

References icatalloc(), and NULL.

{
    return icatalloc((char *) NULL, string);
}

void ifree ( char *  p  ) 

Definition at line 65 of file ialloc.c.

References free, and NULL.

Referenced by dolink(), infile(), itsdir(), mkdirs(), newabbr(), outzone(), rulesub(), scheck(), and warning().

{
    if (p != NULL)
        (void) free(p);
}

char* imalloc ( int  n  ) 

Definition at line 17 of file ialloc.c.

References malloc, and nonzero.

Referenced by irealloc(), and scheck().

{
    return malloc((size_t) nonzero(n));
}

void* irealloc ( void *  pointer,
int  size 
)

Definition at line 31 of file ialloc.c.

References imalloc(), nonzero, NULL, and realloc.

Referenced by icatalloc().

{
    if (pointer == NULL)
        return imalloc(size);
    return realloc((void *) pointer, (size_t) nonzero(size));
}