Work towards zipos / open(argv[0]) on metal (#667)

This commit is contained in:
tkchia 2022-11-06 15:29:47 +08:00 committed by GitHub
parent 543c93f623
commit cb9a0466f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
17 changed files with 257 additions and 46 deletions

View file

@ -18,6 +18,7 @@
*/
#include "libc/calls/calls.h"
#include "libc/calls/internal.h"
#include "libc/calls/metalfile.internal.h"
#include "libc/calls/struct/metastat.internal.h"
#include "libc/calls/struct/stat.h"
#include "libc/calls/syscall-sysv.internal.h"
@ -60,7 +61,14 @@ ssize_t getfiledescriptorsize(int fd) {
rc = -1;
}
} else if (IsMetal()) {
rc = -1;
if (fd < 0 || fd >= g_fds.n) {
rc = ebadf();
} else if (g_fds.p[fd].kind != kFdFile) {
rc = eacces();
} else {
struct MetalFile *state = (struct MetalFile *)g_fds.p[fd].handle;
rc = state->size;
}
} else if (!IsWindows()) {
if (!__sys_fstat(fd, &st)) {
rc = METASTAT(st, st_size);