Merge pull request #16 from dlrobertson/fixes_and_nits

Fix platform
This commit is contained in:
Jeremy Soller
2018-03-06 19:30:13 -07:00
committed by GitHub
23 changed files with 232 additions and 270 deletions
+5 -4
View File
@@ -3,17 +3,18 @@
#![no_std]
#![allow(non_camel_case_types)]
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
#[macro_use]
extern crate sc;
pub use sys::*;
#[cfg(all(not(feature="no_std"), target_os = "linux"))]
#[path="linux/mod.rs"]
#[cfg(all(not(feature = "no_std"), target_os = "linux"))]
#[path = "linux/mod.rs"]
mod sys;
#[cfg(all(not(feature="no_std"), target_os = "redox"))]
#[path="redox/mod.rs"]
#[cfg(all(not(feature = "no_std"), target_os = "redox"))]
#[path = "redox/mod.rs"]
mod sys;
pub mod types;
+24 -64
View File
@@ -6,40 +6,31 @@ pub fn brk(addr: *const c_void) -> c_int {
unsafe {
let newbrk = syscall!(BRK, addr);
if newbrk < addr as usize {
return -1
-1
} else {
0
}
0
}
}
pub fn chdir(path: *const c_char) -> c_int {
unsafe {
syscall!(CHDIR, path) as c_int
}
unsafe { syscall!(CHDIR, path) as c_int }
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
unsafe {
syscall!(CHOWN, owner as u32, group as u32) as c_int
}
unsafe { syscall!(CHOWN, owner as u32, group as u32) as c_int }
}
pub fn close(fildes: c_int) -> c_int {
unsafe {
syscall!(CLOSE, fildes) as c_int
}
unsafe { syscall!(CLOSE, fildes) as c_int }
}
pub fn dup(fildes: c_int) -> c_int {
unsafe {
syscall!(DUP, fildes) as c_int
}
unsafe { syscall!(DUP, fildes) as c_int }
}
pub fn dup2(fildes: c_int, fildes2:c_int) -> c_int {
unsafe {
syscall!(DUP2, fildes, fildes2) as c_int
}
pub fn dup2(fildes: c_int, fildes2: c_int) -> c_int {
unsafe { syscall!(DUP2, fildes, fildes2) as c_int }
}
pub fn exit(status: c_int) -> ! {
@@ -50,27 +41,19 @@ pub fn exit(status: c_int) -> ! {
}
pub fn fchown(fildes: c_int, owner: uid_t, group: gid_t) -> c_int {
unsafe {
syscall!(FCHOWN, owner, group) as c_int
}
unsafe { syscall!(FCHOWN, fildes, owner, group) as c_int }
}
pub fn fchdir(fildes: c_int) -> c_int {
unsafe {
syscall!(FCHDIR, fildes) as c_int
}
unsafe { syscall!(FCHDIR, fildes) as c_int }
}
pub fn fsync(fildes: c_int) -> c_int {
unsafe {
syscall!(FSYNC, fildes) as c_int
}
unsafe { syscall!(FSYNC, fildes) as c_int }
}
pub fn ftruncate(fildes: c_int, length: off_t) -> c_int {
unsafe {
syscall!(FTRUNCATE, fildes, length) as c_int
}
unsafe { syscall!(FTRUNCATE, fildes, length) as c_int }
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
@@ -81,70 +64,47 @@ pub fn getcwd(buf: *mut c_char, size: size_t) -> *mut c_char {
}
pub fn getegid() -> gid_t {
unsafe {
syscall!(GETEGID)
}
unsafe { syscall!(GETEGID) }
}
pub fn geteuid() -> uid_t {
unsafe {
syscall!(GETEUID)
}
unsafe { syscall!(GETEUID) }
}
pub fn getgid() -> gid_t {
unsafe {
syscall!(GETGID)
}
unsafe { syscall!(GETGID) }
}
pub fn getpgid(pid: pid_t) -> pid_t {
unsafe {
syscall!(GETPGID, pid)
}
unsafe { syscall!(GETPGID, pid) }
}
pub fn getpid() -> pid_t {
unsafe {
syscall!(GETPID)
}
unsafe { syscall!(GETPID) }
}
pub fn getppid() -> pid_t {
unsafe {
syscall!(GETPPID)
}
unsafe { syscall!(GETPPID) }
}
pub fn getuid() -> uid_t {
unsafe {
syscall!(GETUID)
}
unsafe { syscall!(GETUID) }
}
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
unsafe {
syscall!(LINK, path1, path2) as c_int
}
unsafe { syscall!(LINK, path1, path2) as c_int }
}
#[cfg(target_arch = "x86_64")]
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unsafe {
syscall!(OPEN, path, oflag, mode) as c_int
}
unsafe { syscall!(OPEN, path, oflag, mode) as c_int }
}
#[cfg(target_arch = "aarch64")]
pub fn open(path: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unsafe {
syscall!(OPENAT, AT_FDCWD, path, oflag, mode) as c_int
}
unsafe { syscall!(OPENAT, AT_FDCWD, path, oflag, mode) as c_int }
}
pub fn write(fildes: c_int, buf: &[u8]) -> ssize_t {
unsafe {
syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t
}
unsafe { syscall!(WRITE, fildes, buf.as_ptr(), buf.len()) as ssize_t }
}
+10 -11
View File
@@ -3,18 +3,19 @@ use syscall;
use c_str;
use types::*;
pub fn brk(addr: *const c_void) -> {
pub fn brk(addr: *const c_void) -> c_int {
syscall::brk(addr as usize).unwrap_or(-1) as c_int
}
pub fn chdir(path: *const c_char) -> c_int {
pub fn chdir(path: *const c_char) -> c_int {
let path = unsafe { c_str(path) };
syscall::chdir(path).unwrap_or(-1) as c_int
}
}
pub fn chown(path: *const c_char, owner: uid_t, group: gid_t) -> c_int {
let fd = syscall::open(cstr_to_slice(path));
syscall::fchown(fd as usize, owner as usize, group as usize).unwrap_or(-1) as c_int
}
pub fn close(fd: c_int) -> c_int {
syscall::close(fd as usize);
@@ -25,7 +26,7 @@ pub fn dup(fd: c_int) -> c_int {
syscall::dup(fd as usize, &[]).unwrap_or(-1) as c_int
}
pub fn dup2(fd1: c_int, fd2) -> c_int {
pub fn dup2(fd1: c_int, fd2: c_int) -> c_int {
syscall::dup2(fd1 as usize, fd2 as usize, &[]).unwrap_or(-1) as c_int
}
@@ -51,17 +52,15 @@ pub fn fsync(fd: c_int) -> c_int {
syscall::fsync(fd as usize).unwrap_or(-1) as c_int
}
pub fn ftruncate(fd: c_int, len: off_t) -> {
pub fn ftruncate(fd: c_int, len: off_t) -> c_int {
syscall::ftruncate(fd as usize, len as usize).unwrap_or(-1) as c_int
}
pub fn getcwd(buf: *mut c_char, size: size_t) -> {
pub fn getcwd(buf: *mut c_char, size: size_t) -> c_int {
// XXX: do something with size maybe
let rbuf = unsafe { c_str(buf) };
syscall::getcwd(rbuf);
unsafe {
&*(rbuf as *mut [c_char])
}
unsafe { &*(rbuf as *mut [c_char]) }
}
pub fn getegid() -> gid_t {
@@ -92,7 +91,7 @@ pub fn getuid() -> uid_t {
syscall::getuid().unwrap_or(-1) as pid_t
}
pub fn link(path1: const c_char, path2: const c_char) -> c_int {
pub fn link(path1: *const c_char, path2: *const c_char) -> c_int {
let path1 = unsafe { c_str(path1) };
let path2 = unsafe { c_str(path2) };
syscall::link(path1, path2).unwrap_or(-1) as c_int
+29
View File
@@ -0,0 +1,29 @@
max_width = 100
hard_tabs = false
tab_spaces = 4
newline_style = "Unix"
indent_style = "Block"
format_strings = false
empty_item_single_line = true
fn_single_line = false
where_single_line = false
imports_indent = "Visual"
imports_layout = "Mixed"
reorder_extern_crates = true
reorder_extern_crates_in_group = true
reorder_imports = false
reorder_imported_names = true
spaces_within_parens_and_brackets = false
remove_blank_lines_at_start_or_end_of_block = true
fn_args_density = "Tall"
brace_style = "SameLineWhere"
trailing_comma = "Vertical"
blank_lines_upper_bound = 1
blank_lines_lower_bound = 0
force_explicit_abi = true
write_mode = "Overwrite"
disable_all_formatting = false
skip_children = false
hide_parse_errors = false
report_todo = "Never"
report_fixme = "Never"
+2 -2
View File
@@ -6,6 +6,6 @@ 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/ctype.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/ctype.h");
}
+2 -2
View File
@@ -6,6 +6,6 @@ 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/fcntl.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/fcntl.h");
}
+2 -2
View File
@@ -9,11 +9,11 @@ use platform::types::*;
pub use sys::*;
#[cfg(target_os = "linux")]
#[path="linux.rs"]
#[path = "linux.rs"]
pub mod sys;
#[cfg(target_os = "redox")]
#[path="redox.rs"]
#[path = "redox.rs"]
pub mod sys;
pub const F_DUPFD: c_int = 0;
+5 -5
View File
@@ -1,8 +1,8 @@
use platform::types::*;
pub const O_RDONLY: c_int = 0x0000;
pub const O_WRONLY: c_int = 0x0001;
pub const O_RDWR: c_int = 0x0002;
pub const O_CREAT: c_int = 0x0040;
pub const O_TRUNC: c_int = 0x0200;
pub const O_RDONLY: c_int = 0x0000;
pub const O_WRONLY: c_int = 0x0001;
pub const O_RDWR: c_int = 0x0002;
pub const O_CREAT: c_int = 0x0040;
pub const O_TRUNC: c_int = 0x0200;
pub const O_ACCMODE: c_int = O_RDONLY | O_WRONLY | O_RDWR;
+17 -17
View File
@@ -1,20 +1,20 @@
use platform::types::*;
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_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;
+2 -2
View File
@@ -6,6 +6,6 @@ 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/grp.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/grp.h");
}
+2 -2
View File
@@ -6,6 +6,6 @@ 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/mman.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/mman.h");
}
+1 -5
View File
@@ -52,11 +52,7 @@ pub extern "C" fn munmap(addr: *mut c_void, len: usize) -> c_int {
}
#[no_mangle]
pub extern "C" fn shm_open(
name: *const c_char,
oflag: c_int,
mode: mode_t,
) -> c_int {
pub extern "C" fn shm_open(name: *const c_char, oflag: c_int, mode: mode_t) -> c_int {
unimplemented!();
}
+2 -2
View File
@@ -6,6 +6,6 @@ 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/semaphore.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/semaphore.h");
}
+6 -8
View File
@@ -12,11 +12,12 @@ pub union sem_t {
_bindgen_union_align: [u64; 4usize],
}
impl Clone for sem_t {
fn clone(&self) -> Self { *self }
fn clone(&self) -> Self {
*self
}
}
#[no_mangle]
pub extern "C" fn sem_init(sem: *mut sem_t, pshared: c_int,
value: c_uint) -> c_int {
pub extern "C" fn sem_init(sem: *mut sem_t, pshared: c_int, value: c_uint) -> c_int {
unimplemented!();
}
@@ -39,8 +40,7 @@ pub extern "C" fn sem_close(sem: *mut sem_t) -> c_int {
}
#[no_mangle]
pub extern "C" fn sem_unlink(name: *const c_char)
-> c_int {
pub extern "C" fn sem_unlink(name: *const c_char) -> c_int {
unimplemented!();
}
@@ -60,8 +60,6 @@ pub extern "C" fn sem_post(sem: *mut sem_t) -> c_int {
}
#[no_mangle]
pub extern "C" fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int)
-> c_int {
pub extern "C" fn sem_getvalue(sem: *mut sem_t, sval: *mut c_int) -> c_int {
unimplemented!();
}
+2 -2
View File
@@ -6,6 +6,6 @@ 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/stdio.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/stdio.h");
}
+37 -65
View File
@@ -30,14 +30,12 @@ pub extern "C" fn clearerr(stream: *mut FILE) {
}
#[no_mangle]
pub extern "C" fn ctermid(s: *mut c_char)
-> *mut c_char {
pub extern "C" fn ctermid(s: *mut c_char) -> *mut c_char {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn cuserid(s: *mut c_char)
-> *mut c_char {
pub extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
unimplemented!();
}
@@ -47,8 +45,7 @@ pub extern "C" fn fclose(stream: *mut FILE) -> c_int {
}
#[no_mangle]
pub extern "C" fn fdopen(fildes: c_int,
mode: *const c_char) -> *mut FILE {
pub extern "C" fn fdopen(fildes: c_int, mode: *const c_char) -> *mut FILE {
unimplemented!();
}
@@ -73,15 +70,12 @@ pub extern "C" fn fgetc(stream: *mut FILE) -> c_int {
}
#[no_mangle]
pub extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t)
-> c_int {
pub extern "C" fn fgetpos(stream: *mut FILE, pos: *mut fpos_t) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fgets(s: *mut c_char,
n: c_int, stream: *mut FILE)
-> *mut c_char {
pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: *mut FILE) -> *mut c_char {
unimplemented!();
}
@@ -96,51 +90,46 @@ pub extern "C" fn flockfile(file: *mut FILE) {
}
#[no_mangle]
pub extern "C" fn fopen(filename: *const c_char,
mode: *const c_char) -> *mut FILE {
pub extern "C" fn fopen(filename: *const c_char, mode: *const c_char) -> *mut FILE {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fputc(c: c_int, stream: *mut FILE)
-> c_int {
pub extern "C" fn fputc(c: c_int, stream: *mut FILE) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fputs(s: *const c_char, stream: *mut FILE)
-> c_int {
pub extern "C" fn fputs(s: *const c_char, stream: *mut FILE) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fread(ptr: *mut c_void, size: usize, nitems: usize,
stream: *mut FILE) -> usize {
pub extern "C" fn fread(ptr: *mut c_void, size: usize, nitems: usize, stream: *mut FILE) -> usize {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn freopen(filename: *const c_char,
mode: *const c_char, stream: *mut FILE)
-> *mut FILE {
pub extern "C" fn freopen(
filename: *const c_char,
mode: *const c_char,
stream: *mut FILE,
) -> *mut FILE {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fseek(stream: *mut FILE, offset: c_long,
whence: c_int) -> c_int {
pub extern "C" fn fseek(stream: *mut FILE, offset: c_long, whence: c_int) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fseeko(stream: *mut FILE, offset: off_t, whence: c_int)
-> c_int {
pub extern "C" fn fseeko(stream: *mut FILE, offset: off_t, whence: c_int) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn fsetpos(stream: *mut FILE, pos: *const fpos_t)
-> c_int {
pub extern "C" fn fsetpos(stream: *mut FILE, pos: *const fpos_t) -> c_int {
unimplemented!();
}
@@ -165,8 +154,12 @@ pub extern "C" fn funlockfile(file: *mut FILE) {
}
#[no_mangle]
pub extern "C" fn fwrite(ptr: *const c_void, size: usize,
nitems: usize, stream: *mut FILE) -> usize {
pub extern "C" fn fwrite(
ptr: *const c_void,
size: usize,
nitems: usize,
stream: *mut FILE,
) -> usize {
unimplemented!();
}
@@ -191,8 +184,7 @@ pub extern "C" fn getchar_unlocked() -> c_int {
}
#[no_mangle]
pub extern "C" fn gets(s: *mut c_char)
-> *mut c_char {
pub extern "C" fn gets(s: *mut c_char) -> *mut c_char {
unimplemented!();
}
@@ -212,14 +204,12 @@ pub extern "C" fn perror(s: *const c_char) {
}
#[no_mangle]
pub extern "C" fn popen(command: *const c_char,
mode: *const c_char) -> *mut FILE {
pub extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *mut FILE {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn putc(c: c_int, stream: *mut FILE)
-> c_int {
pub extern "C" fn putc(c: c_int, stream: *mut FILE) -> c_int {
unimplemented!();
}
@@ -229,14 +219,12 @@ pub extern "C" fn putchar(c: c_int) -> c_int {
}
#[no_mangle]
pub extern "C" fn putc_unlocked(c: c_int, stream: *mut FILE)
-> c_int {
pub extern "C" fn putc_unlocked(c: c_int, stream: *mut FILE) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn putchar_unlocked(c: c_int)
-> c_int {
pub extern "C" fn putchar_unlocked(c: c_int) -> c_int {
unimplemented!();
}
@@ -246,21 +234,17 @@ pub extern "C" fn puts(s: *const c_char) -> c_int {
}
#[no_mangle]
pub extern "C" fn putw(w: c_int, stream: *mut FILE)
-> c_int {
pub extern "C" fn putw(w: c_int, stream: *mut FILE) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn remove(path: *const c_char)
-> c_int {
pub extern "C" fn remove(path: *const c_char) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn rename(old: *const c_char,
new: *const c_char)
-> c_int {
pub extern "C" fn rename(old: *const c_char, new: *const c_char) -> c_int {
unimplemented!();
}
@@ -275,16 +259,12 @@ pub extern "C" fn setbuf(stream: *mut FILE, buf: *mut c_char) {
}
#[no_mangle]
pub extern "C" fn setvbuf(stream: *mut FILE, buf: *mut c_char,
mode: c_int, size: usize)
-> c_int {
pub extern "C" fn setvbuf(stream: *mut FILE, buf: *mut c_char, mode: c_int, size: usize) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn tempnam(dir: *const c_char,
pfx: *const c_char)
-> *mut c_char {
pub extern "C" fn tempnam(dir: *const c_char, pfx: *const c_char) -> *mut c_char {
unimplemented!();
}
@@ -294,14 +274,12 @@ pub extern "C" fn tmpfile() -> *mut FILE {
}
#[no_mangle]
pub extern "C" fn tmpnam(s: *mut c_char)
-> *mut c_char {
pub extern "C" fn tmpnam(s: *mut c_char) -> *mut c_char {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn ungetc(c: c_int, stream: *mut FILE)
-> c_int {
pub extern "C" fn ungetc(c: c_int, stream: *mut FILE) -> c_int {
unimplemented!();
}
@@ -316,21 +294,15 @@ pub unsafe extern "C" fn vprintf(format: *const c_char, ap: va_list) -> c_int {
}
#[no_mangle]
pub extern "C" fn vsnprintf(s: *mut c_char, n: usize,
format: *const c_char,
ap: va_list) -> c_int {
pub extern "C" fn vsnprintf(s: *mut c_char, n: usize, format: *const c_char, ap: va_list) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn vsprintf(s: *mut c_char,
format: *const c_char,
ap: va_list) -> c_int {
pub extern "C" fn vsprintf(s: *mut c_char, format: *const c_char, ap: va_list) -> c_int {
unimplemented!();
}
/*
#[no_mangle]
pub extern "C" fn func(args) -> c_int {
+18 -17
View File
@@ -24,68 +24,69 @@ pub unsafe fn printf<W: fmt::Write>(mut w: W, format: *const c_char, mut ap: VaL
'%' => {
w.write_char('%');
found_percent = false;
},
}
'c' => {
let a = ap.get::<u32>();
w.write_char(a as u8 as char);
found_percent = false;
},
}
'd' | 'i' => {
let a = ap.get::<c_int>();
w.write_fmt(format_args!("{}", a));
found_percent = false;
},
}
'n' => {
let _a = ap.get::<c_int>();
found_percent = false;
},
}
'p' => {
let a = ap.get::<usize>();
w.write_fmt(format_args!("0x{:x}", a));
found_percent = false;
},
}
's' => {
let a = ap.get::<usize>();
w.write_str(str::from_utf8_unchecked(
slice::from_raw_parts(a as *const u8, strlen(a as *const c_char))
));
w.write_str(str::from_utf8_unchecked(slice::from_raw_parts(
a as *const u8,
strlen(a as *const c_char),
)));
found_percent = false;
},
}
'u' => {
let a = ap.get::<c_uint>();
w.write_fmt(format_args!("{}", a));
found_percent = false;
},
}
'x' => {
let a = ap.get::<c_uint>();
w.write_fmt(format_args!("{:x}", a));
found_percent = false;
},
}
'X' => {
let a = ap.get::<c_uint>();
w.write_fmt(format_args!("{:X}", a));
found_percent = false;
},
'-' => {},
'+' => {},
' ' => {},
'#' => {},
'0' ... '9' => {},
}
'-' => {}
'+' => {}
' ' => {}
'#' => {}
'0'...'9' => {}
_ => {}
}
} else if b == b'%' {
+2 -2
View File
@@ -6,6 +6,6 @@ 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/stdlib.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/stdlib.h");
}
+36 -11
View File
@@ -66,7 +66,13 @@ pub extern "C" fn atol(s: *const c_char) -> c_long {
}
#[no_mangle]
pub extern "C" fn bsearch(key: *const c_void, base: *const c_void, nel: size_t, width: size_t, compar: Option<extern "C" fn(*const c_void, *const c_void) -> c_int>) -> *mut c_void {
pub extern "C" fn bsearch(
key: *const c_void,
base: *const c_void,
nel: size_t,
width: size_t,
compar: Option<extern "C" fn(*const c_void, *const c_void) -> c_int>,
) -> *mut c_void {
unimplemented!();
}
@@ -76,7 +82,7 @@ pub unsafe extern "C" fn calloc(nelem: size_t, elsize: size_t) -> *mut c_void {
let size = nelem * elsize;
let ptr = malloc(size);
if ! ptr.is_null() {
if !ptr.is_null() {
intrinsics::write_bytes(ptr as *mut u8, 0, size);
}
ptr
@@ -92,7 +98,7 @@ pub struct div_t {
pub extern "C" fn div(numer: c_int, denom: c_int) -> div_t {
div_t {
quot: numer / denom,
rem: numer % denom
rem: numer % denom,
}
}
@@ -102,7 +108,12 @@ pub extern "C" fn drand48() -> c_double {
}
#[no_mangle]
pub extern "C" fn ecvt(value: c_double, ndigit: c_int, decpt: *mut c_int, sign: *mut c_int) -> *mut c_char {
pub extern "C" fn ecvt(
value: c_double,
ndigit: c_int,
decpt: *mut c_int,
sign: *mut c_int,
) -> *mut c_char {
unimplemented!();
}
@@ -125,7 +136,12 @@ pub unsafe extern "C" fn exit(status: c_int) {
}
#[no_mangle]
pub extern "C" fn fcvt(value: c_double, ndigit: c_int, decpt: *mut c_int, sign: *mut c_int) -> *mut c_char {
pub extern "C" fn fcvt(
value: c_double,
ndigit: c_int,
decpt: *mut c_int,
sign: *mut c_int,
) -> *mut c_char {
unimplemented!();
}
@@ -148,7 +164,11 @@ pub extern "C" fn getenv(name: *const c_char) -> *mut c_char {
}
#[no_mangle]
pub extern "C" fn getsubopt(optionp: *mut *mut c_char, tokens: *const *mut c_char, valuep: *mut *mut c_char) -> c_int {
pub extern "C" fn getsubopt(
optionp: *mut *mut c_char,
tokens: *const *mut c_char,
valuep: *mut *mut c_char,
) -> c_int {
unimplemented!();
}
@@ -196,7 +216,7 @@ pub struct ldiv_t {
pub extern "C" fn ldiv(numer: c_long, denom: c_long) -> ldiv_t {
ldiv_t {
quot: numer / denom,
rem: numer % denom
rem: numer % denom,
}
}
@@ -209,7 +229,7 @@ pub extern "C" fn lrand48() -> c_long {
pub unsafe extern "C" fn malloc(size: size_t) -> *mut c_void {
let align = 8;
let ptr = ralloc::alloc(size + 16, align);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align as u64;
ptr.offset(16) as *mut c_void
@@ -264,7 +284,12 @@ pub extern "C" fn putenv(s: *mut c_char) -> c_int {
}
#[no_mangle]
pub extern "C" fn qsort(base: *mut c_void, nel: size_t, width: size_t, compar: Option<extern "C" fn(*const c_void, *const c_void) -> c_int>) {
pub extern "C" fn qsort(
base: *mut c_void,
nel: size_t,
width: size_t,
compar: Option<extern "C" fn(*const c_void, *const c_void) -> c_int>,
) {
unimplemented!();
}
@@ -289,7 +314,7 @@ pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: size_t) -> *mut c_void
let old_size = *(old_ptr as *mut u64);
let align = *(old_ptr as *mut u64).offset(1);
let ptr = ralloc::realloc(old_ptr, old_size as usize, size + 16, align as usize);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align;
ptr.offset(16) as *mut c_void
@@ -367,7 +392,7 @@ pub extern "C" fn unlockpt(fildes: c_int) -> c_int {
pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
let align = 4096;
let ptr = ralloc::alloc(size + 16, align);
if ! ptr.is_null() {
if !ptr.is_null() {
*(ptr as *mut u64) = (size + 16) as u64;
*(ptr as *mut u64).offset(1) = align as u64;
ptr.offset(16) as *mut c_void
+2 -2
View File
@@ -6,6 +6,6 @@ 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/string.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/string.h");
}
+8 -40
View File
@@ -6,23 +6,13 @@ extern crate platform;
use platform::types::*;
#[no_mangle]
pub extern "C" fn memccpy(
s1: *mut c_void,
s2: *const c_void,
c: c_int,
n: usize,
) -> *mut c_void {
pub extern "C" fn memccpy(s1: *mut c_void, s2: *const c_void, c: c_int, n: usize) -> *mut c_void {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn memchr(
s: *const c_void,
c: c_int,
n: usize,
) -> *mut c_void {
pub extern "C" fn memchr(s: *const c_void, c: c_int, n: usize) -> *mut c_void {
unimplemented!();
}
@@ -108,37 +98,22 @@ pub unsafe extern "C" fn strlen(s: *const c_char) -> size_t {
}
#[no_mangle]
pub extern "C" fn strncat(
s1: *mut c_char,
s2: *const c_char,
n: usize,
) -> *mut c_char {
pub extern "C" fn strncat(s1: *mut c_char, s2: *const c_char, n: usize) -> *mut c_char {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn strncmp(
s1: *const c_char,
s2: *const c_char,
n: usize,
) -> c_int {
pub extern "C" fn strncmp(s1: *const c_char, s2: *const c_char, n: usize) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn strncpy(
s1: *mut c_char,
s2: *const c_char,
n: usize,
) -> *mut c_char {
pub extern "C" fn strncpy(s1: *mut c_char, s2: *const c_char, n: usize) -> *mut c_char {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn strpbrk(
s1: *const c_char,
s2: *const c_char,
) -> *mut c_char {
pub extern "C" fn strpbrk(s1: *const c_char, s2: *const c_char) -> *mut c_char {
unimplemented!();
}
@@ -153,10 +128,7 @@ pub extern "C" fn strspn(s1: *const c_char, s2: *const c_char) -> c_ulong {
}
#[no_mangle]
pub extern "C" fn strstr(
s1: *const c_char,
s2: *const c_char,
) -> *mut c_char {
pub extern "C" fn strstr(s1: *const c_char, s2: *const c_char) -> *mut c_char {
unimplemented!();
}
@@ -175,11 +147,7 @@ pub extern "C" fn strtok_r(
}
#[no_mangle]
pub extern "C" fn strxfrm(
s1: *mut c_char,
s2: *const c_char,
n: usize,
) -> c_ulong {
pub extern "C" fn strxfrm(s1: *mut c_char, s2: *const c_char, n: usize) -> c_ulong {
unimplemented!();
}
+2 -2
View File
@@ -6,6 +6,6 @@ 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/unistd.h");
.expect("failed to generate bindings")
.write_to_file("../../target/include/unistd.h");
}
+16 -3
View File
@@ -110,7 +110,11 @@ pub extern "C" fn execv(path: *const c_char, argv: *const *mut c_char) -> c_int
}
#[no_mangle]
pub extern "C" fn execve(path: *const c_char, argv: *const *mut c_char, envp: *const *mut c_char) -> c_int {
pub extern "C" fn execve(
path: *const c_char,
argv: *const *mut c_char,
envp: *const *mut c_char,
) -> c_int {
unimplemented!();
}
@@ -300,12 +304,21 @@ pub extern "C" fn pread(fildes: c_int, buf: *mut c_void, nbyte: size_t, offset:
}
#[no_mangle]
pub extern "C" fn pthread_atfork(prepare: Option<extern "C" fn()>, parent: Option<extern "C" fn()>, child: Option<extern "C" fn()>) -> c_int {
pub extern "C" fn pthread_atfork(
prepare: Option<extern "C" fn()>,
parent: Option<extern "C" fn()>,
child: Option<extern "C" fn()>,
) -> c_int {
unimplemented!();
}
#[no_mangle]
pub extern "C" fn pwrite(fildes: c_int, buf: *const c_void, nbyte: size_t, offset: off_t) -> ssize_t {
pub extern "C" fn pwrite(
fildes: c_int,
buf: *const c_void,
nbyte: size_t,
offset: off_t,
) -> ssize_t {
unimplemented!();
}