Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement safe io #871

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Port file_open_tmp to safe-io
  • Loading branch information
A6GibKm committed Jun 10, 2024
commit 1b59edb365899d809e3120e3807defbe2e51b111
6 changes: 3 additions & 3 deletions glib/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use std::mem;
#[cfg(feature = "v2_58")]
use std::os::unix::io::{AsFd, AsRawFd};
#[cfg(not(windows))]
use std::os::unix::io::{FromRawFd, IntoRawFd, RawFd};
use std::os::unix::io::{FromRawFd, OwnedFd, RawFd};
use std::ptr;

// #[cfg(windows)]
Expand Down Expand Up @@ -261,7 +261,7 @@ pub fn unix_open_pipe(flags: i32) -> Result<(RawFd, RawFd), Error> {
#[doc(alias = "g_file_open_tmp")]
pub fn file_open_tmp(
tmpl: Option<impl AsRef<std::path::Path>>,
) -> Result<(RawFd, std::path::PathBuf), crate::Error> {
) -> Result<(OwnedFd, std::path::PathBuf), crate::Error> {
unsafe {
let mut name_used = ptr::null_mut();
let mut error = ptr::null_mut();
Expand All @@ -271,7 +271,7 @@ pub fn file_open_tmp(
&mut error,
);
if error.is_null() {
Ok((ret.into_raw_fd(), from_glib_full(name_used)))
Ok((OwnedFd::from_raw_fd(ret), from_glib_full(name_used)))
} else {
Err(from_glib_full(error))
}
Expand Down