summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/ftell.c
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>2015-10-24 02:23:15 +0000
committerache <ache@FreeBSD.org>2015-10-24 02:23:15 +0000
commitd6852ac6f1dfc1396dee130993f8686cf53f5d2c (patch)
treec8f96d268fae59791f07df0c9f770053554f1f6a /lib/libc/stdio/ftell.c
parent9901e2ee18d8dffc84891f9ec0e7de37518bb95f (diff)
downloadFreeBSD-src-d6852ac6f1dfc1396dee130993f8686cf53f5d2c.zip
FreeBSD-src-d6852ac6f1dfc1396dee130993f8686cf53f5d2c.tar.gz
Since no room left in the _flags, reuse __SALC for O_APPEND.
It helps to remove _fcntl() call from _ftello() and optimize seek position calculation in _swrite(). MFC after: 3 weeks
Diffstat (limited to 'lib/libc/stdio/ftell.c')
-rw-r--r--lib/libc/stdio/ftell.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/lib/libc/stdio/ftell.c b/lib/libc/stdio/ftell.c
index 745d500..0d2222b 100644
--- a/lib/libc/stdio/ftell.c
+++ b/lib/libc/stdio/ftell.c
@@ -88,7 +88,6 @@ _ftello(FILE *fp, fpos_t *offset)
{
fpos_t pos;
size_t n;
- int dflags;
if (fp->_seek == NULL) {
errno = ESPIPE; /* historic practice */
@@ -120,21 +119,24 @@ _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) {
- dflags = 0;
- if (fp->_flags & __SAPP)
- dflags = O_APPEND;
- else if (fp->_file != -1 &&
- (dflags = _fcntl(fp->_file, F_GETFL)) < 0)
- return (1);
- if ((dflags & O_APPEND) &&
- (pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
- if ((fp->_flags & __SOPT) || __sflush(fp) ||
- (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
- return (1);
- else {
- *offset = pos;
- return (0);
+ /* XXX: Reuse __SALC for O_APPEND. */
+ if (fp->_flags & (__SAPP|__SALC)) {
+ 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;
}
/*
* Writing. Any buffered characters cause the
OpenPOWER on IntegriCloud