Shop OBEX P1 Docs P2 Docs Learn Events
[flexspin][vfs] accessing fs structure/file-specific data from spin2? — Parallax Forums

[flexspin][vfs] accessing fs structure/file-specific data from spin2?

Hey folks,

Is something like what @Wuerfel_21 has done with a C object here (from MegaYume's fsadapter.c)

#include <compiler.h>
#include <dirent.h>
#include <sys/stat.h>

char *get_name_for_dirent(struct dirent *d) {
    return d->d_name;
}


int get_type_for_dirent(struct dirent *d) {
    switch(d->d_type) {
    case DT_REG:
        return 2;
    case DT_DIR:
        return 1;
    default:
        return 0;
    }
}

int get_type_for_path(const char *path) {
    struct stat buf;
    if(!stat(path,&buf)) {
        if (S_ISDIR(buf.st_mode)) return 1;
        if (S_ISREG(buf.st_mode)) return 2;
    }
}



int exists(const char *path) {
    struct stat buf;
    return stat(path,&buf) == 0;
}

the only way to access things like dirent structs (more generally, to read directory entries) from spin2? If it is that's fine, I just didn't see a documented way to do something like create a dirent struct directly from spin2.

Cheers

Comments

  • The fsadapter stuff (and the whole file browser thing it's attached to) is a few years old, maybe there actually is a better way now that Spin2 has actual structure types. IDK if the libc object would be exporting these though...

Sign In or Register to comment.