about summary refs log tree commit diff
path: root/libio/tst-ftell-active-handler.c
Commit message (Collapse)AuthorAgeFilesLines
* Update copyright dates with scripts/update-copyrights.Joseph Myers2020-01-011-1/+1
|
* Prefer https to http for gnu.org and fsf.org URLsPaul Eggert2019-09-071-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also, change sources.redhat.com to sourceware.org. This patch was automatically generated by running the following shell script, which uses GNU sed, and which avoids modifying files imported from upstream: sed -ri ' s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g ' \ $(find $(git ls-files) -prune -type f \ ! -name '*.po' \ ! -name 'ChangeLog*' \ ! -path COPYING ! -path COPYING.LIB \ ! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \ ! -path manual/texinfo.tex ! -path scripts/config.guess \ ! -path scripts/config.sub ! -path scripts/install-sh \ ! -path scripts/mkinstalldirs ! -path scripts/move-if-change \ ! -path INSTALL ! -path locale/programs/charmap-kw.h \ ! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \ ! '(' -name configure \ -execdir test -f configure.ac -o -f configure.in ';' ')' \ ! '(' -name preconfigure \ -execdir test -f preconfigure.ac ';' ')' \ -print) and then by running 'make dist-prepare' to regenerate files built from the altered files, and then executing the following to cleanup: chmod a+x sysdeps/unix/sysv/linux/riscv/configure # Omit irrelevant whitespace and comment-only changes, # perhaps from a slightly-different Autoconf version. git checkout -f \ sysdeps/csky/configure \ sysdeps/hppa/configure \ sysdeps/riscv/configure \ sysdeps/unix/sysv/linux/csky/configure # Omit changes that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines git checkout -f \ sysdeps/powerpc/powerpc64/ppc-mcount.S \ sysdeps/unix/sysv/linux/s390/s390-64/syscall.S # Omit change that caused a pre-commit check to fail like this: # remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
* Update copyright dates with scripts/update-copyrights.Joseph Myers2019-01-011-1/+1
| | | | | | | * All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2018-01-011-1/+1
| | | | | | | * All files with FSF copyright notices: Update copyright dates using scripts/update-copyrights. * locale/programs/charmap-kw.h: Regenerated. * locale/programs/locfile-kw.h: Likewise.
* Update copyright dates with scripts/update-copyrights.Joseph Myers2017-01-011-1/+1
|
* Update copyright dates with scripts/update-copyrights.Joseph Myers2016-01-041-1/+1
|
* Update copyright dates with scripts/update-copyrights.Joseph Myers2015-01-021-1/+1
|
* Replace %ld with %jd and cast to intmax_tH.J. Lu2014-12-301-6/+6
|
* Fix tst-ftell-active-handler.c warning.Joseph Myers2014-12-101-1/+1
| | | | | | | | | | | | A recent change to libio/tst-ftell-active-handler.c (postdating my last check for warnings on x86) introduced a format warning from a long int variable used with a %zu format. This patch fixes it by using %ld for the format to match the variable. Tested for x86. * libio/tst-ftell-active-handler.c (do_ftruncate_test): Use %ld format for long int variable.
* libio: Fix variable aligment in tst-ftell-active-handlerAdhemerval Zanella2014-12-081-4/+1
| | | | | This patch fixes a stack allocated variable to force it to have wchar_t alignment.
* libio: Fix buffer overrun in tst-ftell-active-handlerAdhemerval Zanella2014-12-051-2/+5
| | | | | | | | | | | | | | | | | On 'do_ftell_test' the code: 365 if (test_modes[i].fd_mode != O_WRONLY) 366 { 367 char tmpbuf[data_len]; 368 369 rewind (fp); 370 371 while (fgets_func (tmpbuf, sizeof (tmpbuf), fp) && !feof (fp)); The 'data_len' is calculated with wsclen and allocated as 'char'. The subsequent fgetws will then try to write at most 'data_len' wchar_t in a buffer with just data_len 'char'. This patch fixes it by allocating the tmpbuf using 'wchar_t' * data_len bytes.
* Reset cached offset when reading to end of stream (BZ #17653)Siddhesh Poyarekar2014-12-041-8/+46
| | | | | | POSIX allows applications to switch file handles when a read results in an end of file. Unset the cached offset at this point so that it is queried again.
* tst-ftell-active-handler: Open file with O_TRUNC for w modesSiddhesh Poyarekar2014-12-041-8/+8
| | | | | | The test case fails to truncate the file when a file is intended to be opened in w or w+ mode. Add O_TRUNC to fix this. The test still succeeds with this change.
* ftell: seek to end only when there are unflushed bytes (BZ #17647)Siddhesh Poyarekar2014-12-041-0/+90
| | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Change offset in fdopen only if setting O_APPENDSiddhesh Poyarekar2014-03-171-0/+55
| | | | | | fdopen should only be allowed to change the offset in the file it attaches to if it is setting O_APPEND. If O_APPEND is already set, it should not change the state of the handle.
* Fix offset caching for streams and use it for ftell (BZ #16680)Siddhesh Poyarekar2014-03-171-4/+108
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The ftell implementation was made conservative to ensure that incorrectly cached offsets never affect it. However, this causes problems for append mode when a file stream is rewound. Additionally, the 'clever' trick of using stat to get position for append mode files caused more problems than it solved and broke old behavior. I have described the various problems that it caused and then finally the solution. For a and a+ mode files, rewinding the stream should result in ftell returning 0 as the offset, but the stat() trick caused it to (incorrectly) always return the end of file. Now I couldn't find anything in POSIX that specifies the stream position after rewind() for a file opened in 'a' mode, but for 'a+' mode it should be set to 0. For 'a' mode too, it probably makes sense to keep it set to 0 in the interest of retaining old behavior. The initial file position for append mode files is implementation defined, so the implementation could either retain the current file position or move the position to the end of file. The earlier ftell implementation would move the offset to end of file for append-only mode, but retain the old offset for a+ mode. It would also cache the offset (this detail is important). My patch broke this and would set the initial position to end of file for both append modes, thus breaking old behavior. I was ignorant enough to write an incorrect test case for it too. The Change: I have now brought back the behavior of seeking to end of file for append-only streams, but with a slight difference. I don't cache the offset though, since we would want ftell to query the current file position through lseek while the stream is not active. Since the offset is moved to the end of file, we can rely on the file position reported by lseek and we don't need to resort to the stat() nonsense. Finally, the cache is always reliable, except when there are unflished writes in an append mode stream (i.e. both a and a+). In the latter case, it is safe to just do an lseek to SEEK_END. The value can be safely cached too, since the file handle is already active at this point. Incidentally, this is the only state change we affect in the file handle (apart from taking locks of course). I have also updated the test case to correct my impression of the initial file position for a+ streams to the initial behavior. I have verified that this does not break any existing tests in the testsuite and also passes with the new tests.
* Fix up return codes for tests in tst-ftell-active-handlerSiddhesh Poyarekar2014-03-171-18/+31
| | | | | | | | | | | | | The test functions used a variable ret to store failure codes for individual tests, but the variable was incorrectly used to record other failure codes too, resulting in overwriting of the tests status. This is now fixed by making sure that the ret variable is used only for recording test failures. * libio/tst-ftell-active-handler.c (do_ftell_test): Don't mix up test status with function return status. (do_write_test): Likewise. (do_append_test): Likewise.
* Fix up formatting in tst-ftell-active-handler.cSiddhesh Poyarekar2014-03-041-7/+7
|
* Separate ftell from fseek logic and avoid modifying FILE data (#16532)Siddhesh Poyarekar2014-03-041-0/+384
ftell semantics are distinct from fseek(SEEK_CUR) especially when it is called on a file handler that is not yet active. Due to this caveat, much care needs to be taken while modifying the handler data and hence, this first iteration on separating out ftell focusses on maintaining handler data integrity at all times while it figures out the current stream offset. The result is that it makes a syscall for every offset request. There is scope for optimizing this by caching offsets when we know that the handler is active. A simple way to find out is when the buffers have data. It is not so simple to find this out when the buffer is empty without adding some kind of flag.