tst_mbrlen.c 1.4 KB

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