From 7cc64627cc95be506202bf515f05142168cc2b06 Mon Sep 17 00:00:00 2001 From: Adam Hoka Date: Tue, 5 Oct 2010 21:33:26 +0200 Subject: [PATCH] WINGs: fts() -> nftw() in wrmdirhier() Plus reorganize headers a bit. Signed-off-by: Tamas TEVESZ --- WINGs/proplist.c | 83 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/WINGs/proplist.c b/WINGs/proplist.c index 2329e178..9e0d12be 100644 --- a/WINGs/proplist.c +++ b/WINGs/proplist.c @@ -1,15 +1,22 @@ +#if __GLIBC__ && \ + (_XOPEN_SOURCE && _XOPEN_SOURCE < 500) || \ + !_XOPEN_SOURCE +#define _XOPEN_SOURCE 500 /* nftw */ +#endif + +#include +#include + +#include #include -#include +#include #include #include #include -#include -#include +#include +#include #include -#include - -#include #include "WUtil.h" #include "wconfig.h" @@ -1689,6 +1696,31 @@ int wmkdirhier(const char *path) return 1; } +/* ARGSUSED2 */ +static int wrmdirhier_fn(const char *path, const struct stat *st, + int type, struct FTW *ftw) +{ + switch(type) { + case FTW_D: + break; + case FTW_DP: + return rmdir(path); + break; + case FTW_F: + case FTW_SL: + case FTW_SLN: + return unlink(path); + break; + case FTW_DNR: + case FTW_NS: + default: + return EPERM; + } + + /* NOTREACHED */ + return 0; +} + /* * remove a directory hierarchy * @@ -1702,46 +1734,21 @@ int wmkdirhier(const char *path) */ int wrmdirhier(const char *path) { - FTS *fts; - FTSENT *p; - char *t; struct stat st; - char *ptree[2]; + int error; + char *t; /* Only remove directories under $GNUSTEP_USER_ROOT */ if ((t = wusergnusteppath()) == NULL) - return 0; + return EPERM; if (strncmp(path, t, strlen(t)) != 0) - return 0; + return EPERM; /* Shortcut if it doesn't exist to begin with */ if (stat(path, &st) == -1) - return 0; - - ptree[0] = (char *)path; - ptree[1] = NULL; - - if (!(fts = fts_open(ptree, FTS_PHYSICAL, NULL))) - return 0; + return ENOENT; - while ((p = fts_read(fts)) != NULL) { - switch(p->fts_info) { - case FTS_D: - continue; - break; - case FTS_DP: - rmdir(p->fts_path); - continue; - break; - case FTS_F: - unlink(p->fts_path); - continue; - break; - default: continue; - } + error = nftw(path, wrmdirhier_fn, 1, FTW_PHYS); - } - - fts_close(fts); - return 1; + return error; } -- 2.11.4.GIT