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