@@ -150,9 +150,31 @@ pub trait FileExt {
150
150
/// short write.
151
151
///
152
152
/// # Bug
153
- /// On some systems, due to a [bug] with [`pwrite64`] (the underlying
154
- /// syscall), files opened with the `O_APPEND` flag fail to respect the
155
- /// offset parameter, always appending to the end of the file instead.
153
+ /// On some systems, `write_at` utilises [`pwrite64`] to write to files.
154
+ /// However, this syscall has a [bug] where files opened with the `O_APPEND`
155
+ /// flag fail to respect the offset parameter, always appending to the end
156
+ /// of the file instead.
157
+ ///
158
+ /// It is possible to inadvertantly set this flag, like in the example below.
159
+ /// Therefore, it is important to be vigilant while changing options to mitigate
160
+ /// unexpected behaviour.
161
+ ///
162
+ /// ```no_run
163
+ /// use std::fs::File;
164
+ /// use std::io;
165
+ /// use std::os::unix::prelude::FileExt;
166
+ ///
167
+ /// fn main() -> io::Result<()> {
168
+ /// // Open a file with the append option (sets the `O_APPEND` flag)
169
+ /// let file = File::options().append(true).open("foo.txt")?;
170
+ ///
171
+ /// // We attempt to write at offset 10; instead appended to EOF
172
+ /// file.write_at(b"sushi", 10)?;
173
+ ///
174
+ /// // foo.txt is 5 bytes long instead of 15
175
+ /// Ok(())
176
+ /// }
177
+ /// ```
156
178
///
157
179
/// [`File::write`]: fs::File::write
158
180
/// [`pwrite64`]: https://man7.org/linux/man-pages/man2/pwrite.2.html
0 commit comments