2 * Copyright (C) 2001, 2002, 2003, 2004, 2005, 2008, 2010 Free Software
5 * Author: Nikos Mavrogiannopoulos
7 * This file is part of GnuTLS.
9 * The GnuTLS is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public License
11 * as published by the Free Software Foundation; either version 2.1 of
12 * the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
26 #include <gnutls_int.h>
27 #include <gnutls_errors.h>
28 #include <gnutls_num.h>
31 gnutls_alloc_function gnutls_secure_malloc
= malloc
;
32 gnutls_alloc_function gnutls_malloc
= malloc
;
33 gnutls_free_function gnutls_free
= free
;
34 gnutls_realloc_function gnutls_realloc
= realloc
;
36 void *(*gnutls_calloc
) (size_t, size_t) = calloc
;
37 char *(*gnutls_strdup
) (const char *) = _gnutls_strdup
;
40 _gnutls_is_secure_mem_null (const void *ign
)
45 int (*_gnutls_is_secure_memory
) (const void *) = _gnutls_is_secure_mem_null
;
49 _gnutls_calloc (size_t nmemb
, size_t size
)
52 size_t n
= xtimes (nmemb
, size
);
53 ret
= (size_in_bounds_p (n
) ? gnutls_malloc (n
) : NULL
);
55 memset (ret
, 0, size
);
60 gnutls_secure_calloc (size_t nmemb
, size_t size
)
63 size_t n
= xtimes (nmemb
, size
);
64 ret
= (size_in_bounds_p (n
) ? gnutls_secure_malloc (n
) : NULL
);
66 memset (ret
, 0, size
);
70 /* This realloc will free ptr in case realloc
74 gnutls_realloc_fast (void *ptr
, size_t size
)
81 ret
= gnutls_realloc (ptr
, size
);
91 _gnutls_strdup (const char *str
)
93 size_t siz
= strlen (str
) + 1;
96 ret
= gnutls_malloc (siz
);
98 memcpy (ret
, str
, siz
);
104 /* don't use them. They are included for documentation.
110 * This function will allocate 's' bytes data, and
111 * return a pointer to memory. This function is supposed
112 * to be used by callbacks.
114 * The allocation function used is the one set by
115 * gnutls_global_set_mem_functions().
118 gnutls_malloc (size_t s
)
124 * @d: pointer to memory
126 * This function will free data pointed by ptr.
128 * The deallocation function used is the one set by
129 * gnutls_global_set_mem_functions().
133 gnutls_free (void *ptr
)