w2c2 icon indicating copy to clipboard operation
w2c2 copied to clipboard

How to access files from the binary

Open coolcoder613eb opened this issue 2 years ago • 5 comments
trafficstars

I have built RustPython for DOS, https://github.com/coolcoder613eb/RustPython And I want to know how make the binary accept files from the command line. right now it says: Screenshot 2023-10-10 at 4 47 15 pm [ERROR rustpython_vm::vm::compile] Failed reading file 'PYBASIC.PY': No such file or directory (os error 44)

coolcoder613eb avatar Oct 10 '23 05:10 coolcoder613eb

Are you sure you are providing the WASI environment with a file descriptor (capability) to the directory? See e.g. https://github.com/turbolent/w2c2/blob/2e9c86f70f2fcf3374d57020389f35ea082fc018/examples/python/main.c#L211-L214

Note that paths are assumed to be WASI paths, which are Unix/POSIX paths (e.g /foo/bar).

w2c2's WASI implementation automatically translates Unix paths to the native format (https://github.com/turbolent/w2c2/blob/2e9c86f70f2fcf3374d57020389f35ea082fc018/wasi/wasi.c#L313-L333), and back

What compiler are you using, DJGPP?

turbolent avatar Oct 14 '23 03:10 turbolent

Yes, DJGPP, and i think i have fixed it, my solution also means you do not need to write out the full path. my code in main.c:

#ifdef __MSDOS__
    if (!wasiFileDescriptorAdd(-1, "C:\\", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }
#endif
    if (!wasiFileDescriptorAdd(-2, ".", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }

    if (!wasiFileDescriptorAdd(-3, "/", NULL)) {
        fprintf(stderr, "failed to add preopen\n");
        return 1;
    }

coolcoder613eb avatar Oct 15 '23 23:10 coolcoder613eb

Not really related, but how would I compile for windows 2000? CPython3.11, and RustPython without freeze-stdlib, don't work on DOS through w2c2 because of 8.3, is there any solution?

coolcoder613eb avatar Oct 15 '23 23:10 coolcoder613eb

How do you run on drive D or later with your fix?

SamuraiCrow avatar Oct 15 '23 23:10 SamuraiCrow

I dont know, haven't tried. I could try doing:

if (!wasiFileDescriptorAdd(-1, "A:\\", NULL)) {
        fprintf(stderr, "failed to add A: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "B:\\", NULL)) {
        fprintf(stderr, "failed to add B: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "C:\\", NULL)) {
        fprintf(stderr, "failed to add C: preopen\n");
    }
if (!wasiFileDescriptorAdd(-1, "D:\\", NULL)) {
        fprintf(stderr, "failed to add D: preopen\n");
    }

etc

coolcoder613eb avatar Oct 15 '23 23:10 coolcoder613eb