elf: Fix use-after-free in ldconfig [BZ #26779]
[glibc.git] / libio / tst-eof.c
blob6baa122ce391776a1741062f810eead71249dfdf
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <unistd.h>
7 static void do_prepare (void);
8 #define PREPARE(argc, argv) do_prepare ()
9 static int do_test (void);
10 #define TEST_FUNCTION do_test ()
11 #include <test-skeleton.c>
14 int fd;
17 static void
18 do_prepare (void)
20 fd = create_temp_file ("tst-eof.", NULL);
21 if (fd == -1)
23 printf ("cannot create temporary file: %m\n");
24 exit (1);
29 static int
30 do_test (void)
32 char buf[40];
33 FILE *fp;
35 if (write (fd, "some string\n", 12) != 12)
37 printf ("cannot write temporary file: %m\n");
38 return 1;
41 if (lseek (fd, 0, SEEK_SET) == (off_t) -1)
43 printf ("cannot reposition temporary file: %m\n");
44 return 1;
47 fp = fdopen (fd, "r");
48 if (fp == NULL)
50 printf ("cannot create stream: %m\n");
51 return 1;
54 if (feof (fp))
56 puts ("EOF set after fdopen");
57 return 1;
60 if (fread (buf, 1, 20, fp) != 12)
62 puts ("didn't read the correct number of bytes");
63 return 1;
66 if (! feof (fp))
68 puts ("EOF not set after fread");
69 return 1;
72 fclose (fp);
74 return 0;