int sys_open(SyscallFrame *f) { char *fname; long l; int omode, fd; File *file; if (argstr(f, 0, &fname) < 0) return -1; if (arglong(f, 1, &l) < 0) return -1; omode = (long)l; if (omode & (OEXEC | OTRUNC | OCEXEC | ORCLOSE)) { // todo errstr return -1; } if (omode & (OWRITE | ORDWR) && !canwrite(fname)) { // todo errstr return -1; } file = getfile(fname); if (file == nil) return -1; file->omode = omode; fd = allocfd(proc, file); if (fd == -1) { // todo errstr releasefile(file); return -1; } return fd; }
int open_HLE() { IOManFile *file = NULL; const char *name = Ra0; s32 flags = a1; u16 mode = a2; if ((!g_GameStarted || EmuConfig.HostFs) && !strncmp(name, "host", 4) && name[4 + strspn(name + 4, "0123456789")] == ':') { if (!freefdcount()) { v0 = -IOP_EMFILE; pc = ra; return 1; } int err = HostFile::open(&file, name, flags, mode); if (err != 0 || !file) { if (err == 0) // ??? err = -IOP_EIO; if (file) // ?????? file->close(); v0 = err; } else { v0 = allocfd(file); if ((s32)v0 < 0) file->close(); } pc = ra; return 1; } return 0; }
int __elk_fdconsole_open(fdset_t *fdset) { // Create a file descriptor for the console. sem_init(&vnode.v_wait, 0, 0); return allocfd(&file); }