replaced references to core with references to crate
This commit is contained in:
parent
ca16d4aa80
commit
42bb7655ba
@ -68,7 +68,7 @@ impl Args {
|
||||
///On error returns pair: `(string index, Utf8Error)`
|
||||
///
|
||||
///The function is safe as long as you pass C style main function arguments.
|
||||
pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result<Self, (usize, core::str::Utf8Error)> {
|
||||
pub unsafe fn new(argc: isize, argv: *const *const u8) -> Result<Self, (usize, crate::str::Utf8Error)> {
|
||||
assert!(argc > 0);
|
||||
assert!(!argv.is_null());
|
||||
|
||||
@ -102,7 +102,7 @@ impl Args {
|
||||
///Returns slice of raw C strings
|
||||
pub fn as_slice(&self) -> &[*const u8] {
|
||||
unsafe {
|
||||
core::slice::from_raw_parts(self.argv, self.argc)
|
||||
crate::slice::from_raw_parts(self.argv, self.argc)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -79,10 +79,10 @@ unsafe fn invalid_cli_args_error() -> libc::c_int {
|
||||
///Converts C string to Rust's, verifying it is UTF-8
|
||||
///
|
||||
///It is UB to pass non-C string as it requires \0
|
||||
pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::Utf8Error> {
|
||||
pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, crate::str::Utf8Error> {
|
||||
let len = libc::strlen(ptr as *const i8);
|
||||
let parts = core::slice::from_raw_parts(ptr, len);
|
||||
core::str::from_utf8(parts)
|
||||
let parts = crate::slice::from_raw_parts(ptr, len);
|
||||
crate::str::from_utf8(parts)
|
||||
}
|
||||
|
||||
///Converts C string to Rust's one assuming it is UTF-8
|
||||
@ -90,8 +90,8 @@ pub unsafe fn c_str_to_rust(ptr: *const u8) -> Result<&'static str, core::str::U
|
||||
///It is UB to pass non-C string as it requires \0
|
||||
pub unsafe fn c_str_to_rust_unchecked(ptr: *const u8) -> &'static str {
|
||||
let len = libc::strlen(ptr as *const i8);
|
||||
let parts = core::slice::from_raw_parts(ptr, len);
|
||||
core::str::from_utf8_unchecked(parts)
|
||||
let parts = crate::slice::from_raw_parts(ptr, len);
|
||||
crate::str::from_utf8_unchecked(parts)
|
||||
}
|
||||
|
||||
extern "Rust" {
|
||||
|
@ -85,13 +85,10 @@
|
||||
//! # }
|
||||
//! ```
|
||||
|
||||
#![no_std]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused)]
|
||||
#![warn(unsafe_op_in_unsafe_fn)]
|
||||
|
||||
use core::{convert::TryFrom, file, line, stringify};
|
||||
|
||||
/// This forces a "C" library linkage
|
||||
#[cfg(not(windows))]
|
||||
#[link(name = "c")]
|
||||
@ -111,9 +108,9 @@ pub const __LIBC_STDERR: i32 = 2;
|
||||
#[doc(hidden)]
|
||||
pub struct __LibCWriter(i32);
|
||||
|
||||
impl core::fmt::Write for __LibCWriter {
|
||||
impl crate::fmt::Write for __LibCWriter {
|
||||
#[inline]
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
fn write_str(&mut self, s: &str) -> crate::fmt::Result {
|
||||
__libc_println(self.0, s)
|
||||
}
|
||||
}
|
||||
@ -125,24 +122,24 @@ impl __LibCWriter {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_fmt(&mut self, args: core::fmt::Arguments) -> core::fmt::Result {
|
||||
core::fmt::Write::write_fmt(self, args)
|
||||
pub fn write_fmt(&mut self, args: crate::fmt::Arguments) -> crate::fmt::Result {
|
||||
crate::fmt::Write::write_fmt(self, args)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
pub fn write_str(&mut self, s: &str) -> crate::fmt::Result {
|
||||
__libc_println(self.0, s)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn write_nl(&mut self) -> core::fmt::Result {
|
||||
pub fn write_nl(&mut self) -> crate::fmt::Result {
|
||||
__libc_println(self.0, __LIBC_NEWLINE)
|
||||
}
|
||||
}
|
||||
|
||||
#[doc(hidden)]
|
||||
#[inline]
|
||||
pub fn __libc_println(handle: i32, msg: &str) -> core::fmt::Result {
|
||||
pub fn __libc_println(handle: i32, msg: &str) -> crate::fmt::Result {
|
||||
let msg = msg.as_bytes();
|
||||
|
||||
let mut written = 0;
|
||||
@ -162,7 +159,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option<usize> {
|
||||
usize::try_from(unsafe {
|
||||
libc::write(
|
||||
handle,
|
||||
bytes.as_ptr().cast::<core::ffi::c_void>(),
|
||||
bytes.as_ptr().cast::<crate::ffi::c_void>(),
|
||||
bytes.len(),
|
||||
)
|
||||
})
|
||||
@ -174,7 +171,7 @@ unsafe fn libc_write(handle: i32, bytes: &[u8]) -> Option<usize> {
|
||||
usize::try_from(unsafe {
|
||||
libc::write(
|
||||
handle,
|
||||
bytes.as_ptr().cast::<core::ffi::c_void>(),
|
||||
bytes.as_ptr().cast::<crate::ffi::c_void>(),
|
||||
libc::c_uint::try_from(bytes.len()).unwrap_or(libc::c_uint::MAX),
|
||||
)
|
||||
})
|
||||
|
@ -35,8 +35,6 @@
|
||||
|
||||
include!(concat!(env!("OUT_DIR"), "/bindings.rs"));
|
||||
|
||||
extern crate core;
|
||||
|
||||
pub fn exit(code: u32) -> ! {
|
||||
unsafe { libc::exit(code as i32 as libc::c_int); }
|
||||
}
|
||||
|
Reference in New Issue
Block a user