diff options
author | Luís Marques <luismarques@lowrisc.org> | 2019-10-22 18:08:57 +0100 |
---|---|---|
committer | Andrew Waterman <andrew@sifive.com> | 2019-10-22 10:08:57 -0700 |
commit | 43969b149eb3be5fe18daa7c69a02467e6f16d15 (patch) | |
tree | 7dab24aa1df371e12a0a1dd924c36311441d51c7 /pk/file.c | |
parent | 15329a8aac5d0f1f1fea01c68230421147c8b50b (diff) | |
download | pk-43969b149eb3be5fe18daa7c69a02467e6f16d15.zip pk-43969b149eb3be5fe18daa7c69a02467e6f16d15.tar.gz pk-43969b149eb3be5fe18daa7c69a02467e6f16d15.tar.bz2 |
Implement dup3 syscall (#162)
Diffstat (limited to 'pk/file.c')
-rw-r--r-- | pk/file.c | 14 |
1 files changed, 14 insertions, 0 deletions
@@ -53,6 +53,20 @@ int file_dup(file_t* f) return -1; } +int file_dup3(file_t* f, int newfd) +{ + if (newfd < 0 || newfd >= MAX_FDS) + return -1; + + if (atomic_cas(&fds[newfd], 0, f) == 0) + { + file_incref(f); + return newfd; + } + + return -1; +} + void file_init() { // create stdin, stdout, stderr and FDs 0-2 |