]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - libxfs/kmem.c
5f65d97c9907525ee5067e6809de03822a00cacb
1 // SPDX-License-Identifier: GPL-2.0
4 #include "libxfs_priv.h"
7 * Simple memory interface
11 kmem_zone_init(int size
, char *name
)
13 kmem_zone_t
*ptr
= malloc(sizeof(kmem_zone_t
));
16 fprintf(stderr
, _("%s: zone init failed (%s, %d bytes): %s\n"),
17 progname
, name
, (int)sizeof(kmem_zone_t
),
21 ptr
->zone_unitsize
= size
;
22 ptr
->zone_name
= name
;
28 kmem_zone_destroy(kmem_zone_t
*zone
)
32 if (getenv("LIBXFS_LEAK_CHECK") && zone
->allocated
) {
34 fprintf(stderr
, "zone %s freed with %d items allocated\n",
35 zone
->zone_name
, zone
->allocated
);
42 kmem_zone_alloc(kmem_zone_t
*zone
, int flags
)
44 void *ptr
= malloc(zone
->zone_unitsize
);
47 fprintf(stderr
, _("%s: zone alloc failed (%s, %d bytes): %s\n"),
48 progname
, zone
->zone_name
, zone
->zone_unitsize
,
56 kmem_zone_zalloc(kmem_zone_t
*zone
, int flags
)
58 void *ptr
= kmem_zone_alloc(zone
, flags
);
60 memset(ptr
, 0, zone
->zone_unitsize
);
66 kmem_alloc(size_t size
, int flags
)
68 void *ptr
= malloc(size
);
71 fprintf(stderr
, _("%s: malloc failed (%d bytes): %s\n"),
72 progname
, (int)size
, strerror(errno
));
79 kmem_zalloc(size_t size
, int flags
)
81 void *ptr
= kmem_alloc(size
, flags
);
88 kmem_realloc(void *ptr
, size_t new_size
, int flags
)
90 ptr
= realloc(ptr
, new_size
);
92 fprintf(stderr
, _("%s: realloc failed (%d bytes): %s\n"),
93 progname
, (int)new_size
, strerror(errno
));