2 To be used only for testing glibc. */
14 "null mode test 1: Invalid or incomplete multibyte or wide character\n" \
15 "multibyte string\n" \
16 "<0 mode test: Invalid argument\n"
17 #define MB_EXP_LEN (sizeof (MB_EXP) - 1)
20 "null mode test 2: Invalid or incomplete multibyte or wide character\n" \
22 ">0 mode test: Invalid argument\n"
23 #define WC_EXP_LEN (sizeof (WC_EXP) - 1)
30 char fname
[] = "/tmp/tst-perror.XXXXXX";
37 error (EXIT_FAILURE
, errno
, "cannot create temporary file");
39 /* Make sure the file gets removed. */
44 if (dup2 (fd
, 2) == -1)
46 printf ("cannot create file descriptor 2: %m\n");
50 stderr
= fdopen (2, "w");
53 printf ("fdopen failed: %m\n");
57 if (fwide (stderr
, 0) != 0)
59 printf ("stderr not initially in mode 0\n");
64 perror ("null mode test 1");
66 if (fwide (stderr
, 0) != 0)
68 puts ("perror changed the mode from 0");
72 fputs ("multibyte string\n", stderr
);
74 if (fwide (stderr
, 0) >= 0)
76 puts ("fputs didn't set orientation to narrow");
81 perror ("<0 mode test");
85 lseek (fd
, 0, SEEK_SET
);
86 n
= read (fd
, buf
, sizeof (buf
));
87 if (n
!= MB_EXP_LEN
|| memcmp (buf
, MB_EXP
, MB_EXP_LEN
) != 0)
89 printf ("multibyte test failed. Expected:\n%s\nGot:\n%.*s\n",
90 MB_EXP
, (int) n
, buf
);
94 puts ("multibyte test succeeded");
96 lseek (fd
, 0, SEEK_SET
);
99 if (dup2 (fd
, 2) == -1)
101 printf ("cannot create file descriptor 2: %m\n");
104 stderr
= fdopen (2, "w");
107 printf ("fdopen failed: %m\n");
111 if (fwide (stderr
, 0) != 0)
113 printf ("stderr not initially in mode 0\n");
118 perror ("null mode test 2");
120 if (fwide (stderr
, 0) != 0)
122 puts ("perror changed the mode from 0");
126 fputws (L
"wide string\n", stderr
);
128 if (fwide (stderr
, 0) <= 0)
130 puts ("fputws didn't set orientation to wide");
135 perror (">0 mode test");
139 lseek (fd
, 0, SEEK_SET
);
140 n
= read (fd
, buf
, sizeof (buf
));
141 if (n
!= WC_EXP_LEN
|| memcmp (buf
, WC_EXP
, WC_EXP_LEN
) != 0)
143 printf ("wide test failed. Expected:\n%s\nGot:\n%.*s\n",
144 WC_EXP
, (int) n
, buf
);
148 puts ("wide test succeeded");
155 #define TEST_FUNCTION do_test ()
156 #include "../test-skeleton.c"