-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmalloc.c
More file actions
46 lines (38 loc) · 1.16 KB
/
xmalloc.c
File metadata and controls
46 lines (38 loc) · 1.16 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
/*
This file is part of process-watcher.
process-watcher is free software: you can redistribute it and/or
modify it under the terms of the Apache 2.0 License as published by
the Apache Software Foundation.
process-watcher is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the License
for more details.
You should have received a copy of the Apache 2.0 License
along with process-watcher.
If not, see <https://www.apache.org/licenses/LICENSE-2.0>.
*/
#include "xmalloc.h"
/* Enable GNU extensions such as fputs_unlocked (). */
#define _GNU_SOURCE
#include <stdlib.h> /* malloc (). */
#include <stdio.h> /* fputs_unlocked (). */
void *
xmalloc (size_t size)
{
void *value = malloc (size);
if (value == 0) {
fputs_unlocked ("virtual memory exhausted\n", stderr);
exit (1);
}
return value;
}
void *
xreallocarray (void *ptr, size_t nmemb, size_t size)
{
void *value = reallocarray (ptr, nmemb, size);
if (value == 0) {
fputs_unlocked ("virtual memory exhausted\n", stderr);
exit (1);
}
return value;
}