2 To be used only for testing glibc. */
12 #include <support/xunistd.h>
15 "null mode test 1: Invalid or incomplete multibyte or wide character\n" \
16 "multibyte string\n" \
17 "<0 mode test: Invalid argument\n"
18 #define MB_EXP_LEN (sizeof (MB_EXP) - 1)
21 "null mode test 2: Invalid or incomplete multibyte or wide character\n" \
23 ">0 mode test: Invalid argument\n"
24 #define WC_EXP_LEN (sizeof (WC_EXP) - 1)
31 char fname
[] = "/tmp/tst-perror.XXXXXX";
38 error (EXIT_FAILURE
, errno
, "cannot create temporary file");
40 /* Make sure the file gets removed. */
45 if (dup2 (fd
, 2) == -1)
47 printf ("cannot create file descriptor 2: %m\n");
51 stderr
= fdopen (2, "w");
54 printf ("fdopen failed: %m\n");
58 if (fwide (stderr
, 0) != 0)
60 printf ("stderr not initially in mode 0\n");
65 perror ("null mode test 1");
67 if (fwide (stderr
, 0) != 0)
69 puts ("perror changed the mode from 0");
73 fputs ("multibyte string\n", stderr
);
75 if (fwide (stderr
, 0) >= 0)
77 puts ("fputs didn't set orientation to narrow");
82 perror ("<0 mode test");
86 lseek (fd
, 0, SEEK_SET
);
87 n
= read (fd
, buf
, sizeof (buf
));
88 if (n
!= MB_EXP_LEN
|| memcmp (buf
, MB_EXP
, MB_EXP_LEN
) != 0)
90 printf ("multibyte test failed. Expected:\n%s\nGot:\n%.*s\n",
91 MB_EXP
, (int) n
, buf
);
95 puts ("multibyte test succeeded");
97 lseek (fd
, 0, SEEK_SET
);
100 if (dup2 (fd
, 2) == -1)
102 printf ("cannot create file descriptor 2: %m\n");
105 stderr
= fdopen (2, "w");
108 printf ("fdopen failed: %m\n");
112 if (fwide (stderr
, 0) != 0)
114 printf ("stderr not initially in mode 0\n");
119 perror ("null mode test 2");
121 if (fwide (stderr
, 0) != 0)
123 puts ("perror changed the mode from 0");
127 fputws (L
"wide string\n", stderr
);
129 if (fwide (stderr
, 0) <= 0)
131 puts ("fputws didn't set orientation to wide");
136 perror (">0 mode test");
140 lseek (fd
, 0, SEEK_SET
);
141 n
= read (fd
, buf
, sizeof (buf
));
142 if (n
!= WC_EXP_LEN
|| memcmp (buf
, WC_EXP
, WC_EXP_LEN
) != 0)
144 printf ("wide test failed. Expected:\n%s\nGot:\n%.*s\n",
145 WC_EXP
, (int) n
, buf
);
149 puts ("wide test succeeded");
156 #define TEST_FUNCTION do_test ()
157 #include "../test-skeleton.c"