diff --git a/src/header/stdio/mod.rs b/src/header/stdio/mod.rs index 7e7c37ff90..8470c59887 100644 --- a/src/header/stdio/mod.rs +++ b/src/header/stdio/mod.rs @@ -784,7 +784,9 @@ pub unsafe extern "C" fn ftell_locked(stream: &mut FILE) -> off_t { return -1; } + // Adjust for read buffer, ungetc, and write buffer pos - (stream.read_size - stream.read_pos) as off_t - stream.unget.len() as off_t + + stream.writer.pending() as off_t } /// See .