~ubuntu-branches/ubuntu/precise/postgresql-9.1/precise-security

« back to all changes in this revision

Viewing changes to src/timezone/ialloc.c

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-05-11 10:41:53 UTC
  • Revision ID: james.westby@ubuntu.com-20110511104153-psbh2o58553fv1m0
Tags: upstream-9.1~beta1
ImportĀ upstreamĀ versionĀ 9.1~beta1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is in the public domain, so clarified as of
 
3
 * 2006-07-17 by Arthur David Olson.
 
4
 *
 
5
 * IDENTIFICATION
 
6
 *        src/timezone/ialloc.c
 
7
 */
 
8
 
 
9
#include "postgres_fe.h"
 
10
 
 
11
#include "private.h"
 
12
 
 
13
 
 
14
#define nonzero(n)      (((n) == 0) ? 1 : (n))
 
15
 
 
16
char *
 
17
imalloc(int n)
 
18
{
 
19
        return malloc((size_t) nonzero(n));
 
20
}
 
21
 
 
22
char *
 
23
icalloc(int nelem, int elsize)
 
24
{
 
25
        if (nelem == 0 || elsize == 0)
 
26
                nelem = elsize = 1;
 
27
        return calloc((size_t) nelem, (size_t) elsize);
 
28
}
 
29
 
 
30
void *
 
31
irealloc(void *pointer, int size)
 
32
{
 
33
        if (pointer == NULL)
 
34
                return imalloc(size);
 
35
        return realloc((void *) pointer, (size_t) nonzero(size));
 
36
}
 
37
 
 
38
char *
 
39
icatalloc(char *old, const char *new)
 
40
{
 
41
        char       *result;
 
42
        int                     oldsize,
 
43
                                newsize;
 
44
 
 
45
        newsize = (new == NULL) ? 0 : strlen(new);
 
46
        if (old == NULL)
 
47
                oldsize = 0;
 
48
        else if (newsize == 0)
 
49
                return old;
 
50
        else
 
51
                oldsize = strlen(old);
 
52
        if ((result = irealloc(old, oldsize + newsize + 1)) != NULL)
 
53
                if (new != NULL)
 
54
                        (void) strcpy(result + oldsize, new);
 
55
        return result;
 
56
}
 
57
 
 
58
char *
 
59
icpyalloc(const char *string)
 
60
{
 
61
        return icatalloc((char *) NULL, string);
 
62
}
 
63
 
 
64
void
 
65
ifree(char *p)
 
66
{
 
67
        if (p != NULL)
 
68
                (void) free(p);
 
69
}
 
70
 
 
71
void
 
72
icfree(char *p)
 
73
{
 
74
        if (p != NULL)
 
75
                (void) free(p);
 
76
}