Patrick Welche <prlw1@cam.ac.uk>
[netbsd-mini2440.git] / external / bsd / ntp / dist / include / ssl_applink.c
blob14a2d7b83891c8029bf623861ce2ca6e69e695d4
1 /* $NetBSD$ */
3 /*
4 * include/ssl_applink.c -- common NTP code for openssl/applink.c
6 * Each program which uses OpenSSL should include this file in _one_
7 * of its source files and call ssl_applink() before any OpenSSL
8 * functions.
9 */
11 #if defined(OPENSSL) && defined(SYS_WINNT)
12 # ifdef _MSC_VER
13 # pragma warning(push)
14 # pragma warning(disable: 4152)
15 # endif
16 # include <openssl/applink.c>
17 # ifdef _MSC_VER
18 # pragma warning(pop)
19 # endif
20 #endif
22 #if defined(OPENSSL) && defined(_MSC_VER) && defined(_DEBUG)
23 #define WRAP_DBG_MALLOC
24 #endif
26 #ifdef WRAP_DBG_MALLOC
27 void *wrap_dbg_malloc(size_t s, const char *f, int l);
28 void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l);
29 void wrap_dbg_free(void *p);
30 #endif
33 #if defined(OPENSSL) && defined(SYS_WINNT)
34 void ssl_applink(void);
36 void
37 ssl_applink(void)
39 #ifdef WRAP_DBG_MALLOC
40 CRYPTO_set_mem_ex_functions(wrap_dbg_malloc, wrap_dbg_realloc, wrap_dbg_free);
41 #else
42 CRYPTO_malloc_init();
43 #endif
45 #else /* !OPENSSL || !SYS_WINNT */
46 #define ssl_applink() do {} while (0)
47 #endif
50 #ifdef WRAP_DBG_MALLOC
52 * OpenSSL malloc overriding uses different parameters
53 * for DEBUG malloc/realloc/free (lacking block type).
54 * Simple wrappers convert.
56 void *wrap_dbg_malloc(size_t s, const char *f, int l)
58 void *ret;
60 ret = _malloc_dbg(s, _NORMAL_BLOCK, f, l);
61 return ret;
64 void *wrap_dbg_realloc(void *p, size_t s, const char *f, int l)
66 void *ret;
68 ret = _realloc_dbg(p, s, _NORMAL_BLOCK, f, l);
69 return ret;
72 void wrap_dbg_free(void *p)
74 _free_dbg(p, _NORMAL_BLOCK);
76 #endif /* WRAP_DBG_MALLOC */