Back to index

glibc  2.9
tst_mbrlen.c
Go to the documentation of this file.
00001 /*
00002   MBRLEN: size_t mbrlen (char *s, size_t n, mbstate_t *ps)
00003 */
00004 
00005 #define TST_FUNCTION mbrlen
00006 
00007 #include "tsp_common.c"
00008 #include "dat_mbrlen.c"
00009 
00010 
00011 int
00012 tst_mbrlen (FILE * fp, int debug_flg)
00013 {
00014   TST_DECL_VARS (size_t);
00015   char s_flg;
00016   const char *s_in;
00017   size_t n;
00018   char t_flg;
00019   char t_ini;
00020   static mbstate_t s = { 0 };
00021   mbstate_t *ps;
00022 
00023   TST_DO_TEST (mbrlen)
00024   {
00025     TST_HEAD_LOCALE (mbrlen, S_MBRLEN);
00026     TST_DO_REC (mbrlen)
00027     {
00028       if (mbrlen (NULL, 0, &s) != 0)
00029        {
00030          err_count++;
00031          Result (C_FAILURE, S_MBRLEN, CASE_3,
00032                 "Initialization (external mbstate object) failed "
00033                 "- skipped this test case.");
00034          continue;
00035        }
00036 
00037       TST_DO_SEQ (MBRLEN_SEQNUM)
00038       {
00039        TST_GET_ERRET_SEQ (mbrlen);
00040        s_flg = TST_INPUT_SEQ (mbrlen).s_flg;
00041        s_in = TST_INPUT_SEQ (mbrlen).s;
00042        n = TST_INPUT_SEQ (mbrlen).n;
00043        t_flg = TST_INPUT_SEQ (mbrlen).t_flg;
00044        t_ini = TST_INPUT_SEQ (mbrlen).t_init;
00045        if (s_flg == 0)
00046          {
00047            s_in = NULL;
00048          }
00049 
00050        if (n == USE_MBCURMAX)      /* rewrite tst_mblen() like this */
00051          {
00052            n = MB_CUR_MAX;
00053          }
00054 
00055        ps = (t_flg == 0) ? NULL : &s;
00056 
00057        if (t_ini != 0)
00058          {
00059            memset (&s, 0, sizeof (s));
00060            mbrlen (NULL, 0, NULL);
00061          }
00062 
00063        TST_CLEAR_ERRNO;
00064        ret = mbrlen (s_in, n, ps);
00065        TST_SAVE_ERRNO;
00066 
00067        if (debug_flg)
00068          {
00069            fprintf (stdout, "mbrlen() [ %s : %d : %d ] ret = %zd\n",
00070                    locale, rec + 1, seq_num + 1, ret);
00071            fprintf (stdout, "                       errno = %d\n", errno_save);
00072          }
00073 
00074        TST_IF_RETURN (S_MBRLEN)
00075        {
00076        };
00077       }
00078     }
00079   }
00080 
00081   return err_count;
00082 }