Last change
on this file was 2036, checked in by bird, 20 years ago |
Initial revision
|
-
Property cvs2svn:cvs-rev
set to
1.1
-
Property svn:eol-style
set to
native
-
Property svn:executable
set to
*
-
Property svn:keywords
set to
Author Date Id Revision
|
File size:
1.5 KB
|
Line | |
---|
1 | #define _XOPEN_SOURCE 500
|
---|
2 | #include <stdio.h>
|
---|
3 | #include <stdlib.h>
|
---|
4 | #include <locale.h>
|
---|
5 | #include <wchar.h>
|
---|
6 |
|
---|
7 | const char write_chars[] = "ABC"; /* Characters on testfile. */
|
---|
8 | const wint_t unget_wchar = L'A'; /* Ungotten wide character. */
|
---|
9 |
|
---|
10 | char *fname;
|
---|
11 |
|
---|
12 |
|
---|
13 | static int do_test (void);
|
---|
14 | #define TEST_FUNCTION do_test ()
|
---|
15 |
|
---|
16 | #include "../test-skeleton.c"
|
---|
17 |
|
---|
18 |
|
---|
19 | static int
|
---|
20 | do_test (void)
|
---|
21 | {
|
---|
22 | wint_t wc;
|
---|
23 | FILE *fp;
|
---|
24 | int fd;
|
---|
25 |
|
---|
26 | fname = (char *) malloc (strlen (test_dir) + sizeof "/bug-ungetwc1.XXXXXX");
|
---|
27 | if (fname == NULL)
|
---|
28 | {
|
---|
29 | puts ("no memory");
|
---|
30 | return 1;
|
---|
31 | }
|
---|
32 | strcpy (stpcpy (fname, test_dir), "/bug-ungetwc1.XXXXXX");
|
---|
33 | fd = mkstemp (fname);
|
---|
34 | if (fd == -1)
|
---|
35 | {
|
---|
36 | printf ("cannot open temporary file: %m\n");
|
---|
37 | return 1;
|
---|
38 | }
|
---|
39 | add_temp_file (fname);
|
---|
40 |
|
---|
41 | setlocale(LC_ALL, "");
|
---|
42 |
|
---|
43 | /* Output to the file. */
|
---|
44 | if ((fp = fdopen (fd, "w")) == NULL)
|
---|
45 | {
|
---|
46 | fprintf (stderr, "Cannot make `%s' file\n", fname);
|
---|
47 | exit (EXIT_FAILURE);
|
---|
48 | }
|
---|
49 |
|
---|
50 | fprintf (fp, "%s", write_chars);
|
---|
51 | fclose (fp);
|
---|
52 |
|
---|
53 | /* Read from the file. */
|
---|
54 | fp = fopen (fname, "r");
|
---|
55 |
|
---|
56 | while (!feof (fp))
|
---|
57 | wc = getwc (fp);
|
---|
58 | printf ("\nThe end-of-file indicator is set.\n");
|
---|
59 |
|
---|
60 | /* Unget a wide character. */
|
---|
61 | ungetwc (unget_wchar, fp);
|
---|
62 | printf ("< `%lc' is ungotten.\n", unget_wchar);
|
---|
63 |
|
---|
64 | /* Check the end-of-file indicator. */
|
---|
65 | if (feof (fp))
|
---|
66 | printf ("The end-of-file indicator is still set.\n");
|
---|
67 | else
|
---|
68 | printf ("The end-of-file flag is cleared.\n");
|
---|
69 |
|
---|
70 | fflush (stdout);
|
---|
71 | fclose (fp);
|
---|
72 |
|
---|
73 | return 0;
|
---|
74 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.