Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
git-mirror
/
glibc
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
0
Security
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security
Insights
Files
9781a37
argp
assert
benchtests
bits
catgets
conf
conform
crypt
csu
ctype
debug
dirent
dlfcn
elf
gmon
gnulib
grp
gshadow
hesiod
hurd
iconv
iconvdata
include
inet
intl
io
libidn
libio
locale
localedata
login
mach
malloc
manual
math
misc
nis
nptl
nptl_db
nscd
nss
po
posix
pwd
resolv
resource
rt
scripts
setjmp
shadow
signal
socket
soft-fp
stdio-common
stdlib
streams
string
sunrpc
sysdeps
sysvipc
termios
time
timezone
wcsmbs
bits
Depend
Makefile
Versions
btowc.c
c16rtomb.c
isoc99_fwscanf.c
isoc99_swscanf.c
isoc99_vfwscanf.c
isoc99_vswscanf.c
isoc99_vwscanf.c
isoc99_wscanf.c
mbrlen.c
mbrtoc16.c
mbrtowc.c
mbsinit.c
mbsnrtowcs.c
mbsrtowcs.c
mbsrtowcs_l.c
test-wcschr.c
test-wcscmp.c
test-wcscpy.c
test-wcslen.c
test-wcsrchr.c
test-wmemcmp.c
tst-btowc.c
tst-c16c32-1.c
tst-mbrtowc.c
tst-mbrtowc2.c
tst-mbsrtowcs.c
tst-wchar-h.c
tst-wcpncpy.c
tst-wcrtomb.c
tst-wcsnlen.c
tst-wcstof.c
uchar.h
wchar.h
wcpcpy.c
wcpncpy.c
wcrtomb.c
wcsatcliff.c
wcscasecmp.c
wcscasecmp_l.c
wcscat.c
wcschr.c
wcschrnul.c
wcscmp.c
wcscoll.c
wcscoll_l.c
wcscpy.c
wcscspn.c
wcsdup.c
wcslen.c
wcsmbs-tst1.c
wcsmbsload.c
wcsmbsload.h
wcsncase.c
wcsncase_l.c
wcsncat.c
wcsncmp.c
wcsncpy.c
wcsnlen.c
wcsnrtombs.c
wcspbrk.c
wcsrchr.c
wcsrtombs.c
wcsspn.c
wcsstr.c
wcstod.c
wcstod_l.c
wcstof.c
wcstof_l.c
wcstok.c
wcstol.c
wcstol_l.c
wcstold.c
wcstold_l.c
wcstoll.c
wcstoll_l.c
wcstoul.c
wcstoul_l.c
wcstoull.c
wcstoull_l.c
wcswidth.c
wcsxfrm.c
wcsxfrm_l.c
wctob.c
wcwidth.c
wcwidth.h
wmemchr.c
wmemcmp.c
wmemcpy.c
wmemmove.c
wmempcpy.c
wmemset.c
wctype
.gitattributes
.gitignore
BUGS
CONFORMANCE
COPYING
COPYING.LIB
ChangeLog
ChangeLog.1
ChangeLog.10
ChangeLog.11
ChangeLog.12
ChangeLog.13
ChangeLog.14
ChangeLog.15
ChangeLog.16
ChangeLog.17
ChangeLog.2
ChangeLog.3
ChangeLog.4
ChangeLog.5
ChangeLog.6
ChangeLog.7
ChangeLog.8
ChangeLog.9
ChangeLog.old-ports
ChangeLog.old-ports-aarch64
ChangeLog.old-ports-aix
ChangeLog.old-ports-alpha
ChangeLog.old-ports-am33
ChangeLog.old-ports-arm
ChangeLog.old-ports-cris
ChangeLog.old-ports-hppa
ChangeLog.old-ports-ia64
ChangeLog.old-ports-linux-generic
ChangeLog.old-ports-m68k
ChangeLog.old-ports-microblaze
ChangeLog.old-ports-mips
ChangeLog.old-ports-powerpc
ChangeLog.old-ports-tile
INSTALL
LICENSES
Makeconfig
Makefile
Makefile.in
Makerules
NAMESPACE
NEWS
PROJECTS
README
Rules
WUR-REPORT
abi-tags
aclocal.m4
config.h.in
config.make.in
configure
configure.ac
cppflags-iterator.mk
extra-lib.mk
extra-modules.mk
libc-abis
o-iterator.mk
shlib-versions
test-skeleton.c
version.h
Breadcrumbs
glibc
/
wcsmbs
/
mbrtowc.c
Blame
Blame
Latest commit
History
History
129 lines (111 loc) · 3.68 KB
Breadcrumbs
glibc
/
wcsmbs
/
mbrtowc.c
Top
File metadata and controls
Code
Blame
129 lines (111 loc) · 3.68 KB
Raw
/* Copyright (C) 1996-2015 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@gnu.org>, 1996. The GNU C Library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. The GNU C Library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with the GNU C Library; if not, see <http://www.gnu.org/licenses/>. */ #include <assert.h> #include <dlfcn.h> #include <errno.h> #include <gconv.h> #include <wchar.h> #include <wcsmbsload.h> #include <sysdep.h> #ifndef EILSEQ # define EILSEQ EINVAL #endif /* This is the private state used if PS is NULL. */ static mbstate_t state; size_t __mbrtowc (wchar_t *pwc, const char *s, size_t n, mbstate_t *ps) { wchar_t buf[1]; struct __gconv_step_data data; int status; size_t result; size_t dummy; const unsigned char *inbuf, *endbuf; unsigned char *outbuf = (unsigned char *) (pwc ?: buf); const struct gconv_fcts *fcts; /* Set information for this step. */ data.__invocation_counter = 0; data.__internal_use = 1; data.__flags = __GCONV_IS_LAST; data.__statep = ps ?: &state; /* A first special case is if S is NULL. This means put PS in the initial state. */ if (s == NULL) { outbuf = (unsigned char *) buf; s = ""; n = 1; } if (n == 0) return (size_t) -2; /* Tell where we want the result. */ data.__outbuf = outbuf; data.__outbufend = outbuf + sizeof (wchar_t); /* Get the conversion functions. */ fcts = get_gconv_fcts (_NL_CURRENT_DATA (LC_CTYPE)); /* Do a normal conversion. */ inbuf = (const unsigned char *) s; endbuf = inbuf + n; if (__glibc_unlikely (endbuf < inbuf)) { endbuf = (const unsigned char *) ~(uintptr_t) 0; if (endbuf == inbuf) goto ilseq; } __gconv_fct fct = fcts->towc->__fct; #ifdef PTR_DEMANGLE if (fcts->towc->__shlib_handle != NULL) PTR_DEMANGLE (fct); #endif status = DL_CALL_FCT (fct, (fcts->towc, &data, &inbuf, endbuf, NULL, &dummy, 0, 1)); /* There must not be any problems with the conversion but illegal input characters. The output buffer must be large enough, otherwise the definition of MB_CUR_MAX is not correct. All the other possible errors also must not happen. */ assert (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT || status == __GCONV_ILLEGAL_INPUT || status == __GCONV_INCOMPLETE_INPUT || status == __GCONV_FULL_OUTPUT); if (status == __GCONV_OK || status == __GCONV_EMPTY_INPUT || status == __GCONV_FULL_OUTPUT) { if (data.__outbuf != (unsigned char *) outbuf && *(wchar_t *) outbuf == L'\0') { /* The converted character is the NUL character. */ assert (__mbsinit (data.__statep)); result = 0; } else result = inbuf - (const unsigned char *) s; } else if (status == __GCONV_INCOMPLETE_INPUT) result = (size_t) -2; else { ilseq: result = (size_t) -1; __set_errno (EILSEQ); } return result; } libc_hidden_def (__mbrtowc) weak_alias (__mbrtowc, mbrtowc) libc_hidden_weak (mbrtowc) /* There should be no difference between the UTF-32 handling required by mbrtoc32 and the wchar_t handling which has long since been implemented in mbrtowc. */ weak_alias (__mbrtowc, mbrtoc32)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
You can’t perform that action at this time.