2 This file is part of tgl-library
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or(at your option) any later version.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18 Copyright Vitaly Valtman 2013-2015
24 #include <openssl/err.h>
28 #define talloc tgl_allocator->alloc
29 #define talloc0 tgl_alloc0
30 #define tfree tgl_allocator->free
31 #define tfree_str tgl_free_str
32 #define tfree_secure tgl_free_secure
33 #define trealloc tgl_allocator->realloc
34 #define tcheck tgl_allocator->check
35 #define texists tgl_allocator->exists
36 #define tstrdup tgl_strdup
37 #define tstrndup tgl_strndup
38 #define tasprintf tgl_asprintf
39 #define tsnprintf tgl_snprintf
42 struct tgl_allocator *tgl_allocator;
43 double tglt_get_double_time(void);
45 void logprintf_x(int level, const char *format, ...);
47 int tgl_inflate(void *input, int ilen, void *output, int olen);
49 //void ensure_ptr(void *p);
51 static inline void out_of_memory(void)
53 fprintf(stderr, "Out of memory\n");
57 static inline void ensure(int r)
60 fprintf(stderr, "Open SSL error\n");
61 ERR_print_errors_fp(stderr);
66 static inline void ensure_ptr(void *p)
73 void *tgl_alloc_debug(size_t size);
74 void *tgl_alloc_release(size_t size);
75 void *tgl_realloc_debug(void *ptr, size_t old_size, size_t size);
76 void *tgl_realloc_release(void *ptr, size_t old_size, size_t size);
77 void *tgl_alloc0(size_t size);
78 char *tgl_strdup(const char *s);
79 char *tgl_strndup(const char *s, size_t n);
80 void tgl_free_debug(void *ptr, int size);
81 void tgl_free_release(void *ptr, int size);
82 //void tgl_free_str(void *ptr);
83 //void tgl_free_secure(void *ptr, int size);
84 void tgl_check_debug(void);
85 void tgl_exists_debug(void *ptr, int size);
86 void tgl_check_release(void);
87 void tgl_exists_release(void *ptr, int size);
88 int tgl_snprintf(char *buf, int len, const char *format, ...) __attribute__((format(printf, 3, 4)));
89 int tgl_asprintf(char **res, const char *format, ...) __attribute__((format(printf, 2, 3)));
90 void tglt_secure_random(void *s, int l);
91 void tgl_my_clock_gettime(int clock_id, struct timespec *T);
94 static inline void tgl_free_str(void *ptr)
99 tfree(ptr, strlen(ptr) + 1);
102 static inline void tgl_free_secure(void *ptr, int size)
104 memset(ptr, 0, size);
108 static inline void hexdump(void *ptr, void *end_ptr)
111 while (ptr < end_ptr) {
112 fprintf(stderr, "%02x",(int)*(unsigned char *)ptr);
116 fprintf(stderr, "\n");
121 fprintf(stderr, "\n");