/[osn-commons]/trunk/uar/xmalloc.c
ViewVC logotype

Contents of /trunk/uar/xmalloc.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 23 - (show annotations)
Mon Aug 5 17:15:48 2024 UTC (7 months, 3 weeks ago) by rakinar2
File MIME type: text/x-c
File size: 999 byte(s)
feat: add programs implementing the universal archive format
1 #include "xmalloc.h"
2 #include <errno.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6
7 void *
8 xmalloc (size_t size)
9 {
10 void *ptr = malloc (size);
11
12 if (ptr == NULL)
13 {
14 fprintf (stderr, "xmalloc(%zu): failed to allocate memory: %s",
15 size, strerror (errno));
16 abort ();
17 }
18
19 return ptr;
20 }
21
22 void *
23 xcalloc (size_t nmemb, size_t size)
24 {
25 void *ptr = calloc (nmemb, size);
26
27 if (ptr == NULL)
28 {
29 fprintf (stderr, "xcalloc(%zu, %zu): failed to allocate memory: %s",
30 nmemb, size, strerror (errno));
31 abort ();
32 }
33
34 return ptr;
35 }
36
37 void *
38 xrealloc (void *ptr, size_t size)
39 {
40 void *new_ptr = realloc (ptr, size);
41
42 if (new_ptr == NULL)
43 {
44 fprintf (stderr,
45 "xrealloc(%p, %zu): failed to re-allocate memory: %s", ptr,
46 size, strerror (errno));
47 abort ();
48 }
49
50 return new_ptr;
51 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26