1 /*
2 * Copyright (c) 2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include "common/napi_helper.cpp"
17 #include "common/native_common.h"
18 #include "cstdio"
19 #include "cstdlib"
20 #include "napi/native_api.h"
21 #include <cerrno>
22 #include <clocale>
23 #include <cstdarg>
24 #include <cstdio>
25 #include <cstdlib>
26 #include <cstring>
27 #include <ctime>
28 #include <cwchar>
29 #include <js_native_api.h>
30 #include <linux/elf-fdpic.h>
31 #include <node_api.h>
32 #include <unistd.h>
33
34 #define FAIL (-1)
35 #define NORMAL 1
36 #define MAX (20)
37 #define ONEVAL 1
38 #define MINUSONE (-1)
39 #define NUMBER 5
40 #define MAX_NUMBER 60
41
42 #define PARAM_0 0
43 #define PARAM_1 1
44 #define PARAM_2 2
45 #define PARAM_10 10
46 #define PARAM_20 20
47 #define PARAM_0x0 0x0
48 #define PARAM_0x00ad 0x00ad
49 #define PARAM_UNNORMAL (-1)
50 #define RETURN_0 0
51 #define RETURN_ONE 1
52 #define FAILD (-1)
53 #define ERRON_0 0
54 #define SIZE_3 3
55 #define SIZE_5 5
56 #define SIZE_6 6
57 #define SIZE_10 10
58 #define SIZE_13 13
59 #define SIZE_18 18
60 #define SIZE_20 20
61 #define SIZE_25 25
62 #define SIZE_30 30
63 #define SIZE_80 80
64 #define SIZE_100 100
65 #define SIZE_256 256
66 #define SIZE_1024 1024
67 #define SIZE_4096 4096
68 #define SIZE_8192 8192
69 #define ASCII_LA 97
70 #define SUCCESS 1
71 #define ARRY_MAX 128
72 #define ZEROVAL 0
73 #define ZERO 0
74
vfwprintfTest(FILE * stream,wchar_t * fmt,...)75 int vfwprintfTest(FILE *stream, wchar_t *fmt, ...)
76 {
77 va_list ap;
78 va_start(ap, fmt);
79 int vfwval = vfwprintf(stream, fmt, ap);
80 va_end(ap);
81 return vfwval;
82 }
83
Vfwprintf(napi_env env,napi_callback_info info)84 static napi_value Vfwprintf(napi_env env, napi_callback_info info)
85 {
86 wchar_t value[] = L"hello %ls";
87 char file_name[SIZE_256] = "/data/storage/el2/base/files/test.txt";
88 FILE *file = fopen(file_name, "w");
89 int vfwval = vfwprintfTest(file, value, L"world");
90 napi_value result;
91 if (vfwval < PARAM_0) {
92 napi_create_int32(env, MINUSONE, &result);
93 } else {
94 napi_create_int32(env, PARAM_0, &result);
95 }
96 fclose(file);
97 return result;
98 }
99
vfwscanfTest(FILE * fp,const wchar_t * format,...)100 int vfwscanfTest(FILE *fp, const wchar_t *format, ...)
101 {
102 va_list args;
103 va_start(args, format);
104 int vfwval = vfwscanf(fp, format, args);
105 va_end(args);
106 return vfwval;
107 }
108
Vfwscanf(napi_env env,napi_callback_info info)109 static napi_value Vfwscanf(napi_env env, napi_callback_info info)
110 {
111 setlocale(LC_ALL, "en_US.UTF-8");
112 wchar_t symbol[] = L"\u0915\u0916\u0917\u0918\u0919";
113 wchar_t names[NUMBER][NUMBER] = {L"Ka", L"Kha", L"Ga", L"Gha", L"Nga"};
114 FILE *fp = fopen("/data/storage/el2/base/files/test.txt", "w+");
115 for (int i = PARAM_0; i < NUMBER; i++)
116 fwprintf(fp, L"%lc %ls ", symbol[i], names[i]);
117 rewind(fp);
118 napi_value result;
119 wchar_t ch, str[NUMBER];
120 for (int i = PARAM_0; i < NUMBER; i++) {
121 vfwscanfTest(fp, L"%lc %ls ", &ch, str);
122 if (wcscmp(str, names[i]) != PARAM_0) {
123 napi_create_int32(env, MINUSONE, &result);
124 } else {
125 napi_create_int32(env, PARAM_0, &result);
126 }
127 }
128 fclose(fp);
129 unlink("/data/storage/el2/base/files/test.txt");
130 return result;
131 }
132
vswprintfTest(wchar_t * ws,size_t len,const wchar_t * format,...)133 int vswprintfTest(wchar_t *ws, size_t len, const wchar_t *format, ...)
134 {
135 va_list arg;
136 va_start(arg, format);
137 int vswval = vswprintf(ws, len, format, arg);
138 va_end(arg);
139 return vswval;
140 }
141
Vswprintf(napi_env env,napi_callback_info info)142 static napi_value Vswprintf(napi_env env, napi_callback_info info)
143 {
144 wchar_t ws[MAX_NUMBER];
145 wchar_t str[] = L"\u0025 \u0026 \u0027 \u0028 \u0029";
146 int vswval = vswprintfTest(ws, MAX_NUMBER, L"Some Latin letters : %ls\n", str);
147 napi_value result;
148 if (vswval < PARAM_0) {
149 napi_create_int32(env, MINUSONE, &result);
150 } else {
151 napi_create_int32(env, PARAM_0, &result);
152 }
153 return result;
154 }
155
vwprintfTest(wchar_t * fmt,...)156 int vwprintfTest(wchar_t *fmt, ...)
157 {
158 va_list ap;
159 va_start(ap, fmt);
160 int vmpval = vwprintf(fmt, ap);
161 va_end(ap);
162 return vmpval;
163 }
164
Vwprintf(napi_env env,napi_callback_info info)165 static napi_value Vwprintf(napi_env env, napi_callback_info info)
166 {
167 wchar_t value[] = L"hello %ls\n";
168 int vmpval = vwprintfTest(value, L"world");
169 napi_value result;
170 if (vmpval < PARAM_0) {
171 napi_create_int32(env, MINUSONE, &result);
172 } else {
173 napi_create_int32(env, PARAM_0, &result);
174 }
175 return result;
176 }
177
GetWideMatches(wchar_t * format,...)178 int GetWideMatches(wchar_t *format, ...)
179 {
180 errno = ERRON_0;
181 va_list args;
182 va_start(args, format);
183 int vwsval = vwscanf(format, args);
184 va_end(args);
185 return vwsval;
186 }
Wcpcpy(napi_env env,napi_callback_info info)187 static napi_value Wcpcpy(napi_env env, napi_callback_info info)
188 {
189 wchar_t deSt[20];
190 wchar_t src[] = L"123456";
191 wcpcpy(deSt, src);
192 int value = wcslen(deSt);
193
194 napi_value result = nullptr;
195 napi_create_int32(env, value, &result);
196
197 return result;
198 }
199
Wcscat(napi_env env,napi_callback_info info)200 static napi_value Wcscat(napi_env env, napi_callback_info info)
201 {
202 wchar_t deSt[50] = L"1234";
203 wchar_t src[50] = L"5678";
204 wcscat(deSt, src);
205 int value = wcslen(deSt);
206
207 napi_value result = nullptr;
208 napi_create_int32(env, value, &result);
209
210 return result;
211 }
212
Wcschr(napi_env env,napi_callback_info info)213 static napi_value Wcschr(napi_env env, napi_callback_info info)
214 {
215 wchar_t deSt[] = L"1234";
216 wchar_t src = L'5';
217 int value = FAIL;
218 if (wcschr(deSt, src) == nullptr) {
219 value = PARAM_0;
220 }
221
222 napi_value result = nullptr;
223 napi_create_int32(env, value, &result);
224
225 return result;
226 }
227
Wcscmp(napi_env env,napi_callback_info info)228 static napi_value Wcscmp(napi_env env, napi_callback_info info)
229 {
230 wchar_t deSt[50] = L"12345";
231 wchar_t src[50] = L"12345";
232 int wcscmpValue = wcscmp(deSt, src);
233 napi_value result = nullptr;
234 napi_create_int32(env, wcscmpValue, &result);
235
236 return result;
237 }
238
Wcscoll(napi_env env,napi_callback_info info)239 static napi_value Wcscoll(napi_env env, napi_callback_info info)
240 {
241 wchar_t deSt[50] = L"12345";
242 wchar_t src[50] = L"12345";
243 int wcscmpValue = wcscoll(deSt, src);
244 napi_value result = nullptr;
245 napi_create_int32(env, wcscmpValue, &result);
246
247 return result;
248 }
249
Wcscpy(napi_env env,napi_callback_info info)250 static napi_value Wcscpy(napi_env env, napi_callback_info info)
251 {
252 wchar_t deSt[20];
253 wchar_t src[] = L"123456";
254 wcscpy(deSt, src);
255 int value = wcslen(deSt);
256
257 napi_value result = nullptr;
258 napi_create_int32(env, value, &result);
259
260 return result;
261 }
262
Wcscspn(napi_env env,napi_callback_info info)263 static napi_value Wcscspn(napi_env env, napi_callback_info info)
264 {
265 wchar_t deSt[9] = L"12345";
266 wchar_t src[] = L"52678";
267 size_t value = wcscspn(deSt, src);
268 napi_value result = nullptr;
269 napi_create_int32(env, value, &result);
270
271 return result;
272 }
273
Wcsdup(napi_env env,napi_callback_info info)274 static napi_value Wcsdup(napi_env env, napi_callback_info info)
275 {
276 wchar_t deSt[] = L"12345";
277 int value = FAIL;
278 if (wcsdup(deSt) != nullptr) {
279 value = PARAM_0;
280 }
281 napi_value result = nullptr;
282 napi_create_int32(env, value, &result);
283
284 return result;
285 }
286
Wcslen(napi_env env,napi_callback_info info)287 static napi_value Wcslen(napi_env env, napi_callback_info info)
288 {
289 wchar_t src[] = L"abcd";
290 int value = wcslen(src);
291 napi_value result = nullptr;
292 napi_create_int32(env, value, &result);
293
294 return result;
295 }
296
Wcsncat(napi_env env,napi_callback_info info)297 static napi_value Wcsncat(napi_env env, napi_callback_info info)
298 {
299 wchar_t deSt[50] = L"123";
300 wchar_t src[] = L"456";
301 wcsncat(deSt, src, NORMAL);
302 int value = wcslen(deSt);
303
304 napi_value result = nullptr;
305 napi_create_int32(env, value, &result);
306
307 return result;
308 }
309
Wcsncmp(napi_env env,napi_callback_info info)310 static napi_value Wcsncmp(napi_env env, napi_callback_info info)
311 {
312 size_t argc = PARAM_1;
313 napi_value args[1] = {nullptr};
314 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
315 int valueFirst;
316 napi_get_value_int32(env, args[0], &valueFirst);
317 wchar_t deSt[50] = L"1232";
318 wchar_t src[50] = L"1231";
319 int wcsncmp_value = wcsncmp(deSt, src, valueFirst);
320 napi_value result = nullptr;
321 napi_create_int32(env, wcsncmp_value, &result);
322
323 return result;
324 }
325
Wcsnlen(napi_env env,napi_callback_info info)326 static napi_value Wcsnlen(napi_env env, napi_callback_info info)
327 {
328 size_t argc = PARAM_1;
329 napi_value args[1] = {nullptr};
330 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
331 int valueFirst;
332 napi_get_value_int32(env, args[0], &valueFirst);
333 wchar_t src[] = L"abcde";
334 int value = wcsnlen(src, valueFirst);
335
336 napi_value result = nullptr;
337 napi_create_int32(env, value, &result);
338
339 return result;
340 }
341
Wcspbrk(napi_env env,napi_callback_info info)342 static napi_value Wcspbrk(napi_env env, napi_callback_info info)
343 {
344 wchar_t deSt[] = L"abcd";
345 wchar_t src[] = L"a";
346 wchar_t *wcspbrk_value = wcspbrk(deSt, src);
347 int value = FAIL;
348 if (wcspbrk_value != nullptr) {
349 value = PARAM_0;
350 }
351 napi_value result = nullptr;
352 napi_create_int32(env, value, &result);
353
354 return result;
355 }
356
Mbrtowc(napi_env env,napi_callback_info info)357 static napi_value Mbrtowc(napi_env env, napi_callback_info info)
358 {
359 int ret = FAIL;
360 char pt[] = "mbrtowc example";
361 int max = strlen(pt);
362 wchar_t dest;
363 size_t length;
364 mbstate_t mbs;
365 mbrlen(nullptr, PARAM_0, &mbs);
366 length = mbrtowc(&dest, pt, max, &mbs);
367 if (length > PARAM_0) {
368 ret = SUCCESS;
369 } else {
370 ret = FAIL;
371 }
372 napi_value result = nullptr;
373 napi_create_int32(env, ret, &result);
374 return result;
375 }
376
Fputwc(napi_env env,napi_callback_info info)377 static napi_value Fputwc(napi_env env, napi_callback_info info)
378 {
379 const char *path = "/data/storage/el2/base/files/Fzl.txt";
380 wchar_t str[] = L"T";
381 int ret = FAIL;
382 wint_t wc;
383 FILE *fp = fopen(path, "w+");
384
385 for (unsigned int i = PARAM_0; i < wcslen(str); i++) {
386 wc = fputwc(str[i], fp);
387 if (wc == str[i]) {
388 ret = PARAM_0;
389 }
390 }
391
392 fclose(fp);
393 napi_value result = nullptr;
394 napi_create_int32(env, ret, &result);
395
396 return result;
397 }
398
Getwchar(napi_env env,napi_callback_info info)399 static napi_value Getwchar(napi_env env, napi_callback_info info)
400 {
401 wint_t wc = getwchar();
402 napi_value result = nullptr;
403 if (wc == WEOF) {
404 napi_create_int32(env, FAIL, &result);
405 } else {
406 napi_create_int32(env, SUCCESS, &result);
407 }
408 return result;
409 }
410
Putwc(napi_env env,napi_callback_info info)411 static napi_value Putwc(napi_env env, napi_callback_info info)
412 {
413 const char *ptr = "/data/storage/el2/base/files/test.txt";
414 FILE *fptr = fopen(ptr, "w+");
415 wchar_t wc = L'p';
416 putwc(wc, fptr);
417 rewind(fptr);
418 wint_t wret = getwc(fptr);
419 napi_value result = nullptr;
420 if (wret == wc) {
421 napi_create_int32(env, PARAM_0, &result);
422 } else {
423 napi_create_int32(env, PARAM_UNNORMAL, &result);
424 }
425 fclose(fptr);
426 return result;
427 }
428
PutWChar(napi_env env,napi_callback_info info)429 static napi_value PutWChar(napi_env env, napi_callback_info info)
430 {
431 wchar_t wc = L'p';
432 char ret = putwchar(wc);
433 napi_value result = nullptr;
434 if (ret == wc) {
435 napi_create_int32(env, PARAM_0, &result);
436 } else {
437 napi_create_int32(env, PARAM_UNNORMAL, &result);
438 }
439 return result;
440 }
441
OpenWmemstream(napi_env env,napi_callback_info info)442 static napi_value OpenWmemstream(napi_env env, napi_callback_info info)
443 {
444 size_t len = PARAM_UNNORMAL;
445 int ret = PARAM_0;
446 wchar_t *ptr = nullptr;
447
448 FILE *fp = open_wmemstream(&ptr, &len);
449
450 ret = fprintf(fp, "open_wmemstream success!");
451 ret = fclose(fp);
452 free(ptr);
453 ptr = nullptr;
454 napi_value result = nullptr;
455
456 napi_create_int32(env, ret, &result);
457 return result;
458 }
Mbsinit(napi_env env,napi_callback_info info)459 static napi_value Mbsinit(napi_env env, napi_callback_info info)
460 {
461 mbstate_t mbst;
462 memset(&mbst, PARAM_0, sizeof(mbst));
463 int ret = mbsinit(&mbst);
464 if (ret != PARAM_0) {
465 ret = SUCCESS;
466 } else {
467 ret = FAIL;
468 }
469 napi_value result = nullptr;
470 napi_create_int32(env, ret, &result);
471 return result;
472 }
Mbsnrtowcs(napi_env env,napi_callback_info info)473 static napi_value Mbsnrtowcs(napi_env env, napi_callback_info info)
474 {
475 const char *test = "musl test";
476 wchar_t wc[ARRY_MAX];
477 memset(wc, PARAM_0, sizeof(wc));
478 size_t ret = mbsnrtowcs(wc, &test, PARAM_2, ARRY_MAX, nullptr);
479 if (ret != PARAM_UNNORMAL) {
480 ret = SUCCESS;
481 } else {
482 ret = FAIL;
483 }
484 napi_value result = nullptr;
485 napi_create_int32(env, ret, &result);
486 return result;
487 }
488
Mbsrtowcs(napi_env env,napi_callback_info info)489 static napi_value Mbsrtowcs(napi_env env, napi_callback_info info)
490 {
491 setlocale(LC_ALL, "en_US.utf8");
492 const char *src = "\u0763\u0757";
493 wchar_t dest[20];
494 mbstate_t ps = mbstate_t();
495 int max = PARAM_10;
496 int ret = mbsrtowcs(dest, &src, max, &ps);
497 if (ret != PARAM_UNNORMAL) {
498 ret = SUCCESS;
499 } else {
500 ret = FAIL;
501 }
502 napi_value result = nullptr;
503 napi_create_int32(env, ret, &result);
504 return result;
505 }
Mbstowcs(napi_env env,napi_callback_info info)506 static napi_value Mbstowcs(napi_env env, napi_callback_info info)
507 {
508 const char *src = "mbstowcs_0100";
509 wchar_t dst[ARRY_MAX];
510 memset(dst, PARAM_0x0, sizeof(wchar_t) * ARRY_MAX);
511 size_t ret = mbstowcs(dst, src, strlen(src));
512 if (ret > PARAM_0) {
513 ret = SUCCESS;
514 } else {
515 ret = FAIL;
516 }
517 napi_value result = nullptr;
518 napi_create_int32(env, ret, &result);
519 return result;
520 }
Mbtowc(napi_env env,napi_callback_info info)521 static napi_value Mbtowc(napi_env env, napi_callback_info info)
522 {
523 const char *test = "musl";
524 wchar_t wc[ARRY_MAX];
525 size_t ret = PARAM_0;
526 ret = mbtowc(wc, test, PARAM_1);
527 if (ret == PARAM_1) {
528 ret = SUCCESS;
529 } else {
530 ret = FAIL;
531 }
532 napi_value result = nullptr;
533 napi_create_int32(env, ret, &result);
534 return result;
535 }
536
Swprintf(napi_env env,napi_callback_info info)537 static napi_value Swprintf(napi_env env, napi_callback_info info)
538 {
539 wchar_t hebrew_str[] = L"\u05D0 \u05D1 \u05E1 \u05D3 \u05EA";
540 wchar_t buffer[MAX];
541 int value = swprintf(buffer, MAX, L"%ls", hebrew_str);
542 napi_value resultS = nullptr;
543 napi_create_int32(env, value, &resultS);
544 return resultS;
545 }
546
Swscanf(napi_env env,napi_callback_info info)547 static napi_value Swscanf(napi_env env, napi_callback_info info)
548 {
549 wchar_t wstr[] = L"swscanf 123";
550 int i, j;
551 int value = swscanf(wstr, L"%d %d", &i, &j);
552 napi_value result = nullptr;
553 napi_create_int32(env, value, &result);
554 return result;
555 }
556
Wscanf(napi_env env,napi_callback_info info)557 static napi_value Wscanf(napi_env env, napi_callback_info info)
558 {
559 wchar_t wstr[] = L"swscanf 123";
560 int i, j;
561 int value = wscanf(wstr, L"%d %d", &i, &j);
562 napi_value result = nullptr;
563 napi_create_int32(env, value, &result);
564 return result;
565 }
566
Vwscanf(napi_env env,napi_callback_info info)567 static napi_value Vwscanf(napi_env env, napi_callback_info info)
568 {
569 wchar_t wstr[] = L"swscanf 123";
570 va_list aptr;
571 int value = vwscanf(wstr, aptr);
572 napi_value result = nullptr;
573 napi_create_int32(env, value, &result);
574 return result;
575 }
576
Towlower(napi_env env,napi_callback_info info)577 static napi_value Towlower(napi_env env, napi_callback_info info)
578 {
579 size_t argc = PARAM_1;
580 napi_value args[1] = {nullptr};
581 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
582 int param;
583 napi_get_value_int32(env, args[0], ¶m);
584 int towlower_value = FAILD;
585 if (param == PARAM_0) {
586 char ch = 'A';
587 char result = towlower(ch);
588 if (result == 'a') {
589 towlower_value = RETURN_0;
590 }
591 } else if (param == PARAM_1) {
592 char ch = PARAM_2;
593 char result = towlower(ch);
594 if (result == ch) {
595 towlower_value = RETURN_0;
596 }
597
598 } else if (param == PARAM_2) {
599 char ch = 'a';
600 char result = towlower(ch);
601 if (result == 'a') {
602 towlower_value = RETURN_0;
603 }
604 } else {
605 char ch = '$';
606 char result = towlower(ch);
607 if (result == '$') {
608 towlower_value = RETURN_0;
609 }
610 }
611
612 napi_value result = nullptr;
613 napi_create_int32(env, towlower_value, &result);
614
615 return result;
616 }
617
Towupper(napi_env env,napi_callback_info info)618 static napi_value Towupper(napi_env env, napi_callback_info info)
619 {
620 size_t argc = PARAM_1;
621 napi_value args[1] = {nullptr};
622 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
623 int param;
624 napi_get_value_int32(env, args[0], ¶m);
625
626 int towupper_value = FAILD;
627 if (param == PARAM_0) {
628 char ch = 'a';
629 char result = towupper(ch);
630 if (result == 'A') {
631 towupper_value = RETURN_0;
632 }
633 } else if (param == PARAM_1) {
634 char ch = PARAM_2;
635 char result = towupper(ch);
636 if (result == ch) {
637 towupper_value = RETURN_0;
638 }
639
640 } else if (param == PARAM_2) {
641 char ch = 'A';
642 char result = towupper(ch);
643 if (result == 'A') {
644 towupper_value = RETURN_0;
645 }
646 } else {
647 char ch = '$';
648 char result = towupper(ch);
649 if (result == '$') {
650 towupper_value = RETURN_0;
651 }
652 }
653
654 napi_value result = nullptr;
655 napi_create_int32(env, towupper_value, &result);
656
657 return result;
658 }
659
Wcpncpy(napi_env env,napi_callback_info info)660 static napi_value Wcpncpy(napi_env env, napi_callback_info info)
661 {
662 size_t argc = PARAM_1;
663 napi_value args[1] = {nullptr};
664 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
665 int sizeParam;
666 napi_get_value_int32(env, args[0], &sizeParam);
667
668 wchar_t src[] = L"Source string";
669 wchar_t dest[SIZE_18];
670
671 int resultValue = RETURN_0;
672 wchar_t *wcpncpyValue = wcpncpy(dest, src, sizeParam);
673
674 if (wcscmp(wcpncpyValue, dest + sizeParam) != PARAM_0) {
675 resultValue = FAILD;
676 }
677 napi_value result = nullptr;
678 napi_create_int32(env, resultValue, &result);
679
680 return result;
681 }
682
Wcrtomb(napi_env env,napi_callback_info info)683 static napi_value Wcrtomb(napi_env env, napi_callback_info info)
684 {
685 wchar_t src = L'A';
686 char dest[SIZE_25];
687 mbstate_t ps = mbstate_t();
688
689 int wcrtomb_value = wcrtomb(dest, src, &ps);
690
691 napi_value result = nullptr;
692 napi_create_int32(env, wcrtomb_value, &result);
693
694 return result;
695 }
696
Wcscasecmp(napi_env env,napi_callback_info info)697 static napi_value Wcscasecmp(napi_env env, napi_callback_info info)
698 {
699 size_t argc = PARAM_1;
700 napi_value args[1] = {nullptr};
701 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
702 int param;
703 napi_get_value_int32(env, args[0], ¶m);
704
705 int wcscasecmp_value;
706 if (param == PARAM_0) {
707 wcscasecmp_value = wcscasecmp(L"hello", L"HELLO");
708 } else if (param > PARAM_0) {
709 wcscasecmp_value = wcscasecmp(L"helloA", L"HELLO");
710 } else {
711 wcscasecmp_value = wcscasecmp(L"hello", L"HELLOA");
712 }
713
714 napi_value result = nullptr;
715 napi_create_int32(env, wcscasecmp_value, &result);
716
717 return result;
718 }
719
WcscasecmpL(napi_env env,napi_callback_info info)720 static napi_value WcscasecmpL(napi_env env, napi_callback_info info)
721 {
722 size_t argc = PARAM_1;
723 napi_value args[1] = {nullptr};
724 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
725 int param;
726 napi_get_value_int32(env, args[0], ¶m);
727
728 locale_t locale = nullptr;
729 int wcscasecmpLValue;
730 if (param == PARAM_0) {
731 wcscasecmpLValue = wcscasecmp_l(L"hello", L"HELLO", locale);
732 } else if (param > PARAM_0) {
733 wcscasecmpLValue = wcscasecmp_l(L"helloA", L"HELLO", locale);
734 } else {
735 wcscasecmpLValue = wcscasecmp_l(L"hello", L"HELLOA", locale);
736 }
737
738 napi_value result = nullptr;
739 napi_create_int32(env, wcscasecmpLValue, &result);
740
741 return result;
742 }
743
WcscollL(napi_env env,napi_callback_info info)744 static napi_value WcscollL(napi_env env, napi_callback_info info)
745 {
746 size_t argc = PARAM_1;
747 napi_value args[1] = {nullptr};
748 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
749 int param;
750 napi_get_value_int32(env, args[0], ¶m);
751
752 locale_t locale = nullptr;
753 int wcscmpValue;
754 if (param == PARAM_0) {
755 wcscmpValue = wcscoll_l(L"12345", L"12345", locale);
756 } else if (param > PARAM_0) {
757 wcscmpValue = wcscoll_l(L"12345A", L"12345", locale);
758 } else {
759 wcscmpValue = wcscoll_l(L"12345", L"12345A", locale);
760 }
761
762 napi_value result = nullptr;
763 napi_create_int32(env, wcscmpValue, &result);
764
765 return result;
766 }
767
Wcsftime(napi_env env,napi_callback_info info)768 static napi_value Wcsftime(napi_env env, napi_callback_info info)
769 {
770 time_t rtime;
771 struct tm *timeinfo;
772 wchar_t buffer[80];
773 time(&rtime);
774 timeinfo = localtime(&rtime);
775 int wcsftime_value = wcsftime(buffer, SIZE_80, L"%Y", timeinfo);
776
777 napi_value result = nullptr;
778 napi_create_double(env, wcsftime_value, &result);
779
780 return result;
781 }
782
WcsftimeL(napi_env env,napi_callback_info info)783 static napi_value WcsftimeL(napi_env env, napi_callback_info info)
784 {
785 time_t rtime;
786 struct tm *timeinfo;
787 wchar_t buffer[SIZE_80];
788 time(&rtime);
789 timeinfo = localtime(&rtime);
790 locale_t locale = nullptr;
791 int wcsftime_l_value = wcsftime_l(buffer, SIZE_80, L"%Y", timeinfo, locale);
792
793 napi_value result = nullptr;
794 napi_create_double(env, wcsftime_l_value, &result);
795
796 return result;
797 }
798
Wcsncasecmp(napi_env env,napi_callback_info info)799 static napi_value Wcsncasecmp(napi_env env, napi_callback_info info)
800 {
801 size_t argc = PARAM_1;
802 napi_value args[1] = {nullptr};
803 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
804 int sizeParam;
805 napi_get_value_int32(env, args[0], &sizeParam);
806
807 int wcsncasecmp_value;
808 if (sizeParam == PARAM_0) {
809 wcsncasecmp_value = wcsncasecmp(L"hello", L"HELLO", SIZE_6);
810 } else if (sizeParam > PARAM_0) {
811 wcsncasecmp_value = wcsncasecmp(L"hello2", L"HELLO1", SIZE_6);
812 } else {
813 wcsncasecmp_value = wcsncasecmp(L"hello1", L"HELLO2", SIZE_6);
814 }
815
816 napi_value result = nullptr;
817 napi_create_int32(env, wcsncasecmp_value, &result);
818
819 return result;
820 }
821
WcsncasecmpL(napi_env env,napi_callback_info info)822 static napi_value WcsncasecmpL(napi_env env, napi_callback_info info)
823 {
824 size_t argc = PARAM_1;
825 napi_value args[1] = {nullptr};
826 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
827 int sizeParam;
828 napi_get_value_int32(env, args[0], &sizeParam);
829
830 locale_t locale = nullptr;
831 int wcsncasecmp_l_value;
832 if (sizeParam == PARAM_0) {
833 wcsncasecmp_l_value = wcsncasecmp_l(L"hello", L"HELLO", SIZE_6, locale);
834 } else if (sizeParam > PARAM_0) {
835 wcsncasecmp_l_value = wcsncasecmp_l(L"hello2", L"HELLO1", SIZE_6, locale);
836 } else {
837 wcsncasecmp_l_value = wcsncasecmp_l(L"hello1", L"HELLO2", SIZE_6, locale);
838 }
839
840 napi_value result = nullptr;
841 napi_create_int32(env, wcsncasecmp_l_value, &result);
842
843 return result;
844 }
845
Wcsncpy(napi_env env,napi_callback_info info)846 static napi_value Wcsncpy(napi_env env, napi_callback_info info)
847 {
848 size_t argc = PARAM_1;
849 napi_value args[1] = {nullptr};
850 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
851 int sizeParam;
852 napi_get_value_int32(env, args[0], &sizeParam);
853
854 int resultValue = RETURN_0;
855 if (sizeParam == PARAM_1) {
856 const wchar_t src[] = L"Hello";
857 wchar_t buf[SIZE_6];
858 wmemset(buf, L'A', SIZE_6);
859 wchar_t *dest = static_cast<wchar_t *>(buf);
860
861 if (dest == wcsncpy(dest, src, SIZE_6)) {
862 resultValue = RETURN_ONE;
863 }
864
865 } else {
866 wchar_t src[] = L"Hello";
867 wchar_t *result = wcsncpy(nullptr, src, PARAM_0);
868 if (result == nullptr) {
869 resultValue = RETURN_ONE;
870 }
871 }
872
873 napi_value result = nullptr;
874 napi_create_int32(env, resultValue, &result);
875
876 return result;
877 }
878
Wcsrchr(napi_env env,napi_callback_info info)879 static napi_value Wcsrchr(napi_env env, napi_callback_info info)
880 {
881 size_t argc = PARAM_1;
882 napi_value args[1] = {nullptr};
883 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
884 int param;
885 napi_get_value_int32(env, args[0], ¶m);
886
887 wchar_t dest[] = L"abcdefg";
888 wchar_t *p;
889 int resultValue;
890 if (param == PARAM_0) {
891 p = wcsrchr(dest, L'a');
892 if (p) {
893 resultValue = RETURN_0;
894 } else {
895 resultValue = FAILD;
896 }
897 } else {
898 p = wcsrchr(dest, L'1');
899 if (p) {
900 resultValue = RETURN_0;
901 } else {
902 resultValue = FAILD;
903 }
904 }
905
906 napi_value result = nullptr;
907 napi_create_int32(env, resultValue, &result);
908
909 return result;
910 }
911
Wcsrtombs(napi_env env,napi_callback_info info)912 static napi_value Wcsrtombs(napi_env env, napi_callback_info info)
913 {
914 size_t argc = PARAM_1;
915 napi_value args[1] = {nullptr};
916 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
917 int sizeParam;
918 napi_get_value_int32(env, args[0], &sizeParam);
919
920 const wchar_t *src = L"abcdefg";
921 char dest[SIZE_20];
922 mbstate_t ps = mbstate_t();
923
924 size_t wcsrtombsValue = wcsrtombs(dest, &src, sizeParam, &ps);
925
926 napi_value result = nullptr;
927 napi_create_int32(env, wcsrtombsValue, &result);
928
929 return result;
930 }
931
Wcsspn(napi_env env,napi_callback_info info)932 static napi_value Wcsspn(napi_env env, napi_callback_info info)
933 {
934 size_t argc = PARAM_1;
935 napi_value args[1] = {nullptr};
936 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
937 int param;
938 napi_get_value_int32(env, args[0], ¶m);
939
940 wchar_t dest[] = L"abcdefg";
941
942 int wcsspn_value;
943 if (param == PARAM_0) {
944 wchar_t src[] = L"abc";
945 wcsspn_value = wcsspn(dest, src);
946
947 } else {
948 wchar_t src[] = L"123";
949 wcsspn_value = wcsspn(dest, src);
950 }
951
952 napi_value result = nullptr;
953 napi_create_int32(env, wcsspn_value, &result);
954
955 return result;
956 }
957
Wcsstr(napi_env env,napi_callback_info info)958 static napi_value Wcsstr(napi_env env, napi_callback_info info)
959 {
960 size_t argc = PARAM_1;
961 napi_value args[1] = {nullptr};
962 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
963 int param;
964 napi_get_value_int32(env, args[0], ¶m);
965
966 wchar_t dest[] = L"ab cd efg";
967
968 int wcsstrValue;
969 if (param == PARAM_0) {
970 wchar_t src[] = L"cd";
971 wchar_t *p = wcsstr(dest, src);
972 if (p) {
973 wcsstrValue = RETURN_0;
974 } else {
975 wcsstrValue = FAILD;
976 }
977
978 } else {
979 wchar_t src[] = L"1";
980 wchar_t *p = wcsstr(dest, src);
981 if (p) {
982 wcsstrValue = RETURN_0;
983 } else {
984 wcsstrValue = FAILD;
985 }
986 }
987
988 napi_value result = nullptr;
989 napi_create_int32(env, wcsstrValue, &result);
990
991 return result;
992 }
993
Wcstod(napi_env env,napi_callback_info info)994 static napi_value Wcstod(napi_env env, napi_callback_info info)
995 {
996 size_t argc = PARAM_1;
997 napi_value args[1] = {nullptr};
998 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
999 int param;
1000 napi_get_value_int32(env, args[0], ¶m);
1001
1002 double wcstod_value;
1003 if (param == PARAM_0) {
1004 wchar_t dest[] = L"abcdefg";
1005 wchar_t *end;
1006 wcstod_value = wcstod(dest, &end);
1007 } else {
1008 wchar_t dest[] = L"95.6abcdefg";
1009 wchar_t *end;
1010 wcstod_value = wcstod(dest, &end);
1011 }
1012
1013 napi_value result = nullptr;
1014 napi_create_double(env, wcstod_value, &result);
1015
1016 return result;
1017 }
1018
Wcstof(napi_env env,napi_callback_info info)1019 static napi_value Wcstof(napi_env env, napi_callback_info info)
1020 {
1021 size_t argc = PARAM_1;
1022 napi_value args[1] = {nullptr};
1023 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1024 int param;
1025 napi_get_value_int32(env, args[0], ¶m);
1026
1027 double wcstof_value;
1028 if (param == PARAM_0) {
1029 wchar_t dest[] = L"abcdefg";
1030 wchar_t *end;
1031 wcstof_value = wcstof(dest, &end);
1032 } else {
1033 wchar_t dest[] = L"95.6abcdefg";
1034 wchar_t *end;
1035 wcstof_value = wcstof(dest, &end);
1036 }
1037
1038 napi_value result = nullptr;
1039 napi_create_double(env, wcstof_value, &result);
1040
1041 return result;
1042 }
1043
Wcstok(napi_env env,napi_callback_info info)1044 static napi_value Wcstok(napi_env env, napi_callback_info info)
1045 {
1046 size_t argc = PARAM_1;
1047 napi_value args[1] = {nullptr};
1048 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1049 int param;
1050 napi_get_value_int32(env, args[0], ¶m);
1051
1052 wchar_t *ptr;
1053 int wcstokValue = FAILD;
1054 if (param == PARAM_0) {
1055 wchar_t str[] = L"123,456";
1056 wchar_t delim[] = L",";
1057 wchar_t *want = wcstok(str, delim, &ptr);
1058 if (wcscmp(want, L"123") == PARAM_0) {
1059 wcstokValue = RETURN_0;
1060 }
1061 } else {
1062 wchar_t str[] = L"123,456";
1063 wchar_t delim[] = L"/";
1064 wchar_t *want = wcstok(str, delim, &ptr);
1065 if (wcscmp(want, str) == PARAM_0) {
1066 wcstokValue = RETURN_0;
1067 }
1068 }
1069
1070 napi_value result = nullptr;
1071 napi_create_int32(env, wcstokValue, &result);
1072
1073 return result;
1074 }
1075
Wcstol(napi_env env,napi_callback_info info)1076 static napi_value Wcstol(napi_env env, napi_callback_info info)
1077 {
1078 size_t argc = PARAM_1;
1079 napi_value args[1] = {nullptr};
1080 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1081
1082 int param;
1083 napi_get_value_int32(env, args[0], ¶m);
1084
1085 double wcstol_value;
1086 if (param == PARAM_0) {
1087 wcstol_value = wcstol(L"123AB-20", nullptr, SIZE_10);
1088 } else {
1089 wchar_t *endString = nullptr;
1090 wcstol_value = wcstol(L"123xyz", &endString, SIZE_10);
1091 }
1092
1093 napi_value result = nullptr;
1094 napi_create_double(env, wcstol_value, &result);
1095
1096 return result;
1097 }
1098
Wcstold(napi_env env,napi_callback_info info)1099 static napi_value Wcstold(napi_env env, napi_callback_info info)
1100 {
1101 size_t argc = PARAM_1;
1102 napi_value args[1] = {nullptr};
1103 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1104
1105 int param;
1106 napi_get_value_int32(env, args[0], ¶m);
1107
1108 double wcstoldValue;
1109 if (param == PARAM_0) {
1110 wchar_t str[] = L"123AB-20";
1111 wchar_t *end = nullptr;
1112 wcstoldValue = wcstold(str, &end);
1113 } else {
1114 wchar_t str[] = L"123xyz";
1115 wchar_t *end = nullptr;
1116 wcstoldValue = wcstold(str, &end);
1117 }
1118
1119 napi_value result = nullptr;
1120 napi_create_double(env, wcstoldValue, &result);
1121
1122 return result;
1123 }
1124
Wcstoll(napi_env env,napi_callback_info info)1125 static napi_value Wcstoll(napi_env env, napi_callback_info info)
1126 {
1127 size_t argc = PARAM_1;
1128 napi_value args[1] = {nullptr};
1129 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1130
1131 int param;
1132 napi_get_value_int32(env, args[0], ¶m);
1133
1134 double wcstollValue;
1135 if (param == PARAM_0) {
1136 wcstollValue = wcstoll(L"123AB-20", nullptr, SIZE_10);
1137 } else {
1138 wchar_t *endString = nullptr;
1139 wcstollValue = wcstoll(L"123xyz", &endString, SIZE_10);
1140 }
1141
1142 napi_value result = nullptr;
1143 napi_create_double(env, wcstollValue, &result);
1144
1145 return result;
1146 }
1147
Wcstombs(napi_env env,napi_callback_info info)1148 static napi_value Wcstombs(napi_env env, napi_callback_info info)
1149 {
1150 size_t argc = PARAM_1;
1151 napi_value args[1] = {nullptr};
1152 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1153
1154 int param;
1155 napi_get_value_int32(env, args[0], ¶m);
1156
1157 wchar_t src[] = L"HelloWorld";
1158 char dest[SIZE_100];
1159 int wcstombsValue = wcstombs(dest, src, param);
1160
1161 napi_value result = nullptr;
1162 napi_create_double(env, wcstombsValue, &result);
1163
1164 return result;
1165 }
1166
Wcstoul(napi_env env,napi_callback_info info)1167 static napi_value Wcstoul(napi_env env, napi_callback_info info)
1168 {
1169 size_t argc = PARAM_1;
1170 napi_value args[1] = {nullptr};
1171 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1172
1173 int param;
1174 napi_get_value_int32(env, args[0], ¶m);
1175
1176 double wcstoul_value;
1177 if (param == PARAM_0) {
1178 wcstoul_value = wcstoul(L"123AB-20", nullptr, SIZE_10);
1179 } else {
1180 wchar_t *endString = nullptr;
1181 wcstoul_value = wcstoul(L"123xyz", &endString, SIZE_10);
1182 }
1183
1184 napi_value result = nullptr;
1185 napi_create_double(env, wcstoul_value, &result);
1186
1187 return result;
1188 }
1189
Wcstoull(napi_env env,napi_callback_info info)1190 static napi_value Wcstoull(napi_env env, napi_callback_info info)
1191 {
1192 size_t argc = PARAM_1;
1193 napi_value args[1] = {nullptr};
1194 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1195
1196 int param;
1197 napi_get_value_int32(env, args[0], ¶m);
1198
1199 double wcstoullValue;
1200 if (param == PARAM_0) {
1201 wcstoullValue = wcstoull(L"123AB-20", nullptr, SIZE_10);
1202 } else {
1203 wchar_t *endString = nullptr;
1204 wcstoullValue = wcstoll(L"123xyz", &endString, SIZE_10);
1205 }
1206
1207 napi_value result = nullptr;
1208 napi_create_double(env, wcstoullValue, &result);
1209
1210 return result;
1211 }
1212
Wcswidth(napi_env env,napi_callback_info info)1213 static napi_value Wcswidth(napi_env env, napi_callback_info info)
1214 {
1215 size_t argc = PARAM_1;
1216 napi_value args[1] = {nullptr};
1217 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1218
1219 int param;
1220 napi_get_value_int32(env, args[0], ¶m);
1221
1222 int wcswidth_value;
1223 if (param == PARAM_0) {
1224 wcswidth_value = wcswidth(L"abc", PARAM_2);
1225 } else {
1226 wcswidth_value = wcswidth(L"a\tb", PARAM_2);
1227 }
1228
1229 napi_value result = nullptr;
1230 napi_create_double(env, wcswidth_value, &result);
1231
1232 return result;
1233 }
1234
Wcsxfrm(napi_env env,napi_callback_info info)1235 static napi_value Wcsxfrm(napi_env env, napi_callback_info info)
1236 {
1237 size_t argc = PARAM_1;
1238 napi_value args[1] = {nullptr};
1239 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1240 int param;
1241 napi_get_value_int32(env, args[0], ¶m);
1242
1243 wchar_t src[SIZE_10];
1244 int wcsxfrmValue = wcsxfrm(src, L"abcdefg", param);
1245
1246 napi_value result = nullptr;
1247 napi_create_int32(env, wcsxfrmValue, &result);
1248
1249 return result;
1250 }
1251
Wcsnrtombs(napi_env env,napi_callback_info info)1252 static napi_value Wcsnrtombs(napi_env env, napi_callback_info info)
1253 {
1254 size_t argc = PARAM_1;
1255 napi_value args[1] = {nullptr};
1256 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1257 int sizeParam;
1258 napi_get_value_int32(env, args[0], &sizeParam);
1259
1260 const wchar_t *src = L"abcdefg";
1261 char dest[SIZE_20];
1262 mbstate_t ps = mbstate_t();
1263
1264 size_t wcsrtombsValue = wcsnrtombs(dest, &src, sizeParam, sizeParam, &ps);
1265
1266 napi_value result = nullptr;
1267 napi_create_int32(env, wcsrtombsValue, &result);
1268
1269 return result;
1270 }
1271
WcsxfrmL(napi_env env,napi_callback_info info)1272 static napi_value WcsxfrmL(napi_env env, napi_callback_info info)
1273 {
1274 size_t argc = PARAM_1;
1275 napi_value args[1] = {nullptr};
1276 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1277 int param;
1278 napi_get_value_int32(env, args[0], ¶m);
1279
1280 wchar_t src[SIZE_10];
1281 locale_t locale = nullptr;
1282 int wcsxfrmValue = wcsxfrm_l(src, L"abcdefg", param, locale);
1283
1284 napi_value result = nullptr;
1285 napi_create_int32(env, wcsxfrmValue, &result);
1286
1287 return result;
1288 }
1289
Wctob(napi_env env,napi_callback_info info)1290 static napi_value Wctob(napi_env env, napi_callback_info info)
1291 {
1292 size_t argc = PARAM_1;
1293 napi_value args[1] = {nullptr};
1294 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1295 int param;
1296 napi_get_value_int32(env, args[0], ¶m);
1297 int resultValue = FAILD;
1298 if (param == PARAM_0) {
1299 wchar_t c = L'A';
1300 int result = wctob(c);
1301 if (result == 'A') {
1302 resultValue = RETURN_0;
1303 }
1304 } else {
1305 wchar_t c = L'\u00df';
1306 int result = wctob(c);
1307 if (result == EOF) {
1308 resultValue = RETURN_0;
1309 }
1310 }
1311
1312 napi_value result = nullptr;
1313 napi_create_int32(env, resultValue, &result);
1314
1315 return result;
1316 }
1317
Wctomb(napi_env env,napi_callback_info info)1318 static napi_value Wctomb(napi_env env, napi_callback_info info)
1319 {
1320 size_t argc = PARAM_1;
1321 napi_value args[1] = {nullptr};
1322 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1323 int param;
1324 napi_get_value_int32(env, args[0], ¶m);
1325 int resultValue = FAILD;
1326 if (param == PARAM_0) {
1327 wchar_t c = L'h';
1328 char byte[SIZE_256] = {PARAM_0};
1329 int result = wctomb(byte, c);
1330 if (result == PARAM_1) {
1331 resultValue = RETURN_0;
1332 }
1333 } else if (param == PARAM_1) {
1334 wchar_t c = L'\0';
1335 char byte[SIZE_256] = {PARAM_0};
1336 int result = wctomb(byte, c);
1337 if (result == PARAM_1) {
1338 resultValue = RETURN_0;
1339 }
1340 } else if (param == PARAM_2) {
1341 wchar_t c = L'h';
1342 int result = wctomb(nullptr, c);
1343 if (result == PARAM_0) {
1344 resultValue = RETURN_0;
1345 }
1346 } else {
1347 wchar_t c = L'\0';
1348 int result = wctomb(nullptr, c);
1349 if (result == PARAM_0) {
1350 resultValue = RETURN_0;
1351 }
1352 }
1353
1354 napi_value result = nullptr;
1355 napi_create_int32(env, resultValue, &result);
1356
1357 return result;
1358 }
1359
Wcwidth(napi_env env,napi_callback_info info)1360 static napi_value Wcwidth(napi_env env, napi_callback_info info)
1361 {
1362 size_t argc = PARAM_1;
1363 napi_value args[1] = {nullptr};
1364 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1365 int param;
1366 napi_get_value_int32(env, args[0], ¶m);
1367 int resultValue = FAILD;
1368 if (param == PARAM_0) {
1369 int result = wcwidth(PARAM_0);
1370 if (result == PARAM_0) {
1371 resultValue = PARAM_0;
1372 }
1373 } else {
1374 int result = wcwidth(PARAM_0x00ad);
1375 if (result == PARAM_1) {
1376 resultValue = RETURN_ONE;
1377 }
1378 }
1379
1380 napi_value result = nullptr;
1381 napi_create_int32(env, resultValue, &result);
1382
1383 return result;
1384 }
1385
Wmemchr(napi_env env,napi_callback_info info)1386 static napi_value Wmemchr(napi_env env, napi_callback_info info)
1387 {
1388 size_t argc = PARAM_1;
1389 napi_value args[1] = {nullptr};
1390 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1391 int param;
1392 napi_get_value_int32(env, args[0], ¶m);
1393 int resultValue = FAILD;
1394 if (param == PARAM_0) {
1395 wchar_t str[] = L"ABCDEFG";
1396 wchar_t target = L'C';
1397 size_t sz = sizeof(str) / sizeof(*str);
1398 wchar_t *result = wmemchr(str, target, sz);
1399 if (result) {
1400 resultValue = RETURN_0;
1401 }
1402 } else if (param == PARAM_1) {
1403 wchar_t str[] = L"ABCDEFG";
1404 wchar_t target = L'H';
1405 size_t sz = sizeof(str) / sizeof(*str);
1406 wchar_t *result = wmemchr(str, target, sz);
1407 if (!result) {
1408 resultValue = RETURN_0;
1409 }
1410 } else {
1411 wchar_t str[] = L"ABCDEFG";
1412 wchar_t target = L'C';
1413 size_t sz = PARAM_0;
1414 wchar_t *result = wmemchr(str, target, sz);
1415 if (!result) {
1416 resultValue = RETURN_0;
1417 }
1418 }
1419
1420 napi_value result = nullptr;
1421 napi_create_int32(env, resultValue, &result);
1422
1423 return result;
1424 }
1425
Wmemcmp(napi_env env,napi_callback_info info)1426 static napi_value Wmemcmp(napi_env env, napi_callback_info info)
1427 {
1428 size_t argc = PARAM_1;
1429 napi_value args[1] = {nullptr};
1430 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1431 int param;
1432 napi_get_value_int32(env, args[0], ¶m);
1433 int resultValue = FAILD;
1434 if (param == PARAM_0) {
1435 wchar_t l[] = L"ABCD";
1436 wchar_t r[] = L"ABCD";
1437 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
1438 if (result == PARAM_0) {
1439 resultValue = RETURN_0;
1440 }
1441 } else if (param == 1) {
1442 wchar_t l[] = L"ABCD";
1443 wchar_t r[] = L"ABCE";
1444 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
1445 if (result < PARAM_0) {
1446 resultValue = RETURN_0;
1447 }
1448 } else if (param == PARAM_2) {
1449 wchar_t l[] = L"ABCD";
1450 wchar_t r[] = L"ABCC";
1451 int result = wmemcmp(l, r, sizeof(l) / sizeof(*l));
1452 if (result > PARAM_0) {
1453 resultValue = RETURN_0;
1454 }
1455 } else {
1456 wchar_t l[] = L"ABCD";
1457 wchar_t r[] = L"ABCC";
1458 int n = PARAM_0;
1459 int result = wmemcmp(l, r, n);
1460 if (result == PARAM_0) {
1461 resultValue = RETURN_0;
1462 }
1463 }
1464
1465 napi_value result = nullptr;
1466 napi_create_int32(env, resultValue, &result);
1467
1468 return result;
1469 }
1470
Wmemcpy(napi_env env,napi_callback_info info)1471 static napi_value Wmemcpy(napi_env env, napi_callback_info info)
1472 {
1473 size_t argc = PARAM_1;
1474 napi_value args[1] = {nullptr};
1475 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1476 int param;
1477 napi_get_value_int32(env, args[0], ¶m);
1478 int resultValue = FAILD;
1479 if (param == PARAM_0) {
1480 wchar_t des[SIZE_30];
1481 wchar_t src[] = L"This is a c test for wmemcpy";
1482 int n = SIZE_13;
1483 wmemcpy(des, src, n);
1484 if (!wcsncmp(des, src, n)) {
1485 resultValue = RETURN_0;
1486 }
1487 } else if (param == PARAM_1) {
1488 wchar_t des[SIZE_3];
1489 wchar_t src[] = L"aaa";
1490 int n = SIZE_3;
1491 wmemcpy(des, src, n);
1492 if (!wcsncmp(des, src, n)) {
1493 resultValue = RETURN_0;
1494 }
1495 } else {
1496 wchar_t des[SIZE_3];
1497 wchar_t src[] = L"aaa";
1498 int n = PARAM_0;
1499 wmemcpy(des, src, n);
1500 if (!wcsncmp(des, src, n)) {
1501 resultValue = RETURN_0;
1502 }
1503 }
1504
1505 napi_value result = nullptr;
1506 napi_create_int32(env, resultValue, &result);
1507
1508 return result;
1509 }
1510
Wmemmove(napi_env env,napi_callback_info info)1511 static napi_value Wmemmove(napi_env env, napi_callback_info info)
1512 {
1513 size_t argc = PARAM_1;
1514 napi_value args[1] = {nullptr};
1515 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1516 int param;
1517 napi_get_value_int32(env, args[0], ¶m);
1518 int resultValue = FAILD;
1519 if (param == PARAM_0) {
1520 wchar_t des[] = L"This is a c test for wmemmove function";
1521 const wchar_t src[] = L"src content";
1522 int count = SIZE_5;
1523 wchar_t tmp[count + PARAM_1];
1524 wcsncpy(tmp, src, count);
1525 wmemmove(des, src, count);
1526 if (!wcsncmp(des, tmp, count)) {
1527 resultValue = RETURN_0;
1528 }
1529 } else {
1530 wchar_t src[] = L"This is a c test for wmemmove function";
1531 wchar_t *des = &src[PARAM_0];
1532 int count = SIZE_5;
1533 wchar_t *result = wmemmove(des, src, count);
1534 if (result == des) {
1535 resultValue = RETURN_0;
1536 }
1537 }
1538
1539 napi_value result = nullptr;
1540 napi_create_int32(env, resultValue, &result);
1541
1542 return result;
1543 }
1544
Wmemset(napi_env env,napi_callback_info info)1545 static napi_value Wmemset(napi_env env, napi_callback_info info)
1546 {
1547 int resultValue = PARAM_0;
1548 wchar_t ch = L'G';
1549 wchar_t des[SIZE_20];
1550 int count = SIZE_5;
1551 wmemset(des, ch, count);
1552 for (int i = PARAM_0; i < count; i++) {
1553 if (des[i] != ch) {
1554 resultValue = FAIL;
1555 }
1556 }
1557 napi_value result = nullptr;
1558 napi_create_int32(env, resultValue, &result);
1559 return result;
1560 }
1561
Wprintf(napi_env env,napi_callback_info info)1562 static napi_value Wprintf(napi_env env, napi_callback_info info)
1563 {
1564 int resultValue = wprintf(L"%lc\n", L'a');
1565 napi_value result = nullptr;
1566 napi_create_int32(env, resultValue, &result);
1567
1568 return result;
1569 }
1570
Wcswcs(napi_env env,napi_callback_info info)1571 static napi_value Wcswcs(napi_env env, napi_callback_info info)
1572 {
1573 size_t argc = PARAM_1;
1574 napi_value args[1] = {nullptr};
1575 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1576 int param;
1577 napi_get_value_int32(env, args[0], ¶m);
1578 int resultValue = FAILD;
1579 if (param == PARAM_0) {
1580 wchar_t *ret = wcswcs(L"abcd", L"a");
1581 if (ret != nullptr) {
1582 resultValue = RETURN_0;
1583 }
1584 } else {
1585 wchar_t *ret = wcswcs(L"", L"");
1586 if (ret == nullptr) {
1587 resultValue = FAILD;
1588 }
1589 }
1590
1591 napi_value result = nullptr;
1592 napi_create_int32(env, resultValue, &result);
1593
1594 return result;
1595 }
1596
Ungetwc(napi_env env,napi_callback_info info)1597 static napi_value Ungetwc(napi_env env, napi_callback_info info)
1598 {
1599 size_t argc = PARAM_1;
1600 napi_value args[1] = {nullptr};
1601 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1602
1603 int valueFirst;
1604 napi_get_value_int32(env, args[0], &valueFirst);
1605
1606 wint_t wint_t1 = PARAM_0;
1607 if (valueFirst == ASCII_LA) {
1608 wint_t1 = L'a';
1609 }
1610 wint_t ungetwcValue = ungetwc(wint_t1, stdin);
1611
1612 napi_value result = nullptr;
1613 napi_create_uint32(env, ungetwcValue, &result);
1614 return result;
1615 }
1616
Btowc(napi_env env,napi_callback_info info)1617 static napi_value Btowc(napi_env env, napi_callback_info info)
1618 {
1619 size_t argc = PARAM_1;
1620 napi_value args[1] = {nullptr};
1621 napi_get_cb_info(env, info, &argc, args, nullptr, nullptr);
1622 int index;
1623 napi_get_value_int32(env, args[0], &index);
1624 char param[] = "Btowc";
1625 wchar_t value = btowc(param[index]);
1626
1627 napi_value result = nullptr;
1628 napi_create_int32(env, value, &result);
1629
1630 return result;
1631 }
1632
Fwscanf(napi_env env,napi_callback_info info)1633 static napi_value Fwscanf(napi_env env, napi_callback_info info)
1634 {
1635 FILE *fp = fopen("/data/storage/el2/base/files/Fzl.txt", "w+");
1636
1637 wchar_t str[10], ch[10];
1638 setlocale(LC_ALL, "en_US.UTF-8");
1639 fwprintf(fp, L"%ls %lc", L"Summation", L'\u2211');
1640 fwprintf(fp, L"%ls %lc", L"Integral", L'\u222b');
1641
1642 rewind(fp);
1643 int ret = fwscanf(fp, L"%ls %lc", str, &ch);
1644 int value = FAIL;
1645 if (ret > PARAM_0) {
1646 value = SUCCESS;
1647 }
1648 fclose(fp);
1649 napi_value result = nullptr;
1650 napi_create_int32(env, value, &result);
1651
1652 return result;
1653 }
1654
Fwprintf(napi_env env,napi_callback_info info)1655 static napi_value Fwprintf(napi_env env, napi_callback_info info)
1656 {
1657 int value = fwprintf(stdout, L"This is a test!!");
1658 int ret = FAIL;
1659 if (value >= PARAM_0) {
1660 ret = SUCCESS;
1661 }
1662 napi_value result = nullptr;
1663 napi_create_int32(env, ret, &result);
1664
1665 return result;
1666 }
1667
Fwide(napi_env env,napi_callback_info info)1668 static napi_value Fwide(napi_env env, napi_callback_info info)
1669 {
1670 const char *path = "/data/storage/el2/base/files/Fzl.txt";
1671 FILE *fp = fopen(path, "w+");
1672 int param = PARAM_20;
1673 int value = fwide(fp, param);
1674 int ret = FAIL;
1675 if (value > PARAM_0) {
1676 ret = SUCCESS;
1677 }
1678 napi_value result = nullptr;
1679 napi_create_int32(env, ret, &result);
1680 fclose(fp);
1681 return result;
1682 }
1683
Fputws(napi_env env,napi_callback_info info)1684 static napi_value Fputws(napi_env env, napi_callback_info info)
1685 {
1686 const char *ptr = "/data/storage/el2/base/files/Fzl.txt";
1687 FILE *fptr = fopen(ptr, "w+");
1688 setlocale(LC_ALL, "en_US.utf8");
1689 int ret = fputws(L"this is the test", fptr);
1690 int value = FAIL;
1691 if (ret != FAIL) {
1692 value = PARAM_0;
1693 }
1694 fclose(fptr);
1695 remove(ptr);
1696 fptr = nullptr;
1697 ptr = nullptr;
1698 napi_value result = nullptr;
1699 napi_create_int32(env, value, &result);
1700
1701 return result;
1702 }
1703
FGetWs(napi_env env,napi_callback_info info)1704 static napi_value FGetWs(napi_env env, napi_callback_info info)
1705 {
1706 errno = ZERO;
1707 wchar_t mystring[100];
1708 char str[] = "test";
1709 FILE *fp = fopen("/data/storage/el2/base/files/Fzl.txt", "w+");
1710 NAPI_ASSERT(env, fp != nullptr, "FGetWs fopen Error");
1711 fwrite(str, sizeof(char), sizeof(str), fp);
1712 fseek(fp, ZEROVAL, SEEK_SET);
1713 wchar_t *ret = fgetws(mystring, SIZE_100, fp);
1714 napi_value result = nullptr;
1715 if (ret == mystring) {
1716 napi_create_int32(env, ZEROVAL, &result);
1717 } else {
1718 napi_create_int32(env, FAIL, &result);
1719 }
1720 fclose(fp);
1721 return result;
1722 }
1723
FGetWc(napi_env env,napi_callback_info info)1724 static napi_value FGetWc(napi_env env, napi_callback_info info)
1725 {
1726 setlocale(LC_ALL, "en_US.utf8");
1727 FILE *fp = fopen("/data/storage/el2/base/files/Fzl.txt", "w+");
1728 NAPI_ASSERT(env, fp != nullptr, "FGetWc fopen Error");
1729 fputs("кошка\n", fp);
1730 wint_t wc;
1731 napi_value result = nullptr;
1732 wc = fgetwc(fp);
1733 if (wc == WEOF) {
1734 napi_create_int32(env, ZEROVAL, &result);
1735 } else {
1736 napi_create_int32(env, FAIL, &result);
1737 }
1738 fclose(fp);
1739 return result;
1740 }
1741
vswscanfTest(const wchar_t * buffer,const wchar_t * format,...)1742 int vswscanfTest(const wchar_t *buffer, const wchar_t *format, ...)
1743 {
1744 int result = ZEROVAL;
1745 va_list args;
1746 va_start(args, format);
1747 vswscanf(buffer, format, args);
1748 va_end(args);
1749 return result;
1750 }
1751
Vswscanf(napi_env env,napi_callback_info info)1752 static napi_value Vswscanf(napi_env env, napi_callback_info info)
1753 {
1754 setlocale(LC_ALL, "en_US.UTF-8");
1755 wchar_t symbol[] = L"\u0fd7\u00c6\u20b9\u2127\u17d8";
1756 wchar_t str[20];
1757 int vswval = vswscanfTest(symbol, L"%ls", str);
1758 napi_value result;
1759 if (vswval < PARAM_0) {
1760 napi_create_int32(env, MINUSONE, &result);
1761 } else {
1762 napi_create_int32(env, PARAM_0, &result);
1763 }
1764 return result;
1765 }
1766
Getwc(napi_env env,napi_callback_info info)1767 static napi_value Getwc(napi_env env, napi_callback_info info)
1768 {
1769 const char *ptr = "/data/storage/el2/base/files/test.txt";
1770 FILE *fptr = fopen(ptr, "w+");
1771 NAPI_ASSERT(env, fptr != nullptr, "Getwc fopen Error");
1772 wchar_t wc = L'p';
1773 putwc(wc, fptr);
1774 rewind(fptr);
1775 wint_t wret = getwc(fptr);
1776 napi_value result = nullptr;
1777 if (wret == wc) {
1778 napi_create_int32(env, ZEROVAL, &result);
1779 } else {
1780 napi_create_int32(env, FAIL, &result);
1781 }
1782 fclose(fptr);
1783 return result;
1784 }
1785
Mbrlen(napi_env env,napi_callback_info info)1786 static napi_value Mbrlen(napi_env env, napi_callback_info info)
1787 {
1788 char test[] = {'m', 'u', 's', 'l'};
1789 size_t limitsize = sizeof(test[0]);
1790 size_t ret = mbrlen(&test[0], limitsize, nullptr);
1791 napi_value result = nullptr;
1792 napi_create_int32(env, ret, &result);
1793 return result;
1794 }
1795 EXTERN_C_START
Init(napi_env env,napi_value exports)1796 static napi_value Init(napi_env env, napi_value exports)
1797 {
1798 napi_property_descriptor desc[] = {
1799 {"vfwprintf", nullptr, Vfwprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1800 {"vfwscanf", nullptr, Vfwscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1801 {"vswprintf", nullptr, Vswprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1802 {"vwprintf", nullptr, Vwprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1803 {"wcpcpy", nullptr, Wcpcpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1804 {"wcscat", nullptr, Wcscat, nullptr, nullptr, nullptr, napi_default, nullptr},
1805 {"wcschr", nullptr, Wcschr, nullptr, nullptr, nullptr, napi_default, nullptr},
1806 {"wcscmp", nullptr, Wcscmp, nullptr, nullptr, nullptr, napi_default, nullptr},
1807 {"wcscoll", nullptr, Wcscoll, nullptr, nullptr, nullptr, napi_default, nullptr},
1808 {"wcscpy", nullptr, Wcscpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1809 {"wcscspn", nullptr, Wcscspn, nullptr, nullptr, nullptr, napi_default, nullptr},
1810 {"wcslen", nullptr, Wcslen, nullptr, nullptr, nullptr, napi_default, nullptr},
1811 {"wcsncat", nullptr, Wcsncat, nullptr, nullptr, nullptr, napi_default, nullptr},
1812 {"wcsdup", nullptr, Wcsdup, nullptr, nullptr, nullptr, napi_default, nullptr},
1813 {"wcsncmp", nullptr, Wcsncmp, nullptr, nullptr, nullptr, napi_default, nullptr},
1814 {"wcsncpy", nullptr, Wcsncpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1815 {"wcsnlen", nullptr, Wcsnlen, nullptr, nullptr, nullptr, napi_default, nullptr},
1816 {"wcspbrk", nullptr, Wcspbrk, nullptr, nullptr, nullptr, napi_default, nullptr},
1817 {"swprintf", nullptr, Swprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1818 {"swscanf", nullptr, Swscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1819 {"wscanf", nullptr, Wscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1820 {"vwscanf", nullptr, Vwscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1821 {"towlower", nullptr, Towlower, nullptr, nullptr, nullptr, napi_default, nullptr},
1822 {"towupper", nullptr, Towupper, nullptr, nullptr, nullptr, napi_default, nullptr},
1823 {"wcpncpy", nullptr, Wcpncpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1824 {"wcrtomb", nullptr, Wcrtomb, nullptr, nullptr, nullptr, napi_default, nullptr},
1825 {"wcscasecmp", nullptr, Wcscasecmp, nullptr, nullptr, nullptr, napi_default, nullptr},
1826 {"wcscasecmpL", nullptr, WcscasecmpL, nullptr, nullptr, nullptr, napi_default, nullptr},
1827 {"wcscollL", nullptr, WcscollL, nullptr, nullptr, nullptr, napi_default, nullptr},
1828 {"wcsftime", nullptr, Wcsftime, nullptr, nullptr, nullptr, napi_default, nullptr},
1829 {"wcsftimeL", nullptr, WcsftimeL, nullptr, nullptr, nullptr, napi_default, nullptr},
1830 {"wcsncasecmp", nullptr, Wcsncasecmp, nullptr, nullptr, nullptr, napi_default, nullptr},
1831 {"wcsncasecmpL", nullptr, WcsncasecmpL, nullptr, nullptr, nullptr, napi_default, nullptr},
1832 {"wcsncpy", nullptr, Wcsncpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1833 {"wcsnrtombs", nullptr, Wcsnrtombs, nullptr, nullptr, nullptr, napi_default, nullptr},
1834 {"wcsrchr", nullptr, Wcsrchr, nullptr, nullptr, nullptr, napi_default, nullptr},
1835 {"wcsrtombs", nullptr, Wcsrtombs, nullptr, nullptr, nullptr, napi_default, nullptr},
1836 {"wcsspn", nullptr, Wcsspn, nullptr, nullptr, nullptr, napi_default, nullptr},
1837 {"wcsstr", nullptr, Wcsstr, nullptr, nullptr, nullptr, napi_default, nullptr},
1838 {"wcstod", nullptr, Wcstod, nullptr, nullptr, nullptr, napi_default, nullptr},
1839 {"wcstof", nullptr, Wcstof, nullptr, nullptr, nullptr, napi_default, nullptr},
1840 {"wcstok", nullptr, Wcstok, nullptr, nullptr, nullptr, napi_default, nullptr},
1841 {"wcstol", nullptr, Wcstol, nullptr, nullptr, nullptr, napi_default, nullptr},
1842 {"wcstold", nullptr, Wcstold, nullptr, nullptr, nullptr, napi_default, nullptr},
1843 {"wcstoll", nullptr, Wcstoll, nullptr, nullptr, nullptr, napi_default, nullptr},
1844 {"wcstombs", nullptr, Wcstombs, nullptr, nullptr, nullptr, napi_default, nullptr},
1845 {"wcstoul", nullptr, Wcstoul, nullptr, nullptr, nullptr, napi_default, nullptr},
1846 {"wcstoull", nullptr, Wcstoull, nullptr, nullptr, nullptr, napi_default, nullptr},
1847 {"wcswidth", nullptr, Wcswidth, nullptr, nullptr, nullptr, napi_default, nullptr},
1848 {"wcsxfrm", nullptr, Wcsxfrm, nullptr, nullptr, nullptr, napi_default, nullptr},
1849 {"wcsxfrmL", nullptr, WcsxfrmL, nullptr, nullptr, nullptr, napi_default, nullptr},
1850 {"wctob", nullptr, Wctob, nullptr, nullptr, nullptr, napi_default, nullptr},
1851 {"wctomb", nullptr, Wctomb, nullptr, nullptr, nullptr, napi_default, nullptr},
1852 {"wcwidth", nullptr, Wcwidth, nullptr, nullptr, nullptr, napi_default, nullptr},
1853 {"wmemchr", nullptr, Wmemchr, nullptr, nullptr, nullptr, napi_default, nullptr},
1854 {"wmemcmp", nullptr, Wmemcmp, nullptr, nullptr, nullptr, napi_default, nullptr},
1855 {"wmemcpy", nullptr, Wmemcpy, nullptr, nullptr, nullptr, napi_default, nullptr},
1856 {"wmemmove", nullptr, Wmemmove, nullptr, nullptr, nullptr, napi_default, nullptr},
1857 {"wmemset", nullptr, Wmemset, nullptr, nullptr, nullptr, napi_default, nullptr},
1858 {"wprintf", nullptr, Wprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1859 {"wcswcs", nullptr, Wcswcs, nullptr, nullptr, nullptr, napi_default, nullptr},
1860 {"ungetwc", nullptr, Ungetwc, nullptr, nullptr, nullptr, napi_default, nullptr},
1861 {"btowc", nullptr, Btowc, nullptr, nullptr, nullptr, napi_default, nullptr},
1862 {"fwprintf", nullptr, Fwprintf, nullptr, nullptr, nullptr, napi_default, nullptr},
1863 {"fwscanf", nullptr, Fwscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1864 {"fputwc", nullptr, Fputwc, nullptr, nullptr, nullptr, napi_default, nullptr},
1865 {"fputws", nullptr, Fputws, nullptr, nullptr, nullptr, napi_default, nullptr},
1866 {"fwide", nullptr, Fwide, nullptr, nullptr, nullptr, napi_default, nullptr},
1867 {"putwc", nullptr, Putwc, nullptr, nullptr, nullptr, napi_default, nullptr},
1868 {"getwchar", nullptr, Getwchar, nullptr, nullptr, nullptr, napi_default, nullptr},
1869 {"putWChar", nullptr, PutWChar, nullptr, nullptr, nullptr, napi_default, nullptr},
1870 {"openWmemstream", nullptr, OpenWmemstream, nullptr, nullptr, nullptr, napi_default, nullptr},
1871 {"mbrtowc", nullptr, Mbrtowc, nullptr, nullptr, nullptr, napi_default, nullptr},
1872 {"mbsinit", nullptr, Mbsinit, nullptr, nullptr, nullptr, napi_default, nullptr},
1873 {"mbsnrtowcs", nullptr, Mbsnrtowcs, nullptr, nullptr, nullptr, napi_default, nullptr},
1874 {"mbsrtowcs", nullptr, Mbsrtowcs, nullptr, nullptr, nullptr, napi_default, nullptr},
1875 {"mbstowcs", nullptr, Mbstowcs, nullptr, nullptr, nullptr, napi_default, nullptr},
1876 {"mbtowc", nullptr, Mbtowc, nullptr, nullptr, nullptr, napi_default, nullptr},
1877 {"fgetws", nullptr, FGetWs, nullptr, nullptr, nullptr, napi_default, nullptr},
1878 {"fgetwc", nullptr, FGetWc, nullptr, nullptr, nullptr, napi_default, nullptr},
1879 {"vswscanf", nullptr, Vswscanf, nullptr, nullptr, nullptr, napi_default, nullptr},
1880 {"getwc", nullptr, Getwc, nullptr, nullptr, nullptr, napi_default, nullptr},
1881 {"mbrlen", nullptr, Mbrlen, nullptr, nullptr, nullptr, napi_default, nullptr},
1882 };
1883 napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
1884 return exports;
1885 }
1886
1887 EXTERN_C_END
1888
1889 static napi_module demoModule = {
1890 .nm_version = 1,
1891 .nm_flags = 0,
1892 .nm_filename = nullptr,
1893 .nm_register_func = Init,
1894 .nm_modname = "wchar",
1895 .nm_priv = ((void *)0),
1896 .reserved = {0},
1897 };
1898
RegisterEntryModule(void)1899 extern "C" __attribute__((constructor)) void RegisterEntryModule(void) { napi_module_register(&demoModule); }
1900