Make unistd.h pre-c((-safe.
[glibc.git] / stdio-common / tst-put-error.c
blob115dbd509ad701ab02def9686c8b3791e1781a1f
1 #include <errno.h>
2 #include <error.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
8 static int
9 do_test (void)
11 char tmpl[] = "/tmp/tst-put-error.XXXXXX";
12 int fd = mkstemp (tmpl);
13 if (fd == -1)
14 error (EXIT_FAILURE, errno, "cannot create temporary file");
15 FILE *fp = fdopen (fd, "w");
16 if (fp == NULL)
17 error (EXIT_FAILURE, errno, "fdopen");
18 setlinebuf (fp);
19 close (fd);
20 unlink (tmpl);
21 int n = fprintf (fp, "hello world\n");
22 printf ("fprintf = %d\n", n);
23 if (n >= 0)
24 error (EXIT_FAILURE, 0, "first fprintf succeeded");
25 n = fprintf (fp, "hello world\n");
26 printf ("fprintf = %d\n", n);
27 if (n >= 0)
28 error (EXIT_FAILURE, 0, "second fprintf succeeded");
29 return 0;
32 #define TEST_FUNCTION do_test ()
33 #include "../test-skeleton.c"