summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2015-11-08 18:00:44 +0000
committerache <ache@FreeBSD.org>2015-11-08 18:00:44 +0000
commit2c458eb4a30841743c60cd8f8642621addbf0754 (patch)
treec1d62230bbf7d794d8348c73e211a19963868cd5 /lib
parent31006b5c68aa377c000619fa0e53bedeaf77ce92 (diff)
downloadFreeBSD-src-2c458eb4a30841743c60cd8f8642621addbf0754.zip
FreeBSD-src-2c458eb4a30841743c60cd8f8642621addbf0754.tar.gz
Reorganize code to elimitate one _sseek() call for append modes.
MFC after: 1 week
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/stdio/ftell.c35
1 files changed, 14 insertions, 21 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 152617f..f0e244b 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -98,7 +98,20 @@ _ftello(FILE *fp, fpos_t *offset)
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
*/
- if (fp->_flags & __SOFF)
+ if (!(fp->_flags & __SRD) && (fp->_flags & __SWR) &&
+ fp->_p != NULL && fp->_p - fp->_bf._base > 0 &&
+ ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) {
+ if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
+ if (errno == ESPIPE ||
+ (fp->_flags & __SOPT) || __sflush(fp) ||
+ (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
+ return (1);
+ else {
+ *offset = pos;
+ return (0);
+ }
+ }
+ } else if (fp->_flags & __SOFF)
pos = fp->_offset;
else {
pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
@@ -125,26 +138,6 @@ _ftello(FILE *fp, fpos_t *offset)
* position to be greater than that in the
* underlying object.
*/
- if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) {
- int serrno = errno;
-
- errno = 0;
- if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
- if (errno == ESPIPE ||
- (fp->_flags & __SOPT) || __sflush(fp) ||
- (pos =
- _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
- return (1);
- else {
- errno = serrno;
- *offset = pos;
- return (0);
- }
- }
- errno = serrno;
- /* fp->_p can be changed in _sseek(), recalculate. */
- n = fp->_p - fp->_bf._base;
- }
if (pos > OFF_MAX - n) {
errno = EOVERFLOW;
return (1);
OpenPOWER on IntegriCloud