(linenum→info "unix/slp.c:2238")

glibc/2.7/libio/bug-wfflush.c

    1: /* Test program for bug in wide streams.  */
    2: 
    3: #include <stdio.h>
    4: #include <wchar.h>
    5: 
    6: static void do_prepare (void);
    7: #define PREPARE(argc, argv) do_prepare ()
    8: static int do_test (void);
    9: #define TEST_FUNCTION do_test ()
   10: #include <test-skeleton.c>
   11: 
   12: static char *temp_file;
   13: 
   14: static void
   15: do_prepare (void)
   16: {
   17:   int fd = create_temp_file ("bug-ungetc.", &temp_file);
   18:   if (fd == -1)
   19:     {
   20:       printf ("cannot create temporary file: %m\n");
   21:       exit (1);
   22:     }
   23:   write (fd, "1!", 2);
   24:   close (fd);
   25: }
   26: 
   27: static int
   28: do_test (void)
   29: {
   30:   FILE *f = fopen (temp_file, "r+");
   31: 
   32:   if (f == NULL)
   33:     {
   34:       printf ("fopen: %m\n");
   35:       return 1;
   36:     }
   37: 
   38: #define L_(s) L##s
   39:   //#define fwscanf fscanf
   40:   //#define fwprintf fprintf
   41: 
   42:   int i;
   43:   if (fwscanf (f, L_("%d!"), &i) != 1)
   44:     {
   45:       printf ("fwscanf failed\n");
   46:       return 1;
   47:     }
   48: 
   49:   rewind (f);
   50:   if (ferror (f))
   51:     {
   52:       printf ("rewind: %m\n");
   53:       return 1;
   54:     }
   55: 
   56:   if (fputws (L_("1!"), f) == EOF)
   57:     {
   58:       printf ("fputws: %m\n");
   59:       return 1;
   60:     }
   61: 
   62:   if (fflush (f) != 0)
   63:     {
   64:       printf ("fflush: %m\n");
   65:       return 1;
   66:     }
   67: 
   68:   if (fclose (f) != 0)
   69:     {
   70:       printf ("fclose: %m\n");
   71:       return 1;
   72:     }
   73: 
   74:   puts ("Test succeeded.");
   75:   return 0;
   76: }
Syntax (Markdown)