(hsearch_r): Add back ensurance that hval is not zero.
[glibc/history.git] / stdio-common / tst-fdopen.c
blobe70a0cd6a516b7cf989ee9d6d1ceccf0f0ecd497
1 /* Test for fdopen bugs. */
3 #include <stdio.h>
4 #include <unistd.h>
5 #include <fcntl.h>
7 #undef assert
8 #define assert(x) \
9 if (!(x)) \
10 { \
11 fputs ("test failed: " #x "\n", stderr); \
12 retval = 1; \
13 goto the_end; \
16 char buffer[256];
18 int
19 main (int argc, char *argv[])
21 char *name;
22 FILE *fp = NULL;
23 int retval = 0;
24 int fd;
26 name = tmpnam (NULL);
27 fp = fopen (name, "w");
28 assert (fp != NULL)
29 fputs ("foobar and baz", fp);
30 fclose (fp);
31 fp = NULL;
33 fd = open (name, O_RDONLY);
34 assert (fd != -1);
35 assert (lseek (fd, 5, SEEK_SET) == 5);
36 /* The file position indicator associated with the new stream is set to
37 the position indicated by the file offset associated with the file
38 descriptor. */
39 fp = fdopen (fd, "r");
40 assert (fp != NULL);
41 assert (getc (fp) == 'r');
42 assert (getc (fp) == ' ');
44 the_end:
45 if (fp != NULL)
46 fclose (fp);
47 unlink (name);
49 return retval;