use libc::{FILE, fread, feof, ferror}; #[no_mangle] pub extern "C" fn read_all_from_file(file: *mut FILE) -> bool { let mut buf = [0u8; 1 << 12]; let mut r = 0; println!("fread() starts"); while unsafe { feof(file) } == 0 { let hr = unsafe { fread(buf.as_mut_ptr().cast(), 1, 1 << 12, file) }; println!("fread() got {} bytes", hr); if hr == 0 { if unsafe { feof(file) } != 0 { println!("feof(file) returns non-zero"); break; } if unsafe { ferror(file) } != 0 { println!("ferror() returns non-zero"); return false; } } else { r += hr; } } println!("fread() got {} bytes totally", r); true }