]>
Commit | Line | Data |
---|---|---|
1b113598 UD |
1 | #include <errno.h> |
2 | #include <ftw.h> | |
3 | #include <stdio.h> | |
4 | #include <stdlib.h> | |
98519d62 | 5 | #include <string.h> |
1b113598 UD |
6 | #include <unistd.h> |
7 | ||
46089c83 UD |
8 | static int cb_called; |
9 | ||
1b113598 UD |
10 | static int |
11 | cb (const char *fname, const struct stat *st, int flag) | |
12 | { | |
13 | printf ("%s %d\n", fname, flag); | |
46089c83 | 14 | cb_called = 1; |
1b113598 UD |
15 | return 0; |
16 | } | |
17 | ||
18 | int | |
19 | main (void) | |
20 | { | |
21 | char tmp[] = "/tmp/ftwXXXXXX"; | |
46089c83 | 22 | char tmp2[] = "/tmp/ftwXXXXXX/ftwXXXXXX"; |
1b113598 | 23 | char *dname; |
46089c83 | 24 | char *dname2; |
1b113598 UD |
25 | int r; |
26 | int e; | |
27 | ||
d555194c UD |
28 | if (getuid () == 0) |
29 | { | |
30 | puts ("this test needs to be run by ordinary user"); | |
31 | exit (0); | |
32 | } | |
33 | ||
1b113598 UD |
34 | dname = mkdtemp (tmp); |
35 | if (dname == NULL) | |
36 | { | |
37 | printf ("mkdtemp: %m\n"); | |
38 | exit (1); | |
39 | } | |
40 | ||
46089c83 UD |
41 | memcpy (tmp2, tmp, strlen (tmp)); |
42 | dname2 = mkdtemp (tmp2); | |
43 | if (dname2 == NULL) | |
44 | { | |
45 | printf ("mkdtemp: %m\n"); | |
46 | rmdir (dname); | |
47 | exit (1); | |
48 | } | |
49 | ||
50 | if (chmod (dname, S_IWUSR|S_IWGRP|S_IWOTH) != 0) | |
1b113598 UD |
51 | { |
52 | printf ("chmod: %m\n"); | |
46089c83 | 53 | rmdir (dname); |
1b113598 UD |
54 | exit (1); |
55 | } | |
56 | ||
46089c83 | 57 | r = ftw (dname2, cb, 10); |
1b113598 UD |
58 | e = errno; |
59 | printf ("r = %d", r); | |
60 | if (r != 0) | |
61 | printf (", errno = %d", errno); | |
62 | puts (""); | |
63 | ||
64 | chmod (dname, S_IRWXU|S_IRWXG|S_IRWXO); | |
46089c83 | 65 | rmdir (dname2); |
1b113598 UD |
66 | rmdir (dname); |
67 | ||
46089c83 | 68 | return (r != -1 && e == EACCES) || cb_called; |
1b113598 | 69 | } |