- add wctob() function. (I forgot it at the last commit.)

- fix btowc(); I quite misunderstood about it.
This commit is contained in:
tshiozak 2003-03-03 07:39:53 +00:00
parent 65eac0ca35
commit 5af70bc478
4 changed files with 77 additions and 8 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: wchar.h,v 1.13 2003/03/02 22:18:11 tshiozak Exp $ */
/* $NetBSD: wchar.h,v 1.14 2003/03/03 07:39:53 tshiozak Exp $ */
/*-
* Copyright (c)1999 Citrus Project,
@ -101,7 +101,7 @@ typedef _BSD_SIZE_T_ size_t;
#define putwchar(wc) putwc((wc), stdout)
__BEGIN_DECLS
wint_t btowc __P((int c));
wint_t btowc __P((int));
size_t mbrlen __P((const char * __restrict, size_t, mbstate_t * __restrict));
size_t mbrtowc __P((wchar_t * __restrict, const char * __restrict, size_t,
mbstate_t * __restrict));
@ -138,6 +138,7 @@ wchar_t *wmemset __P((wchar_t *, wchar_t, size_t));
size_t wcslcat __P((wchar_t *, const wchar_t *, size_t));
size_t wcslcpy __P((wchar_t *, const wchar_t *, size_t));
int wcswidth __P((const wchar_t *, size_t));
int wctob __P((wint_t));
int wcwidth __P((wchar_t));
unsigned long int wcstoul __P((const wchar_t * __restrict, wchar_t ** __restrict,

View File

@ -1,5 +1,5 @@
# from: @(#)Makefile.inc 5.1 (Berkeley) 2/18/91
# $NetBSD: Makefile.inc,v 1.40 2003/03/02 22:18:12 tshiozak Exp $
# $NetBSD: Makefile.inc,v 1.41 2003/03/03 07:39:54 tshiozak Exp $
# locale sources
.PATH: ${ARCHDIR}/locale ${.CURDIR}/locale
@ -7,7 +7,7 @@
SRCS+= _def_messages.c _def_monetary.c _def_numeric.c _def_time.c \
btowc.c ctypeio.c localeconv.c nl_langinfo.c \
setlocale.c setlocale1.c setlocale32.c __mb_cur_max.c \
wcscoll.c wcstol.c wcstoul.c wcstod.c wcsxfrm.c aliasname.c
wcscoll.c wcstol.c wcstoul.c wcstod.c wcsxfrm.c wctob.c aliasname.c
MAN+= nl_langinfo.3 setlocale.3
MLINKS+=setlocale.3 localeconv.3

View File

@ -1,4 +1,4 @@
/* $NetBSD: btowc.c,v 1.1 2003/03/02 22:18:14 tshiozak Exp $ */
/* $NetBSD: btowc.c,v 1.2 2003/03/03 07:39:54 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: btowc.c,v 1.1 2003/03/02 22:18:14 tshiozak Exp $");
__RCSID("$NetBSD: btowc.c,v 1.2 2003/03/03 07:39:54 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
@ -38,14 +38,23 @@ __RCSID("$NetBSD: btowc.c,v 1.1 2003/03/02 22:18:14 tshiozak Exp $");
#include <stdio.h>
/*
* Compare strings with using collating information.
* convert a single byte character to a corresponding wide character.
*/
wint_t
btowc(c)
int c;
{
char mb;
mbstate_t mbs;
wchar_t wc;
if (c==EOF)
return (WEOF);
return ((wint_t)(unsigned char)c);
mb = (unsigned char)c;
memset(&mbs, 0, sizeof(mbs));
if (mbrtowc(&wc, &mb, 1, &mbs) != 1)
return (WEOF);
return ((wint_t)wc);
}

59
lib/libc/locale/wctob.c Normal file
View File

@ -0,0 +1,59 @@
/* $NetBSD: wctob.c,v 1.1 2003/03/03 07:39:55 tshiozak Exp $ */
/*-
* Copyright (c)2003 Citrus Project,
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#include <sys/cdefs.h>
#if defined(LIBC_SCCS) && !defined(lint)
__RCSID("$NetBSD: wctob.c,v 1.1 2003/03/03 07:39:55 tshiozak Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
#include <assert.h>
#include <wchar.h>
#include <stdio.h>
#include <limits.h>
/*
* convert a single byte character to a corresponding wide character.
*/
int
wctob(wc)
wint_t wc;
{
char mb[MB_LEN_MAX];
mbstate_t mbs;
if (wc==WEOF)
return (EOF);
memset(&mbs, 0, sizeof(mbs));
if (wcrtomb(mb, wc, &mbs) != 1)
return (WEOF);
return ((int)(unsigned char)mb[0]);
}