powerpc64le: Enforce -mabi=ibmlongdouble when -mfloat128 used
[glibc.git] / stdio-common / tst-fdopen.c
blob136fff5858adf77363f62fbec3c04769a62864b3
1 /* Test for fdopen bugs. */
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <fcntl.h>
8 #undef assert
9 #define assert(x) \
10 if (!(x)) \
11 { \
12 fputs ("test failed: " #x "\n", stderr); \
13 retval = 1; \
14 goto the_end; \
17 char buffer[256];
19 int
20 main (int argc, char *argv[])
22 char name[] = "/tmp/tst-fdopen.XXXXXX";
23 FILE *fp = NULL;
24 int retval = 0;
25 int fd;
27 fd = mkstemp (name);
28 if (fd == -1)
30 printf ("mkstemp failed: %m\n");
31 return 1;
33 close (fd);
34 fp = fopen (name, "w");
35 assert (fp != NULL)
36 fputs ("foobar and baz", fp);
37 fclose (fp);
38 fp = NULL;
40 fd = open (name, O_RDONLY);
41 assert (fd != -1);
42 assert (lseek (fd, 5, SEEK_SET) == 5);
43 /* The file position indicator associated with the new stream is set to
44 the position indicated by the file offset associated with the file
45 descriptor. */
46 fp = fdopen (fd, "r");
47 assert (fp != NULL);
48 assert (getc (fp) == 'r');
49 assert (getc (fp) == ' ');
51 the_end:
52 if (fp != NULL)
53 fclose (fp);
54 unlink (name);
56 return retval;