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 VIS_NOLOCALE to avoid ambiguous conversions.
details: https://anonhg.NetBSD.org/src/rev/3383867dec73
branches: trunk
changeset: 338417:3383867dec73
user: christos <christos%NetBSD.org@localhost>
date: Sat May 23 11:47:56 2015 +0000
description:
Add VIS_NOLOCALE to avoid ambiguous conversions.
diffstat:
lib/libc/gen/vis.3 | 9 +++++++--
lib/libc/gen/vis.c | 26 ++++++++++++++++----------
2 files changed, 23 insertions(+), 12 deletions(-)
diffs (98 lines):
diff -r 27025e98e9ca -r 3383867dec73 lib/libc/gen/vis.3
--- a/lib/libc/gen/vis.3 Sat May 23 09:18:01 2015 +0000
+++ b/lib/libc/gen/vis.3 Sat May 23 11:47:56 2015 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: vis.3,v 1.42 2014/09/26 02:30:27 wiz Exp $
+.\" $NetBSD: vis.3,v 1.43 2015/05/23 11:47:56 christos Exp $
.\"
.\" Copyright (c) 1989, 1991, 1993
.\" The Regents of the University of California. All rights reserved.
@@ -29,7 +29,7 @@
.\"
.\" @(#)vis.3 8.1 (Berkeley) 6/9/93
.\"
-.Dd September 26, 2014
+.Dd May 23, 2015
.Dt VIS 3
.Os
.Sh NAME
@@ -436,6 +436,11 @@
environment variable which defines the set of characters
that can be copied without encoding.
.Pp
+If
+.Dv VIS_NOLOCALE
+is set, processing is done assuming the C locale and overriding
+any other environment settings.
+.Pp
When 8-bit data is present in the input,
.Ev LC_CTYPE
must be set to the correct locale or to the C locale.
diff -r 27025e98e9ca -r 3383867dec73 lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c Sat May 23 09:18:01 2015 +0000
+++ b/lib/libc/gen/vis.c Sat May 23 11:47:56 2015 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vis.c,v 1.66 2014/09/26 15:58:59 roy Exp $ */
+/* $NetBSD: vis.c,v 1.67 2015/05/23 11:47:56 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.66 2014/09/26 15:58:59 roy Exp $");
+__RCSID("$NetBSD: vis.c,v 1.67 2015/05/23 11:47:56 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#ifdef __FBSDID
__FBSDID("$FreeBSD$");
@@ -334,7 +334,7 @@
if ((dst = calloc(len + MAXEXTRAS, sizeof(*dst))) == NULL)
return NULL;
- if (mbstowcs(dst, src, len) == (size_t)-1) {
+ if ((flags & VIS_NOLOCALE) || mbstowcs(dst, src, len) == (size_t)-1) {
size_t i;
for (i = 0; i < len; i++)
dst[i] = (wchar_t)(u_char)src[i];
@@ -373,7 +373,7 @@
uint64_t bmsk, wmsk;
wint_t c;
visfun_t f;
- int clen = 0, cerr = 0, error = -1, i, shft;
+ int clen = 0, cerr, error = -1, i, shft;
ssize_t mbslength, maxolen;
_DIAGASSERT(mbdst != NULL);
@@ -402,9 +402,13 @@
dst = pdst;
src = psrc;
- /* Use caller's multibyte conversion error flag. */
- if (cerr_ptr)
- cerr = *cerr_ptr;
+ if (flags & VIS_NOLOCALE) {
+ /* Do one byte at a time conversion */
+ cerr = 1;
+ } else {
+ /* Use caller's multibyte conversion error flag. */
+ cerr = cerr_ptr ? *cerr_ptr : 0;
+ }
/*
* Input loop.
@@ -531,9 +535,11 @@
/* Terminate the output string. */
*mbdst = '\0';
- /* Pass conversion error flag out. */
- if (cerr_ptr)
- *cerr_ptr = cerr;
+ if (flags & VIS_NOLOCALE) {
+ /* Pass conversion error flag out. */
+ if (cerr_ptr)
+ *cerr_ptr = cerr;
+ }
free(extra);
free(pdst);
Home |
Main Index |
Thread Index |
Old Index