2 Commits

Author SHA1 Message Date
Cutieguwu
952e796e28 Probably won't work. 2026-01-01 15:29:13 -05:00
Cutieguwu
9198193365 Update io.rs 2026-01-01 14:37:56 -05:00

View File

@@ -1,6 +1,7 @@
use std::ffi::CString;
use std::fs::{File, OpenOptions}; use std::fs::{File, OpenOptions};
use std::io::{self, Seek, SeekFrom}; use std::io::{self, Seek, SeekFrom};
use std::os::unix::fs::OpenOptionsExt; use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd};
use crate::cli::CONFIG; use crate::cli::CONFIG;
@@ -20,21 +21,22 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
len len
} }
pub fn load_input() -> anyhow::Result<File> {
OpenOptions::new()
.read(true)
.custom_flags(libc::O_DIRECT)
.open(&CONFIG.input)
.with_context(|| format!("Failed to open input file: {}", &CONFIG.input.display()))
/* /*
use std::ffi::CString; * IO Error Poisoning:
use std::os::fd::FromRawFd; *
*
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned()).unwrap(); * Attempt 1:
let flags = libc::O_DIRECT | libc::O_RDONLY; *
let f = unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) }; * Wrap C calls w/ `ffi`. Most importantly, execute the `close()` through C.
*
* I cannot seem to execute `close()`... one hopes that reassigning will drop
* calling `close()` on the old fd, but I don't know.
*/ */
pub fn load_input() -> anyhow::Result<File> {
let path = CString::new(CONFIG.input.to_str().unwrap().to_owned())?;
let flags = libc::O_RDONLY | libc::O_DIRECT;
Ok(unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) })
} }
pub fn load_output() -> anyhow::Result<File> { pub fn load_output() -> anyhow::Result<File> {