diff options
author | Werner Koch <[email protected]> | 2017-11-17 10:00:39 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2017-11-17 10:00:39 +0000 |
commit | 80c18e1b212cc91946864db7a53da50e9f91b861 (patch) | |
tree | 2a925cf0e741bee400c033b2f922f8f0d55412cf /src/init.c | |
parent | core: Add logging API. (diff) | |
download | libgpg-error-80c18e1b212cc91946864db7a53da50e9f91b861.tar.gz libgpg-error-80c18e1b212cc91946864db7a53da50e9f91b861.zip |
core: New API functions gpgrt_malloc, gpgrt_calloc, and gpgrt_realloc.
* src/visibility.c (gpgrt_realloc): New API function.
(gpgrt_malloc): New API function.
(gpgrt_calloc): New API function.
* src/visibility.h: Add corresponding macros.
* src/gpg-error.def.in: Add them.
* src/gpg-error.vers: Add them.
* src/init.c (_gpgrt_calloc): New.
* src/gpg-error.h.in: Add prototypes.
Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'src/init.c')
-rw-r--r-- | src/init.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -194,6 +194,27 @@ _gpgrt_malloc (size_t n) } +void * +_gpgrt_calloc (size_t n, size_t m) +{ + size_t bytes; + void *p; + + bytes = n * m; /* size_t is unsigned so the behavior on overflow is + defined. */ + if (m && bytes / m != n) + { + _gpg_err_set_errno (ENOMEM); + return NULL; + } + + p = _gpgrt_realloc (NULL, bytes); + if (p) + memset (p, 0, bytes); + return p; +} + + /* The free to be used for data returned by the public API. */ void _gpgrt_free (void *a) |