Compare commits
2 Commits
1e80713263
...
read-poiso
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
952e796e28 | ||
|
|
9198193365 |
32
src/io.rs
32
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;
|
||||
|
||||
@@ -20,21 +21,22 @@ pub fn get_stream_length<S: Seek>(stream: &mut S) -> io::Result<u64> {
|
||||
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;
|
||||
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)) };
|
||||
/*
|
||||
* IO Error Poisoning:
|
||||
*
|
||||
*
|
||||
* 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<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> {
|
||||
|
||||
Reference in New Issue
Block a user