Skip to content
Snippets Groups Projects
Unverified Commit 4da873ae authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub
Browse files

Merge pull request #43 from MggMuggins/master

Imp va_arg for fcntl; fcntl test
parents 76e53e86 96358469
No related branches found
No related tags found
No related merge requests found
...@@ -3,11 +3,20 @@ ...@@ -3,11 +3,20 @@
int open(const char* filename, int flags, ...) { int open(const char* filename, int flags, ...) {
mode_t mode = 0; mode_t mode = 0;
va_list ap; va_list ap;
va_start(ap, flags); va_start(ap, flags);
mode = va_arg(ap, mode_t); mode = va_arg(ap, mode_t);
va_end(ap); va_end(ap);
return sys_open(filename, flags, mode); return sys_open(filename, flags, mode);
} }
int fcntl(int fildes, int cmd, ...) {
int args = 0;
va_list ap;
va_start(ap, cmd);
args = va_arg(ap, int);
va_end(ap);
return sys_fcntl(fildes, cmd, args);
}
#endif #endif
...@@ -37,7 +37,7 @@ pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int { ...@@ -37,7 +37,7 @@ pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int {
} }
#[no_mangle] #[no_mangle]
pub extern "C" fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { pub extern "C" fn sys_fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int {
platform::fcntl(fildes, cmd, arg) platform::fcntl(fildes, cmd, arg)
} }
......
...@@ -10,6 +10,7 @@ BINS=\ ...@@ -10,6 +10,7 @@ BINS=\
dup \ dup \
error \ error \
fchdir \ fchdir \
fcntl \
fsync \ fsync \
ftruncate \ ftruncate \
getid \ getid \
......
File added
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
int main() {
//Lose our fd and pull it again
creat("fcntl.out", 0777);
int newfd = open("fcntl.out", 0);
int newfd2 = fcntl(newfd, F_DUPFD, 0);
printf("fd %d duped into fd %d\n", newfd, newfd2);
close(newfd);
close(newfd2);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment