summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2016-09-07 17:06:24 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2016-09-07 17:06:24 +0000
commitd37fb6b5074d0365fecad13c4deabd3a7f6cc76f (patch)
tree393e097070a1c56d90baafe2c84f6b8d3f0418c2
parent43d42e216511af3f05fd1c574a1d16b45616f541 (diff)
trivial cleanup:
- delete unused headers - add missing function prototype - delete needless casts of return values - KNF: return is not a function - KNF: do not use a pointer as a boolean - consistent wording in comments: s/octets/bytes/ OK gcc: no object change after strip -g
-rw-r--r--lib/libc/citrus/citrus_none.c41
-rw-r--r--lib/libc/citrus/citrus_utf8.c108
2 files changed, 70 insertions, 79 deletions
diff --git a/lib/libc/citrus/citrus_none.c b/lib/libc/citrus/citrus_none.c
index 98c0abeda8d..13c7ca6d666 100644
--- a/lib/libc/citrus/citrus_none.c
+++ b/lib/libc/citrus/citrus_none.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: citrus_none.c,v 1.7 2016/09/05 09:47:03 schwarze Exp $ */
+/* $OpenBSD: citrus_none.c,v 1.8 2016/09/07 17:06:23 schwarze Exp $ */
/* $NetBSD: citrus_none.c,v 1.18 2008/06/14 16:01:07 tnozaki Exp $ */
/*-
@@ -30,15 +30,14 @@
#include <sys/types.h>
#include <errno.h>
-#include <limits.h>
#include <string.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
#include <wchar.h>
#include "citrus_ctype.h"
+static inline char wrapv(unsigned char);
+
+
/*
* Convert an unsigned char value into a char value without relying on
* signed overflow behavior.
@@ -47,9 +46,9 @@ static inline char
wrapv(unsigned char ch)
{
if (ch >= 0x80)
- return ((int)ch - 0x100);
+ return (int)ch - 0x100;
else
- return (ch);
+ return ch;
}
size_t
@@ -59,10 +58,10 @@ _citrus_none_ctype_mbrtowc(wchar_t * __restrict pwc,
if (s == NULL)
return 0;
if (n == 0)
- return (size_t)-2;
- if (pwc)
+ return -2;
+ if (pwc != NULL)
*pwc = (wchar_t)(unsigned char)*s;
- return (*s != '\0');
+ return *s != '\0';
}
size_t
@@ -77,26 +76,26 @@ _citrus_none_ctype_mbsnrtowcs(wchar_t * __restrict dst,
for (i = 0; i < nmc && i < len; i++)
if ((dst[i] = (wchar_t)(unsigned char)(*src)[i]) == L'\0') {
*src = NULL;
- return (i);
+ return i;
}
*src += i;
- return (i);
+ return i;
}
size_t
_citrus_none_ctype_wcrtomb(char * __restrict s, wchar_t wc)
{
if (s == NULL)
- return (1);
+ return 1;
if (wc < 0 || wc > 0xff) {
errno = EILSEQ;
- return (-1);
+ return -1;
}
*s = wrapv(wc);
- return (1);
+ return 1;
}
size_t
@@ -110,12 +109,12 @@ _citrus_none_ctype_wcsnrtombs(char * __restrict dst,
wchar_t wc = (*src)[i];
if (wc < 0 || wc > 0xff) {
errno = EILSEQ;
- return (-1);
+ return -1;
}
if (wc == L'\0')
- return (i);
+ return i;
}
- return (i);
+ return i;
}
for (i = 0; i < nwc && i < len; i++) {
@@ -123,14 +122,14 @@ _citrus_none_ctype_wcsnrtombs(char * __restrict dst,
if (wc < 0 || wc > 0xff) {
*src += i;
errno = EILSEQ;
- return (-1);
+ return -1;
}
dst[i] = wrapv(wc);
if (wc == L'\0') {
*src = NULL;
- return (i);
+ return i;
}
}
*src += i;
- return (i);
+ return i;
}
diff --git a/lib/libc/citrus/citrus_utf8.c b/lib/libc/citrus/citrus_utf8.c
index 016e5d5428e..ebbb76ba4f9 100644
--- a/lib/libc/citrus/citrus_utf8.c
+++ b/lib/libc/citrus/citrus_utf8.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: citrus_utf8.c,v 1.16 2016/09/05 09:47:03 schwarze Exp $ */
+/* $OpenBSD: citrus_utf8.c,v 1.17 2016/09/07 17:06:23 schwarze Exp $ */
/*-
* Copyright (c) 2002-2004 Tim J. Robbins
@@ -26,14 +26,9 @@
* SUCH DAMAGE.
*/
-#include <sys/errno.h>
#include <sys/types.h>
-#include <sys/limits.h>
#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
#include <string.h>
#include <wchar.h>
@@ -59,7 +54,7 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
if (us->want < 0 || us->want > _CITRUS_UTF8_MB_CUR_MAX) {
errno = EINVAL;
- return ((size_t)-1);
+ return -1;
}
if (s == NULL) {
@@ -68,23 +63,21 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
pwc = NULL;
}
- if (n == 0) {
- /* Incomplete multibyte sequence */
- return ((size_t)-2);
- }
+ if (n == 0)
+ return -2;
if (us->want == 0 && ((ch = (unsigned char)*s) & ~0x7f) == 0) {
/* Fast path for plain ASCII characters. */
if (pwc != NULL)
*pwc = ch;
- return (ch != '\0' ? 1 : 0);
+ return ch != '\0' ? 1 : 0;
}
if (us->want == 0) {
/*
- * Determine the number of octets that make up this character
- * from the first octet, and a mask that extracts the
- * interesting bits of the first octet. We already know
+ * Determine the number of bytes that make up this character
+ * from the first byte, and a mask that extracts the
+ * interesting bits of the first byte. We already know
* the character is at least two bytes long.
*
* We also specify a lower bound for the character code to
@@ -116,7 +109,7 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
* See RFC 3629.
*/
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
} else {
want = us->want;
@@ -124,7 +117,7 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
}
/*
- * Decode the octet sequence representing the character in chunks
+ * Decode the byte sequence representing the character in chunks
* of 6 bits, most significant first.
*/
if (us->want == 0)
@@ -134,11 +127,11 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
for (i = (us->want == 0) ? 1 : 0; i < MINIMUM(want, n); i++) {
if ((*s & 0xc0) != 0x80) {
/*
- * Malformed input; bad characters in the middle
+ * Malformed input; bad byte in the middle
* of a character.
*/
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
wch <<= 6;
wch |= *s++ & 0x3f;
@@ -148,39 +141,39 @@ _citrus_utf8_ctype_mbrtowc(wchar_t * __restrict pwc,
us->want = want - i;
us->lbound = lbound;
us->ch = wch;
- return ((size_t)-2);
+ return -2;
}
if (wch < lbound) {
/*
* Malformed input; redundant encoding.
*/
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
if (wch >= 0xd800 && wch <= 0xdfff) {
/*
* Malformed input; invalid code points.
*/
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
if (wch > 0x10ffff) {
/*
* Malformed input; invalid code points.
*/
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
if (pwc != NULL)
*pwc = wch;
us->want = 0;
- return (wch == L'\0' ? 0 : want);
+ return wch == L'\0' ? 0 : want;
}
int
_citrus_utf8_ctype_mbsinit(const mbstate_t * __restrict ps)
{
- return (((const struct _utf8_state *)ps)->want == 0);
+ return ((const struct _utf8_state *)ps)->want == 0;
}
size_t
@@ -201,26 +194,26 @@ _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst,
*/
if (nmc > 0 && us->want > 0 && (unsigned char)(*src)[0] < 0x80) {
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
for (i = o = 0; i < nmc; i += r, o++) {
if ((unsigned char)(*src)[i] < 0x80) {
/* Fast path for plain ASCII characters. */
if ((*src)[i] == '\0')
- return (o);
+ return o;
r = 1;
} else {
r = _citrus_utf8_ctype_mbrtowc(NULL, *src + i,
nmc - i, us);
if (r == (size_t)-1)
- return (r);
+ return r;
if (r == (size_t)-2)
- return (o);
+ return o;
if (r == 0)
- return (o);
+ return o;
}
}
- return (o);
+ return o;
}
/*
@@ -228,9 +221,10 @@ _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst,
* character appears as anything but the first byte of a
* multibyte sequence. Check now to avoid doing it in the loop.
*/
- if (len > 0 && nmc > 0 && us->want > 0 && (unsigned char)(*src)[0] < 0x80) {
+ if (len > 0 && nmc > 0 && us->want > 0 &&
+ (unsigned char)(*src)[0] < 0x80) {
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
for (i = o = 0; i < nmc && o < len; i += r, o++) {
if ((unsigned char)(*src)[i] < 0x80) {
@@ -238,7 +232,7 @@ _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst,
dst[o] = (wchar_t)(unsigned char)(*src)[i];
if ((*src)[i] == '\0') {
*src = NULL;
- return (o);
+ return o;
}
r = 1;
} else {
@@ -246,20 +240,20 @@ _citrus_utf8_ctype_mbsnrtowcs(wchar_t * __restrict dst,
nmc - i, us);
if (r == (size_t)-1) {
*src += i;
- return (r);
+ return r;
}
if (r == (size_t)-2) {
*src += nmc;
- return (o);
+ return o;
}
if (r == 0) {
*src = NULL;
- return (o);
+ return o;
}
}
}
*src += i;
- return (o);
+ return o;
}
size_t
@@ -274,29 +268,27 @@ _citrus_utf8_ctype_wcrtomb(char * __restrict s, wchar_t wc,
if (us->want != 0) {
errno = EINVAL;
- return ((size_t)-1);
+ return -1;
}
- if (s == NULL) {
- /* Reset to initial shift state (no-op) */
- return (1);
- }
+ if (s == NULL)
+ return 1;
if (wc < 0 || (wc > 0xd7ff && wc < 0xe000) || wc > 0x10ffff) {
errno = EILSEQ;
- return ((size_t)-1);
+ return -1;
}
/*
- * Determine the number of octets needed to represent this character.
+ * Determine the number of bytes needed to represent this character.
* We always output the shortest sequence possible. Also specify the
- * first few bits of the first octet, which contains the information
+ * first few bits of the first byte, which contains the information
* about the sequence length.
*/
if (wc <= 0x7f) {
/* Fast path for plain ASCII characters. */
*s = (char)wc;
- return (1);
+ return 1;
} else if (wc <= 0x7ff) {
lead = 0xc0;
len = 2;
@@ -309,8 +301,8 @@ _citrus_utf8_ctype_wcrtomb(char * __restrict s, wchar_t wc,
}
/*
- * Output the octets representing the character in chunks
- * of 6 bits, least significant last. The first octet is
+ * Output the bytes representing the character in chunks
+ * of 6 bits, least significant last. The first byte is
* a special case because it contains the sequence length
* information.
*/
@@ -320,7 +312,7 @@ _citrus_utf8_ctype_wcrtomb(char * __restrict s, wchar_t wc,
}
*s = (wc & 0xff) | lead;
- return (len);
+ return len;
}
size_t
@@ -336,7 +328,7 @@ _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst,
if (us->want != 0) {
errno = EINVAL;
- return ((size_t)-1);
+ return -1;
}
if (dst == NULL) {
@@ -345,15 +337,15 @@ _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst,
if (wc >= 0 && wc < 0x80) {
/* Fast path for plain ASCII characters. */
if (wc == 0)
- return (o);
+ return o;
r = 1;
} else {
r = _citrus_utf8_ctype_wcrtomb(buf, wc, us);
if (r == (size_t)-1)
- return (r);
+ return r;
}
}
- return (o);
+ return o;
}
for (i = o = 0; i < nwc && o < len; i++, o += r) {
@@ -363,7 +355,7 @@ _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst,
dst[o] = (wchar_t)wc;
if (wc == 0) {
*src = NULL;
- return (o);
+ return o;
}
r = 1;
} else if (len - o >= _CITRUS_UTF8_MB_CUR_MAX) {
@@ -371,14 +363,14 @@ _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst,
r = _citrus_utf8_ctype_wcrtomb(dst + o, wc, us);
if (r == (size_t)-1) {
*src += i;
- return (r);
+ return r;
}
} else {
/* May not be enough space; use temp buffer. */
r = _citrus_utf8_ctype_wcrtomb(buf, wc, us);
if (r == (size_t)-1) {
*src += i;
- return (r);
+ return r;
}
if (r > len - o)
break;
@@ -386,5 +378,5 @@ _citrus_utf8_ctype_wcsnrtombs(char * __restrict dst,
}
}
*src += i;
- return (o);
+ return o;
}