aboutsummaryrefslogtreecommitdiffstats
path: root/libc/stdio/ftell.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/stdio/ftell.c')
-rw-r--r--libc/stdio/ftell.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/libc/stdio/ftell.c b/libc/stdio/ftell.c
index b7d449e18..9f850ee85 100644
--- a/libc/stdio/ftell.c
+++ b/libc/stdio/ftell.c
@@ -45,20 +45,22 @@ ftello(FILE *fp)
if (fp->_seek == NULL) {
errno = ESPIPE; /* historic practice */
- return ((off_t)-1);
+ pos = -1;
+ goto out;
}
/*
* Find offset of underlying I/O object, then
* adjust for buffered bytes.
*/
+ FLOCKFILE(fp);
__sflush(fp); /* may adjust seek offset on append stream */
if (fp->_flags & __SOFF)
pos = fp->_offset;
else {
pos = (*fp->_seek)(fp->_cookie, (fpos_t)0, SEEK_CUR);
- if (pos == -1L)
- return (pos);
+ if (pos == -1)
+ goto out;
}
if (fp->_flags & __SRD) {
/*
@@ -77,6 +79,7 @@ ftello(FILE *fp)
*/
pos += fp->_p - fp->_bf._base;
}
+out: FUNLOCKFILE(fp);
return (pos);
}