diff --git a/lib/libc/locale/mblen.c b/lib/libc/locale/mblen.c index b5b92d172af3..a54e05111b59 100644 --- a/lib/libc/locale/mblen.c +++ b/lib/libc/locale/mblen.c @@ -38,19 +38,18 @@ __FBSDID("$FreeBSD$"); #include -#include #include +#include #include int -mblen(s, n) - const char *s; - size_t n; +mblen(const char *s, size_t n) { - char const *e; + const char *e; - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ + if (s == NULL || *s == '\0') + /* No support for state dependent encodings. */ + return (0); if (sgetrune(s, n, &e) == _INVALID_RUNE) { errno = EILSEQ; diff --git a/lib/libc/locale/mbstowcs.c b/lib/libc/locale/mbstowcs.c index 3657c832d309..a9adb8ab3321 100644 --- a/lib/libc/locale/mbstowcs.c +++ b/lib/libc/locale/mbstowcs.c @@ -44,22 +44,20 @@ __FBSDID("$FreeBSD$"); #include size_t -mbstowcs(pwcs, s, n) - wchar_t * __restrict pwcs; - const char * __restrict s; - size_t n; +mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n) { - char const *e; - int cnt = 0; + const char *e; + int cnt; rune_t r; - if (!s) { + if (s == NULL) { errno = EINVAL; return (-1); } if (pwcs == NULL) { /* Convert and count only, do not store. */ + cnt = 0; while ((r = sgetrune(s, MB_LEN_MAX, &e)) != _INVALID_RUNE && r != 0) { s = e; @@ -72,13 +70,14 @@ mbstowcs(pwcs, s, n) } /* Convert, store and count characters. */ + cnt = 0; while (n-- > 0) { *pwcs = sgetrune(s, MB_LEN_MAX, &e); if (*pwcs == _INVALID_RUNE) { errno = EILSEQ; return (-1); } - if (*pwcs++ == 0) + if (*pwcs++ == L'\0') break; s = e; ++cnt; diff --git a/lib/libc/locale/mbtowc.c b/lib/libc/locale/mbtowc.c index 206a3a3e6336..a690bec171dc 100644 --- a/lib/libc/locale/mbtowc.c +++ b/lib/libc/locale/mbtowc.c @@ -43,22 +43,20 @@ __FBSDID("$FreeBSD$"); #include int -mbtowc(pwc, s, n) - wchar_t * __restrict pwc; - const char * __restrict s; - size_t n; +mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n) { - char const *e; + const char *e; rune_t r; - if (s == 0 || *s == 0) - return (0); /* No support for state dependent encodings. */ + if (s == NULL || *s == '\0') + /* No support for state dependent encodings. */ + return (0); if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { errno = EILSEQ; return (s - e); } - if (pwc) + if (pwc != NULL) *pwc = r; return (e - s); } diff --git a/lib/libc/locale/wcstombs.c b/lib/libc/locale/wcstombs.c index 25652a870756..796e3c217af5 100644 --- a/lib/libc/locale/wcstombs.c +++ b/lib/libc/locale/wcstombs.c @@ -44,16 +44,13 @@ __FBSDID("$FreeBSD$"); #include size_t -wcstombs(s, pwcs, n) - char * __restrict s; - const wchar_t * __restrict pwcs; - size_t n; +wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n) { char buf[MB_LEN_MAX]; char *e; int cnt, nb; - if (!pwcs || n > INT_MAX) { + if (pwcs == NULL || n > INT_MAX) { errno = EINVAL; return (-1); } @@ -63,7 +60,7 @@ wcstombs(s, pwcs, n) if (s == NULL) { /* Convert and count only, do not store. */ while (*pwcs != L'\0') { - if (!sputrune(*pwcs++, buf, MB_LEN_MAX, &e)) { + if (sputrune(*pwcs++, buf, MB_LEN_MAX, &e) == 0) { errno = EILSEQ; return (-1); } @@ -75,15 +72,15 @@ wcstombs(s, pwcs, n) /* Convert, store and count characters. */ nb = n; while (nb > 0) { - if (*pwcs == 0) { - *s = 0; + if (*pwcs == L'\0') { + *s = '\0'; break; } - if (!sputrune(*pwcs++, s, nb, &e)) { + if (sputrune(*pwcs++, s, nb, &e) == 0) { errno = EILSEQ; return (-1); } - if (!e) /* too long */ + if (e == NULL) /* too long */ return (cnt); cnt += e - s; nb -= e - s; diff --git a/lib/libc/locale/wctomb.c b/lib/libc/locale/wctomb.c index 2a225f48fa6f..da934b272290 100644 --- a/lib/libc/locale/wctomb.c +++ b/lib/libc/locale/wctomb.c @@ -44,17 +44,16 @@ __FBSDID("$FreeBSD$"); #include int -wctomb(s, wchar) - char *s; - wchar_t wchar; +wctomb(char *s, wchar_t wchar) { char *e; - if (s == 0) - return (0); /* No support for state dependent encodings. */ + if (s == NULL) + /* No support for state dependent encodings. */ + return (0); - if (wchar == 0) { - *s = 0; + if (wchar == L'\0') { + *s = '\0'; return (1); }