aboutsummaryrefslogtreecommitdiffstats
path: root/src/init.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2017-11-17 10:00:39 +0000
committerWerner Koch <[email protected]>2017-11-17 10:00:39 +0000
commit80c18e1b212cc91946864db7a53da50e9f91b861 (patch)
tree2a925cf0e741bee400c033b2f922f8f0d55412cf /src/init.c
parentcore: Add logging API. (diff)
downloadlibgpg-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.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/init.c b/src/init.c
index b01e089..0154091 100644
--- a/src/init.c
+++ b/src/init.c
@@ -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)