From b720d0181f807fe84ecb77b0cd7c5dff23c3a7d3 Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Sat, 3 Mar 2018 08:25:53 -0700 Subject: [PATCH] Add fcntl --- fcntl/.gitignore | 2 ++ fcntl/Cargo.toml | 10 ++++++++ fcntl/build.rs | 11 ++++++++ fcntl/cbindgen.toml | 5 ++++ fcntl/src/lib.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++ unistd/Cargo.toml | 4 --- 6 files changed, 89 insertions(+), 4 deletions(-) create mode 100644 fcntl/.gitignore create mode 100644 fcntl/Cargo.toml create mode 100644 fcntl/build.rs create mode 100644 fcntl/cbindgen.toml create mode 100644 fcntl/src/lib.rs diff --git a/fcntl/.gitignore b/fcntl/.gitignore new file mode 100644 index 0000000000..042776aad7 --- /dev/null +++ b/fcntl/.gitignore @@ -0,0 +1,2 @@ +/Cargo.lock +/target/ diff --git a/fcntl/Cargo.toml b/fcntl/Cargo.toml new file mode 100644 index 0000000000..fa3f01a67c --- /dev/null +++ b/fcntl/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "fcntl" +version = "0.1.0" +authors = ["Jeremy Soller "] + +[build-dependencies] +cbindgen = "0.5" + +[dependencies] +libc = "0.2" diff --git a/fcntl/build.rs b/fcntl/build.rs new file mode 100644 index 0000000000..34ef21a705 --- /dev/null +++ b/fcntl/build.rs @@ -0,0 +1,11 @@ +extern crate cbindgen; + +use std::env; + +fn main() { + let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap(); + + cbindgen::generate(crate_dir) + .expect("Unable to generate bindings") + .write_to_file("target/fcntl.h"); +} diff --git a/fcntl/cbindgen.toml b/fcntl/cbindgen.toml new file mode 100644 index 0000000000..4193206804 --- /dev/null +++ b/fcntl/cbindgen.toml @@ -0,0 +1,5 @@ +include_guard = "_FCNTL_H" +language = "C" + +[enum] +prefix_with_name = true diff --git a/fcntl/src/lib.rs b/fcntl/src/lib.rs new file mode 100644 index 0000000000..95bea1c378 --- /dev/null +++ b/fcntl/src/lib.rs @@ -0,0 +1,61 @@ +/// fcntl implementation for Redox, following http://pubs.opengroup.org/onlinepubs/7908799/xsh/fcntl.h.html + +extern crate libc; + +use libc::*; + +pub const F_DUPFD: c_int = 0; +pub const F_GETFD: c_int = 1; +pub const F_SETFD: c_int = 2; +pub const F_GETFL: c_int = 3; +pub const F_SETFL: c_int = 4; +pub const F_GETLK: c_int = 5; +pub const F_SETLK: c_int = 6; +pub const F_SETLKW: c_int = 7; + +pub const FD_CLOEXEC: c_int = 0x0100_0000; + +pub const F_RDLCK: c_int = 0; +pub const F_WRLCK: c_int = 1; +pub const F_UNLCK: c_int = 2; + +pub const O_RDONLY: c_int = 0x0001_0000; +pub const O_WRONLY: c_int = 0x0002_0000; +pub const O_RDWR: c_int = 0x0003_0000; +pub const O_NONBLOCK: c_int = 0x0004_0000; +pub const O_APPEND: c_int = 0x0008_0000; +pub const O_SHLOCK: c_int = 0x0010_0000; +pub const O_EXLOCK: c_int = 0x0020_0000; +pub const O_ASYNC: c_int = 0x0040_0000; +pub const O_FSYNC: c_int = 0x0080_0000; +pub const O_CLOEXEC: c_int = 0x0100_0000; +pub const O_CREAT: c_int = 0x0200_0000; +pub const O_TRUNC: c_int = 0x0400_0000; +pub const O_EXCL: c_int = 0x0800_0000; +pub const O_DIRECTORY: c_int = 0x1000_0000; +pub const O_STAT: c_int = 0x2000_0000; +pub const O_SYMLINK: c_int = 0x4000_0000; +pub const O_NOFOLLOW: c_int = 0x8000_0000; +pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR; + +#[no_mangle] +pub extern "C" fn creat(path: *const c_char, mode: mode_t) -> c_int { + open(path, O_WRONLY | O_CREAT | O_TRUNC, mode) +} + +#[no_mangle] +pub extern "C" fn fcntl(fildes: c_int, cmd: c_int, arg: c_int) -> c_int { + unimplemented!(); +} + +#[no_mangle] +pub extern "C" fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int { + unimplemented!(); +} + +/* +#[no_mangle] +pub extern "C" fn func(args) -> c_int { + unimplemented!(); +} +*/ diff --git a/unistd/Cargo.toml b/unistd/Cargo.toml index 1d4f993953..e57a536766 100644 --- a/unistd/Cargo.toml +++ b/unistd/Cargo.toml @@ -3,10 +3,6 @@ name = "unistd" version = "0.1.0" authors = ["Jeremy Soller "] -[lib] -name = "unistd" -crate-type = ["cdylib"] - [build-dependencies] cbindgen = "0.5"