]> git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blame - libxfs/kmem.c
xfs: harden directory integrity checks some more
[thirdparty/xfsprogs-dev.git] / libxfs / kmem.c
CommitLineData
5e656dbb
BN
1
2
9c799827 3#include "libxfs_priv.h"
5e656dbb
BN
4
5/*
6 * Simple memory interface
7 */
8
9kmem_zone_t *
10kmem_zone_init(int size, char *name)
11{
12 kmem_zone_t *ptr = malloc(sizeof(kmem_zone_t));
13
14 if (ptr == NULL) {
15 fprintf(stderr, _("%s: zone init failed (%s, %d bytes): %s\n"),
f8149110 16 progname, name, (int)sizeof(kmem_zone_t),
5e656dbb
BN
17 strerror(errno));
18 exit(1);
19 }
20 ptr->zone_unitsize = size;
21 ptr->zone_name = name;
22 ptr->allocated = 0;
23 return ptr;
24}
25
26void *
27kmem_zone_alloc(kmem_zone_t *zone, int flags)
28{
29 void *ptr = malloc(zone->zone_unitsize);
30
31 if (ptr == NULL) {
32 fprintf(stderr, _("%s: zone alloc failed (%s, %d bytes): %s\n"),
33 progname, zone->zone_name, zone->zone_unitsize,
34 strerror(errno));
35 exit(1);
36 }
37 zone->allocated++;
38 return ptr;
39}
40void *
41kmem_zone_zalloc(kmem_zone_t *zone, int flags)
42{
43 void *ptr = kmem_zone_alloc(zone, flags);
44
45 memset(ptr, 0, zone->zone_unitsize);
46 return ptr;
47}
48
49
50void *
51kmem_alloc(size_t size, int flags)
52{
53 void *ptr = malloc(size);
54
55 if (ptr == NULL) {
56 fprintf(stderr, _("%s: malloc failed (%d bytes): %s\n"),
57 progname, (int)size, strerror(errno));
58 exit(1);
59 }
60 return ptr;
61}
62
63void *
64kmem_zalloc(size_t size, int flags)
65{
66 void *ptr = kmem_alloc(size, flags);
67
68 memset(ptr, 0, size);
69 return ptr;
70}
71
72void *
408c66dd 73kmem_realloc(void *ptr, size_t new_size, int flags)
5e656dbb
BN
74{
75 ptr = realloc(ptr, new_size);
76 if (ptr == NULL) {
77 fprintf(stderr, _("%s: realloc failed (%d bytes): %s\n"),
78 progname, (int)new_size, strerror(errno));
79 exit(1);
80 }
81 return ptr;
82}