summaryrefslogtreecommitdiff
path: root/lib/libc
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2014-11-17 19:48:28 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2014-11-17 19:48:28 +0000
commit8933c41929e6a6b5823341de683f9c1ce55d51af (patch)
treecbbc49912754175fc6ba27e9b813cd8498e1e482 /lib/libc
parente1366c2537a2d03af722f810f68cd720c62e89fa (diff)
Add stravis(), an allocating version of strvis(). OK doug@
Diffstat (limited to 'lib/libc')
-rw-r--r--lib/libc/gen/vis.c25
1 files changed, 23 insertions, 2 deletions
diff --git a/lib/libc/gen/vis.c b/lib/libc/gen/vis.c
index a1f4b0fd8b8..579fa81822e 100644
--- a/lib/libc/gen/vis.c
+++ b/lib/libc/gen/vis.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vis.c,v 1.22 2011/03/13 22:21:32 guenther Exp $ */
+/* $OpenBSD: vis.c,v 1.23 2014/11/17 19:48:27 millert Exp $ */
/*-
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
@@ -29,9 +29,11 @@
*/
#include <sys/types.h>
-#include <limits.h>
+#include <errno.h>
#include <ctype.h>
+#include <limits.h>
#include <string.h>
+#include <stdlib.h>
#include <vis.h>
#define isoctal(c) (((u_char)(c)) >= '0' && ((u_char)(c)) <= '7')
@@ -204,6 +206,25 @@ strnvis(char *dst, const char *src, size_t siz, int flag)
}
int
+stravis(char **outp, const char *src, int flag)
+{
+ char *buf;
+ int len, serrno;
+
+ buf = reallocarray(NULL, 4, strlen(src) + 1);
+ if (buf == NULL)
+ return -1;
+ len = strvis(buf, src, flag);
+ serrno = errno;
+ *outp = realloc(buf, len + 1);
+ if (*outp == NULL) {
+ *outp = buf;
+ errno = serrno;
+ }
+ return (len);
+}
+
+int
strvisx(char *dst, const char *src, size_t len, int flag)
{
char c;