Module Name: src Committed By: christos Date: Thu Jan 14 20:41:23 UTC 2016
Modified Files: src/lib/libc/gen: Makefile.inc vis.3 vis.c Log Message: add stravis(3) from OpenBSD To generate a diff of this commit: cvs rdiff -u -r1.192 -r1.193 src/lib/libc/gen/Makefile.inc cvs rdiff -u -r1.43 -r1.44 src/lib/libc/gen/vis.3 cvs rdiff -u -r1.70 -r1.71 src/lib/libc/gen/vis.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/Makefile.inc diff -u src/lib/libc/gen/Makefile.inc:1.192 src/lib/libc/gen/Makefile.inc:1.193 --- src/lib/libc/gen/Makefile.inc:1.192 Sun Oct 25 12:01:04 2015 +++ src/lib/libc/gen/Makefile.inc Thu Jan 14 15:41:23 2016 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.inc,v 1.192 2015/10/25 16:01:04 pooka Exp $ +# $NetBSD: Makefile.inc,v 1.193 2016/01/14 20:41:23 christos Exp $ # from: @(#)Makefile.inc 8.6 (Berkeley) 5/4/95 # gen sources @@ -188,7 +188,7 @@ MLINKS+=unvis.3 strnunvis.3 unvis.3 strn MLINKS+=vis.3 svis.3 vis.3 strvis.3 vis.3 strvisx.3 vis.3 strsvis.3 \ vis.3 strsvisx.3 vis.3 nvis.3 MLINKS+=vis.3 snvis.3 vis.3 strnvis.3 vis.3 strnvisx.3 vis.3 strsnvis.3 \ - vis.3 strsnvisx.3 + vis.3 strsnvisx.3 vis.3 stravis.3 CPPFLAGS.ctype_.c+= -I${LIBCDIR}/locale CPPFLAGS.isctype.c+= -I${LIBCDIR}/locale Index: src/lib/libc/gen/vis.3 diff -u src/lib/libc/gen/vis.3:1.43 src/lib/libc/gen/vis.3:1.44 --- src/lib/libc/gen/vis.3:1.43 Sat May 23 07:47:56 2015 +++ src/lib/libc/gen/vis.3 Thu Jan 14 15:41:23 2016 @@ -1,4 +1,4 @@ -.\" $NetBSD: vis.3,v 1.43 2015/05/23 11:47:56 christos Exp $ +.\" $NetBSD: vis.3,v 1.44 2016/01/14 20:41:23 christos Exp $ .\" .\" Copyright (c) 1989, 1991, 1993 .\" The Regents of the University of California. All rights reserved. @@ -29,13 +29,14 @@ .\" .\" @(#)vis.3 8.1 (Berkeley) 6/9/93 .\" -.Dd May 23, 2015 +.Dd January 14, 2015 .Dt VIS 3 .Os .Sh NAME .Nm vis , .Nm nvis , .Nm strvis , +.Nm stravis , .Nm strnvis , .Nm strvisx , .Nm strnvisx , @@ -59,6 +60,8 @@ .Ft int .Fn strvis "char *dst" "const char *src" "int flag" .Ft int +.Fn stravis "char **dst" "const char *src" "int flag" +.Ft int .Fn strnvis "char *dst" "size_t dlen" "const char *src" "int flag" .Ft int .Fn strvisx "char *dst" "const char *src" "size_t len" "int flag" @@ -111,6 +114,7 @@ encoding format (explained below). .Pp The .Fn strvis , +.Fn stravis , .Fn strnvis , .Fn strvisx , and @@ -157,6 +161,9 @@ forms return the number of characters in (not including the trailing .Dv NUL ) . The +.Fn stravis +function allocates space dynamically to hold the string. +The .Dq Nm n versions of the functions also take an additional argument .Fa dlen Index: src/lib/libc/gen/vis.c diff -u src/lib/libc/gen/vis.c:1.70 src/lib/libc/gen/vis.c:1.71 --- src/lib/libc/gen/vis.c:1.70 Tue May 26 17:42:46 2015 +++ src/lib/libc/gen/vis.c Thu Jan 14 15:41:23 2016 @@ -1,4 +1,4 @@ -/* $NetBSD: vis.c,v 1.70 2015/05/26 21:42:46 christos Exp $ */ +/* $NetBSD: vis.c,v 1.71 2016/01/14 20:41:23 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -57,7 +57,7 @@ #include <sys/cdefs.h> #if defined(LIBC_SCCS) && !defined(lint) -__RCSID("$NetBSD: vis.c,v 1.70 2015/05/26 21:42:46 christos Exp $"); +__RCSID("$NetBSD: vis.c,v 1.71 2016/01/14 20:41:23 christos Exp $"); #endif /* LIBC_SCCS and not lint */ #ifdef __FBSDID __FBSDID("$FreeBSD$"); @@ -389,7 +389,7 @@ makeextralist(int flags, const char *src * All user-visible functions call this one. */ static int -istrsenvisx(char *mbdst, size_t *dlen, const char *mbsrc, size_t mblength, +istrsenvisx(char **mbdstp, size_t *dlen, const char *mbsrc, size_t mblength, int flags, const char *mbextra, int *cerr_ptr) { wchar_t *dst, *src, *pdst, *psrc, *start, *extra; @@ -398,9 +398,10 @@ istrsenvisx(char *mbdst, size_t *dlen, c wint_t c; visfun_t f; int clen = 0, cerr, error = -1, i, shft; + char *mbdst, *mdst; ssize_t mbslength, maxolen; - _DIAGASSERT(mbdst != NULL); + _DIAGASSERT(mbdstp != NULL); _DIAGASSERT(mbsrc != NULL || mblength == 0); _DIAGASSERT(mbextra != NULL); @@ -419,10 +420,18 @@ istrsenvisx(char *mbdst, size_t *dlen, c /* Allocate space for the wide char strings */ psrc = pdst = extra = NULL; + mdst = NULL; if ((psrc = calloc(mblength + 1, sizeof(*psrc))) == NULL) return -1; if ((pdst = calloc((4 * mblength) + 1, sizeof(*pdst))) == NULL) goto out; + if (*mbdstp == NULL) { + if ((mdst = calloc((4 * mblength) + 1, sizeof(*mdst))) == NULL) + goto out; + *mbdstp = mdst; + } + + mbdst = *mbdstp; dst = pdst; src = psrc; @@ -487,7 +496,7 @@ istrsenvisx(char *mbdst, size_t *dlen, c errno = ENOSPC; goto out; } - *mbdst = '\0'; /* can't create extra, return "" */ + *mbdst = '\0'; /* can't create extra, return "" */ error = 0; goto out; } @@ -574,14 +583,15 @@ out: free(extra); free(pdst); free(psrc); + free(mdst); return error; } static int -istrsenvisxl(char *mbdst, size_t *dlen, const char *mbsrc, +istrsenvisxl(char **mbdstp, size_t *dlen, const char *mbsrc, int flags, const char *mbextra, int *cerr_ptr) { - return istrsenvisx(mbdst, dlen, mbsrc, + return istrsenvisx(mbdstp, dlen, mbsrc, mbsrc != NULL ? strlen(mbsrc) : 0, flags, mbextra, cerr_ptr); } @@ -604,7 +614,7 @@ svis(char *mbdst, int c, int flags, int cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, NULL, cc, 1, flags, mbextra, NULL); + ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, mbextra, NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -619,7 +629,7 @@ snvis(char *mbdst, size_t dlen, int c, i cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, mbextra, NULL); + ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, mbextra, NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -628,33 +638,33 @@ snvis(char *mbdst, size_t dlen, int c, i int strsvis(char *mbdst, const char *mbsrc, int flags, const char *mbextra) { - return istrsenvisxl(mbdst, NULL, mbsrc, flags, mbextra, NULL); + return istrsenvisxl(&mbdst, NULL, mbsrc, flags, mbextra, NULL); } int strsnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags, const char *mbextra) { - return istrsenvisxl(mbdst, &dlen, mbsrc, flags, mbextra, NULL); + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, mbextra, NULL); } int strsvisx(char *mbdst, const char *mbsrc, size_t len, int flags, const char *mbextra) { - return istrsenvisx(mbdst, NULL, mbsrc, len, flags, mbextra, NULL); + return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, mbextra, NULL); } int strsnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, const char *mbextra) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, NULL); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, NULL); } int strsenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, const char *mbextra, int *cerr_ptr) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, mbextra, cerr_ptr); } #endif @@ -671,7 +681,7 @@ vis(char *mbdst, int c, int flags, int n cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, NULL, cc, 1, flags, "", NULL); + ret = istrsenvisx(&mbdst, NULL, cc, 1, flags, "", NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -686,7 +696,7 @@ nvis(char *mbdst, size_t dlen, int c, in cc[0] = c; cc[1] = nextc; - ret = istrsenvisx(mbdst, &dlen, cc, 1, flags, "", NULL); + ret = istrsenvisx(&mbdst, &dlen, cc, 1, flags, "", NULL); if (ret < 0) return NULL; return mbdst + ret; @@ -703,13 +713,20 @@ nvis(char *mbdst, size_t dlen, int c, in int strvis(char *mbdst, const char *mbsrc, int flags) { - return istrsenvisxl(mbdst, NULL, mbsrc, flags, "", NULL); + return istrsenvisxl(&mbdst, NULL, mbsrc, flags, "", NULL); } int strnvis(char *mbdst, size_t dlen, const char *mbsrc, int flags) { - return istrsenvisxl(mbdst, &dlen, mbsrc, flags, "", NULL); + return istrsenvisxl(&mbdst, &dlen, mbsrc, flags, "", NULL); +} + +int +stravis(char **mbdstp, const char *mbsrc, int flags) +{ + *mbdstp = NULL; + return istrsenvisxl(mbdstp, NULL, mbsrc, flags, "", NULL); } /* @@ -726,19 +743,19 @@ strnvis(char *mbdst, size_t dlen, const int strvisx(char *mbdst, const char *mbsrc, size_t len, int flags) { - return istrsenvisx(mbdst, NULL, mbsrc, len, flags, "", NULL); + return istrsenvisx(&mbdst, NULL, mbsrc, len, flags, "", NULL); } int strnvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", NULL); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", NULL); } int strenvisx(char *mbdst, size_t dlen, const char *mbsrc, size_t len, int flags, int *cerr_ptr) { - return istrsenvisx(mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr); + return istrsenvisx(&mbdst, &dlen, mbsrc, len, flags, "", cerr_ptr); } #endif