aboutsummaryrefslogtreecommitdiff
path: root/src/base/fs/walker.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/base/fs/walker.c')
-rw-r--r--src/base/fs/walker.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/base/fs/walker.c b/src/base/fs/walker.c
new file mode 100644
index 0000000..65ff391
--- /dev/null
+++ b/src/base/fs/walker.c
@@ -0,0 +1,39 @@
+#include "internal.h"
+
+static
+void
+delete(fs·History *h)
+{
+ SET_FREE(h, sys·Memory, nil);
+}
+
+int
+fs·init(fs·Walker *fs, char *path)
+{
+ fs->base = fs->end = fs->path;
+
+ if(!path || !path[0]){
+ path = getcwd(fs->path, arrlen(fs->path));
+ if (!path)
+ return 1;
+ fs->end += strlen(path);
+ }else
+ fs->end = str·copyn(fs->base, path, arrlen(fs->path));
+
+ if(fs->path[0] != '/')
+ fs->fd = AT_FDCWD;
+
+ if(!fs->hist && !(fs->flags & fs·nolinks))
+ fs->hist = calloc(1, sizeof(*fs->hist));
+
+ return 0;
+}
+
+void
+fs·fini(fs·Walker *fs)
+{
+ if(fs->hist){
+ delete(fs->hist);
+ free(fs->hist);
+ }
+}