use std::ffi::{c_int, CString, OsStr}; use std::io; use std::os::fd::{FromRawFd, OwnedFd}; use std::os::unix::ffi::OsStrExt; use crate::sys; pub fn stream_fd>( identifier: I, priority: c_int, level_prefix: bool, ) -> Result { let ident = CString::new(identifier.as_ref().as_bytes()).map_err(|_| { io::Error::new( io::ErrorKind::Other, "invalid identifier for journal stream", ) })?; let fd = unsafe { sys::sd_journal_stream_fd(ident.as_bytes().as_ptr(), priority, level_prefix as c_int) }; if fd < 0 { Err(std::io::Error::from_raw_os_error(-fd)) } else { Ok(unsafe { OwnedFd::from_raw_fd(fd) }) } }