#[no_mangle]
unsafe extern "C" fn fwrite(ptr: *const (), size: usize, count: usize, stream: *const ()) -> usize {
todo!("fwrite {:?} {} {} {:?}", ptr, size, count, stream)
}
#[no_mangle]
unsafe extern "C" fn fopen(filename: *const u8, mode: *const u8) -> *const () {
todo!("fopen {:?} {:?}", filename, mode)
}
#[no_mangle]
unsafe extern "C" fn fgets(str: *const u8, count: u32, file: *const ()) -> *const u8 {
todo!("fgets {:?} {} {:?}", str, count, file)
}
#[no_mangle]
unsafe extern "C" fn fclose(stream: *const ()) -> i32 {
todo!("fclose {:?}", stream);
}
#[cfg(feature = "esp32s2")]
#[no_mangle]
unsafe extern "C" fn atoi(str: *const i8) -> i32 {
trace!("atoi {:?}", str);
let mut sign: i32 = 1;
let mut res: i32 = 0;
let mut idx = 0;
while str.add(idx).read() as u8 == b' ' {
idx += 1;
}
let c = str.add(idx).read() as u8;
if c == b'-' || c == b'+' {
if c == b'-' {
sign = -1;
}
idx += 1;
}
loop {
let c = str.add(idx).read() as u8;
if !c.is_ascii_digit() {
break;
}
if res > i32::MAX / 10 || (res == i32::MAX / 10 && c - b'0' > 7) {
return if sign == 1 { i32::MAX } else { i32::MIN };
}
res = 10 * res + (c - b'0') as i32;
idx += 1;
}
res * sign
}
#[derive(Debug, Copy, Clone)]
#[repr(C)]
struct Tm {
tm_sec: u32, tm_min: u32, tm_hour: u32, tm_mday: u32, tm_mon: u32, tm_year: u32, tm_wday: u32, tm_yday: u32, tm_isdst: u32, }
#[no_mangle]
unsafe extern "C" fn mktime(time: *const Tm) -> i64 {
trace!("mktime {:?}", time);
let time = *time;
let mut days_in_month = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
let is_leap_year = |year: u32| year % 4 == 0 && (year % 100 != 0 || year % 400 == 0);
let mut days = 0;
let year = time.tm_year + 1900;
for y in 1970..year {
days += if is_leap_year(y) { 366 } else { 365 };
}
if is_leap_year(year) {
days_in_month[1] = 29;
}
for m in 0..time.tm_mon {
days += days_in_month[m as usize];
}
days += time.tm_mday - 1;
let seconds = days * 24 * 60 * 60 + time.tm_hour * 60 * 60 + time.tm_min * 60 + time.tm_sec;
seconds as i64
}