Merge branch 'bitstime-crypt-ctype-cleanup' into 'master'

cleanup bits_time, crypt and ctype headers

See merge request redox-os/relibc!1025
This commit is contained in:
Jeremy Soller
2026-02-20 05:50:58 -07:00
5 changed files with 15 additions and 25 deletions
+5 -13
View File
@@ -16,12 +16,8 @@ impl timespec {
/// similar logic with timeradd
pub fn add(base: timespec, interval: timespec) -> Option<timespec> {
let Some(delta_sec) = base.tv_sec.checked_add(interval.tv_sec) else {
return None;
};
let Some(delta_nsec) = base.tv_nsec.checked_add(interval.tv_nsec) else {
return None;
};
let delta_sec = base.tv_sec.checked_add(interval.tv_sec)?;
let delta_nsec = base.tv_nsec.checked_add(interval.tv_nsec)?;
if delta_sec < 0 || delta_nsec < 0 {
return None;
@@ -34,12 +30,8 @@ impl timespec {
}
/// similar logic with timersub
pub fn subtract(later: timespec, earlier: timespec) -> Option<timespec> {
let Some(delta_sec) = later.tv_sec.checked_sub(earlier.tv_sec) else {
return None;
};
let Some(delta_nsec) = later.tv_nsec.checked_sub(earlier.tv_nsec) else {
return None;
};
let delta_sec = later.tv_sec.checked_sub(earlier.tv_sec)?;
let delta_nsec = later.tv_nsec.checked_sub(earlier.tv_nsec)?;
let time = if delta_nsec < 0 {
let roundup_sec = -delta_nsec / NANOSECONDS + 1;
@@ -63,7 +55,7 @@ impl timespec {
Some(time)
}
pub fn is_default(&self) -> bool {
return self.tv_nsec == 0 && self.tv_sec == 0;
self.tv_nsec == 0 && self.tv_sec == 0
}
}
+1 -1
View File
@@ -73,7 +73,7 @@ pub fn crypt_blowfish(passw: &str, setting: &str) -> Option<String> {
// We only consider the first 72 chars; truncate if necessary.
let passw_t = if vec.len() > 72 { &vec[..72] } else { &vec };
let passw: &[c_uchar] = &passw_t;
let passw: &[c_uchar] = passw_t;
let setting = setting.as_bytes();
let mut output = vec![0; BHASH_OUTPUT_SIZE + 1];
+2 -2
View File
@@ -1,7 +1,7 @@
use super::gen_salt;
use alloc::string::{String, ToString};
use base64ct::{Base64Bcrypt, Encoding};
use core::{str, u32};
use core::str;
use pbkdf2::pbkdf2_hmac;
use sha2::Sha256;
@@ -42,7 +42,7 @@ pub fn crypt_pbkdf2(passw: &str, setting: &str) -> Option<String> {
return None;
}
let actual_salt = if salt.len() > 0 {
let actual_salt = if !salt.is_empty() {
salt.to_string()
} else {
gen_salt()?
+4 -6
View File
@@ -2,7 +2,7 @@ use super::gen_salt;
use crate::platform::types::{c_uchar, c_uint};
use alloc::string::{String, ToString};
use base64ct::{Base64Bcrypt, Encoding};
use core::{str, u32};
use core::str;
use scrypt::{Params, scrypt};
/// Map for encoding and decoding
@@ -29,14 +29,12 @@ fn dencode_uint(value: &str) -> Option<c_uint> {
return None;
}
let result = value
value
.chars()
.enumerate()
.try_fold(0 as c_uint, |acc, (i, c)| {
acc.checked_add((to_digit(c, 30)? as c_uint) << (i * 6))
});
Some(result?)
})
}
/// Reads settings for password encryption
@@ -54,7 +52,7 @@ fn read_setting(setting: &str) -> Option<(c_uchar, c_uint, c_uint, String)> {
let p = dencode_uint(&setting[6..11])?;
let salt = &setting[11..];
let actual_salt = if salt.len() > 0 {
let actual_salt = if !salt.is_empty() {
salt.to_string()
} else {
gen_salt()?
+3 -3
View File
@@ -53,7 +53,7 @@ pub extern "C" fn isblank_l(c: c_int, _loc: locale_t) -> c_int {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl.html>.
#[unsafe(no_mangle)]
pub extern "C" fn iscntrl(c: c_int) -> c_int {
c_int::from((c >= 0x00 && c <= 0x1f) || c == 0x7f)
c_int::from((0x00..=0x1f).contains(&c) || c == 0x7f)
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/iscntrl_l.html>.
@@ -77,7 +77,7 @@ pub extern "C" fn isdigit_l(c: c_int, _loc: locale_t) -> c_int {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph.html>.
#[unsafe(no_mangle)]
pub extern "C" fn isgraph(c: c_int) -> c_int {
c_int::from(c >= 0x21 && c <= 0x7e)
c_int::from((0x21..=0x7e).contains(&c))
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isgraph_l.html>.
@@ -101,7 +101,7 @@ pub extern "C" fn islower_l(c: c_int, _loc: locale_t) -> c_int {
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint.html>.
#[unsafe(no_mangle)]
pub extern "C" fn isprint(c: c_int) -> c_int {
c_int::from(c >= 0x20 && c < 0x7f)
c_int::from((0x20..0x7f).contains(&c))
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/isprint_l.html>.