diff options
-rw-r--r-- | misc.c | 29 | ||||
-rw-r--r-- | misc.h | 4 |
2 files changed, 31 insertions, 2 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.c,v 1.144 2020/01/23 07:10:22 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.c,v 1.145 2020/01/24 23:54:40 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. | 4 | * Copyright (c) 2005,2006 Damien Miller. All rights reserved. |
@@ -1244,6 +1244,33 @@ tohex(const void *vp, size_t l) | |||
1244 | return (r); | 1244 | return (r); |
1245 | } | 1245 | } |
1246 | 1246 | ||
1247 | /* | ||
1248 | * Extend string *sp by the specified format. If *sp is not NULL (or empty), | ||
1249 | * then the separator 'sep' will be prepended before the formatted arguments. | ||
1250 | * Extended strings are heap allocated. | ||
1251 | */ | ||
1252 | void | ||
1253 | xextendf(char **sp, const char *sep, const char *fmt, ...) | ||
1254 | { | ||
1255 | va_list ap; | ||
1256 | char *tmp1, *tmp2; | ||
1257 | |||
1258 | va_start(ap, fmt); | ||
1259 | xvasprintf(&tmp1, fmt, ap); | ||
1260 | va_end(ap); | ||
1261 | |||
1262 | if (*sp == NULL || **sp == '\0') { | ||
1263 | free(*sp); | ||
1264 | *sp = tmp1; | ||
1265 | return; | ||
1266 | } | ||
1267 | xasprintf(&tmp2, "%s%s%s", *sp, sep == NULL ? "" : sep, tmp1); | ||
1268 | free(tmp1); | ||
1269 | free(*sp); | ||
1270 | *sp = tmp2; | ||
1271 | } | ||
1272 | |||
1273 | |||
1247 | u_int64_t | 1274 | u_int64_t |
1248 | get_u64(const void *vp) | 1275 | get_u64(const void *vp) |
1249 | { | 1276 | { |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: misc.h,v 1.83 2020/01/23 07:10:22 dtucker Exp $ */ | 1 | /* $OpenBSD: misc.h,v 1.84 2020/01/24 23:54:40 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -69,6 +69,8 @@ long convtime(const char *); | |||
69 | char *tilde_expand_filename(const char *, uid_t); | 69 | char *tilde_expand_filename(const char *, uid_t); |
70 | char *percent_expand(const char *, ...) __attribute__((__sentinel__)); | 70 | char *percent_expand(const char *, ...) __attribute__((__sentinel__)); |
71 | char *tohex(const void *, size_t); | 71 | char *tohex(const void *, size_t); |
72 | void xextendf(char **s, const char *sep, const char *fmt, ...) | ||
73 | __attribute__((__format__ (printf, 3, 4))) __attribute__((__nonnull__ (3))); | ||
72 | void sanitise_stdfd(void); | 74 | void sanitise_stdfd(void); |
73 | void ms_subtract_diff(struct timeval *, int *); | 75 | void ms_subtract_diff(struct timeval *, int *); |
74 | void ms_to_timeval(struct timeval *, int); | 76 | void ms_to_timeval(struct timeval *, int); |