summary refs log tree commit diff
path: root/sys_util
diff options
context:
space:
mode:
Diffstat (limited to 'sys_util')
-rw-r--r--sys_util/src/file_traits.rs (renamed from sys_util/src/file_sync.rs)16
-rw-r--r--sys_util/src/lib.rs4
2 files changed, 18 insertions, 2 deletions
diff --git a/sys_util/src/file_sync.rs b/sys_util/src/file_traits.rs
index a67be05..2dfc28d 100644
--- a/sys_util/src/file_sync.rs
+++ b/sys_util/src/file_traits.rs
@@ -19,3 +19,19 @@ impl FileSync for File {
         self.sync_all()
     }
 }
+
+/// A trait for setting the size of a file.
+/// This is equivalent to File's `set_len` method, but
+/// wrapped in a trait so that it can be implemented for
+/// other types.
+pub trait FileSetLen {
+    // Set the size of this file.
+    // This is the moral equivalent of `ftruncate()`.
+    fn set_len(&self, _len: u64) -> Result<()>;
+}
+
+impl FileSetLen for File {
+    fn set_len(&self, len: u64) -> Result<()> {
+        File::set_len(self, len)
+    }
+}
diff --git a/sys_util/src/lib.rs b/sys_util/src/lib.rs
index 38fa81f..185489c 100644
--- a/sys_util/src/lib.rs
+++ b/sys_util/src/lib.rs
@@ -21,7 +21,7 @@ pub mod syslog;
 mod errno;
 mod eventfd;
 mod file_flags;
-mod file_sync;
+mod file_traits;
 mod fork;
 mod guest_address;
 mod guest_memory;
@@ -62,7 +62,7 @@ pub use tempdir::*;
 pub use terminal::*;
 pub use timerfd::*;
 
-pub use file_sync::FileSync;
+pub use file_traits::{FileSetLen, FileSync};
 pub use guest_memory::Error as GuestMemoryError;
 pub use mmap::Error as MmapError;
 pub use seek_hole::SeekHole;