stdlib and stdio header cleanup

This commit is contained in:
auronandace
2026-02-28 19:01:06 +00:00
parent fa04b004c6
commit b44bf78793
3 changed files with 23 additions and 23 deletions
+14 -14
View File
@@ -327,10 +327,10 @@ pub unsafe extern "C" fn cuserid(s: *mut c_char) -> *mut c_char {
unsafe {
pwd::getpwuid_r(
unistd::geteuid(),
&mut pwd,
&raw mut pwd,
buf.as_mut_ptr(),
buf.len(),
&mut pwdbuf,
&raw mut pwdbuf,
)
};
if pwdbuf.is_null() {
@@ -438,7 +438,7 @@ pub unsafe extern "C" fn fgetc(stream: *mut FILE) -> c_int {
return -1;
}
unsafe { getc_unlocked(&mut *stream) }
unsafe { getc_unlocked(&raw mut *stream) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fgetpos.html>.
@@ -611,7 +611,7 @@ pub unsafe extern "C" fn fputc(c: c_int, stream: *mut FILE) -> c_int {
return -1;
}
unsafe { putc_unlocked(c, &mut *stream) }
unsafe { putc_unlocked(c, &raw mut *stream) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fputs.html>.
@@ -853,7 +853,7 @@ pub unsafe extern "C" fn fwrite(
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getc(stream: *mut FILE) -> c_int {
let mut stream = unsafe { (*stream).lock() };
unsafe { getc_unlocked(&mut *stream) }
unsafe { getc_unlocked(&raw mut *stream) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getchar.html>.
@@ -861,7 +861,7 @@ pub unsafe extern "C" fn getc(stream: *mut FILE) -> c_int {
/// Get a single char from `stdin`
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getchar() -> c_int {
unsafe { fgetc(&mut *stdin) }
unsafe { fgetc(&raw mut *stdin) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getc_unlocked.html>.
@@ -886,7 +886,7 @@ pub unsafe extern "C" fn getc_unlocked(stream: *mut FILE) -> c_int {
/// Get a char from `stdin` without locking `stdin`
#[unsafe(no_mangle)]
pub unsafe extern "C" fn getchar_unlocked() -> c_int {
unsafe { getc_unlocked(&mut *stdin) }
unsafe { getc_unlocked(&raw mut *stdin) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9699919799/functions/gets.html>.
@@ -897,7 +897,7 @@ pub unsafe extern "C" fn getchar_unlocked() -> c_int {
/// Get a string from `stdin`
#[unsafe(no_mangle)]
pub unsafe extern "C" fn gets(s: *mut c_char) -> *mut c_char {
unsafe { fgets(s, c_int::MAX, &mut *stdin) }
unsafe { fgets(s, c_int::MAX, &raw mut *stdin) }
}
/// See <https://pubs.opengroup.org/onlinepubs/7908799/xsh/getw.html>.
@@ -1066,7 +1066,7 @@ pub unsafe extern "C" fn popen(command: *const c_char, mode: *const c_char) -> *
#[unsafe(no_mangle)]
pub unsafe extern "C" fn putc(c: c_int, stream: *mut FILE) -> c_int {
let mut stream = unsafe { (*stream).lock() };
unsafe { putc_unlocked(c, &mut *stream) }
unsafe { putc_unlocked(c, &raw mut *stream) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/putchar.html>.
@@ -1074,7 +1074,7 @@ pub unsafe extern "C" fn putc(c: c_int, stream: *mut FILE) -> c_int {
/// Put a character `c` into `stdout`
#[unsafe(no_mangle)]
pub unsafe extern "C" fn putchar(c: c_int) -> c_int {
unsafe { fputc(c, &mut *stdout) }
unsafe { fputc(c, &raw mut *stdout) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/getc_unlocked.html>.
@@ -1419,13 +1419,13 @@ pub unsafe extern "C" fn dprintf(fd: c_int, format: *const c_char, mut __valist:
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfprintf.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn vprintf(format: *const c_char, ap: va_list) -> c_int {
unsafe { vfprintf(&mut *stdout, format, ap) }
unsafe { vfprintf(&raw mut *stdout, format, ap) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fprintf.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn printf(format: *const c_char, mut __valist: ...) -> c_int {
unsafe { vfprintf(&mut *stdout, format, __valist.as_va_list()) }
unsafe { vfprintf(&raw mut *stdout, format, __valist.as_va_list()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfprintf.html>.
@@ -1541,13 +1541,13 @@ pub unsafe extern "C" fn fscanf(
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfscanf.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn vscanf(format: *const c_char, ap: va_list) -> c_int {
unsafe { vfscanf(&mut *stdin, format, ap) }
unsafe { vfscanf(&raw mut *stdin, format, ap) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/fscanf.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn scanf(format: *const c_char, mut __valist: ...) -> c_int {
unsafe { vfscanf(&mut *stdin, format, __valist.as_va_list()) }
unsafe { vfscanf(&raw mut *stdin, format, __valist.as_va_list()) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/vfscanf.html>.
+8 -8
View File
@@ -187,7 +187,7 @@ macro_rules! dec_num_from_ascii {
($s:expr, $t:ty) => {{
let mut s = $s;
// Iterate past whitespace
while ctype::isspace(unsafe { *s } as c_int) != 0 {
while ctype::isspace(c_int::from(unsafe { *s })) != 0 {
s = unsafe { s.offset(1) };
}
@@ -206,7 +206,7 @@ macro_rules! dec_num_from_ascii {
};
let mut n: $t = 0;
while ctype::isdigit(unsafe { *s } as c_int) != 0 {
while ctype::isdigit(c_int::from(unsafe { *s })) != 0 {
n = 10 * n - (unsafe { *s } as $t - 0x30);
s = unsafe { s.offset(1) };
}
@@ -368,7 +368,7 @@ pub unsafe extern "C" fn exit(status: c_int) -> ! {
// Look for the neighbor functions in memory until the end
let mut f = unsafe { &__fini_array_end } as *const _;
#[allow(clippy::op_ref)]
while f > unsafe { &__fini_array_start } {
while f > &raw const __fini_array_start {
f = unsafe { f.offset(-1) };
(unsafe { *f })();
}
@@ -719,7 +719,7 @@ pub unsafe extern "C" fn memalign(alignment: size_t, size: size_t) -> *mut c_voi
pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int {
let mut wc: wchar_t = 0;
let mut state: mbstate_t = mbstate_t {};
let result: usize = unsafe { mbrtowc(&mut wc, s, n, &mut state) };
let result: usize = unsafe { mbrtowc(&raw mut wc, s, n, &raw mut state) };
if result == -1isize as usize {
return -1;
@@ -735,14 +735,14 @@ pub unsafe extern "C" fn mblen(s: *const c_char, n: size_t) -> c_int {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mbstowcs(pwcs: *mut wchar_t, mut s: *const c_char, n: size_t) -> size_t {
let mut state: mbstate_t = mbstate_t {};
unsafe { mbsrtowcs(pwcs, &mut s, n, &mut state) }
unsafe { mbsrtowcs(pwcs, &raw mut s, n, &raw mut state) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/mbtowc.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn mbtowc(pwc: *mut wchar_t, s: *const c_char, n: size_t) -> c_int {
let mut state: mbstate_t = mbstate_t {};
(unsafe { mbrtowc(pwc, s, n, &mut state) }) as c_int
(unsafe { mbrtowc(pwc, s, n, &raw mut state) }) as c_int
}
fn inner_mktemp<T, F>(name: *mut c_char, suffix_len: c_int, mut attempt: F) -> Option<T>
@@ -1682,14 +1682,14 @@ pub unsafe extern "C" fn valloc(size: size_t) -> *mut c_void {
#[unsafe(no_mangle)]
pub unsafe extern "C" fn wcstombs(s: *mut c_char, mut pwcs: *const wchar_t, n: size_t) -> size_t {
let mut state: mbstate_t = mbstate_t {};
unsafe { wcsrtombs(s, &mut pwcs, n, &mut state) }
unsafe { wcsrtombs(s, &raw mut pwcs, n, &raw mut state) }
}
/// See <https://pubs.opengroup.org/onlinepubs/9799919799/functions/wctomb.html>.
#[unsafe(no_mangle)]
pub unsafe extern "C" fn wctomb(s: *mut c_char, wc: wchar_t) -> c_int {
let mut state: mbstate_t = mbstate_t {};
let result: usize = unsafe { wcrtomb(s, wc, &mut state) };
let result: usize = unsafe { wcrtomb(s, wc, &raw mut state) };
if result == -1isize as usize {
return -1;
+1 -1
View File
@@ -227,7 +227,7 @@ macro_rules! strto_float_impl {
let mut s = $s;
let endptr = $endptr;
while ctype::isspace(unsafe{*s} as c_int) != 0 {
while ctype::isspace(c_int::from(unsafe{*s})) != 0 {
s = unsafe{ s.offset(1)};
}