(root)/
glibc-2.38/
stdio-common/
bug20.c
       1  /* BZ #5225 */
       2  #include <stdio.h>
       3  #include <string.h>
       4  #include <wchar.h>
       5  
       6  static int
       7  do_test (void)
       8  {
       9    wchar_t in[] = L"123,abc,321";
      10    /* This is the critical part for this test.  format must be in
      11       read-only memory.  */
      12    static const wchar_t format[50] = L"%d,%[^,],%d";
      13    int out_d1, out_d2;
      14    char out_s[50];
      15    printf ("in='%ls' format='%ls'\n", in, format);
      16    if (swscanf (in, format, &out_d1, out_s, &out_d2) != 3)
      17      {
      18        puts ("swscanf did not return 3");
      19        return 1;
      20      }
      21    printf ("in='%ls' format='%ls'\n", in, format);
      22    printf ("out_d1=%d out_s='%s' out_d2=%d\n", out_d1, out_s, out_d2);
      23    if (out_d1 != 123 || strcmp (out_s, "abc") != 0 || out_d2 != 321)
      24      {
      25        puts ("swscanf did not return the correct values");
      26        return 1;
      27      }
      28    return 0;
      29  }
      30  
      31  #define TEST_FUNCTION do_test ()
      32  #include "../test-skeleton.c"