Implement sys/file.h

This commit is contained in:
jD91mZM2
2018-07-30 10:04:58 +02:00
parent d3e4fa71a5
commit 2a303c4b60
8 changed files with 59 additions and 2 deletions
+4
View File
@@ -84,6 +84,10 @@ pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
e(unsafe { syscall!(FCHOWN, fildes, owner, group) }) as c_int
}
pub fn flock(fd: c_int, operation: c_int) -> c_int {
e(unsafe { syscall!(FLOCK, fd, operation) }) as c_int
}
pub fn fstat(fildes: c_int, buf: *mut stat) -> c_int {
let empty_cstr: *const c_char = unsafe { ::cstr_from_bytes_with_nul_unchecked(b"\0") };
e(unsafe { syscall!(NEWFSTATAT, fildes, empty_cstr, buf, AT_EMPTY_PATH) }) as c_int
+5
View File
@@ -226,6 +226,11 @@ pub fn fcntl(fd: c_int, cmd: c_int, args: c_int) -> c_int {
e(syscall::fcntl(fd as usize, cmd as usize, args as usize)) as c_int
}
pub fn flock(_fd: c_int, _operation: c_int) -> c_int {
// TODO: Redox does not have file locking yet
0
}
pub fn fork() -> pid_t {
e(unsafe { syscall::clone(0) }) as pid_t
}
+1
View File
@@ -1,3 +1,4 @@
use core::mem;
#[cfg(target_os = "redox")]
use syscall::data::TimeSpec as redox_timespec;
// Use repr(u8) as LLVM expects `void*` to be the same as `i8*` to help enable
+10
View File
@@ -0,0 +1,10 @@
[package]
name = "sys_file"
version = "0.1.0"
authors = ["jD91mZM2 <me@krake.one>"]
[build-dependencies]
cbindgen = { path = "../../cbindgen" }
[dependencies]
platform = { path = "../platform" }
+11
View File
@@ -0,0 +1,11 @@
extern crate cbindgen;
use std::{env, fs};
fn main() {
let crate_dir = env::var("CARGO_MANIFEST_DIR").expect("CARGO_MANIFEST_DIR not set");
fs::create_dir_all("../../target/include").expect("failed to create include directory");
cbindgen::generate(crate_dir)
.expect("failed to generate bindings")
.write_to_file("../../target/include/sys/file.h");
}
+6
View File
@@ -0,0 +1,6 @@
include_guard = "_SYS_FILE_H"
language = "C"
style = "Tag"
[enum]
prefix_with_name = true
+21
View File
@@ -0,0 +1,21 @@
//! sys/file.h implementation
#![no_std]
extern crate platform;
use platform::types::*;
pub const LOCK_SH: usize = 1;
pub const LOCK_EX: usize = 1 << 1;
pub const LOCK_NB: usize = 1 << 2;
pub const LOCK_UN: usize = 1 << 3;
pub const L_SET: usize = 0;
pub const L_INCR: usize = 1;
pub const L_XTND: usize = 2;
#[no_mangle]
pub extern "C" fn flock(fd: c_int, operation: c_int) -> c_int {
platform::flock(fd, operation)
}
+1 -2
View File
@@ -1,5 +1,4 @@
sys_includes = []
include_guard = "_IOCTL_H"
include_guard = "_SYS_IOCTL_H"
language = "C"
# WORKAROUND: