Implement sys/times.h on linux

This commit is contained in:
jD91mZM2
2018-07-29 09:23:56 +02:00
parent e7e9d57db5
commit f82b48b839
13 changed files with 94 additions and 0 deletions
Generated
+9
View File
@@ -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"
+1
View File
@@ -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" }
+1
View File
@@ -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;
+4
View File
@@ -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
}
+9
View File
@@ -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
+8
View File
@@ -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
}
+10
View File
@@ -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" }
+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/times.h");
}
+6
View File
@@ -0,0 +1,6 @@
include_guard = "_SYS_TIMES_H"
language = "C"
style = "Tag"
[enum]
prefix_with_name = true
+20
View File
@@ -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)
}
+1
View File
@@ -70,6 +70,7 @@ stdlib/alloc
stdlib/bsearch
stdlib/mktemp
time/gettimeofday
time/times
unistd/chdir
unistd/gethostname
unistd/getid
+1
View File
@@ -73,6 +73,7 @@ BINS=\
stdlib/bsearch \
stdlib/mktemp \
time/gettimeofday \
time/times \
unistd/chdir \
unistd/gethostname \
unistd/getid \
+13
View File
@@ -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);
}