Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc/gen Minor nits, and make it compile in FreeBSD (NBB...
details: https://anonhg.NetBSD.org/src/rev/37e642428e2e
branches: trunk
changeset: 785077:37e642428e2e
user: christos <christos%NetBSD.org@localhost>
date: Wed Feb 20 20:27:42 2013 +0000
description:
Minor nits, and make it compile in FreeBSD (NBBY needs sys/params.h)
diffstat:
lib/libc/gen/vis.c | 45 +++++++++++++++++++++++++++++----------------
1 files changed, 29 insertions(+), 16 deletions(-)
diffs (126 lines):
diff -r 8fff414cb798 -r 37e642428e2e lib/libc/gen/vis.c
--- a/lib/libc/gen/vis.c Wed Feb 20 20:05:26 2013 +0000
+++ b/lib/libc/gen/vis.c Wed Feb 20 20:27:42 2013 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: vis.c,v 1.58 2013/02/20 19:59:34 tron Exp $ */
+/* $NetBSD: vis.c,v 1.59 2013/02/20 20:27:42 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.58 2013/02/20 19:59:34 tron Exp $");
+__RCSID("$NetBSD: vis.c,v 1.59 2013/02/20 20:27:42 christos Exp $");
#endif /* LIBC_SCCS and not lint */
#ifdef __FBSDID
__FBSDID("$FreeBSD$");
@@ -66,6 +66,7 @@
#include "namespace.h"
#include <sys/types.h>
+#include <sys/param.h>
#include <assert.h>
#include <vis.h>
@@ -105,7 +106,7 @@
#define MAXEXTRAS 10
-#ifdef notyet
+#ifndef __NetBSD__
/*
* On NetBSD MB_LEN_MAX is currently 32 which does not fit on any integer
* integral type and it is probably wrong, since currently the maximum
@@ -113,8 +114,19 @@
* loops below are using sizeof(uint64_t) - 1 instead of MB_LEN_MAX, and
* the assertion is commented out.
*/
-__CTASSERT(MB_LEN_MAX <= sizeof(uint64_t))
+#ifdef __FreeBSD__
+/*
+ * On FreeBSD including <sys/systm.h> for CTASSERT only works in kernel
+ * mode.
+ */
+#ifndef CTASSERT
+#define CTASSERT(x) _CTASSERT(x, __LINE__)
+#define _CTASSERT(x, y) __CTASSERT(x, y)
+#define __CTASSERT(x, y) typedef char __assert ## y[(x) ? 1 : -1]
#endif
+#endif /* __FreeBSD__ */
+CTASSERT(MB_LEN_MAX <= sizeof(uint64_t));
+#endif /* !__NetBSD__ */
/*
* This is do_hvis, for HTTP style (RFC 1808)
@@ -240,7 +252,7 @@
* This is do_vis, the central code of vis.
* dst: Pointer to the destination buffer
* c: Character to encode
- * flags: Flag word
+ * flags: Flags word
* nextc: The character following 'c'
* extra: Pointer to the list of extra characters to be
* backslash-protected.
@@ -260,13 +272,13 @@
/* See comment in istrsenvisx() output loop, below. */
wmsk = 0;
- for (i = sizeof(uint64_t) - 1; i >= 0; i--) {
+ for (i = sizeof(wmsk) - 1; i >= 0; i--) {
shft = i * NBBY;
- bmsk = (uint64_t)(0xffL << shft);
+ bmsk = (uint64_t)0xffLL << shft;
wmsk |= bmsk;
if ((c & wmsk) || i == 0)
dst = do_mbyte(dst, (wint_t)(
- (unsigned int)(c & bmsk) >> shft),
+ (uint64_t)(c & bmsk) >> shft),
flags, nextc, iswextra);
}
@@ -370,7 +382,7 @@
dst = pdst;
src = psrc;
- /* Use caller's multibyte conversion error flags. */
+ /* Use caller's multibyte conversion error flag. */
if (cerr_ptr)
cerr = *cerr_ptr;
@@ -469,18 +481,19 @@
* Conversion error, process as a byte(s) instead.
* Examine each byte and higher-order bytes for
* data. E.g.,
- * 0x0000a264 -> a2 64
- * 0x1f00a264 -> 1f 00 a2 64
+ * 0x000000000000a264 -> a2 64
+ * 0x000000001f00a264 -> 1f 00 a2 64
*/
clen = 0;
wmsk = 0;
- for (i = sizeof(uint64_t) - 1; i >= 0; i--) {
+ for (i = sizeof(wmsk) - 1; i >= 0; i--) {
shft = i * NBBY;
- bmsk = (uint64_t)(0xffL << shft);
+ bmsk = (uint64_t)0xffLL << shft;
wmsk |= bmsk;
if ((*dst & wmsk) || i == 0)
- mbdst[clen++] = (char)((unsigned int)
- (*dst & bmsk) >> shft);
+ mbdst[clen++] = (char)(
+ (uint64_t)(*dst & bmsk) >>
+ shft);
}
cerr = 1;
}
@@ -498,7 +511,7 @@
/* Terminate the output string. */
*mbdst = '\0';
- /* Pass conversion error flags out. */
+ /* Pass conversion error flag out. */
if (cerr_ptr)
*cerr_ptr = cerr;
Home |
Main Index |
Thread Index |
Old Index