lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame^] | 1 | /* |
| 2 | MBRLEN: size_t mbrlen (char *s, size_t n, mbstate_t *ps) |
| 3 | */ |
| 4 | |
| 5 | #define TST_FUNCTION mbrlen |
| 6 | |
| 7 | #include "tsp_common.c" |
| 8 | #include "dat_mbrlen.c" |
| 9 | |
| 10 | |
| 11 | int |
| 12 | tst_mbrlen (FILE * fp, int debug_flg) |
| 13 | { |
| 14 | TST_DECL_VARS (size_t); |
| 15 | char s_flg; |
| 16 | const char *s_in; |
| 17 | size_t n; |
| 18 | char t_flg; |
| 19 | char t_ini; |
| 20 | static mbstate_t s = { 0 }; |
| 21 | mbstate_t *ps; |
| 22 | |
| 23 | TST_DO_TEST (mbrlen) |
| 24 | { |
| 25 | TST_HEAD_LOCALE (mbrlen, S_MBRLEN); |
| 26 | TST_DO_REC (mbrlen) |
| 27 | { |
| 28 | if (mbrlen (NULL, 0, &s) != 0) |
| 29 | { |
| 30 | err_count++; |
| 31 | Result (C_FAILURE, S_MBRLEN, CASE_3, |
| 32 | "Initialization (external mbstate object) failed " |
| 33 | "- skipped this test case."); |
| 34 | continue; |
| 35 | } |
| 36 | |
| 37 | TST_DO_SEQ (MBRLEN_SEQNUM) |
| 38 | { |
| 39 | TST_GET_ERRET_SEQ (mbrlen); |
| 40 | s_flg = TST_INPUT_SEQ (mbrlen).s_flg; |
| 41 | s_in = TST_INPUT_SEQ (mbrlen).s; |
| 42 | n = TST_INPUT_SEQ (mbrlen).n; |
| 43 | t_flg = TST_INPUT_SEQ (mbrlen).t_flg; |
| 44 | t_ini = TST_INPUT_SEQ (mbrlen).t_init; |
| 45 | if (s_flg == 0) |
| 46 | { |
| 47 | s_in = NULL; |
| 48 | } |
| 49 | |
| 50 | if (n == USE_MBCURMAX) /* rewrite tst_mblen() like this */ |
| 51 | { |
| 52 | n = MB_CUR_MAX; |
| 53 | } |
| 54 | |
| 55 | ps = (t_flg == 0) ? NULL : &s; |
| 56 | |
| 57 | if (t_ini != 0) |
| 58 | { |
| 59 | memset (&s, 0, sizeof (s)); |
| 60 | mbrlen (NULL, 0, NULL); |
| 61 | } |
| 62 | |
| 63 | TST_CLEAR_ERRNO; |
| 64 | ret = mbrlen (s_in, n, ps); |
| 65 | TST_SAVE_ERRNO; |
| 66 | |
| 67 | if (debug_flg) |
| 68 | { |
| 69 | fprintf (stdout, "mbrlen() [ %s : %d : %d ] ret = %zd\n", |
| 70 | locale, rec + 1, seq_num + 1, ret); |
| 71 | fprintf (stdout, " errno = %d\n", errno_save); |
| 72 | } |
| 73 | |
| 74 | TST_IF_RETURN (S_MBRLEN) |
| 75 | { |
| 76 | }; |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | return err_count; |
| 82 | } |