Run fmt.sh
This commit is contained in:
@@ -9,7 +9,6 @@ fn_single_line = false
|
||||
where_single_line = false
|
||||
imports_indent = "Visual"
|
||||
imports_layout = "Mixed"
|
||||
reorder_imports = false
|
||||
fn_args_density = "Tall"
|
||||
brace_style = "SameLineWhere"
|
||||
trailing_comma = "Vertical"
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
extern crate fenv;
|
||||
extern crate platform;
|
||||
|
||||
use platform::types::*;
|
||||
use fenv::{fegetround, FE_TONEAREST};
|
||||
use platform::types::*;
|
||||
|
||||
pub const FLT_RADIX: c_int = 2;
|
||||
|
||||
|
||||
+24
-15
@@ -1,6 +1,7 @@
|
||||
#![no_std]
|
||||
|
||||
#[macro_use] extern crate stdlib;
|
||||
#[macro_use]
|
||||
extern crate stdlib;
|
||||
extern crate ctype;
|
||||
extern crate errno;
|
||||
extern crate platform;
|
||||
@@ -17,22 +18,23 @@ pub extern "C" fn imaxabs(i: intmax_t) -> intmax_t {
|
||||
#[repr(C)]
|
||||
pub struct intmaxdiv_t {
|
||||
quot: intmax_t,
|
||||
rem: intmax_t
|
||||
rem: intmax_t,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn imaxdiv(i: intmax_t, j: intmax_t) -> intmaxdiv_t {
|
||||
intmaxdiv_t {
|
||||
quot: i / j,
|
||||
rem: i % j
|
||||
rem: i % j,
|
||||
}
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strtoimax(s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int)
|
||||
-> intmax_t {
|
||||
pub unsafe extern "C" fn strtoimax(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int,
|
||||
) -> intmax_t {
|
||||
use stdlib::*;
|
||||
strto_impl!(
|
||||
intmax_t,
|
||||
@@ -46,10 +48,11 @@ pub unsafe extern "C" fn strtoimax(s: *const c_char,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn strtoumax(s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int)
|
||||
-> uintmax_t {
|
||||
pub unsafe extern "C" fn strtoumax(
|
||||
s: *const c_char,
|
||||
endptr: *mut *mut c_char,
|
||||
base: c_int,
|
||||
) -> uintmax_t {
|
||||
use stdlib::*;
|
||||
strto_impl!(
|
||||
uintmax_t,
|
||||
@@ -64,13 +67,19 @@ pub unsafe extern "C" fn strtoumax(s: *const c_char,
|
||||
|
||||
#[allow(unused)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wcstoimax(nptr: *const wchar_t, endptr: *mut *mut wchar_t,
|
||||
base: c_int) -> intmax_t {
|
||||
pub extern "C" fn wcstoimax(
|
||||
nptr: *const wchar_t,
|
||||
endptr: *mut *mut wchar_t,
|
||||
base: c_int,
|
||||
) -> intmax_t {
|
||||
unimplemented!();
|
||||
}
|
||||
#[allow(unused)]
|
||||
#[no_mangle]
|
||||
pub extern "C" fn wcstoumax(nptr: *const wchar_t, endptr: *mut *mut wchar_t,
|
||||
base: c_int) -> uintmax_t {
|
||||
pub extern "C" fn wcstoumax(
|
||||
nptr: *const wchar_t,
|
||||
endptr: *mut *mut wchar_t,
|
||||
base: c_int,
|
||||
) -> uintmax_t {
|
||||
unimplemented!();
|
||||
}
|
||||
|
||||
+6
-2
@@ -55,11 +55,15 @@ pub extern "C" fn rust_eh_personality() {}
|
||||
#[lang = "oom"]
|
||||
#[linkage = "weak"]
|
||||
#[no_mangle]
|
||||
pub extern fn rust_oom(layout: ::core::alloc::Layout) -> ! {
|
||||
pub extern "C" fn rust_oom(layout: ::core::alloc::Layout) -> ! {
|
||||
use core::fmt::Write;
|
||||
|
||||
let mut w = platform::FileWriter(2);
|
||||
let _ = w.write_fmt(format_args!("RELIBC OOM: {} bytes aligned to {} bytes\n", layout.size(), layout.align()));
|
||||
let _ = w.write_fmt(format_args!(
|
||||
"RELIBC OOM: {} bytes aligned to {} bytes\n",
|
||||
layout.size(),
|
||||
layout.align()
|
||||
));
|
||||
|
||||
platform::exit(1);
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ static CURRENT_LOCALE: lconv = lconv {
|
||||
p_cs_precedes: c_char::max_value(),
|
||||
p_sep_by_space: c_char::max_value(),
|
||||
p_sign_posn: c_char::max_value(),
|
||||
thousands_sep: EMPTY_PTR
|
||||
thousands_sep: EMPTY_PTR,
|
||||
};
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
use core::slice;
|
||||
use core::mem;
|
||||
use syscall;
|
||||
use syscall::flag::*;
|
||||
use syscall::data::TimeSpec as redox_timespec;
|
||||
use syscall::data::Stat as redox_stat;
|
||||
use syscall::data::TimeSpec as redox_timespec;
|
||||
use syscall::flag::*;
|
||||
|
||||
use c_str;
|
||||
use errno;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub mod sys;
|
||||
#[path = "redox.rs"]
|
||||
pub mod sys;
|
||||
|
||||
pub const SIG_BLOCK: c_int = 0;
|
||||
pub const SIG_BLOCK: c_int = 0;
|
||||
pub const SIG_UNBLOCK: c_int = 1;
|
||||
pub const SIG_SETMASK: c_int = 2;
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use core::sync::atomic::AtomicBool;
|
||||
use core::cell::UnsafeCell;
|
||||
use super::{constants, BUFSIZ, FILE, UNGET};
|
||||
use core::cell::UnsafeCell;
|
||||
use core::sync::atomic::AtomicBool;
|
||||
|
||||
struct GlobalFile(UnsafeCell<FILE>);
|
||||
impl GlobalFile {
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
use super::{internal, BUFSIZ, FILE, UNGET};
|
||||
use ralloc;
|
||||
use core::{mem, ptr};
|
||||
use core::sync::atomic::AtomicBool;
|
||||
use platform::types::*;
|
||||
use super::constants::*;
|
||||
use super::{internal, BUFSIZ, FILE, UNGET};
|
||||
use core::sync::atomic::AtomicBool;
|
||||
use core::{mem, ptr};
|
||||
use errno;
|
||||
use fcntl::*;
|
||||
use platform;
|
||||
use errno;
|
||||
use platform::types::*;
|
||||
use ralloc;
|
||||
|
||||
/// Parse mode flags as a string and output a mode flags integer
|
||||
pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 {
|
||||
@@ -39,8 +39,8 @@ pub unsafe fn parse_mode_flags(mode_str: *const c_char) -> i32 {
|
||||
|
||||
/// Open a file with the file descriptor `fd` in the mode `mode`
|
||||
pub unsafe fn _fdopen(fd: c_int, mode: *const c_char) -> Option<*mut FILE> {
|
||||
use string::strchr;
|
||||
use core::mem::size_of;
|
||||
use string::strchr;
|
||||
if *mode != b'r' as i8 && *mode != b'w' as i8 && *mode != b'a' as i8 {
|
||||
platform::errno = errno::EINVAL;
|
||||
return None;
|
||||
|
||||
+18
-18
@@ -16,15 +16,15 @@ extern crate ralloc;
|
||||
extern crate string;
|
||||
extern crate va_list as vl;
|
||||
|
||||
use core::{str,ptr,mem};
|
||||
use core::fmt::{self, Error, Result};
|
||||
use core::fmt::Write as WriteFmt;
|
||||
use core::fmt::{self, Error, Result};
|
||||
use core::sync::atomic::{AtomicBool, Ordering};
|
||||
use core::{mem, ptr, str};
|
||||
|
||||
use alloc::vec::Vec;
|
||||
use errno::STR_ERROR;
|
||||
use platform::types::*;
|
||||
use platform::{c_str, errno, Read, Write};
|
||||
use alloc::vec::Vec;
|
||||
use vl::VaList as va_list;
|
||||
|
||||
mod printf;
|
||||
@@ -44,14 +44,14 @@ mod internal;
|
||||
/// This struct gets exposed to the C API.
|
||||
///
|
||||
pub struct FILE {
|
||||
flags: i32,
|
||||
read: Option<(usize, usize)>,
|
||||
write: Option<(usize, usize, usize)>,
|
||||
fd: c_int,
|
||||
buf: Vec<u8>,
|
||||
flags: i32,
|
||||
read: Option<(usize, usize)>,
|
||||
write: Option<(usize, usize, usize)>,
|
||||
fd: c_int,
|
||||
buf: Vec<u8>,
|
||||
buf_char: i8,
|
||||
lock: AtomicBool,
|
||||
unget: usize,
|
||||
lock: AtomicBool,
|
||||
unget: usize,
|
||||
}
|
||||
|
||||
impl FILE {
|
||||
@@ -142,11 +142,7 @@ impl FILE {
|
||||
unreachable!()
|
||||
}
|
||||
pub fn read(&mut self, buf: &mut [u8]) -> usize {
|
||||
let adj = if self.buf.len() > 0 {
|
||||
0
|
||||
} else {
|
||||
1
|
||||
};
|
||||
let adj = if self.buf.len() > 0 { 0 } else { 1 };
|
||||
let mut file_buf = &mut self.buf[self.unget..];
|
||||
let count = if buf.len() <= 1 + adj {
|
||||
platform::read(self.fd, &mut file_buf)
|
||||
@@ -357,7 +353,7 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
|
||||
'outer: while stream.read(&mut []) == 0 && stream.flags & F_ERR == 0 {
|
||||
if let Some((rpos, rend)) = stream.read {
|
||||
let mut idiff = 0usize;
|
||||
for _ in (0..(len-1) as usize).take_while(|x| rpos + x < rend) {
|
||||
for _ in (0..(len - 1) as usize).take_while(|x| rpos + x < rend) {
|
||||
let pos = (n - len) as usize;
|
||||
st[pos] = stream.buf[rpos + idiff] as i8;
|
||||
idiff += 1;
|
||||
@@ -366,7 +362,7 @@ pub extern "C" fn fgets(s: *mut c_char, n: c_int, stream: &mut FILE) -> *mut c_c
|
||||
break 'outer;
|
||||
}
|
||||
}
|
||||
stream.read = Some((rpos+idiff, rend));
|
||||
stream.read = Some((rpos + idiff, rend));
|
||||
if len <= 1 {
|
||||
break;
|
||||
}
|
||||
@@ -586,7 +582,11 @@ pub extern "C" fn fseeko(stream: &mut FILE, offset: off_t, whence: c_int) -> c_i
|
||||
/// Seek to a position `pos` in the file from the beginning of the file
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn fsetpos(stream: &mut FILE, pos: Option<&fpos_t>) -> c_int {
|
||||
fseek(stream, *pos.expect("You must specify a valid position"), SEEK_SET)
|
||||
fseek(
|
||||
stream,
|
||||
*pos.expect("You must specify a valid position"),
|
||||
SEEK_SET,
|
||||
)
|
||||
}
|
||||
|
||||
/// Get the current position of the cursor in the file
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use core::{slice, str};
|
||||
|
||||
use platform::{self, Write};
|
||||
use platform::types::*;
|
||||
use platform::{self, Write};
|
||||
use vl::VaList;
|
||||
|
||||
pub unsafe fn printf<W: Write>(mut w: W, format: *const c_char, mut ap: VaList) -> c_int {
|
||||
@@ -97,7 +97,8 @@ pub unsafe fn printf<W: Write>(mut w: W, format: *const c_char, mut ap: VaList)
|
||||
'#' => Ok(()),
|
||||
'0'...'9' => Ok(()),
|
||||
_ => Ok(()),
|
||||
}.is_err() {
|
||||
}.is_err()
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
} else if b == b'%' {
|
||||
|
||||
+112
-62
@@ -14,7 +14,7 @@ enum IntKind {
|
||||
LongLong,
|
||||
IntMax,
|
||||
PtrDiff,
|
||||
Size
|
||||
Size,
|
||||
}
|
||||
|
||||
/// Helper function for progressing a C string
|
||||
@@ -28,7 +28,11 @@ unsafe fn next_byte(string: &mut *const c_char) -> Result<u8, c_int> {
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaList) -> Result<c_int, c_int> {
|
||||
unsafe fn inner_scanf<R: Read>(
|
||||
mut r: R,
|
||||
mut format: *const c_char,
|
||||
mut ap: VaList,
|
||||
) -> Result<c_int, c_int> {
|
||||
let mut matched = 0;
|
||||
let mut byte = 0;
|
||||
let mut skip_read = false;
|
||||
@@ -37,9 +41,11 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
macro_rules! read {
|
||||
() => {{
|
||||
let n = r.read_u8(&mut byte);
|
||||
if n { count += 1; }
|
||||
if n {
|
||||
count += 1;
|
||||
}
|
||||
n
|
||||
}}
|
||||
}};
|
||||
}
|
||||
|
||||
macro_rules! maybe_read {
|
||||
@@ -100,7 +106,7 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
} else {
|
||||
match width.parse::<usize>() {
|
||||
Ok(n) => Some(n),
|
||||
Err(_) => return Err(-1)
|
||||
Err(_) => return Err(-1),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,7 +123,7 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
b'q' | b'L' => IntKind::LongLong,
|
||||
b't' => IntKind::PtrDiff,
|
||||
b'z' => IntKind::Size,
|
||||
_ => break
|
||||
_ => break,
|
||||
};
|
||||
|
||||
c = next_byte(&mut format)?;
|
||||
@@ -139,8 +145,9 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
} else if !read!() {
|
||||
return Ok(matched);
|
||||
}
|
||||
},
|
||||
b'd' | b'i' | b'o' | b'u' | b'x' | b'X' | b'f' | b'e' | b'g' | b'E' | b'a' | b'p' => {
|
||||
}
|
||||
b'd' | b'i' | b'o' | b'u' | b'x' | b'X' | b'f' | b'e' | b'g' | b'E' | b'a'
|
||||
| b'p' => {
|
||||
while (byte as char).is_whitespace() {
|
||||
if !read!() {
|
||||
return Ok(matched);
|
||||
@@ -162,13 +169,18 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
let mut dot = false;
|
||||
|
||||
while width.map(|w| w > 0).unwrap_or(true)
|
||||
&& ((byte >= b'0' && byte <= b'7')
|
||||
|| (radix >= 10 && (byte >= b'8' && byte <= b'9'))
|
||||
|| (float && !dot && byte == b'.')
|
||||
|| (radix == 16 && ((byte >= b'a' && byte <= b'f')
|
||||
|| (byte >= b'A' && byte <= b'F')))) {
|
||||
if auto && n.is_empty() && byte == b'0'
|
||||
&& width.map(|w| w > 0).unwrap_or(true) {
|
||||
&& ((byte >= b'0' && byte <= b'7')
|
||||
|| (radix >= 10 && (byte >= b'8' && byte <= b'9'))
|
||||
|| (float && !dot && byte == b'.')
|
||||
|| (radix == 16
|
||||
&& ((byte >= b'a' && byte <= b'f')
|
||||
|| (byte >= b'A' && byte <= b'F'))))
|
||||
{
|
||||
if auto
|
||||
&& n.is_empty()
|
||||
&& byte == b'0'
|
||||
&& width.map(|w| w > 0).unwrap_or(true)
|
||||
{
|
||||
if !pointer {
|
||||
radix = 8;
|
||||
}
|
||||
@@ -176,7 +188,9 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
if !read!() {
|
||||
break;
|
||||
}
|
||||
if width.map(|w| w > 0).unwrap_or(true) && (byte == b'x' || byte == b'X') {
|
||||
if width.map(|w| w > 0).unwrap_or(true)
|
||||
&& (byte == b'x' || byte == b'X')
|
||||
{
|
||||
radix = 16;
|
||||
width = width.map(|w| w - 1);
|
||||
if width.map(|w| w > 0).unwrap_or(true) {
|
||||
@@ -201,33 +215,37 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
}
|
||||
|
||||
macro_rules! parse_type {
|
||||
(noformat $type:ident) => {
|
||||
{
|
||||
let n = if n.is_empty() { 0 as $type } else {
|
||||
n.parse::<$type>()
|
||||
.map_err(|_| 0)?
|
||||
};
|
||||
if !ignore {
|
||||
*ap.get::<*mut $type>() = n;
|
||||
matched += 1;
|
||||
}
|
||||
(noformat $type:ident) => {{
|
||||
let n = if n.is_empty() {
|
||||
0 as $type
|
||||
} else {
|
||||
n.parse::<$type>().map_err(|_| 0)?
|
||||
};
|
||||
if !ignore {
|
||||
*ap.get::<*mut $type>() = n;
|
||||
matched += 1;
|
||||
}
|
||||
}};
|
||||
(c_double) => {
|
||||
parse_type!(noformat c_double);
|
||||
};
|
||||
(c_double) => { parse_type!(noformat c_double); };
|
||||
(c_float) => { parse_type!(noformat c_float); };
|
||||
($type:ident) => { parse_type!($type, $type); };
|
||||
($type:ident, $final:ty) => {
|
||||
{
|
||||
let n = if n.is_empty() { 0 as $type } else {
|
||||
$type::from_str_radix(&n, radix)
|
||||
.map_err(|_| 0)?
|
||||
};
|
||||
if !ignore {
|
||||
*ap.get::<*mut $final>() = n as $final;
|
||||
matched += 1;
|
||||
}
|
||||
(c_float) => {
|
||||
parse_type!(noformat c_float);
|
||||
};
|
||||
($type:ident) => {
|
||||
parse_type!($type, $type);
|
||||
};
|
||||
($type:ident, $final:ty) => {{
|
||||
let n = if n.is_empty() {
|
||||
0 as $type
|
||||
} else {
|
||||
$type::from_str_radix(&n, radix).map_err(|_| 0)?
|
||||
};
|
||||
if !ignore {
|
||||
*ap.get::<*mut $final>() = n as $final;
|
||||
matched += 1;
|
||||
}
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
||||
if float {
|
||||
@@ -277,10 +295,10 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
parse_type!(size_t)
|
||||
} else {
|
||||
parse_type!(ssize_t)
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
},
|
||||
}
|
||||
b's' => {
|
||||
while (byte as char).is_whitespace() {
|
||||
if !read!() {
|
||||
@@ -307,7 +325,7 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
*ptr = 0;
|
||||
matched += 1;
|
||||
}
|
||||
},
|
||||
}
|
||||
b'c' => {
|
||||
let mut ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.get()) };
|
||||
|
||||
@@ -326,7 +344,7 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
if ptr.is_some() {
|
||||
matched += 1;
|
||||
}
|
||||
},
|
||||
}
|
||||
b'[' => {
|
||||
c = next_byte(&mut format)?;
|
||||
|
||||
@@ -363,7 +381,8 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
|
||||
let mut ptr: Option<*mut c_char> = if ignore { None } else { Some(ap.get()) };
|
||||
|
||||
while width.map(|w| w > 0).unwrap_or(true) && !invert == matches.contains(&byte) {
|
||||
while width.map(|w| w > 0).unwrap_or(true) && !invert == matches.contains(&byte)
|
||||
{
|
||||
if let Some(ref mut ptr) = ptr {
|
||||
**ptr = byte as c_char;
|
||||
*ptr = ptr.offset(1);
|
||||
@@ -380,13 +399,13 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
*ptr = 0;
|
||||
matched += 1;
|
||||
}
|
||||
},
|
||||
}
|
||||
b'n' => {
|
||||
if !ignore {
|
||||
*ap.get::<*mut c_int>() = count as c_int;
|
||||
}
|
||||
},
|
||||
_ => return Err(-1)
|
||||
}
|
||||
_ => return Err(-1),
|
||||
}
|
||||
|
||||
if width != Some(0) && c != b'n' {
|
||||
@@ -401,7 +420,7 @@ unsafe fn inner_scanf<R: Read>(mut r: R, mut format: *const c_char, mut ap: VaLi
|
||||
pub unsafe fn scanf<R: Read>(r: R, format: *const c_char, ap: VaList) -> c_int {
|
||||
match inner_scanf(r, format, ap) {
|
||||
Ok(n) => n,
|
||||
Err(n) => n
|
||||
Err(n) => n,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -420,7 +439,19 @@ macro_rules! va_primitives {
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
va_primitives!(c_uchar, c_ushort, c_uint, c_ulong, c_char, c_short, c_int, c_long, c_float, c_double, *mut c_void);
|
||||
va_primitives!(
|
||||
c_uchar,
|
||||
c_ushort,
|
||||
c_uint,
|
||||
c_ulong,
|
||||
c_char,
|
||||
c_short,
|
||||
c_int,
|
||||
c_long,
|
||||
c_float,
|
||||
c_double,
|
||||
*mut c_void
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
trait FromVoidPtr {
|
||||
@@ -437,21 +468,31 @@ macro_rules! from_void_ptr {
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
from_void_ptr!(c_uchar, c_ushort, c_uint, c_ulong, c_char, c_short, c_int, c_long, c_float, c_double,
|
||||
size_t, ssize_t, *mut c_void);
|
||||
from_void_ptr!(
|
||||
c_uchar,
|
||||
c_ushort,
|
||||
c_uint,
|
||||
c_ulong,
|
||||
c_char,
|
||||
c_short,
|
||||
c_int,
|
||||
c_long,
|
||||
c_float,
|
||||
c_double,
|
||||
size_t,
|
||||
ssize_t,
|
||||
*mut c_void
|
||||
);
|
||||
|
||||
#[cfg(test)]
|
||||
pub struct VaList<'a> {
|
||||
args: &'a mut [&'a mut VaPrimitive],
|
||||
i: usize
|
||||
i: usize,
|
||||
}
|
||||
#[cfg(test)]
|
||||
impl<'a> VaList<'a> {
|
||||
pub fn new(args: &'a mut [&'a mut VaPrimitive]) -> VaList<'a> {
|
||||
VaList {
|
||||
args: args,
|
||||
i: 0
|
||||
}
|
||||
VaList { args: args, i: 0 }
|
||||
}
|
||||
pub fn get<T: FromVoidPtr>(&mut self) -> T {
|
||||
let ptr = T::from_void_ptr(self.args[self.i].as_mut_ptr());
|
||||
@@ -462,17 +503,20 @@ impl<'a> VaList<'a> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use core::ptr;
|
||||
use platform::StringReader;
|
||||
use super::*;
|
||||
|
||||
fn scanf<'a>(format: &str, args: &'a mut [&'a mut VaPrimitive], input: &str) -> c_int {
|
||||
unsafe {
|
||||
let mut format = format.to_string();
|
||||
let format = format.as_bytes_mut();
|
||||
let format = format.as_mut_ptr();
|
||||
let out = super::inner_scanf(StringReader(input.as_bytes()), format as *mut c_char, VaList::new(args))
|
||||
.expect("running test scanf failed");
|
||||
let out = super::inner_scanf(
|
||||
StringReader(input.as_bytes()),
|
||||
format as *mut c_char,
|
||||
VaList::new(args),
|
||||
).expect("running test scanf failed");
|
||||
out
|
||||
}
|
||||
}
|
||||
@@ -490,7 +534,10 @@ mod tests {
|
||||
let mut a: c_uint = 0;
|
||||
let mut b: c_int = 0;
|
||||
let mut c: c_int = 0;
|
||||
assert_eq!(scanf("%x %i %i\0", &mut [&mut a, &mut b, &mut c], "12 0x345 010"), 3);
|
||||
assert_eq!(
|
||||
scanf("%x %i %i\0", &mut [&mut a, &mut b, &mut c], "12 0x345 010"),
|
||||
3
|
||||
);
|
||||
assert_eq!(a, 0x12);
|
||||
assert_eq!(b, 0x345);
|
||||
assert_eq!(c, 0o10);
|
||||
@@ -535,7 +582,10 @@ mod tests {
|
||||
fn count() {
|
||||
let mut a: c_int = 0;
|
||||
let mut b: c_int = 0;
|
||||
assert_eq!(scanf("test: %2i%n\0", &mut [&mut a, &mut b], "test: 0xFF"), 1);
|
||||
assert_eq!(
|
||||
scanf("test: %2i%n\0", &mut [&mut a, &mut b], "test: 0xFF"),
|
||||
1
|
||||
);
|
||||
assert_eq!(a, 0);
|
||||
assert_eq!(b, 8);
|
||||
}
|
||||
|
||||
+14
-14
@@ -8,17 +8,17 @@ extern crate errno;
|
||||
extern crate platform;
|
||||
extern crate ralloc;
|
||||
extern crate rand;
|
||||
extern crate string;
|
||||
extern crate time;
|
||||
extern crate wchar;
|
||||
extern crate string;
|
||||
|
||||
use core::{ptr, str};
|
||||
use rand::{Rng, SeedableRng};
|
||||
use rand::rngs::JitterRng;
|
||||
use rand::prng::XorShiftRng;
|
||||
use rand::distributions::Alphanumeric;
|
||||
use wchar::*;
|
||||
use rand::prng::XorShiftRng;
|
||||
use rand::rngs::JitterRng;
|
||||
use rand::{Rng, SeedableRng};
|
||||
use string::*;
|
||||
use wchar::*;
|
||||
|
||||
use errno::*;
|
||||
use platform::types::*;
|
||||
@@ -361,18 +361,18 @@ pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_voi
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int {
|
||||
let mut wc : wchar_t = 0;
|
||||
let mut state : mbstate_t = mbstate_t { };
|
||||
let result : usize = mbrtowc(&mut wc, s, n, &mut state);
|
||||
let mut wc: wchar_t = 0;
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
let result: usize = mbrtowc(&mut wc, s, n, &mut state);
|
||||
|
||||
if result == -1isize as usize {
|
||||
if result == -1isize as usize {
|
||||
return -1;
|
||||
}
|
||||
if result == -2isize as usize {
|
||||
if result == -2isize as usize {
|
||||
return -1;
|
||||
}
|
||||
|
||||
result as i32
|
||||
|
||||
result as i32
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
@@ -387,9 +387,9 @@ pub extern "C" fn mbtowc(pwc: *mut wchar_t, s: *const c_char, n: size_t) -> c_in
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn mktemp(name: *mut c_char) -> *mut c_char {
|
||||
use core::slice;
|
||||
use core::iter;
|
||||
use core::mem;
|
||||
use core::slice;
|
||||
let len = unsafe { strlen(name) };
|
||||
if len < 6 {
|
||||
unsafe { platform::errno = errno::EINVAL };
|
||||
@@ -851,7 +851,7 @@ pub extern "C" fn wcstombs(s: *mut c_char, pwcs: *mut *const wchar_t, n: size_t)
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn wctomb(s: *mut c_char, wc: wchar_t) -> c_int {
|
||||
let mut state : mbstate_t = mbstate_t {};
|
||||
let mut state: mbstate_t = mbstate_t {};
|
||||
let result: usize = wcrtomb(s, wc, &mut state);
|
||||
|
||||
if result == -1isize as usize {
|
||||
|
||||
@@ -5,12 +5,12 @@ extern crate errno;
|
||||
extern crate platform;
|
||||
extern crate ralloc;
|
||||
|
||||
use platform::types::*;
|
||||
use errno::*;
|
||||
use core::cmp;
|
||||
use core::usize;
|
||||
use core::ptr;
|
||||
use core::mem;
|
||||
use core::ptr;
|
||||
use core::usize;
|
||||
use errno::*;
|
||||
use platform::types::*;
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn memccpy(
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
mod inner {
|
||||
extern crate platform;
|
||||
|
||||
use core::ptr;
|
||||
use self::platform::types::*;
|
||||
use core::ptr;
|
||||
|
||||
const LENGTH: usize = 65;
|
||||
|
||||
@@ -15,12 +15,12 @@ mod inner {
|
||||
#[no_mangle]
|
||||
#[repr(C)]
|
||||
pub struct utsname {
|
||||
pub sysname: [c_char; LENGTH],
|
||||
pub nodename: [c_char; LENGTH],
|
||||
pub release: [c_char; LENGTH],
|
||||
pub version: [c_char; LENGTH],
|
||||
pub machine: [c_char; LENGTH],
|
||||
pub domainname: [c_char; LENGTH]
|
||||
pub sysname: [c_char; LENGTH],
|
||||
pub nodename: [c_char; LENGTH],
|
||||
pub release: [c_char; LENGTH],
|
||||
pub version: [c_char; LENGTH],
|
||||
pub machine: [c_char; LENGTH],
|
||||
pub domainname: [c_char; LENGTH],
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
|
||||
@@ -6,8 +6,8 @@ pub mod sys;
|
||||
#[path = "redox.rs"]
|
||||
pub mod sys;
|
||||
|
||||
pub use sys::*;
|
||||
use platform::types::*;
|
||||
pub use sys::*;
|
||||
|
||||
// Move epoch from 01.01.1970 to 01.03.0000 (yes, Year 0) - this is the first
|
||||
// day of a 400-year long "era", right after additional day of leap year.
|
||||
@@ -40,7 +40,7 @@ pub(crate) const UTC: *const c_char = b"UTC\0" as *const u8 as *const c_char;
|
||||
|
||||
pub(crate) const DAY_NAMES: [&str; 7] = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
|
||||
pub(crate) const MON_NAMES: [&str; 12] = [
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec",
|
||||
];
|
||||
|
||||
pub(crate) const CLOCK_REALTIME: clockid_t = 0;
|
||||
|
||||
+2
-2
@@ -9,11 +9,11 @@ extern crate platform;
|
||||
pub mod constants;
|
||||
mod helpers;
|
||||
|
||||
use platform::types::*;
|
||||
use constants::*;
|
||||
use helpers::*;
|
||||
use core::mem::transmute;
|
||||
use errno::EIO;
|
||||
use helpers::*;
|
||||
use platform::types::*;
|
||||
|
||||
/*
|
||||
*#[repr(C)]
|
||||
|
||||
@@ -34,7 +34,8 @@ pub unsafe extern "C" fn getopt(
|
||||
-1
|
||||
} else {
|
||||
let current_arg = *argv.offset(optind as isize);
|
||||
if current_arg.is_null() || *current_arg != b'-' as c_char
|
||||
if current_arg.is_null()
|
||||
|| *current_arg != b'-' as c_char
|
||||
|| string::strcmp(current_arg, b"-\0".as_ptr() as _) == 0
|
||||
{
|
||||
-1
|
||||
|
||||
+16
-9
@@ -3,14 +3,15 @@
|
||||
#![no_std]
|
||||
#![cfg_attr(target_os = "redox", feature(alloc))]
|
||||
|
||||
#[cfg(target_os = "redox")] extern crate alloc;
|
||||
#[cfg(target_os = "redox")]
|
||||
extern crate alloc;
|
||||
extern crate platform;
|
||||
extern crate stdio;
|
||||
extern crate string;
|
||||
extern crate sys_utsname;
|
||||
|
||||
pub use platform::types::*;
|
||||
pub use getopt::*;
|
||||
pub use platform::types::*;
|
||||
|
||||
use core::ptr;
|
||||
|
||||
@@ -132,13 +133,15 @@ pub unsafe extern "C" fn execve(
|
||||
argv: *const *mut c_char,
|
||||
envp: *const *mut c_char,
|
||||
) -> c_int {
|
||||
#[cfg(target_os = "linux")] {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
platform::execve(path, argv, envp)
|
||||
}
|
||||
#[cfg(target_os = "redox")] {
|
||||
#[cfg(target_os = "redox")]
|
||||
{
|
||||
use alloc::Vec;
|
||||
use platform::{c_str, e};
|
||||
use platform::syscall::flag::*;
|
||||
use platform::{c_str, e};
|
||||
|
||||
let mut env = envp;
|
||||
while !(*env).is_null() {
|
||||
@@ -275,7 +278,8 @@ pub extern "C" fn gethostid() -> c_long {
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn gethostname(mut name: *mut c_char, len: size_t) -> c_int {
|
||||
#[cfg(target_os = "linux")] {
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
use core::mem;
|
||||
|
||||
// len only needs to be mutable on linux
|
||||
@@ -288,7 +292,9 @@ pub unsafe extern "C" fn gethostname(mut name: *mut c_char, len: size_t) -> c_in
|
||||
return err;
|
||||
}
|
||||
for c in uts.nodename.iter() {
|
||||
if len == 0 { break; }
|
||||
if len == 0 {
|
||||
break;
|
||||
}
|
||||
len -= 1;
|
||||
|
||||
*name = *c;
|
||||
@@ -301,9 +307,10 @@ pub unsafe extern "C" fn gethostname(mut name: *mut c_char, len: size_t) -> c_in
|
||||
name = name.offset(1);
|
||||
}
|
||||
}
|
||||
#[cfg(target_os = "redox")] {
|
||||
use platform::{e, FileReader, Read};
|
||||
#[cfg(target_os = "redox")]
|
||||
{
|
||||
use platform::syscall::flag::*;
|
||||
use platform::{e, FileReader, Read};
|
||||
|
||||
let fd = e(platform::syscall::open("/etc/hostname", O_RDONLY)) as i32;
|
||||
if fd < 0 {
|
||||
|
||||
@@ -9,11 +9,11 @@ extern crate stdio;
|
||||
extern crate time;
|
||||
extern crate va_list as vl;
|
||||
|
||||
use platform::types::*;
|
||||
use time::*;
|
||||
use core::usize;
|
||||
use core::ptr;
|
||||
use core::usize;
|
||||
use platform::types::*;
|
||||
use stdio::*;
|
||||
use time::*;
|
||||
use vl::VaList as va_list;
|
||||
|
||||
mod utf8;
|
||||
|
||||
@@ -4,9 +4,9 @@
|
||||
extern crate errno;
|
||||
extern crate platform;
|
||||
|
||||
use platform::types::*;
|
||||
use core::{char, slice, str, usize};
|
||||
use mbstate_t;
|
||||
use core::{slice,str,usize,char};
|
||||
use platform::types::*;
|
||||
|
||||
//It's guaranteed that we don't have any nullpointers here
|
||||
pub unsafe fn mbrtowc(pwc: *mut wchar_t, s: *const c_char, n: usize, ps: *mut mbstate_t) -> usize {
|
||||
|
||||
Reference in New Issue
Block a user