From b7f8f93489417661f363e0b25601b408877d8274 Mon Sep 17 00:00:00 2001 From: Jonathan Date: Sun, 8 Jan 2023 18:09:55 +0000 Subject: feat: I/O safety `ftruncate` --- src/unistd.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/unistd.rs b/src/unistd.rs index ae1cca95..8cad67f4 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -35,6 +35,7 @@ use std::ffi::{CString, OsStr}; use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStringExt; use std::os::unix::io::RawFd; +use std::os::unix::io::{AsFd, AsRawFd}; use std::path::PathBuf; use std::{fmt, mem, ptr}; @@ -1255,8 +1256,8 @@ pub fn truncate(path: &P, len: off_t) -> Result<()> { /// /// See also /// [ftruncate(2)](https://pubs.opengroup.org/onlinepubs/9699919799/functions/ftruncate.html) -pub fn ftruncate(fd: RawFd, len: off_t) -> Result<()> { - Errno::result(unsafe { libc::ftruncate(fd, len) }).map(drop) +pub fn ftruncate(fd: Fd, len: off_t) -> Result<()> { + Errno::result(unsafe { libc::ftruncate(fd.as_fd().as_raw_fd(), len) }).map(drop) } pub fn isatty(fd: RawFd) -> Result { -- cgit v1.2.3