2 Copyright (C) 2016, 2017 Ben Kibbey <bjk@luxsci.net>
4 This file is part of libpwmd.
6 This library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 This library 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 GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with this library; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
34 _xrealloc_gpgrt (void *p
, size_t n
)
45 return _xrealloc (p
, n
);
65 m
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
66 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
67 wipememory (p
, 0, m
->size
);
72 _xmalloc (size_t size
)
79 m
= malloc (sizeof (struct memchunk_s
)+size
);
84 return (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
88 _xcalloc (size_t nmemb
, size_t size
)
93 m
= malloc (sizeof (struct memchunk_s
)+(nmemb
*size
));
98 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
99 memset (p
, 0, m
->size
);
104 _xrealloc (void *ptr
, size_t size
)
107 struct memchunk_s
*m
, *mp
;
112 m
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
113 p
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
114 wipememory (p
, 0, m
->size
);
119 return _xmalloc (size
);
121 m
= malloc (sizeof (struct memchunk_s
)+size
);
126 np
= (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));
128 mp
= (struct memchunk_s
*)((char *)ptr
-(offsetof (struct memchunk_s
, data
)));
129 p
= (void *)((char *)mp
+(offsetof (struct memchunk_s
, data
)));
131 n
= size
> mp
->size
? mp
->size
: size
;
133 wipememory (p
, 0, mp
->size
);
136 return (void *)((char *)m
+(offsetof (struct memchunk_s
, data
)));