w2c2
w2c2 copied to clipboard
How to access files from the binary
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:
[ERROR rustpython_vm::vm::compile] Failed reading file 'PYBASIC.PY': No such file or directory (os error 44)
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?
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;
}
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?
How do you run on drive D or later with your fix?
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