forked from robertdavidgraham/rdpscan
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil-xmalloc.c
More file actions
72 lines (65 loc) · 1.11 KB
/
Copy pathutil-xmalloc.c
File metadata and controls
72 lines (65 loc) · 1.11 KB
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
#include "util-xmalloc.h"
#include "util-log.h"
#include <stdlib.h>
#include <string.h>
#ifndef EX_UNAVAILABLE
#define EX_UNAVAILABLE (69)
#endif
void *
xmalloc(size_t size)
{
void *mem = malloc(size);
if (mem == NULL)
{
error("xmalloc %d\n", size);
exit(EX_UNAVAILABLE);
}
return mem;
}
/* Exit on NULL pointer. Use to verify result from XGetImage etc */
void
exit_if_null(void *ptr)
{
if (ptr == NULL)
{
error("unexpected null pointer. Out of memory?\n");
exit(EX_UNAVAILABLE);
}
}
/* strdup */
char *
xstrdup(const char *s)
{
char *mem;
#ifdef _WIN32
#define strdup(x) _strdup(x)
#endif
mem = strdup(s);
if (mem == NULL)
{
perror("strdup");
exit(EX_UNAVAILABLE);
}
return mem;
}
/* realloc; exit if out of memory */
void *
xrealloc(void *oldmem, size_t size)
{
void *mem;
if (size == 0)
size = 1;
mem = realloc(oldmem, size);
if (mem == NULL)
{
error("xrealloc %ld\n", size);
exit(EX_UNAVAILABLE);
}
return mem;
}
/* free */
void
xfree(void *mem)
{
free(mem);
}