1 /***************************************************************************
2 begin : Sat Jun 28 2003
3 copyright : (C) 2019 by Martin Preuss
4 email : martin@libchipcard.de
5
6 ***************************************************************************
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21 * MA 02111-1307 USA *
22 * *
23 ***************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include <config.h>
27 #endif
28
29 #include <gwenhywfar/memory.h>
30
31 #include <stdlib.h>
32 #include <stdio.h>
33 #include <string.h>
34 #include <assert.h>
35
36
37
38
GWEN_Memory_malloc(size_t wsize)39 void *GWEN_Memory_malloc(size_t wsize)
40 {
41 void *p;
42
43 if (GWEN_UNLIKELY(wsize==0)) {
44 fprintf(stderr, "GWEN error: allocating 0 bytes, maybe a program error\n");
45 abort();
46 }
47
48 p=malloc(wsize);
49 if (p==NULL) {
50 fprintf(stderr, "GWEN error: Not allocated %lu bytes (memory full?)\n",
51 (unsigned long int) wsize);
52 }
53 assert(p);
54 return p;
55 }
56
57
58
GWEN_Memory_realloc(void * oldp,size_t nsize)59 void *GWEN_Memory_realloc(void *oldp, size_t nsize)
60 {
61 assert(oldp);
62 assert(nsize);
63
64 return realloc(oldp, nsize);
65 }
66
67
68
GWEN_Memory_dealloc(void * p)69 void GWEN_Memory_dealloc(void *p)
70 {
71 free(p);
72 }
73
74
75
GWEN_Memory_strdup(const char * s)76 char *GWEN_Memory_strdup(const char *s)
77 {
78 assert(s);
79 return strdup(s);
80 }
81
82
83
84