Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,8 @@ impl File {
/// # Errors
///
/// This function will return an error if the file is not opened for writing.
/// Also, std::io::ErrorKind::InvalidInput will be returned if the desired
/// length would cause an overflow due to the implementation specifics.
///
/// # Examples
///
Expand Down
12 changes: 9 additions & 3 deletions src/libstd/sys/unix/fs.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::os::unix::prelude::*;

use crate::convert::TryInto;
use crate::ffi::{CString, CStr, OsString, OsStr};
use crate::fmt;
use crate::io::{self, Error, ErrorKind, SeekFrom, IoSlice, IoSliceMut};
Expand Down Expand Up @@ -554,9 +555,14 @@ impl File {
return crate::sys::android::ftruncate64(self.0.raw(), size);

#[cfg(not(target_os = "android"))]
return cvt_r(|| unsafe {
ftruncate64(self.0.raw(), size as off64_t)
}).map(|_| ());
{
Copy link
Contributor

@tesuji tesuji Aug 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import use crate::convert::TryInto; only to this block.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

let size: off64_t = size
.try_into()
.map_err(|e| io::Error::new(io::ErrorKind::InvalidInput, e))?;
cvt_r(|| unsafe {
ftruncate64(self.0.raw(), size)
}).map(|_| ())
}
}

pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
Expand Down