aboutsummaryrefslogtreecommitdiffstats
path: root/kbx/keybox-defs.h
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-12-22 11:55:32 +0000
committerWerner Koch <[email protected]>2017-12-22 11:55:46 +0000
commitf3ba66781a07af2e32f5887e6e15acdd4822a431 (patch)
tree06d8e033bdf2298f0822727ebcc43690fb1d2a2a /kbx/keybox-defs.h
parentcommon: Use larger buffer for homedir in case of 64 bit UIDs. (diff)
downloadgnupg-f3ba66781a07af2e32f5887e6e15acdd4822a431.tar.gz
gnupg-f3ba66781a07af2e32f5887e6e15acdd4822a431.zip
kbx: Simplify by removing custom memory functions.
* kbx/keybox-util.c (keybox_set_malloc_hooks): Remove. (_keybox_malloc, _keybox_calloc, keybox_realloc) (_keybox_free): Remove. (keybox_file_rename): Remove. Was not used. * sm/gpgsm.c (main): Remove call to keybox_set_malloc_hooks. * kbx/kbxutil.c (main): Ditto. * kbx/keybox-defs.h: Remove all separate includes. Include util.h. remove convenience macros. * common/logging.h (return_if_fail): New. Originally from keybox-defs.h but now using log_debug. (return_null_if_fail): Ditto. (return_val_if_fail): Ditto. (never_reached): Ditto. -- Originally the KBX code was written to allow standalone use. However this required lot of ugliness like separate memory allocators and such. It also precludes the use of some standard functions from common due to their use of the common gnupg malloc functions. Dropping all that makes things easier. Minor disadvantages: the kbx call done for gpg will now use gcry malloc fucntions and not the standard malloc functions. This might be a bit slower but removing them even fixes a possible bug in keybox_tmp_names which is used in gpg and uses gpg's xfree which is actually gcry_free. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'kbx/keybox-defs.h')
-rw-r--r--kbx/keybox-defs.h69
1 files changed, 3 insertions, 66 deletions
diff --git a/kbx/keybox-defs.h b/kbx/keybox-defs.h
index fd331f12b..be2dd721f 100644
--- a/kbx/keybox-defs.h
+++ b/kbx/keybox-defs.h
@@ -33,16 +33,7 @@
#include <sys/types.h> /* off_t */
-/* We include the type definitions from jnlib instead of defining our
- owns here. This will not allow us build KBX in a standalone way
- but there is currently no need for it anyway. Same goes for
- stringhelp.h which for example provides a replacement for stpcpy -
- fixme: Better use the LIBOBJ mechnism. */
-#include "../common/types.h"
-#include "../common/stringhelp.h"
-#include "../common/dotlock.h"
-#include "../common/logging.h"
-
+#include "../common/util.h"
#include "keybox.h"
@@ -209,64 +200,10 @@ int _keybox_dump_cut_records (const char *filename, unsigned long from,
/*-- keybox-util.c --*/
-void *_keybox_malloc (size_t n);
-void *_keybox_calloc (size_t n, size_t m);
-void *_keybox_realloc (void *p, size_t n);
-void _keybox_free (void *p);
-
-#define xtrymalloc(a) _keybox_malloc ((a))
-#define xtrycalloc(a,b) _keybox_calloc ((a),(b))
-#define xtryrealloc(a,b) _keybox_realloc((a),(b))
-#define xfree(a) _keybox_free ((a))
-
-
-#define DIM(v) (sizeof(v)/sizeof((v)[0]))
-#define DIMof(type,member) DIM(((type *)0)->member)
-#ifndef STR
-# define STR(v) #v
-#endif
-#define STR2(v) STR(v)
/*
- a couple of handy macros
-*/
-
-#define return_if_fail(expr) do { \
- if (!(expr)) { \
- fprintf (stderr, "%s:%d: assertion '%s' failed\n", \
- __FILE__, __LINE__, #expr ); \
- return; \
- } } while (0)
-#define return_null_if_fail(expr) do { \
- if (!(expr)) { \
- fprintf (stderr, "%s:%d: assertion '%s' failed\n", \
- __FILE__, __LINE__, #expr ); \
- return NULL; \
- } } while (0)
-#define return_val_if_fail(expr,val) do { \
- if (!(expr)) { \
- fprintf (stderr, "%s:%d: assertion '%s' failed\n", \
- __FILE__, __LINE__, #expr ); \
- return (val); \
- } } while (0)
-#define never_reached() do { \
- fprintf (stderr, "%s:%d: oops; should never get here\n", \
- __FILE__, __LINE__ ); \
- } while (0)
-
-
-/* some macros to replace ctype ones and avoid locale problems */
-#define digitp(p) (*(p) >= '0' && *(p) <= '9')
-#define hexdigitp(a) (digitp (a) \
- || (*(a) >= 'A' && *(a) <= 'F') \
- || (*(a) >= 'a' && *(a) <= 'f'))
-/* the atoi macros assume that the buffer has only valid digits */
-#define atoi_1(p) (*(p) - '0' )
-#define atoi_2(p) ((atoi_1(p) * 10) + atoi_1((p)+1))
-#define atoi_4(p) ((atoi_2(p) * 100) + atoi_2((p)+2))
-#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
- *(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
-#define xtoi_2(p) ((xtoi_1(p) * 16) + xtoi_1((p)+1))
+ * A couple of handy macros
+ */
#endif /*KEYBOX_DEFS_H*/