]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/kmem.c
3 #include "libxfs_priv.h"
6 * Simple memory interface
10 kmem_zone_init(int size
, char *name
)
12 kmem_zone_t
*ptr
= malloc(sizeof(kmem_zone_t
));
15 fprintf(stderr
, _("%s: zone init failed (%s, %d bytes): %s\n"),
16 progname
, name
, (int)sizeof(kmem_zone_t
),
20 ptr
->zone_unitsize
= size
;
21 ptr
->zone_name
= name
;
27 kmem_zone_destroy(kmem_zone_t
*zone
)
31 if (getenv("LIBXFS_LEAK_CHECK") && zone
->allocated
) {
33 fprintf(stderr
, "zone %s freed with %d items allocated\n",
34 zone
->zone_name
, zone
->allocated
);
41 kmem_zone_alloc(kmem_zone_t
*zone
, int flags
)
43 void *ptr
= malloc(zone
->zone_unitsize
);
46 fprintf(stderr
, _("%s: zone alloc failed (%s, %d bytes): %s\n"),
47 progname
, zone
->zone_name
, zone
->zone_unitsize
,
55 kmem_zone_zalloc(kmem_zone_t
*zone
, int flags
)
57 void *ptr
= kmem_zone_alloc(zone
, flags
);
59 memset(ptr
, 0, zone
->zone_unitsize
);
65 kmem_alloc(size_t size
, int flags
)
67 void *ptr
= malloc(size
);
70 fprintf(stderr
, _("%s: malloc failed (%d bytes): %s\n"),
71 progname
, (int)size
, strerror(errno
));
78 kmem_zalloc(size_t size
, int flags
)
80 void *ptr
= kmem_alloc(size
, flags
);
87 kmem_realloc(void *ptr
, size_t new_size
, int flags
)
89 ptr
= realloc(ptr
, new_size
);
91 fprintf(stderr
, _("%s: realloc failed (%d bytes): %s\n"),
92 progname
, (int)new_size
, strerror(errno
));