pwmc: Reset filename upon .open failure.
[libpwmd.git] / src / mem.h
blobda0f4b55c1c88e2056fc8156b3ff61e7565578ad
1 /*
2 Copyright (C) 2016 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
19 USA
21 #ifndef MEM_H
22 #define MEM_H
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdlib.h>
29 /* To avoid that a compiler optimizes certain memset calls away, these
30 macros may be used instead. Thanks g10Code. */
31 #define wipememory(_ptr,_set,_len) do { \
32 volatile char *_vptr=(volatile char *)(_ptr); \
33 size_t _vlen=(_len); \
34 while(_vlen) { *_vptr=(_set); _vptr++; _vlen--; } \
35 } while(0)
37 #ifdef __cplusplus
38 extern "C"
40 #endif
42 #ifdef MEM_DEBUG
43 #define _xfree free
44 #define _xmalloc malloc
45 #define _xrealloc realloc
46 #define _xcalloc calloc
47 void *xrealloc_gpgrt (void *, size_t);
48 #else
49 void _xfree (void *ptr)
50 __attribute__ ((visibility ("hidden")));
51 void *_xmalloc (size_t size)
52 __attribute__ ((visibility ("hidden")));
53 void *_xrealloc (void *ptr, size_t size)
54 __attribute__ ((visibility ("hidden")));
55 void *_xcalloc (size_t nmemb, size_t size)
56 __attribute__ ((visibility ("hidden")));
57 void *_xrealloc_gpgrt (void *, size_t)
58 __attribute__ ((visibility ("hidden")));
59 #endif
61 #ifdef __cplusplus
63 #endif
65 #endif