From 952e796e28997082d55a5851a7738b578db0a001 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Thu, 1 Jan 2026 15:29:13 -0500 Subject: [PATCH] Probably won't work. --- src/io.rs | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/io.rs b/src/io.rs index 3473270..8b66638 100644 --- a/src/io.rs +++ b/src/io.rs @@ -1,6 +1,7 @@ +use std::ffi::CString; use std::fs::{File, OpenOptions}; use std::io::{self, Seek, SeekFrom}; -use std::os::unix::fs::OpenOptionsExt; +use std::os::fd::{AsRawFd, FromRawFd, IntoRawFd}; use crate::cli::CONFIG; @@ -27,23 +28,15 @@ pub fn get_stream_length(stream: &mut S) -> io::Result { * Attempt 1: * * 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 { - 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; - use std::os::fd::FromRawFd; - - let path = CString::new(CONFIG.input.to_str().unwrap().to_owned()).unwrap(); - let flags = libc::O_DIRECT | libc::O_RDONLY; - let f = unsafe { File::from_raw_fd(libc::open(path.as_ptr(), flags)) }; - */ + 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 {