From be349d7042de84c3c5157a5c1fbcad580aed33e1 Mon Sep 17 00:00:00 2001 From: Siddhesh Poyarekar Date: Thu, 4 Dec 2014 08:08:37 +0530 Subject: ftell: seek to end only when there are unflushed bytes (BZ #17647) Currently we seek to end of file if there are unflushed writes or the stream is in write mode, to get the current offset for writing in append mode, which is the end of file. The latter case (i.e. stream is in write mode, but no unflushed writes) is unnecessary since it will only happen when the stream has just been flushed, in which case the recorded offset ought to be reliable. Removing that case lets ftell give the correct offset when it follows an ftruncate. The latter truncates the file, but does not change the file position, due to which it is permissible to call ftell without an intervening fseek call. Tested on x86_64 to verify that the added test case fails without the patch and succeeds with it, and that there are no additional regressions due to it. [BZ #17647] * libio/fileops.c (do_ftell): Seek only when there are unflushed writes. * libio/wfileops.c (do_ftell_wide): Likewise. * libio/tst-ftell-active-handler.c (do_ftruncate_test): New test case. (do_one_test): Call it. --- ChangeLog | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'ChangeLog') diff --git a/ChangeLog b/ChangeLog index b064598548..83048e1c34 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2914-12-04 Siddhesh Poyarekar + + [BZ #17647] + * libio/fileops.c (do_ftell): Seek only when there are + unflushed writes. + * libio/wfileops.c (do_ftell_wide): Likewise. + * libio/tst-ftell-active-handler.c (do_ftruncate_test): New + test case. + (do_one_test): Call it. + 2014-12-03 Joseph Myers * conform/list-header-symbols.pl (%extra_syms): Add getdate_err -- cgit 1.4.1