aboutsummaryrefslogtreecommitdiff
path: root/src/base/fs/walker.c
blob: 65ff39196cebc0613c55f3418b87803cf2eba040 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
    }
}