arg_t dup_op(int fd, int base) { int8_t newd; if ((newd = uf_alloc_n(base)) == -1) return (-1); udata.u_files[newd] = udata.u_files[fd]; ++of_tab[udata.u_files[fd]].o_refs; return (newd); }
arg_t _fcntl(void) { uint8_t *acc; int newd; if (getinode(fd) == NULLINODE) return (-1); acc = &of_tab[udata.u_files[fd]].o_access; switch (request) { case F_SETFL: *acc = (*acc & ~(O_APPEND | O_NDELAY)) | (data & (O_APPEND | O_NDELAY)); return 0; case F_GETFL: return data; case F_GETFD: return udata.u_cloexec & (1 << fd) ? O_CLOEXEC : 0; case F_SETFD: if (data & O_CLOEXEC) udata.u_cloexec |= (1 << fd); else udata.u_cloexec &= (1 << fd); return 0; case F_DUPFD: if ((newd = uf_alloc_n(data)) == -1) return (-1); udata.u_files[newd] = udata.u_files[fd]; ++of_tab[udata.u_files[fd]].o_refs; return 0; default: udata.u_error = EINVAL; return -1; } }
int8_t uf_alloc(void) { return uf_alloc_n(0); }