From 90b12bd71bb9fc79a4640b9112c13ef529d0196a Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 5 Dec 2014 22:26:11 +0000 Subject: Initial commit --- src/libs6/ftrigw_clean.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/libs6/ftrigw_clean.c (limited to 'src/libs6/ftrigw_clean.c') diff --git a/src/libs6/ftrigw_clean.c b/src/libs6/ftrigw_clean.c new file mode 100644 index 0000000..1198828 --- /dev/null +++ b/src/libs6/ftrigw_clean.c @@ -0,0 +1,39 @@ +/* ISC license. */ + +#include +#include +#include +#include +#include +#include "ftrig1.h" +#include + +int ftrigw_clean (char const *path) +{ + unsigned int pathlen = str_len(path) ; + int e = 0 ; + DIR *dir = opendir(path) ; + if (!dir) return 0 ; + { + char tmp[pathlen + FTRIG1_PREFIXLEN + 45] ; + byte_copy(tmp, pathlen, path) ; + tmp[pathlen] = '/' ; tmp[pathlen + FTRIG1_PREFIXLEN + 44] = 0 ; + for (;;) + { + direntry *d ; + int fd ; + errno = 0 ; + d = readdir(dir) ; + if (!d) break ; + if (str_diffn(d->d_name, FTRIG1_PREFIX, FTRIG1_PREFIXLEN)) continue ; + if (str_len(d->d_name) != FTRIG1_PREFIXLEN + 43) continue ; + byte_copy(tmp + pathlen + 1, FTRIG1_PREFIXLEN + 43, d->d_name) ; + fd = open_write(tmp) ; + if (fd >= 0) fd_close(fd) ; + else if ((errno == ENXIO) && (unlink(tmp) < 0)) e = errno ; + } + } + if (errno) e = errno ; + dir_close(dir) ; + return e ? (errno = e, 0) : 1 ; +} -- cgit v1.2.3