svn commit: r291050 - stable/10/lib/libc/stdio

Andrey A. Chernov ache at FreeBSD.org
Thu Nov 19 02:04:18 UTC 2015


Author: ache
Date: Thu Nov 19 02:04:16 2015
New Revision: 291050
URL: https://svnweb.freebsd.org/changeset/base/291050

Log:
  MFC: r290549,r290729
  
  r290549:
  
  Reorganize code to elimitate one _sseek() call for append modes.
  
  r290729:
  
  1) Remove my overcomplicated error fallback and just return error
  immediatelly as old code does, now for append modes too.
  Real use case for such fallback is impossible (unless specially crafted).
  
  2) Remove now unneded include I forgot to remove in prev. commits.

Modified:
  stable/10/lib/libc/stdio/ftell.c
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/lib/libc/stdio/ftell.c
==============================================================================
--- stable/10/lib/libc/stdio/ftell.c	Thu Nov 19 01:58:12 2015	(r291049)
+++ stable/10/lib/libc/stdio/ftell.c	Thu Nov 19 02:04:16 2015	(r291050)
@@ -39,7 +39,6 @@ __FBSDID("$FreeBSD$");
 #include "namespace.h"
 #include <sys/types.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <limits.h>
 #include <stdio.h>
 #include "un-namespace.h"
@@ -98,7 +97,13 @@ _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))) {
+		pos = _sseek(fp, (fpos_t)0, SEEK_END);
+		if (pos == -1)
+			return (1);
+	} else if (fp->_flags & __SOFF)
 		pos = fp->_offset;
 	else {
 		pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
@@ -125,26 +130,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);


More information about the svn-src-all mailing list