2001-12-11 00:59:02 +01:00
|
|
|
#include <errno.h>
|
|
|
|
#include <ftw.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2001-12-28 17:43:13 +01:00
|
|
|
#include <string.h>
|
2001-12-11 00:59:02 +01:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2001-12-18 00:10:14 +01:00
|
|
|
static int cb_called;
|
|
|
|
|
2001-12-11 00:59:02 +01:00
|
|
|
static int
|
|
|
|
cb (const char *fname, const struct stat *st, int flag)
|
|
|
|
{
|
|
|
|
printf ("%s %d\n", fname, flag);
|
2001-12-18 00:10:14 +01:00
|
|
|
cb_called = 1;
|
2001-12-11 00:59:02 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main (void)
|
|
|
|
{
|
|
|
|
char tmp[] = "/tmp/ftwXXXXXX";
|
2001-12-18 00:10:14 +01:00
|
|
|
char tmp2[] = "/tmp/ftwXXXXXX/ftwXXXXXX";
|
2001-12-11 00:59:02 +01:00
|
|
|
char *dname;
|
2001-12-18 00:10:14 +01:00
|
|
|
char *dname2;
|
2001-12-11 00:59:02 +01:00
|
|
|
int r;
|
|
|
|
int e;
|
|
|
|
|
2002-02-07 18:54:45 +01:00
|
|
|
if (getuid () == 0)
|
|
|
|
{
|
|
|
|
puts ("this test needs to be run by ordinary user");
|
|
|
|
exit (0);
|
|
|
|
}
|
|
|
|
|
2001-12-11 00:59:02 +01:00
|
|
|
dname = mkdtemp (tmp);
|
|
|
|
if (dname == NULL)
|
|
|
|
{
|
|
|
|
printf ("mkdtemp: %m\n");
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2001-12-18 00:10:14 +01:00
|
|
|
memcpy (tmp2, tmp, strlen (tmp));
|
|
|
|
dname2 = mkdtemp (tmp2);
|
|
|
|
if (dname2 == NULL)
|
|
|
|
{
|
|
|
|
printf ("mkdtemp: %m\n");
|
|
|
|
rmdir (dname);
|
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chmod (dname, S_IWUSR|S_IWGRP|S_IWOTH) != 0)
|
2001-12-11 00:59:02 +01:00
|
|
|
{
|
|
|
|
printf ("chmod: %m\n");
|
2001-12-18 00:10:14 +01:00
|
|
|
rmdir (dname);
|
2001-12-11 00:59:02 +01:00
|
|
|
exit (1);
|
|
|
|
}
|
|
|
|
|
2001-12-18 00:10:14 +01:00
|
|
|
r = ftw (dname2, cb, 10);
|
2001-12-11 00:59:02 +01:00
|
|
|
e = errno;
|
|
|
|
printf ("r = %d", r);
|
|
|
|
if (r != 0)
|
|
|
|
printf (", errno = %d", errno);
|
|
|
|
puts ("");
|
|
|
|
|
|
|
|
chmod (dname, S_IRWXU|S_IRWXG|S_IRWXO);
|
2001-12-18 00:10:14 +01:00
|
|
|
rmdir (dname2);
|
2001-12-11 00:59:02 +01:00
|
|
|
rmdir (dname);
|
|
|
|
|
2001-12-18 00:10:14 +01:00
|
|
|
return (r != -1 && e == EACCES) || cb_called;
|
2001-12-11 00:59:02 +01:00
|
|
|
}
|