base/sys/linux/
file_traits.rs

1// Copyright 2018 The ChromiumOS Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! This module exposes Linux's off64_t, pread*64, and pwrite*64 identifiers as the non-64 POSIX
6//! versions, similar to defining _FILE_OFFSET_BITS=64 in a C program.
7
8use std::fs::File;
9use std::io::Error;
10use std::io::Result;
11
12use super::fallocate;
13use super::FallocateMode;
14use crate::FileAllocate;
15
16impl FileAllocate for File {
17    fn allocate(&self, offset: u64, len: u64) -> Result<()> {
18        fallocate(self, FallocateMode::Allocate, offset, len)
19            .map_err(|e| Error::from_raw_os_error(e.errno()))
20    }
21}
22
23// This module allows the macros in unix/file_traits.rsto refer to $crate::platform::X and ensures
24// other crates don't need to add additional crates to their Cargo.toml.
25pub mod lib {
26    pub use libc::off64_t as off_t;
27    pub use libc::pread64 as pread;
28    pub use libc::preadv64 as preadv;
29    pub use libc::pwrite64 as pwrite;
30    pub use libc::pwritev64 as pwritev;
31}