file kaio_write64.c was initially added on branch fedora-branch.
[glibc/history.git] / io / bug-ftw3.c
blob19740f49f357e461ca5f6a4057843b1194812563
1 #include <errno.h>
2 #include <ftw.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <string.h>
6 #include <unistd.h>
8 static int cb_called;
10 static int
11 cb (const char *fname, const struct stat *st, int flag)
13 printf ("%s %d\n", fname, flag);
14 cb_called = 1;
15 return 0;
18 int
19 main (void)
21 char tmp[] = "/tmp/ftwXXXXXX";
22 char tmp2[] = "/tmp/ftwXXXXXX/ftwXXXXXX";
23 char *dname;
24 char *dname2;
25 int r;
26 int e;
28 if (getuid () == 0)
30 puts ("this test needs to be run by ordinary user");
31 exit (0);
34 dname = mkdtemp (tmp);
35 if (dname == NULL)
37 printf ("mkdtemp: %m\n");
38 exit (1);
41 memcpy (tmp2, tmp, strlen (tmp));
42 dname2 = mkdtemp (tmp2);
43 if (dname2 == NULL)
45 printf ("mkdtemp: %m\n");
46 rmdir (dname);
47 exit (1);
50 if (chmod (dname, S_IWUSR|S_IWGRP|S_IWOTH) != 0)
52 printf ("chmod: %m\n");
53 rmdir (dname);
54 exit (1);
57 r = ftw (dname2, cb, 10);
58 e = errno;
59 printf ("r = %d", r);
60 if (r != 0)
61 printf (", errno = %d", errno);
62 puts ("");
64 chmod (dname, S_IRWXU|S_IRWXG|S_IRWXO);
65 rmdir (dname2);
66 rmdir (dname);
68 return (r != -1 && e == EACCES) || cb_called;