mirror of https://github.com/tailix/libkernaux.git
Rust: add constants
This commit is contained in:
parent
e032b1df8e
commit
4cc8674411
|
@ -1,5 +1,12 @@
|
||||||
use libc::{c_char, c_int};
|
use libc::{c_char, c_int};
|
||||||
|
|
||||||
|
pub const UTOA_BUFFER_SIZE: usize = 65;
|
||||||
|
pub const ITOA_BUFFER_SIZE: usize = 66;
|
||||||
|
pub const UTOA10_BUFFER_SIZE: usize = 21;
|
||||||
|
pub const ITOA10_BUFFER_SIZE: usize = 21;
|
||||||
|
pub const UTOA16_BUFFER_SIZE: usize = 17;
|
||||||
|
pub const ITOA16_BUFFER_SIZE: usize = 18;
|
||||||
|
|
||||||
#[link(name = "kernaux")]
|
#[link(name = "kernaux")]
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#[link_name = "kernaux_utoa"]
|
#[link_name = "kernaux_utoa"]
|
||||||
|
@ -24,7 +31,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_utoa() {
|
fn test_utoa() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; UTOA_BUFFER_SIZE] = [0; UTOA_BUFFER_SIZE];
|
||||||
let end: *mut c_char =
|
let end: *mut c_char =
|
||||||
unsafe { utoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
|
unsafe { utoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
|
||||||
let result =
|
let result =
|
||||||
|
@ -35,7 +42,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_itoa() {
|
fn test_itoa() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; ITOA_BUFFER_SIZE] = [0; ITOA_BUFFER_SIZE];
|
||||||
let end: *mut c_char =
|
let end: *mut c_char =
|
||||||
unsafe { itoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
|
unsafe { itoa(0x123, buffer.as_mut_ptr(), 'x' as c_int) };
|
||||||
let result =
|
let result =
|
||||||
|
@ -54,7 +61,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_utoa10() {
|
fn test_utoa10() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; UTOA10_BUFFER_SIZE] = [0; UTOA10_BUFFER_SIZE];
|
||||||
unsafe { utoa10(123, buffer.as_mut_ptr()) };
|
unsafe { utoa10(123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
@ -63,13 +70,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_itoa10() {
|
fn test_itoa10() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; ITOA10_BUFFER_SIZE] = [0; ITOA10_BUFFER_SIZE];
|
||||||
unsafe { itoa10(123, buffer.as_mut_ptr()) };
|
unsafe { itoa10(123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
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");
|
||||||
|
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; ITOA10_BUFFER_SIZE] = [0; ITOA10_BUFFER_SIZE];
|
||||||
unsafe { itoa10(-123, buffer.as_mut_ptr()) };
|
unsafe { itoa10(-123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
@ -78,7 +85,7 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_utoa16() {
|
fn test_utoa16() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; UTOA16_BUFFER_SIZE] = [0; UTOA16_BUFFER_SIZE];
|
||||||
unsafe { utoa16(0x123, buffer.as_mut_ptr()) };
|
unsafe { utoa16(0x123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
@ -87,13 +94,13 @@ mod tests {
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_itoa16() {
|
fn test_itoa16() {
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; ITOA16_BUFFER_SIZE] = [0; ITOA16_BUFFER_SIZE];
|
||||||
unsafe { itoa16(0x123, buffer.as_mut_ptr()) };
|
unsafe { itoa16(0x123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
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");
|
||||||
|
|
||||||
let mut buffer: [i8; 1000] = [0; 1000];
|
let mut buffer: [i8; ITOA16_BUFFER_SIZE] = [0; ITOA16_BUFFER_SIZE];
|
||||||
unsafe { itoa16(-0x123, buffer.as_mut_ptr()) };
|
unsafe { itoa16(-0x123, buffer.as_mut_ptr()) };
|
||||||
let result =
|
let result =
|
||||||
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
unsafe { CStr::from_ptr(buffer.as_ptr()) }.to_str().unwrap();
|
||||||
|
|
Loading…
Reference in New Issue