Deleted Added
full compact
ftell.c (290232) ftell.c (290549)
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1990, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Chris Torek.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 20 unchanged lines hidden (view full) ---

29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 * SUCH DAMAGE.
31 */
32
33#if defined(LIBC_SCCS) && !defined(lint)
34static char sccsid[] = "@(#)ftell.c 8.2 (Berkeley) 5/4/95";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 290232 2015-11-01 08:40:15Z ache $");
37__FBSDID("$FreeBSD: head/lib/libc/stdio/ftell.c 290549 2015-11-08 18:00:44Z ache $");
38
39#include "namespace.h"
40#include <sys/types.h>
41#include <errno.h>
42#include <fcntl.h>
43#include <limits.h>
44#include <stdio.h>
45#include "un-namespace.h"

--- 47 unchanged lines hidden (view full) ---

93 errno = ESPIPE; /* historic practice */
94 return (1);
95 }
96
97 /*
98 * Find offset of underlying I/O object, then
99 * adjust for buffered bytes.
100 */
38
39#include "namespace.h"
40#include <sys/types.h>
41#include <errno.h>
42#include <fcntl.h>
43#include <limits.h>
44#include <stdio.h>
45#include "un-namespace.h"

--- 47 unchanged lines hidden (view full) ---

93 errno = ESPIPE; /* historic practice */
94 return (1);
95 }
96
97 /*
98 * Find offset of underlying I/O object, then
99 * adjust for buffered bytes.
100 */
101 if (fp->_flags & __SOFF)
101 if (!(fp->_flags & __SRD) && (fp->_flags & __SWR) &&
102 fp->_p != NULL && fp->_p - fp->_bf._base > 0 &&
103 ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP))) {
104 if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
105 if (errno == ESPIPE ||
106 (fp->_flags & __SOPT) || __sflush(fp) ||
107 (pos = _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
108 return (1);
109 else {
110 *offset = pos;
111 return (0);
112 }
113 }
114 } else if (fp->_flags & __SOFF)
102 pos = fp->_offset;
103 else {
104 pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
105 if (pos == -1)
106 return (1);
107 }
108 if (fp->_flags & __SRD) {
109 /*

--- 10 unchanged lines hidden (view full) ---

120 pos -= fp->_r; /* Can be negative at this point. */
121 } else if ((fp->_flags & __SWR) && fp->_p != NULL &&
122 (n = fp->_p - fp->_bf._base) > 0) {
123 /*
124 * Writing. Any buffered characters cause the
125 * position to be greater than that in the
126 * underlying object.
127 */
115 pos = fp->_offset;
116 else {
117 pos = _sseek(fp, (fpos_t)0, SEEK_CUR);
118 if (pos == -1)
119 return (1);
120 }
121 if (fp->_flags & __SRD) {
122 /*

--- 10 unchanged lines hidden (view full) ---

133 pos -= fp->_r; /* Can be negative at this point. */
134 } else if ((fp->_flags & __SWR) && fp->_p != NULL &&
135 (n = fp->_p - fp->_bf._base) > 0) {
136 /*
137 * Writing. Any buffered characters cause the
138 * position to be greater than that in the
139 * underlying object.
140 */
128 if ((fp->_flags & __SAPP) || (fp->_flags2 & __S2OAP)) {
129 int serrno = errno;
130
131 errno = 0;
132 if ((pos = _sseek(fp, (fpos_t)0, SEEK_END)) == -1) {
133 if (errno == ESPIPE ||
134 (fp->_flags & __SOPT) || __sflush(fp) ||
135 (pos =
136 _sseek(fp, (fpos_t)0, SEEK_CUR)) == -1)
137 return (1);
138 else {
139 errno = serrno;
140 *offset = pos;
141 return (0);
142 }
143 }
144 errno = serrno;
145 /* fp->_p can be changed in _sseek(), recalculate. */
146 n = fp->_p - fp->_bf._base;
147 }
148 if (pos > OFF_MAX - n) {
149 errno = EOVERFLOW;
150 return (1);
151 }
152 pos += n;
153 }
154 *offset = pos;
155 return (0);
156}
141 if (pos > OFF_MAX - n) {
142 errno = EOVERFLOW;
143 return (1);
144 }
145 pos += n;
146 }
147 *offset = pos;
148 return (0);
149}