2 Copyright (C) 2006-2018 Ben Kibbey <bjk@luxsci.net>
4 This file is part of pwmd.
6 Pwmd is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 2 of the License, or
9 (at your option) any later version.
11 Pwmd is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with Pwmd. If not, see <http://www.gnu.org/licenses/>.
32 xrealloc_gpgrt (void *p
, size_t n
)
37 return xrealloc (p
, n
);
51 } __attribute ((packed
));
62 m
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
63 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
64 wipememory (p
, 0, m
->size
);
76 m
= malloc (sizeof (struct memchunk_s
)+size
);
81 return (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
85 xcalloc (size_t nmemb
, size_t size
)
90 m
= malloc (sizeof (struct memchunk_s
)+(nmemb
*size
));
95 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
96 memset (p
, 0, m
->size
);
101 xrealloc (void *ptr
, size_t size
)
104 struct memchunk_s
*m
, *mp
;
109 m
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
110 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
111 wipememory (p
, 0, m
->size
);
116 return xmalloc (size
);
118 m
= malloc (sizeof (struct memchunk_s
)+size
);
123 np
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
125 mp
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
126 p
= (void *)((char *)mp
+(offsetof (struct memchunk_s
, data
)));
128 n
= size
> mp
->size
? mp
->size
: size
;
130 wipememory (p
, 0, mp
->size
);
133 return (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));