Style sweep.

This commit is contained in:
Tim J. Robbins 2002-10-27 10:41:21 +00:00
parent 8b4d099d5f
commit b6f33850e0
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=106032
5 changed files with 32 additions and 40 deletions

View File

@ -38,19 +38,18 @@
__FBSDID("$FreeBSD$"); __FBSDID("$FreeBSD$");
#include <errno.h> #include <errno.h>
#include <stdlib.h>
#include <stddef.h> #include <stddef.h>
#include <stdlib.h>
#include <rune.h> #include <rune.h>
int int
mblen(s, n) mblen(const char *s, size_t n)
const char *s;
size_t n;
{ {
char const *e; const char *e;
if (s == 0 || *s == 0) if (s == NULL || *s == '\0')
return (0); /* No support for state dependent encodings. */ /* No support for state dependent encodings. */
return (0);
if (sgetrune(s, n, &e) == _INVALID_RUNE) { if (sgetrune(s, n, &e) == _INVALID_RUNE) {
errno = EILSEQ; errno = EILSEQ;

View File

@ -44,22 +44,20 @@ __FBSDID("$FreeBSD$");
#include <rune.h> #include <rune.h>
size_t size_t
mbstowcs(pwcs, s, n) mbstowcs(wchar_t * __restrict pwcs, const char * __restrict s, size_t n)
wchar_t * __restrict pwcs;
const char * __restrict s;
size_t n;
{ {
char const *e; const char *e;
int cnt = 0; int cnt;
rune_t r; rune_t r;
if (!s) { if (s == NULL) {
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
if (pwcs == NULL) { if (pwcs == NULL) {
/* Convert and count only, do not store. */ /* Convert and count only, do not store. */
cnt = 0;
while ((r = sgetrune(s, MB_LEN_MAX, &e)) != _INVALID_RUNE && while ((r = sgetrune(s, MB_LEN_MAX, &e)) != _INVALID_RUNE &&
r != 0) { r != 0) {
s = e; s = e;
@ -72,13 +70,14 @@ mbstowcs(pwcs, s, n)
} }
/* Convert, store and count characters. */ /* Convert, store and count characters. */
cnt = 0;
while (n-- > 0) { while (n-- > 0) {
*pwcs = sgetrune(s, MB_LEN_MAX, &e); *pwcs = sgetrune(s, MB_LEN_MAX, &e);
if (*pwcs == _INVALID_RUNE) { if (*pwcs == _INVALID_RUNE) {
errno = EILSEQ; errno = EILSEQ;
return (-1); return (-1);
} }
if (*pwcs++ == 0) if (*pwcs++ == L'\0')
break; break;
s = e; s = e;
++cnt; ++cnt;

View File

@ -43,22 +43,20 @@ __FBSDID("$FreeBSD$");
#include <rune.h> #include <rune.h>
int int
mbtowc(pwc, s, n) mbtowc(wchar_t * __restrict pwc, const char * __restrict s, size_t n)
wchar_t * __restrict pwc;
const char * __restrict s;
size_t n;
{ {
char const *e; const char *e;
rune_t r; rune_t r;
if (s == 0 || *s == 0) if (s == NULL || *s == '\0')
return (0); /* No support for state dependent encodings. */ /* No support for state dependent encodings. */
return (0);
if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) { if ((r = sgetrune(s, n, &e)) == _INVALID_RUNE) {
errno = EILSEQ; errno = EILSEQ;
return (s - e); return (s - e);
} }
if (pwc) if (pwc != NULL)
*pwc = r; *pwc = r;
return (e - s); return (e - s);
} }

View File

@ -44,16 +44,13 @@ __FBSDID("$FreeBSD$");
#include <rune.h> #include <rune.h>
size_t size_t
wcstombs(s, pwcs, n) wcstombs(char * __restrict s, const wchar_t * __restrict pwcs, size_t n)
char * __restrict s;
const wchar_t * __restrict pwcs;
size_t n;
{ {
char buf[MB_LEN_MAX]; char buf[MB_LEN_MAX];
char *e; char *e;
int cnt, nb; int cnt, nb;
if (!pwcs || n > INT_MAX) { if (pwcs == NULL || n > INT_MAX) {
errno = EINVAL; errno = EINVAL;
return (-1); return (-1);
} }
@ -63,7 +60,7 @@ wcstombs(s, pwcs, n)
if (s == NULL) { if (s == NULL) {
/* Convert and count only, do not store. */ /* Convert and count only, do not store. */
while (*pwcs != L'\0') { while (*pwcs != L'\0') {
if (!sputrune(*pwcs++, buf, MB_LEN_MAX, &e)) { if (sputrune(*pwcs++, buf, MB_LEN_MAX, &e) == 0) {
errno = EILSEQ; errno = EILSEQ;
return (-1); return (-1);
} }
@ -75,15 +72,15 @@ wcstombs(s, pwcs, n)
/* Convert, store and count characters. */ /* Convert, store and count characters. */
nb = n; nb = n;
while (nb > 0) { while (nb > 0) {
if (*pwcs == 0) { if (*pwcs == L'\0') {
*s = 0; *s = '\0';
break; break;
} }
if (!sputrune(*pwcs++, s, nb, &e)) { if (sputrune(*pwcs++, s, nb, &e) == 0) {
errno = EILSEQ; errno = EILSEQ;
return (-1); return (-1);
} }
if (!e) /* too long */ if (e == NULL) /* too long */
return (cnt); return (cnt);
cnt += e - s; cnt += e - s;
nb -= e - s; nb -= e - s;

View File

@ -44,17 +44,16 @@ __FBSDID("$FreeBSD$");
#include <rune.h> #include <rune.h>
int int
wctomb(s, wchar) wctomb(char *s, wchar_t wchar)
char *s;
wchar_t wchar;
{ {
char *e; char *e;
if (s == 0) if (s == NULL)
return (0); /* No support for state dependent encodings. */ /* No support for state dependent encodings. */
return (0);
if (wchar == 0) { if (wchar == L'\0') {
*s = 0; *s = '\0';
return (1); return (1);
} }