1
0
mirror of https://git.savannah.gnu.org/git/gnulib.git synced 2025-08-08 17:22:05 +03:00

New module 'mbtowc'.

* lib/stdlib.in.h (mbtowc): New declaration.
* lib/mbtowc.c: New file.
* lib/mbtowc-impl.h: New file, from libutf8 with modifications
* m4/mbtowc.m4: New file.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_MBTOWC,
REPLACE_MBTOWC.
* modules/stdlib (Makefile.am): Substitute GNULIB_MBTOWC,
REPLACE_MBTOWC.
* modules/mbtowc: New file.
* tests/test-stdlib-c++.cc: Test signature of mbtowc.
* doc/posix-functions/mbtowc.texi: Mention the new module.
* modules/btowc (Depends-on): Add mbtowc.
This commit is contained in:
Bruno Haible
2011-02-22 14:01:29 +01:00
parent c147d9fffb
commit 82e60758d2
11 changed files with 162 additions and 2 deletions

View File

@@ -1,3 +1,19 @@
2011-02-22 Bruno Haible <bruno@clisp.org>
New module 'mbtowc'.
* lib/stdlib.in.h (mbtowc): New declaration.
* lib/mbtowc.c: New file.
* lib/mbtowc-impl.h: New file, from libutf8 with modifications.
* m4/mbtowc.m4: New file.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_MBTOWC,
REPLACE_MBTOWC.
* modules/stdlib (Makefile.am): Substitute GNULIB_MBTOWC,
REPLACE_MBTOWC.
* modules/mbtowc: New file.
* tests/test-stdlib-c++.cc: Test signature of mbtowc.
* doc/posix-functions/mbtowc.texi: Mention the new module.
* modules/btowc (Depends-on): Add mbtowc.
2011-02-22 Bruno Haible <bruno@clisp.org> 2011-02-22 Bruno Haible <bruno@clisp.org>
wcrtomb: Add more tests for native Windows platforms. wcrtomb: Add more tests for native Windows platforms.

View File

