]>
Commit | Line | Data |
---|---|---|
c4292489 UD |
1 | #include <fcntl.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
4 | #include <unistd.h> | |
5 | ||
6 | ||
97887d35 UD |
7 | static void do_prepare (void); |
8 | #define PREPARE(argc, argv) do_prepare () | |
c4292489 UD |
9 | static int do_test (void); |
10 | #define TEST_FUNCTION do_test () | |
11 | #include <test-skeleton.c> | |
12 | ||
13 | ||
97887d35 | 14 | int fd; |
c4292489 | 15 | |
c4292489 | 16 | |
97887d35 UD |
17 | static void |
18 | do_prepare (void) | |
19 | { | |
20 | fd = create_temp_file ("tst-eof.", NULL); | |
c4292489 UD |
21 | if (fd == -1) |
22 | { | |
97887d35 UD |
23 | printf ("cannot create temporary file: %m\n"); |
24 | exit (1); | |
c4292489 | 25 | } |
97887d35 | 26 | } |
c4292489 | 27 | |
97887d35 UD |
28 | |
29 | static int | |
30 | do_test (void) | |
31 | { | |
32 | char buf[40]; | |
33 | FILE *fp; | |
c4292489 UD |
34 | |
35 | if (write (fd, "some string\n", 12) != 12) | |
36 | { | |
37 | printf ("cannot write temporary file: %m\n"); | |
38 | return 1; | |
39 | } | |
40 | ||
41 | if (lseek (fd, 0, SEEK_SET) == (off_t) -1) | |
42 | { | |
43 | printf ("cannot reposition temporary file: %m\n"); | |
44 | return 1; | |
45 | } | |
46 | ||
47 | fp = fdopen (fd, "r"); | |
48 | if (fp == NULL) | |
49 | { | |
50 | printf ("cannot create stream: %m\n"); | |
51 | return 1; | |
52 | } | |
53 | ||
54 | if (feof (fp)) | |
55 | { | |
56 | puts ("EOF set after fdopen"); | |
57 | return 1; | |
58 | } | |
59 | ||
60 | if (fread (buf, 1, 20, fp) != 12) | |
61 | { | |
62 | puts ("didn't read the correct number of bytes"); | |
63 | return 1; | |
64 | } | |
65 | ||
66 | if (! feof (fp)) | |
67 | { | |
68 | puts ("EOF not set after fread"); | |
69 | return 1; | |
70 | } | |
71 | ||
72 | fclose (fp); | |
73 | ||
74 | return 0; | |
75 | } |