1 /*
2 WCRTOMB: wchar_t wcrtomb (char *s, wchar_t wc, mbstate_t *ps)
3 */
4
5 #define TST_FUNCTION wcrtomb
6
7 #include "tsp_common.c"
8 #include "dat_wcrtomb.c"
9
10
11 int
tst_wcrtomb(FILE * fp,int debug_flg)12 tst_wcrtomb (FILE * fp, int debug_flg)
13 {
14 TST_DECL_VARS (wchar_t);
15 wchar_t wc;
16 char s[MBSSIZE], *s_in, *s_ex;
17 char t_flg, t_ini;
18 static mbstate_t t = { 0 };
19 mbstate_t *pt;
20 int err, i;
21
22 TST_DO_TEST (wcrtomb)
23 {
24 TST_HEAD_LOCALE (wcrtomb, S_WCRTOMB);
25 TST_DO_REC (wcrtomb)
26 {
27 TST_GET_ERRET (wcrtomb);
28 s_in = ((TST_INPUT (wcrtomb).s_flg) == 0) ? (char *) NULL : s;
29 wc = TST_INPUT (wcrtomb).wc;
30 t_flg = TST_INPUT (wcrtomb).t_flg;
31 t_ini = TST_INPUT (wcrtomb).t_init;
32 pt = (t_flg == 0) ? NULL : &t;
33
34 if (t_ini != 0)
35 {
36 memset (&t, 0, sizeof (t));
37 }
38
39 TST_CLEAR_ERRNO;
40 ret = wcrtomb (s_in, wc, pt);
41 TST_SAVE_ERRNO;
42
43 if (debug_flg)
44 {
45 fprintf (stdout, "wcrtomb() [ %s : %d ] ret = %lu\n", locale,
46 rec + 1, (unsigned long int) ret);
47 fprintf (stdout, " errno = %d\n", errno_save);
48 }
49
50 TST_IF_RETURN (S_WCRTOMB)
51 {
52 };
53
54 s_ex = TST_EXPECT (wcrtomb).s;
55
56 if (s_in)
57 {
58 for (i = 0, err = 0; *(s_ex + i) != 0 && i < MBSSIZE; i++)
59 {
60 if (s_in[i] != s_ex[i])
61 {
62 err++;
63 err_count++;
64 Result (C_FAILURE, S_WCRTOMB, CASE_4,
65 "copied string is different from an "
66 "expected string");
67 break;
68 }
69 }
70 if (!err)
71 {
72 Result (C_SUCCESS, S_WCRTOMB, CASE_4, MS_PASSED);
73 }
74 }
75 }
76 }
77
78 return err_count;
79 }
80