summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDoug Hogan <doug@cvs.openbsd.org>2015-02-06 05:51:07 +0000
committerDoug Hogan <doug@cvs.openbsd.org>2015-02-06 05:51:07 +0000
commit1ec3fcaca70775496646b4fb77e65b58253c1fa9 (patch)
treedb5d63c3fa5d5a450d4362013ed2115136f4a06e
parent63a38e6197f678bb3dea0e82a2ca8425bedffed7 (diff)
Add support for stravis() to vis.3 and Makefile.inc.
stravis(3) is an OpenBSD extension that was added recently. input + ok schwarze@, jmc@, deraadt@
-rw-r--r--lib/libc/gen/Makefile.inc4
-rw-r--r--lib/libc/gen/vis.347
2 files changed, 43 insertions, 8 deletions
diff --git a/lib/libc/gen/Makefile.inc b/lib/libc/gen/Makefile.inc
index acb1b4ef79f..b386b3d3fda 100644
--- a/lib/libc/gen/Makefile.inc
+++ b/lib/libc/gen/Makefile.inc
@@ -1,4 +1,4 @@
-# $OpenBSD: Makefile.inc,v 1.66 2014/12/09 07:28:46 deraadt Exp $
+# $OpenBSD: Makefile.inc,v 1.67 2015/02/06 05:51:06 doug Exp $
# gen sources
.PATH: ${LIBCSRCDIR}/arch/${MACHINE_CPU}/gen ${LIBCSRCDIR}/gen
@@ -159,4 +159,4 @@ MLINKS+=tolower.3 _tolower.3
MLINKS+=toupper.3 _toupper.3
MLINKS+=ttyname.3 ttyname_r.3 ttyname.3 isatty.3 ttyname.3 ttyslot.3
MLINKS+=unvis.3 strunvis.3 unvis.3 strnunvis.3
-MLINKS+=vis.3 strvis.3 vis.3 strnvis.3 vis.3 strvisx.3
+MLINKS+=vis.3 strvis.3 vis.3 strnvis.3 vis.3 strvisx.3 vis.3 stravis.3
diff --git a/lib/libc/gen/vis.3 b/lib/libc/gen/vis.3
index 2eb4bb65454..0e681e1a066 100644
--- a/lib/libc/gen/vis.3
+++ b/lib/libc/gen/vis.3
@@ -1,4 +1,4 @@
-.\" $OpenBSD: vis.3,v 1.32 2015/01/30 00:01:59 doug Exp $
+.\" $OpenBSD: vis.3,v 1.33 2015/02/06 05:51:06 doug Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -27,14 +27,15 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd $Mdocdate: January 30 2015 $
+.Dd $Mdocdate: February 6 2015 $
.Dt VIS 3
.Os
.Sh NAME
.Nm vis ,
.Nm strvis ,
.Nm strnvis ,
-.Nm strvisx
+.Nm strvisx ,
+.Nm stravis
.Nd visually encode characters
.Sh SYNOPSIS
.In stdlib.h
@@ -47,6 +48,8 @@
.Fn strnvis "char *dst" "const char *src" "size_t dstsize" "int flag"
.Ft int
.Fn strvisx "char *dst" "const char *src" "size_t srclen" "int flag"
+.Ft int
+.Fn stravis "char **outp" "const char *src" "int flag"
.Sh DESCRIPTION
The
.Fn vis
@@ -106,6 +109,22 @@ into a buffer
This
is useful for encoding a block of data that may contain NULs.
.Pp
+The
+.Fn stravis
+function writes a visual representation of the string
+.Fa src
+into a newly allocated string
+.Fa outp ;
+it does not attempt to
+.Xr realloc 3
+.Fa outp .
+.Fa outp
+should be passed to
+.Xr free 3
+to release the allocated storage when it is no longer needed.
+.Fn stravis
+checks for integer overflow when allocating memory.
+.Pp
All forms NUL-terminate
.Fa dst ,
except for
@@ -301,9 +320,22 @@ the return value of
.Fn strnvis
must not be used without checking it against
.Fa dstsize .
+.Pp
+Upon successful completion,
+.Fn stravis
+returns the number of characters in
+.Pf * Fa outp
+(not including the trailing NUL).
+Otherwise,
+.Fn stravis
+returns -1 and sets
+.Va errno
+to
+.Er ENOMEM .
.Sh SEE ALSO
.Xr unvis 1 ,
.Xr vis 1 ,
+.Xr free 3 ,
.Xr snprintf 3 ,
.Xr strlcpy 3 ,
.Xr unvis 3
@@ -314,11 +346,14 @@ The
and
.Fn strvisx
functions first appeared in
-.Bx 4.4
-and
+.Bx 4.4 ,
.Fn strnvis
in
-.Ox 2.9 .
+.Ox 2.9
+and
+.Fn stravis
+in
+.Ox 5.7 .
.Pp
The
.Dv VIS_ALL