1// RUN: %clang %s -o %t && %run %t 2>&1
2
3#include <assert.h>
4#include <stdlib.h>
5#include <string.h>
6#include <wchar.h>
7
8int main(int argc, char **argv) {
9 mbstate_t state;
10 memset(s: &state, c: 0, n: sizeof(state));
11
12 char buff[10];
13 size_t res = wcrtomb(s: buff, wc: L'a', ps: &state);
14 assert(res == 1);
15 assert(buff[0] == 'a');
16
17 res = wcrtomb(s: buff, wc: L'\0', ps: &state);
18 assert(res == 1);
19 assert(buff[0] == '\0');
20
21 res = wcrtomb(NULL, wc: L'\0', ps: &state);
22 assert(res == 1);
23
24 res = wcrtomb(s: buff, wc: L'a', NULL);
25 assert(res == 1);
26 assert(buff[0] == 'a');
27
28 res = wcrtomb(s: buff, wc: L'\0', NULL);
29 assert(res == 1);
30 assert(buff[0] == '\0');
31
32 res = wcrtomb(NULL, wc: L'\0', NULL);
33 assert(res == 1);
34
35 return 0;
36}
37

source code of compiler-rt/test/sanitizer_common/TestCases/wcrtomb.c