Mercurial > trustbridge
comparison common/strhelp.c @ 319:4077eff1dd39
Added terminateing version of asprintf.
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Fri, 04 Apr 2014 17:58:14 +0200 |
parents | c4a989a0d6cf |
children | 17e1c8f37d72 |
comparison
equal
deleted
inserted
replaced
318:6ccaf25219fd | 319:4077eff1dd39 |
---|---|
1 /* Needed to get asprintf */ | |
2 #define _GNU_SOURCE 1 | |
3 | |
1 #include <ctype.h> | 4 #include <ctype.h> |
5 #include <stdarg.h> | |
2 #include <stdbool.h> | 6 #include <stdbool.h> |
3 #include <stdio.h> | 7 #include <stdio.h> |
4 #include <stdlib.h> | 8 #include <stdlib.h> |
5 #include <string.h> | 9 #include <string.h> |
6 #include <assert.h> | 10 #include <assert.h> |
192 { | 196 { |
193 if (p) | 197 if (p) |
194 free (p); | 198 free (p); |
195 } | 199 } |
196 | 200 |
201 int | |
202 xasprintf (char **strp, const char *fmt, ...) | |
203 { | |
204 int ret; | |
205 va_list ap; | |
206 va_start(ap, fmt); | |
207 ret = vasprintf(strp, fmt, ap); | |
208 va_end(ap); | |
209 | |
210 if (ret == -1) | |
211 out_of_core(); | |
212 | |
213 return ret; | |
214 } | |
215 | |
197 #ifdef WIN32 | 216 #ifdef WIN32 |
198 /* Adapted from GPGOL rev. e512053 */ | 217 /* Adapted from GPGOL rev. e512053 */ |
199 char * | 218 char * |
200 wchar_to_utf8 (const wchar_t *string, size_t len) | 219 wchar_to_utf8 (const wchar_t *string, size_t len) |
201 { | 220 { |