Rename test case
[eleutheria.git] / malloc / test1.c
blobbab925f3c1253331aa3667a663439506e6c0c324
1 #include <stdio.h>
2 #include <stdlib.h>
4 #include "mpool.h"
6 int main(void)
8 mpool_t *mpool;
9 mpret_t mpret;
10 char *buffer;
12 /* Initialize memory pool with 1024 bytes */
13 mpret = mpool_init(&mpool, 10, 5);
14 if (mpret == MPOOL_ENOMEM) {
15 fprintf(stderr, "mpool: not enough memory\n");
16 exit(EXIT_FAILURE);
18 else if (mpret == MPOOL_EBADVAL) {
19 fprintf(stderr, "mpool: bad value passed to mpool_init()\n");
20 exit(EXIT_FAILURE);
23 /* Allocate 32 bytes for buffer */
24 if ((buffer = mpool_alloc(mpool, 5)) == NULL) {
25 fprintf(stderr, "mpool: no available block in pool\n");
26 mpool_destroy(mpool);
27 exit(EXIT_FAILURE);
30 /* Read input from standard input stream */
31 fgets(buffer, 1<<5, stdin);
33 /* Print buffer's contents */
34 printf("Buffer: %s", buffer);
37 * Free buffer --
38 * could be omitted, since we call mpool_destroy() afterwards
40 mpool_free(mpool, buffer);
42 /* Destroy memory pool and free all resources */
43 mpool_destroy(mpool);
45 return EXIT_SUCCESS;