regression: add invalid ld80 printf test
[libc-test] / src / functional / fdopen.c
1 #ifndef _XOPEN_SOURCE
2 #define _XOPEN_SOURCE 700
3 #endif
4 #include <errno.h>
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <string.h>
8 #include <unistd.h>
9 #include "test.h"
10
11 #define TEST(c) do { \
12         errno = 0; \
13         if (!(c)) \
14                 t_error("%s failed (errno = %d)\n", #c, errno); \
15 } while(0)
16
17 int main(void)
18 {
19         char tmp[] = "/tmp/testsuite-XXXXXX";
20         char foo[6];
21         int fd;
22         FILE *f;
23
24         TEST((fd = mkstemp(tmp)) > 2);
25         TEST(write(fd, "hello", 6)==6);
26         TEST(f = fdopen(fd, "rb"));
27         if (f) {
28                 TEST(ftello(f)==6);
29                 TEST(fseeko(f, 0, SEEK_SET)==0);
30                 TEST(fgets(foo, sizeof foo, f));
31                 if (strcmp(foo,"hello") != 0)
32                         t_error("fgets read back: \"%s\"; wanted: \"hello\"\n", foo);
33                 fclose(f);
34         }
35         if (fd > 2)
36                 TEST(unlink(tmp) != -1);
37         return t_status;
38 }