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$");
#include <errno.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdlib.h>
#include <rune.h>
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;

View File

@ -44,22 +44,20 @@ __FBSDID("$FreeBSD$");
#include <rune.h>
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;

View File

@ -43,22 +43,20 @@ __FBSDID("$FreeBSD$");
#include <rune.h>
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);
}

View File

@ -44,16 +44,13 @@ __FBSDID("$FreeBSD$");
#include <rune.h>
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;

View File

@ -44,17 +44,16 @@ __FBSDID("$FreeBSD$");
#include <rune.h>
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);
}