diff --git a/Cargo.lock b/Cargo.lock index a0505d021c0d5ece925ff517e6b34e9a8adb32fc..721878128657bd9deae2f1d9edbdce6eaaa2cc3e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,6 +349,7 @@ dependencies = [ "sys_socket 0.1.0", "sys_stat 0.1.0", "sys_time 0.1.0", + "sys_times 0.1.0", "sys_un 0.1.0", "sys_utsname 0.1.0", "sys_wait 0.1.0", @@ -579,6 +580,14 @@ dependencies = [ "platform 0.1.0", ] +[[package]] +name = "sys_times" +version = "0.1.0" +dependencies = [ + "cbindgen 0.5.2", + "platform 0.1.0", +] + [[package]] name = "sys_un" version = "0.1.0" diff --git a/Cargo.toml b/Cargo.toml index ea17f150042320aa06e2c161b0317243f67c8e29..77643812b003055ce6c5b27132edb2acf95c0d83 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -41,6 +41,7 @@ sys_resource = { path = "src/sys_resource" } sys_socket = { path = "src/sys_socket" } sys_stat = { path = "src/sys_stat" } sys_time = { path = "src/sys_time" } +sys_times = { path = "src/sys_times" } sys_un = { path = "src/sys_un" } sys_utsname = { path = "src/sys_utsname" } sys_wait = { path = "src/sys_wait" } diff --git a/src/lib.rs b/src/lib.rs index 8e752a84464fc90ae0ec45e356a325adf538ceef..65e556ac680dff44e4989893674a47692330817e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -31,6 +31,7 @@ pub extern crate sys_resource; pub extern crate sys_socket; pub extern crate sys_stat; pub extern crate sys_time; +pub extern crate sys_times; pub extern crate sys_un; pub extern crate sys_utsname; pub extern crate sys_wait; diff --git a/src/platform/src/linux/mod.rs b/src/platform/src/linux/mod.rs index 790b87ec67d63e8cfc6f83846eb84dff548f2ead..8003b7f27b771e72a5c81b6558f597c8af05e997 100644 --- a/src/platform/src/linux/mod.rs +++ b/src/platform/src/linux/mod.rs @@ -392,6 +392,10 @@ pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *m e(unsafe { syscall!(SOCKETPAIR, domain, kind, protocol, socket_vector) }) as c_int } +pub fn times(out: *mut tms) -> clock_t { + unsafe { syscall!(TIMES, out) as clock_t } +} + pub fn uname(utsname: *mut utsname) -> c_int { e(unsafe { syscall!(UNAME, utsname, 0) }) as c_int } diff --git a/src/platform/src/redox/mod.rs b/src/platform/src/redox/mod.rs index 3619d499ead37721170ef9049f84af7232eb45e7..099f2fd1cbddda25575a4d963e0bc72520e241e7 100644 --- a/src/platform/src/redox/mod.rs +++ b/src/platform/src/redox/mod.rs @@ -821,6 +821,15 @@ pub fn socketpair(domain: c_int, kind: c_int, protocol: c_int, socket_vector: *m -1 } +pub fn times(out: *mut tms) -> clock_t { + let _ = write!( + ::FileWriter(2), + "unimplemented: times({:p})", + out + ); + !0 +} + pub fn unlink(path: *const c_char) -> c_int { let path = unsafe { c_str(path) }; e(syscall::unlink(path)) as c_int diff --git a/src/platform/src/types.rs b/src/platform/src/types.rs index 8438ddf10c9356ad5e0075226de13ec41390715c..eaa7d18cd18ce13ecde4577411d331fff624490a 100644 --- a/src/platform/src/types.rs +++ b/src/platform/src/types.rs @@ -223,3 +223,11 @@ pub struct rusage { pub ru_nvcsw: c_long, pub ru_nivcsw: c_long } + +#[repr(C)] +pub struct tms { + tms_utime: clock_t, + tms_stime: clock_t, + tms_cutime: clock_t, + tms_cstime: clock_t +} diff --git a/src/sys_times/Cargo.toml b/src/sys_times/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..31f1646396f8600eec2749dda168cde3325fba62 --- /dev/null +++ b/src/sys_times/Cargo.toml @@ -0,0 +1,10 @@ +[package] +name = "sys_times" +version = "0.1.0" +authors = ["jD91mZM2 <me@krake.one>"] + +[build-dependencies] +cbindgen = { path = "../../cbindgen" } + +[dependencies] +platform = { path = "../platform" } diff --git a/src/sys_times/build.rs b/src/sys_times/build.rs new file mode 100644 index 0000000000000000000000000000000000000000..d93c16000a4bcdb2c3545b2b01205f21dcf50668 --- /dev/null +++ b/src/sys_times/build.rs @@ -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/times.h"); +} diff --git a/src/sys_times/cbindgen.toml b/src/sys_times/cbindgen.toml new file mode 100644 index 0000000000000000000000000000000000000000..e8995a6f1c0b35b8667a1c754f36e7c953d33ecf --- /dev/null +++ b/src/sys_times/cbindgen.toml @@ -0,0 +1,6 @@ +include_guard = "_SYS_TIMES_H" +language = "C" +style = "Tag" + +[enum] +prefix_with_name = true diff --git a/src/sys_times/src/lib.rs b/src/sys_times/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..85cc11093d49452aa3db35c5394e49eaae3a4d0b --- /dev/null +++ b/src/sys_times/src/lib.rs @@ -0,0 +1,20 @@ +//! sys/times.h implementation + +#![no_std] + +extern crate platform; + +use platform::types::*; + +#[repr(C)] +pub struct tms { + tms_utime: clock_t, + tms_stime: clock_t, + tms_cutime: clock_t, + tms_cstime: clock_t +} + +#[no_mangle] +pub extern "C" fn times(out: *mut tms) -> clock_t { + platform::times(out as *mut platform::types::tms) +} diff --git a/tests/.gitignore b/tests/.gitignore index 74d32a2742d8ea74810f2fc02f53d57953d4f1c2..affa0abff5bac5c66b7e9b5fa295ad2f52bc1318 100644 --- a/tests/.gitignore +++ b/tests/.gitignore @@ -70,6 +70,7 @@ stdlib/alloc stdlib/bsearch stdlib/mktemp time/gettimeofday +time/times unistd/chdir unistd/gethostname unistd/getid diff --git a/tests/Makefile b/tests/Makefile index fdd53fa184c247f1eb5953b4f7409d809d106a72..d313fb34438c83aee860f565ab669782eef5d843 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -73,6 +73,7 @@ BINS=\ stdlib/bsearch \ stdlib/mktemp \ time/gettimeofday \ + time/times \ unistd/chdir \ unistd/gethostname \ unistd/getid \ diff --git a/tests/time/times.c b/tests/time/times.c new file mode 100644 index 0000000000000000000000000000000000000000..975aae2dd042e55d722d36ce68d8105c46f1def4 --- /dev/null +++ b/tests/time/times.c @@ -0,0 +1,13 @@ +#include <stdio.h> +#include <sys/times.h> +#include <unistd.h> + +int main() { + struct tms tms; + printf("return: %ld\n", times(&tms)); + + printf("tm_utime: %ld\n", tms.tms_utime); + printf("tm_stime: %ld\n", tms.tms_stime); + printf("tm_cutime: %ld\n", tms.tms_cutime); + printf("tm_cstime: %ld\n", tms.tms_cstime); +}