mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-07 06:14:13 +01:00
WINGs: fts() -> nftw() in wrmdirhier()
Plus reorganize headers a bit. Signed-off-by: Tamas TEVESZ <ice@extreme.hu>
This commit is contained in:
committed by
Carlos R. Mafra
parent
b16181143c
commit
7cc64627cc
@@ -1,15 +1,22 @@
|
|||||||
|
|
||||||
|
#if __GLIBC__ && \
|
||||||
|
(_XOPEN_SOURCE && _XOPEN_SOURCE < 500) || \
|
||||||
|
!_XOPEN_SOURCE
|
||||||
|
#define _XOPEN_SOURCE 500 /* nftw */
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#include <ctype.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <ftw.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <sys/types.h>
|
#include <string.h>
|
||||||
#include <sys/stat.h>
|
#include <strings.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <ctype.h>
|
|
||||||
|
|
||||||
#include <fts.h>
|
|
||||||
|
|
||||||
#include "WUtil.h"
|
#include "WUtil.h"
|
||||||
#include "wconfig.h"
|
#include "wconfig.h"
|
||||||
@@ -1689,6 +1696,31 @@ int wmkdirhier(const char *path)
|
|||||||
return 1;
|
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
|
* remove a directory hierarchy
|
||||||
*
|
*
|
||||||
@@ -1702,46 +1734,21 @@ int wmkdirhier(const char *path)
|
|||||||
*/
|
*/
|
||||||
int wrmdirhier(const char *path)
|
int wrmdirhier(const char *path)
|
||||||
{
|
{
|
||||||
FTS *fts;
|
|
||||||
FTSENT *p;
|
|
||||||
char *t;
|
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char *ptree[2];
|
int error;
|
||||||
|
char *t;
|
||||||
|
|
||||||
/* Only remove directories under $GNUSTEP_USER_ROOT */
|
/* Only remove directories under $GNUSTEP_USER_ROOT */
|
||||||
if ((t = wusergnusteppath()) == NULL)
|
if ((t = wusergnusteppath()) == NULL)
|
||||||
return 0;
|
return EPERM;
|
||||||
if (strncmp(path, t, strlen(t)) != 0)
|
if (strncmp(path, t, strlen(t)) != 0)
|
||||||
return 0;
|
return EPERM;
|
||||||
|
|
||||||
/* Shortcut if it doesn't exist to begin with */
|
/* Shortcut if it doesn't exist to begin with */
|
||||||
if (stat(path, &st) == -1)
|
if (stat(path, &st) == -1)
|
||||||
return 0;
|
return ENOENT;
|
||||||
|
|
||||||
ptree[0] = (char *)path;
|
error = nftw(path, wrmdirhier_fn, 1, FTW_PHYS);
|
||||||
ptree[1] = NULL;
|
|
||||||
|
|
||||||
if (!(fts = fts_open(ptree, FTS_PHYSICAL, NULL)))
|
return error;
|
||||||
return 0;
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
fts_close(fts);
|
|
||||||
return 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user