mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-11-01 06:58:22 +00:00
file: fix dup
This commit is contained in:
@@ -173,6 +173,10 @@ int fd_clone(proc_t *targproc) {
|
|||||||
int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
|
int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
|
||||||
proc_t *proc = _cpu()->thread->proc;
|
proc_t *proc = _cpu()->thread->proc;
|
||||||
int err = 0;
|
int err = 0;
|
||||||
|
|
||||||
|
if (newfd < 0 || newfd >= FDTABLE_LIMIT)
|
||||||
|
return EBADF;
|
||||||
|
|
||||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||||
|
|
||||||
file_t *file = oldfd < proc->fdcount ? proc->fd[oldfd].file : NULL;
|
file_t *file = oldfd < proc->fdcount ? proc->fd[oldfd].file : NULL;
|
||||||
@@ -182,11 +186,6 @@ int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (exact) {
|
if (exact) {
|
||||||
if (newfd >= FDTABLE_LIMIT) {
|
|
||||||
err = EBADF;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (newfd >= proc->fdcount) {
|
if (newfd >= proc->fdcount) {
|
||||||
err = growtable(newfd + 1);
|
err = growtable(newfd + 1);
|
||||||
if (err)
|
if (err)
|
||||||
|
|||||||
Reference in New Issue
Block a user