summaryrefslogtreecommitdiff
path: root/utf8.c
diff options
context:
space:
mode:
Diffstat (limited to 'utf8.c')
-rw-r--r--utf8.c27
1 files changed, 21 insertions, 6 deletions
diff --git a/utf8.c b/utf8.c
index db7cb8f35..7f63b25ae 100644
--- a/utf8.c
+++ b/utf8.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: utf8.c,v 1.8 2018/08/21 13:56:27 schwarze Exp $ */ 1/* $OpenBSD: utf8.c,v 1.11 2020/05/01 06:28:52 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org> 3 * Copyright (c) 2016 Ingo Schwarze <schwarze@openbsd.org>
4 * 4 *
@@ -43,7 +43,6 @@
43 43
44static int dangerous_locale(void); 44static int dangerous_locale(void);
45static int grow_dst(char **, size_t *, size_t, char **, size_t); 45static int grow_dst(char **, size_t *, size_t, char **, size_t);
46static int vasnmprintf(char **, size_t, int *, const char *, va_list);
47 46
48 47
49/* 48/*
@@ -101,7 +100,7 @@ grow_dst(char **dst, size_t *sz, size_t maxsz, char **dp, size_t need)
101 * written is returned in *wp. 100 * written is returned in *wp.
102 */ 101 */
103 102
104static int 103int
105vasnmprintf(char **str, size_t maxsz, int *wp, const char *fmt, va_list ap) 104vasnmprintf(char **str, size_t maxsz, int *wp, const char *fmt, va_list ap)
106{ 105{
107 char *src; /* Source string returned from vasprintf. */ 106 char *src; /* Source string returned from vasprintf. */
@@ -241,7 +240,7 @@ int
241snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...) 240snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
242{ 241{
243 va_list ap; 242 va_list ap;
244 char *cp; 243 char *cp = NULL;
245 int ret; 244 int ret;
246 245
247 va_start(ap, fmt); 246 va_start(ap, fmt);
@@ -255,6 +254,20 @@ snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
255 return ret; 254 return ret;
256} 255}
257 256
257int
258asmprintf(char **outp, size_t sz, int *wp, const char *fmt, ...)
259{
260 va_list ap;
261 int ret;
262
263 *outp = NULL;
264 va_start(ap, fmt);
265 ret = vasnmprintf(outp, sz, wp, fmt, ap);
266 va_end(ap);
267
268 return ret;
269}
270
258/* 271/*
259 * To stay close to the standard interfaces, the following functions 272 * To stay close to the standard interfaces, the following functions
260 * return the number of non-NUL bytes written. 273 * return the number of non-NUL bytes written.
@@ -263,11 +276,13 @@ snmprintf(char *str, size_t sz, int *wp, const char *fmt, ...)
263int 276int
264vfmprintf(FILE *stream, const char *fmt, va_list ap) 277vfmprintf(FILE *stream, const char *fmt, va_list ap)
265{ 278{
266 char *str; 279 char *str = NULL;
267 int ret; 280 int ret;
268 281
269 if ((ret = vasnmprintf(&str, INT_MAX, NULL, fmt, ap)) < 0) 282 if ((ret = vasnmprintf(&str, INT_MAX, NULL, fmt, ap)) < 0) {
283 free(str);
270 return -1; 284 return -1;
285 }
271 if (fputs(str, stream) == EOF) 286 if (fputs(str, stream) == EOF)
272 ret = -1; 287 ret = -1;
273 free(str); 288 free(str);