-
Notifications
You must be signed in to change notification settings - Fork 2
/
mbrtowc.c
95 lines (76 loc) · 4.22 KB
/
mbrtowc.c
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
/*++
toro C Library
https://github.com/KilianKegel/toro-C-Library#toro-c-library-formerly-known-as-torito-c-library
Copyright (c) 2017-2024, Kilian Kegel. All rights reserved.
SPDX-License-Identifier: GNU General Public License v3.0
Module Name:
mbrtowc.c
Abstract:
Convert a multibyte character in the current locale into the
equivalent wide character, with the capability of restarting
in the middle of a multibyte character.
Author:
Kilian Kegel
--*/
#include <CdeServices.h>
/**
Synopsis
#include <wchar.h>
size_t mbrtowc(wchar_t *wchar, const char *mbchar, size_t count, mbstate_t *mbstate);
Description
https://learn.microsoft.com/en-us/cpp/c-runtime-library/reference/mbrtowc
https://www.open-std.org/JTC1/SC22/WG14/www/docs/n1256.pdf#page=401
@param[in] *wchar
*mbchar
count
*mbstate - ignored
@retval 1 size of converted character
@retval 0 on failure
**/
size_t mbrtowc(wchar_t* wchar, const char* mbchar, size_t count, mbstate_t* mbstate)
{
do
{
if (NULL == wchar || NULL == mbchar)
break;
*wchar = 0 != count ? *mbchar : L'\0';
} while (0);
return (NULL == mbchar || '\0' == *mbchar || 0 == count) ? 0 : 1;
}
// n = mbrtowc(NULL, NULL, 0, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, NULL, 1, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, NULL, 2, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, NULL, 0, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, NULL, 1, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, NULL, 2, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 0, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 1, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 2, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 0, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 1, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "", 2, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "abc", 0, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "abc", 1, NULL) -> wc '' 0xFFFF, n 1
// n = mbrtowc(NULL, "abc", 2, NULL) -> wc '' 0xFFFF, n 1
// n = mbrtowc(NULL, "abc", 0, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(NULL, "abc", 1, &mbstate) -> wc '' 0xFFFF, n 1
// n = mbrtowc(NULL, "abc", 2, &mbstate) -> wc '' 0xFFFF, n 1
// n = mbrtowc(&wc, NULL, 0, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(&wc, NULL, 1, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(&wc, NULL, 2, NULL) -> wc '' 0xFFFF, n 0
// n = mbrtowc(&wc, NULL, 0, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(&wc, NULL, 1, &mbstate) -> wc '' 0xFFFF, n 0
// n = mbrtowc(&wc, NULL, 2, &mbstate) -> wc '' 0xFFFF, n 0
//
// n = mbrtowc(&wc, "", 0, NULL) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "", 1, NULL) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "", 2, NULL) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "", 0, &mbstate) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "", 1, &mbstate) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "", 2, &mbstate) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "abc", 0, NULL) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "abc", 1, NULL) -> wc 'a' 0x0061, n 1
// n = mbrtowc(&wc, "abc", 2, NULL) -> wc 'a' 0x0061, n 1
// n = mbrtowc(&wc, "abc", 0, &mbstate) -> wc ' ' 0x0000, n 0
// n = mbrtowc(&wc, "abc", 1, &mbstate) -> wc 'a' 0x0061, n 1
// n = mbrtowc(&wc, "abc", 2, &mbstate) -> wc 'a' 0x0061, n 1