Ticket #5055: fdtest.c

File fdtest.c, 798 bytes (added by augiedoggie, 14 years ago)

Code which fails on haiku, but runs on Linux (when run as 'fdtest .')

Line 
1#include <dirent.h>
2#include <sys/stat.h>
3#include <sys/types.h>
4#include <unistd.h>
5#include <limits.h>
6#include <fcntl.h>
7#include <stdio.h>
8#include <string.h>
9
10
11int main(int argc, char** argv) {
12 char fullpath[PATH_MAX + 10];
13 int err;
14 struct stat st;
15 struct dirent *ent;
16 int dfd = -1;
17 DIR *dir;
18
19 dfd = open(argv[1], O_RDONLY);
20 if (dfd == -1) {
21 printf("error: open!\n");
22 return 1;
23 }
24
25 dir = fdopendir(dfd);
26 if (!dir) {
27 printf("error: dir!\n");
28 return 1;
29 }
30
31 while ((ent = readdir(dir))) {
32 if (!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
33 continue;
34
35 err = fstatat(dfd, ent->d_name, &st, AT_SYMLINK_NOFOLLOW);
36 if (err == -1) {
37 printf("error: fstatat failed on %s\n", ent->d_name);
38 printf("dfd: %i\n", dfd);
39 break;
40 }
41 }
42
43 close(dfd);
44
45 return 0;
46}