Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen add stravis(3) from OpenBSD
details: https://anonhg.NetBSD.org/src/rev/c4c99e76eea5
branches: trunk
changeset: 342927:c4c99e76eea5
user: christos <christos%NetBSD.org@localhost>
date: Thu Jan 14 20:41:23 2016 +0000
description:
add stravis(3) from OpenBSD
diffstat:
lib/libc/gen/Makefile.inc | 4 +-
lib/libc/gen/vis.3 | 11 +++++++-
lib/libc/gen/vis.c | 59 ++++++++++++++++++++++++++++++----------------
3 files changed, 49 insertions(+), 25 deletions(-)
diffs (276 lines):
diff -r 5b8e8d4b4beb -r c4c99e76eea5 lib/libc/gen/Makefile.inc
--- a/lib/libc/gen/Makefile.inc Thu Jan 14 08:58:02 2016 +0000
+++ b/lib/libc/gen/Makefile.inc Thu Jan 14 20:41:23 2016 +0000
@@ -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+=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
diff -r 5b8e8d4b4beb -r c4c99e76eea5 lib/libc/gen/vis.3
--- a/lib/libc/gen/vis.3 Thu Jan 14 08:58:02 2016 +0000
+++ b/lib/libc/gen/vis.3 Thu Jan 14 20:41:23 2016 +0000
@@ -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 @@
.Pp
The
.Fn strvis ,
+.Fn stravis ,
.Fn strnvis ,
.Fn strvisx ,
and
@@ -157,6 +161,9 @@
(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
diff -r 5b8e8d4b4beb -r c4c99e76eea5 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c Thu Jan 14 08:58:02 2016 +0000
+++ b/lib/libc/gen/vis.c Thu Jan 14 20:41:23 2016 +0000
@@ -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 @@
* 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 @@
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 @@
/* 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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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 @@
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
Home |
Main Index |
Thread Index |
Old Index