-
Notifications
You must be signed in to change notification settings - Fork 15
/
compat.c
91 lines (78 loc) · 1.5 KB
/
compat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
/*-------------------------------------------------------------------------
*
* compat.c
* compatibility definitions for older server versions
*
*-------------------------------------------------------------------------
*/
#include "postgres_fe.h"
#include "pg_catcheck.h"
#if PG_VERSION_NUM < 90300
/* 9.3 and higher have this in fe_memutils.c */
void *
pg_malloc(size_t size)
{
void *tmp;
/* Avoid unportable behavior of malloc(0) */
if (size == 0)
size = 1;
tmp = malloc(size);
if (!tmp)
{
fprintf(stderr, _("out of memory\n"));
exit(EXIT_FAILURE);
}
return tmp;
}
/* 9.3 and higher have this in fe_memutils.c */
void *
pg_malloc0(size_t size)
{
void *tmp;
tmp = pg_malloc(size);
MemSet(tmp, 0, size);
return tmp;
}
/* 9.3 and higher have this in fe_memutils.c */
void *
pg_realloc(void *ptr, size_t size)
{
void *tmp;
/* Avoid unportable behavior of realloc(NULL, 0) */
if (ptr == NULL && size == 0)
size = 1;
tmp = realloc(ptr, size);
if (!tmp)
{
fprintf(stderr, _("out of memory\n"));
exit(EXIT_FAILURE);
}
return tmp;
}
/* 9.3 and higher have this in fe_memutils.c */
char *
pg_strdup(const char *in)
{
char *tmp;
if (!in)
{
fprintf(stderr,
_("cannot duplicate null pointer (internal error)\n"));
exit(EXIT_FAILURE);
}
tmp = strdup(in);
if (!tmp)
{
fprintf(stderr, _("out of memory\n"));
exit(EXIT_FAILURE);
}
return tmp;
}
/* 9.3 and higher have this in fe_memutils.c */
void
pg_free(void *ptr)
{
if (ptr != NULL)
free(ptr);
}
#endif