@@ -4,7 +4,7 @@
POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/mbtowc.html} POSIX specification:@* @url{http://www.opengroup.org/onlinepubs/9699919799/functions/mbtowc.html}
Gnulib module: --- Gnulib module: mbtowc
Portability problems fixed by Gnulib: Portability problems fixed by Gnulib:
@itemize @itemize

44
lib/mbtowc-impl.h Normal file
View File

@@ -0,0 +1,44 @@
/* Convert multibyte character to wide character.
Copyright (C) 2011 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2011.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
/* We don't need a static internal state, because the encoding is not state
dependent, and when mbrtowc returns (size_t)(-2). we throw the result
away. */
int
mbtowc (wchar_t *pwc, const char *s, size_t n)
{
if (s == NULL)
return 0;
else
{
mbstate_t state;
wchar_t wc;
size_t result;
memset (&state, 0, sizeof (mbstate_t));
result = mbrtowc (&wc, s, n, &state);
if (result == (size_t)-1 || result == (size_t)-2)
{
errno = EILSEQ;
return -1;
}
if (pwc != NULL)
*pwc = wc;
return (wc == 0 ? 0 : result);
}
}

26
lib/mbtowc.c Normal file
View File

@@ -0,0 +1,26 @@
/* Convert multibyte character to wide character.
Copyright (C) 2011 Free Software Foundation, Inc.
Written by Bruno Haible <bruno@clisp.org>, 2011.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include <config.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <wchar.h>
#include "mbtowc-impl.h"

View File

@@ -274,6 +274,21 @@ _GL_WARN_ON_USE (malloc, "malloc is not POSIX compliant everywhere - "
"use gnulib module malloc-posix for portability"); "use gnulib module malloc-posix for portability");
#endif #endif
/* Convert a multibyte character to a wide character. */
#if @GNULIB_MBTOWC@
# if @REPLACE_MBTOWC@
# if !(defined __cplusplus && defined GNULIB_NAMESPACE)
# undef mbtowc
# define mbtowc rpl_mbtowc
# endif
_GL_FUNCDECL_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
_GL_CXXALIAS_RPL (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
# else
_GL_CXXALIAS_SYS (mbtowc, int, (wchar_t *pwc, const char *s, size_t n));
# endif
_GL_CXXALIASWARN (mbtowc);
#endif
#if @GNULIB_MKDTEMP@ #if @GNULIB_MKDTEMP@
/* Create a unique temporary directory from TEMPLATE. /* Create a unique temporary directory from TEMPLATE.
The last six characters of TEMPLATE must be "XXXXXX"; The last six characters of TEMPLATE must be "XXXXXX";

23
m4/mbtowc.m4 Normal file
View File

@@ -0,0 +1,23 @@
# mbtowc.m4 serial 1
dnl Copyright (C) 2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
AC_DEFUN([gl_FUNC_MBTOWC],
[
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
if false; then
REPLACE_MBTOWC=1
fi
if test $REPLACE_MBTOWC = 1; then
AC_LIBOBJ([mbtowc])
gl_PREREQ_MBTOWC
fi
])
# Prerequisites of lib/mbtowc.c.
AC_DEFUN([gl_PREREQ_MBTOWC], [
:
])

View File

@@ -1,4 +1,4 @@
# stdlib_h.m4 serial 36 # stdlib_h.m4 serial 37
dnl Copyright (C) 2007-2011 Free Software Foundation, Inc. dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it, dnl gives unlimited permission to copy and/or distribute it,
@@ -44,6 +44,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT]) GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT]) GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT])
GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX]) GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
GNULIB_MBTOWC=0; AC_SUBST([GNULIB_MBTOWC])
GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP]) GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP]) GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP])
GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS]) GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS])
@@ -91,6 +92,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC]) REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC])
REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME]) REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC]) REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
REPLACE_MBTOWC=0; AC_SUBST([REPLACE_MBTOWC])
REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP]) REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV]) REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC]) REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])

View File

@@ -8,6 +8,7 @@ m4/locale-fr.m4
Depends-on: Depends-on:
wchar wchar
mbtowc
configure.ac: configure.ac:
gl_FUNC_BTOWC gl_FUNC_BTOWC

26
modules/mbtowc Normal file
View File

@@ -0,0 +1,26 @@
Description:
mbtowc() function: convert multibyte character to wide character.
Files:
lib/mbtowc.c
lib/mbtowc-impl.h
m4/mbtowc.m4
Depends-on:
stdlib
mbrtowc
configure.ac:
gl_FUNC_MBTOWC
gl_STDLIB_MODULE_INDICATOR([mbtowc])
Makefile.am:
Include:
<stdlib.h>
License:
LGPLv2+
Maintainer:
Bruno Haible

View File

@@ -36,6 +36,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \ -e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
-e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \ -e 's|@''GNULIB_GRANTPT''@|$(GNULIB_GRANTPT)|g' \
-e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \ -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
-e 's|@''GNULIB_MBTOWC''@|$(GNULIB_MBTOWC)|g' \
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \ -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
-e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \ -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
-e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \ -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
@@ -82,6 +83,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H)
-e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \ -e 's|@''REPLACE_CALLOC''@|$(REPLACE_CALLOC)|g' \
-e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \ -e 's|@''REPLACE_CANONICALIZE_FILE_NAME''@|$(REPLACE_CANONICALIZE_FILE_NAME)|g' \
-e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \ -e 's|@''REPLACE_MALLOC''@|$(REPLACE_MALLOC)|g' \
-e 's|@''REPLACE_MBTOWC''@|$(REPLACE_MBTOWC)|g' \
-e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \ -e 's|@''REPLACE_MKSTEMP''@|$(REPLACE_MKSTEMP)|g' \
-e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \ -e 's|@''REPLACE_PUTENV''@|$(REPLACE_PUTENV)|g' \
-e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \ -e 's|@''REPLACE_REALLOC''@|$(REPLACE_REALLOC)|g' \

View File

@@ -60,6 +60,11 @@ SIGNATURE_CHECK (GNULIB_NAMESPACE::grantpt, int, (int));
SIGNATURE_CHECK (GNULIB_NAMESPACE::malloc, void *, (size_t)); SIGNATURE_CHECK (GNULIB_NAMESPACE::malloc, void *, (size_t));
#endif #endif
#if GNULIB_TEST_MBTOWC
SIGNATURE_CHECK (GNULIB_NAMESPACE::mbtowc, int,
(wchar_t *, const char *, size_t));
#endif
#if GNULIB_TEST_MKDTEMP #if GNULIB_TEST_MKDTEMP
SIGNATURE_CHECK (GNULIB_NAMESPACE::mkdtemp, char *, (char *)); SIGNATURE_CHECK (GNULIB_NAMESPACE::mkdtemp, char *, (char *));
#endif #endif