mirror of https://github.com/tailix/libkernaux.git
Rust: add func "kernaux_itoa10"
This commit is contained in:
parent
fa0523c024
commit
caabdccdb9
|
@ -5,6 +5,8 @@ use libc::c_char;
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn kernaux_utoa10(value: u64, buffer: *mut c_char);
|
fn kernaux_utoa10(value: u64, buffer: *mut c_char);
|
||||||
|
#[cfg(test)]
|
||||||
|
fn kernaux_itoa10(value: i64, buffer: *mut c_char);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -21,4 +23,19 @@ mod tests {
|
||||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
assert_eq!(result, "123");
|
assert_eq!(result, "123");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn itoa10() {
|
||||||
|
let mut buffer: [i8; 1000] = [0; 1000];
|
||||||
|
unsafe { kernaux_itoa10(123, buffer.as_mut_ptr()) };
|
||||||
|
let result =
|
||||||
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
assert_eq!(result, "123");
|
||||||
|
|
||||||
|
let mut buffer: [i8; 1000] = [0; 1000];
|
||||||
|
unsafe { kernaux_itoa10(-123, buffer.as_mut_ptr()) };
|
||||||
|
let result =
|
||||||
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
assert_eq!(result, "-123");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue