2 * Copyright (C) 2001-2012 Free Software Foundation, Inc.
4 * Author: Nikos Mavrogiannopoulos
6 * This file is part of GnuTLS.
8 * The GnuTLS is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>
23 #include <gnutls_int.h>
24 #include <gnutls_errors.h>
25 #include <gnutls_num.h>
28 gnutls_alloc_function gnutls_secure_malloc
= malloc
;
29 gnutls_alloc_function gnutls_malloc
= malloc
;
30 gnutls_free_function gnutls_free
= free
;
31 gnutls_realloc_function gnutls_realloc
= realloc
;
33 void *(*gnutls_calloc
) (size_t, size_t) = calloc
;
34 char *(*gnutls_strdup
) (const char *) = _gnutls_strdup
;
37 _gnutls_calloc (size_t nmemb
, size_t size
)
40 size_t n
= xtimes (nmemb
, size
);
41 ret
= (size_in_bounds_p (n
) ? gnutls_malloc (n
) : NULL
);
43 memset (ret
, 0, size
);
48 gnutls_secure_calloc (size_t nmemb
, size_t size
)
51 size_t n
= xtimes (nmemb
, size
);
52 ret
= (size_in_bounds_p (n
) ? gnutls_secure_malloc (n
) : NULL
);
54 memset (ret
, 0, size
);
58 /* This realloc will free ptr in case realloc
62 gnutls_realloc_fast (void *ptr
, size_t size
)
69 ret
= gnutls_realloc (ptr
, size
);
79 _gnutls_strdup (const char *str
)
81 size_t siz
= strlen (str
) + 1;
84 ret
= gnutls_malloc (siz
);
86 memcpy (ret
, str
, siz
);
92 /* don't use them. They are included for documentation.
97 * @s: size to allocate in bytes
99 * This function will allocate 's' bytes data, and
100 * return a pointer to memory. This function is supposed
101 * to be used by callbacks.
103 * The allocation function used is the one set by
104 * gnutls_global_set_mem_functions().
107 gnutls_malloc (size_t s
)
113 * @ptr: pointer to memory
115 * This function will free data pointed by ptr.
117 * The deallocation function used is the one set by
118 * gnutls_global_set_mem_functions().
122 gnutls_free (void *ptr
)