Mercurial > hg > th-libs
annotate th_util.c @ 553:3a852e9f70a6
Bump copyright years.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 03 Jan 2020 10:53:55 +0200 |
parents | 41c1d786ff08 |
children | f2aa3c809247 |
rev | line source |
---|---|
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * Generic utility-functions, macros and defaults |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
553 | 4 * (C) Copyright 2002-2020 Tecnic Software productions (TNSP) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 #include "th_util.h" |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include <stdio.h> |
96 | 10 #include <errno.h> |
11 | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
12 |
4
67f4a4233372
Move defaults to header file.
Matti Hamalainen <ccr@tnsp.org>
parents:
0
diff
changeset
|
13 /* Default settings |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 */ |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
15 static BOOL th_initialized = FALSE; |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
468
diff
changeset
|
16 int th_verbosity = 2; |
60 | 17 char *th_prog_name = NULL, |
18 *th_prog_desc = NULL, | |
19 *th_prog_version = NULL, | |
20 *th_prog_author = NULL, | |
21 *th_prog_license = NULL; | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
22 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
23 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 /* Initialize th_util-library and global variables |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 */ |
60 | 26 void th_init(char *name, char *desc, char *version, |
27 char *author, char *license) | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
28 { |
60 | 29 th_prog_name = name; |
30 th_prog_desc = desc; | |
31 th_prog_version = version; | |
471
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
32 |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
33 #ifdef TH_PROG_AUTHOR |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
34 th_prog_author = author == NULL ? TH_PROG_AUTHOR : NULL; |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
35 #else |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
36 th_prog_author = author; |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
37 #endif |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
38 |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
39 #ifdef TH_PROG_LICENSE |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
40 th_prog_license = license == NULL ? TH_PROG_LICENSE : NULL; |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
41 #else |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
42 th_prog_license = license; |
02a2a46f5485
Allow TH_PROG_AUTHOR and TH_PROG_LICENSE to be defined to override
Matti Hamalainen <ccr@tnsp.org>
parents:
470
diff
changeset
|
43 #endif |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
45 th_initialized = TRUE; |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
46 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
48 |
64 | 49 void th_print_banner(FILE *outFile, const char *name, const char *usage) |
45
e031a062b731
Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
50 { |
470
167b66942c24
Remove newline from start of the banner.
Matti Hamalainen <ccr@tnsp.org>
parents:
469
diff
changeset
|
51 fprintf(outFile, "%s", th_prog_name); |
177
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
52 if (th_prog_version != NULL) |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
53 fprintf(outFile, " v%s", th_prog_version); |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
54 if (th_prog_desc != NULL) |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
55 fprintf(outFile, " (%s)", th_prog_desc); |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
56 fprintf(outFile, "\n"); |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
57 |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
58 if (th_prog_author != NULL) |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
59 fprintf(outFile, "%s\n", th_prog_author); |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
60 |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
61 if (th_prog_license != NULL) |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
62 fprintf(outFile, "%s\n", th_prog_license); |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
63 |
2b07e452fd78
Adjust program banner printing.
Matti Hamalainen <ccr@tnsp.org>
parents:
162
diff
changeset
|
64 fprintf(outFile, "Usage: %s %s\n", name, usage); |
45
e031a062b731
Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
65 } |
e031a062b731
Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
66 |
e031a062b731
Separate program "banner" printing from th_args_help() to th_print_banner().
Matti Hamalainen <ccr@tnsp.org>
parents:
40
diff
changeset
|
67 |
489 | 68 void th_print_version(FILE *outFile) |
69 { | |
70 fprintf(outFile, "%s", th_prog_name); | |
71 if (th_prog_version != NULL) | |
72 fprintf(outFile, " v%s", th_prog_version); | |
73 fprintf(outFile, "\n"); | |
74 } | |
75 | |
76 | |
143 | 77 int th_term_width() |
78 { | |
79 char *var = getenv("COLUMNS"); | |
80 int res = (var != NULL) ? atoi(var) : 80; | |
81 if (res < 5) res = 80; | |
82 return res; | |
83 } | |
84 | |
85 | |
86 int th_term_height() | |
87 { | |
467
b92b18500bf9
Oops. We've been trying to get number of terminal lines from environment
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
88 char *var = getenv("LINES"); |
143 | 89 int res = (var != NULL) ? atoi(var) : 25; |
90 if (res < 1) res = 1; | |
91 return res; | |
92 } | |
93 | |
94 | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 /* Print formatted error, warning and information messages |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
96 * TODO: Implement th_vfprintf() and friends? |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 */ |
11 | 98 void THERR_V(const char *fmt, va_list ap) |
99 { | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
100 assert(th_initialized == TRUE); |
11 | 101 |
102 fprintf(stderr, "%s: ", th_prog_name); | |
103 vfprintf(stderr, fmt, ap); | |
104 } | |
105 | |
106 | |
107 void THMSG_V(int level, const char *fmt, va_list ap) | |
108 { | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
109 assert(th_initialized == TRUE); |
11 | 110 |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
468
diff
changeset
|
111 if (th_verbosity >= level) |
48 | 112 { |
11 | 113 fprintf(stderr, "%s: ", th_prog_name); |
114 vfprintf(stderr, fmt, ap); | |
115 } | |
116 } | |
117 | |
118 | |
119 void THPRINT_V(int level, const char *fmt, va_list ap) | |
120 { | |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
121 assert(th_initialized == TRUE); |
11 | 122 |
469
fe5b803ae449
Rename the global variable th_verbosityLevel to th_verbosity.
Matti Hamalainen <ccr@tnsp.org>
parents:
468
diff
changeset
|
123 if (th_verbosity >= level) |
48 | 124 { |
11 | 125 vfprintf(stderr, fmt, ap); |
126 } | |
127 } | |
128 | |
129 | |
130 void THERR(const char *fmt, ...) | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 { |
10 | 132 va_list ap; |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
133 assert(th_initialized == TRUE); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
134 |
11 | 135 va_start(ap, fmt); |
136 THERR_V(fmt, ap); | |
10 | 137 va_end(ap); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
138 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
11 | 141 void THMSG(int level, const char *fmt, ...) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 { |
10 | 143 va_list ap; |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
144 assert(th_initialized == TRUE); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 |
11 | 146 va_start(ap, fmt); |
147 THMSG_V(level, fmt, ap); | |
148 va_end(ap); | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
149 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
150 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
151 |
11 | 152 void THPRINT(int level, const char *fmt, ...) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
10 | 154 va_list ap; |
457
85fa3d333556
Actually, revert the boolean changes .. meh.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
155 assert(th_initialized == TRUE); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
156 |
11 | 157 va_start(ap, fmt); |
158 THPRINT_V(level, fmt, ap); | |
159 va_end(ap); | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 |
96 | 163 /* Error handling |
164 */ | |
101
a8f732601fdc
Rename th_get_errno() to th_get_error(), it's more appropriate since it does
Matti Hamalainen <ccr@tnsp.org>
parents:
99
diff
changeset
|
165 int th_get_error() |
96 | 166 { |
167 return TH_SYSTEM_ERRORS + errno; | |
168 } | |
169 | |
170 | |
99 | 171 int th_errno_to_error(int error) |
172 { | |
173 return TH_SYSTEM_ERRORS + error; | |
174 } | |
175 | |
176 | |
96 | 177 const char *th_error_str(int error) |
178 { | |
179 if (error >= TH_SYSTEM_ERRORS) | |
180 return strerror(error - TH_SYSTEM_ERRORS); | |
441
2991e6b52d95
Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
181 |
96 | 182 switch (error) |
183 { | |
184 case THERR_OK: return "No error"; | |
185 case THERR_FOPEN: return "File open error"; | |
186 case THERR_FREAD: return "Read error"; | |
187 case THERR_FWRITE: return "Write error"; | |
188 case THERR_FSEEK: return "Seek error"; | |
189 case THERR_NOT_FOUND: return "Resource not found"; | |
190 | |
191 case THERR_INVALID_DATA: return "Invalid data"; | |
192 case THERR_MALLOC: return "Memory allocation failure"; | |
193 case THERR_ALREADY_INIT: return "Already initialized"; | |
194 case THERR_INIT_FAIL: return "Initialization failed"; | |
195 case THERR_INVALID_ARGS: return "Invalid arguments"; | |
196 | |
197 case THERR_NULLPTR: return "NULL pointer"; | |
198 case THERR_NOT_SUPPORTED: return "Operation not supported"; | |
199 case THERR_OUT_OF_DATA: return "Out of data"; | |
200 case THERR_EXTRA_DATA: return "Extra data"; | |
201 case THERR_BOUNDS: return "Bounds check failed"; | |
202 | |
203 case THERR_TIMED_OUT: return "Operation timed out"; | |
441
2991e6b52d95
Get rid of trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
269
diff
changeset
|
204 |
96 | 205 case THERR_AUTH_FAILED: return "Authentication failed"; |
206 | |
207 default: return "Unknown error"; | |
208 } | |
209 } | |
210 | |
211 | |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
212 /* Memory handling routines |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 */ |
462 | 214 void *th_malloc(size_t len) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 { |
462 | 216 return malloc(len); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 |
462 | 220 void *th_malloc0(size_t len) |
68
29f9651465c6
Added a new memory allocator function, th_malloc0(size), which is the same as calloc(1, size).
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
221 { |
462 | 222 return calloc(1, len); |
68
29f9651465c6
Added a new memory allocator function, th_malloc0(size), which is the same as calloc(1, size).
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
223 } |
29f9651465c6
Added a new memory allocator function, th_malloc0(size), which is the same as calloc(1, size).
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
224 |
29f9651465c6
Added a new memory allocator function, th_malloc0(size), which is the same as calloc(1, size).
Matti Hamalainen <ccr@tnsp.org>
parents:
66
diff
changeset
|
225 |
462 | 226 void *th_calloc(size_t n, size_t len) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
227 { |
462 | 228 return calloc(n, len); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
229 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
230 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 |
462 | 232 void *th_realloc(void *ptr, size_t len) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 { |
462 | 234 return realloc(ptr, len); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
235 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
236 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
237 |
194
87dac812cac4
Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
238 void th_free(void *ptr) |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 { |
10 | 240 /* Check for NULL pointers for portability due to some libc |
241 * implementations not handling free(NULL) too well. | |
242 */ | |
194
87dac812cac4
Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
243 if (ptr != NULL) free(ptr); |
0
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 } |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 |
bd61a80a6c54
Initial import into Mercurial repository. Discarding old cvs/svn history
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
246 |
197
88986d0b56ef
Rename th_free_r() to th_free_r_real() and #define a macro wrapper for
Matti Hamalainen <ccr@tnsp.org>
parents:
195
diff
changeset
|
247 void th_free_r_real(void **ptr) |
192
7d25d43a3ce2
Add new function th_free_r(void **ptr) that calls th_free(*ptr) and sets *ptr to NULL.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
248 { |
195 | 249 if (ptr != NULL) |
192
7d25d43a3ce2
Add new function th_free_r(void **ptr) that calls th_free(*ptr) and sets *ptr to NULL.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
250 { |
194
87dac812cac4
Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
251 th_free(*ptr); |
87dac812cac4
Define some argument identifiers in function prototypes and rename some arguments.
Matti Hamalainen <ccr@tnsp.org>
parents:
192
diff
changeset
|
252 *ptr = NULL; |
192
7d25d43a3ce2
Add new function th_free_r(void **ptr) that calls th_free(*ptr) and sets *ptr to NULL.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
253 } |
7d25d43a3ce2
Add new function th_free_r(void **ptr) that calls th_free(*ptr) and sets *ptr to NULL.
Matti Hamalainen <ccr@tnsp.org>
parents:
177
diff
changeset
|
254 } |