add and test ByteLiteral abstraction

This commit is contained in:
auronandace
2026-06-11 17:19:33 +01:00
parent 40767a44fa
commit 2e72022a26
3 changed files with 24 additions and 1 deletions
+21
View File
@@ -0,0 +1,21 @@
use crate::platform::types::c_char;
pub struct ByteLiteral(u8);
impl ByteLiteral {
pub fn cast_unchecked(input: u8) -> c_char {
match input {
b' '..=b'~' => {
#[cfg(any(target_arch = "x86_64", target_arch = "x86"))]
{
input.cast_signed()
}
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
{
input.cast_unsigned()
}
},
_ => panic!("Not a printable ascii character!"),
}
}
}
+2 -1
View File
@@ -6,6 +6,7 @@
//! See <https://github.com/kraj/musl/blob/kraj/master/src/misc/fmtmsg.c>
use crate::{
byte_literal::ByteLiteral,
header::{
fcntl::{O_WRONLY, open},
pthread::{PTHREAD_CANCEL_DISABLE, pthread_setcancelstate},
@@ -77,7 +78,7 @@ unsafe fn strcolcmp(mut lstr: *const c_char, mut bstr: *const c_char) -> c_int {
lstr = lstr.add(1);
bstr = bstr.add(1);
}
if *lstr != 0 || (*bstr != 0 && *bstr != b':'.cast_signed()) {
if *lstr != 0 || (*bstr != 0 && *bstr != ByteLiteral::cast_unchecked(b':')) {
1
} else {
0
+1
View File
@@ -36,6 +36,7 @@ extern crate syscall;
#[macro_use]
mod macros;
pub mod byte_literal;
pub mod c_str;
pub mod c_vec;
pub mod cxa;