mirror of
https://github.com/Mathewnd/Astral.git
synced 2026-10-27 20:58:22 +00:00
file: fd_insert
This commit is contained in:
@@ -196,6 +196,29 @@ int fd_clone(proc_t *targproc) {
|
||||
return error;
|
||||
}
|
||||
|
||||
int fd_insert(file_t *file, int *fdp) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
int err = 0;
|
||||
MUTEX_ACQUIRE(&proc->fdmutex, false);
|
||||
int fd = getfree(0);
|
||||
|
||||
if (fd == -1) {
|
||||
fd = proc->fdcount;
|
||||
err = growtable(proc->fdcount);
|
||||
if (err)
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
proc->fd[fd].file = file;
|
||||
proc->fd[fd].flags = 0;
|
||||
FILE_HOLD(file);
|
||||
*fdp = fd;
|
||||
|
||||
cleanup:
|
||||
MUTEX_RELEASE(&proc->fdmutex);
|
||||
return err;
|
||||
}
|
||||
|
||||
int fd_dup(int oldfd, int newfd, bool exact, int fdflags, int *retfd) {
|
||||
proc_t *proc = _cpu()->thread->proc;
|
||||
int err = 0;
|
||||
|
||||
@@ -28,6 +28,7 @@ int fd_dup(int oldfd, int newfd, bool exact, int flags, int *ret);
|
||||
int fd_clone(proc_t *proc);
|
||||
int fd_setflags(int fd, int flags);
|
||||
int fd_getflags(int fd, int *flags);
|
||||
int fd_insert(file_t *file, int *fdp);
|
||||
|
||||
#define FILE_LOCK(x) MUTEX_ACQUIRE(&(x)->mutex, false)
|
||||
#define FILE_UNLOCK(x) MUTEX_RELEASE(&(x)->mutex)
|
||||
|
||||
Reference in New Issue
Block a user