aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrey A. Chernov <ache@FreeBSD.org>2015-11-01 06:15:14 +0000
committerAndrey A. Chernov <ache@FreeBSD.org>2015-11-01 06:15:14 +0000
commitec6cd152cb356dca3bea06194cec09bdea1dcf8b (patch)
treebd0eb700023f61c4af52d795422ae171f385ee5c
parentfaefad9c125a9478dd46ccadd0b20a2c825de803 (diff)
downloadsrc-ec6cd152cb356dca3bea06194cec09bdea1dcf8b.tar.gz
src-ec6cd152cb356dca3bea06194cec09bdea1dcf8b.zip
Don't seek to the end if write buffer is empty (in append modes).
PR: 204156 MFC after: 1 week
Notes
Notes: svn path=/head/; revision=290230
-rw-r--r--lib/libc/stdio/ftell.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index abb6da11966c..8cf94ee39c91 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -119,7 +119,18 @@ _ftello(FILE *fp, fpos_t *offset)
if (HASUB(fp))
pos -= fp->_r; /* Can be negative at this point. */
} else if ((fp->_flags & __SWR) && fp->_p != NULL) {
- if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) {
+ /*
+ * Writing. Any buffered characters cause the
+ * position to be greater than that in the
+ * underlying object.
+ */
+ n = fp->_p - fp->_bf._base;
+ if (pos > OFF_MAX - n) {
+ errno = EOVERFLOW;
+ return (1);
+ }
+ if (n > 0 &&
+ ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) {
int serrno = errno;
errno = 0;
@@ -137,16 +148,6 @@ _ftello(FILE *fp, fpos_t *offset)
}
errno = serrno;
}
- /*
- * Writing. Any buffered characters cause the
- * position to be greater than that in the
- * underlying object.
- */
- n = fp->_p - fp->_bf._base;
- if (pos > OFF_MAX - n) {
- errno = EOVERFLOW;
- return (1);
- }
pos += n;
}
*offset = pos;