Deleted Added
full compact
stdio.c (249808) stdio.c (249810)
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[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
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[] = "@(#)stdio.c 8.1 (Berkeley) 6/4/93";
35#endif /* LIBC_SCCS and not lint */
36#include <sys/cdefs.h>
37__FBSDID("$FreeBSD: head/lib/libc/stdio/stdio.c 249808 2013-04-23 13:33:13Z emaste $");
37__FBSDID("$FreeBSD: head/lib/libc/stdio/stdio.c 249810 2013-04-23 14:36:44Z emaste $");
38
39#include "namespace.h"
40#include <errno.h>
41#include <fcntl.h>
42#include <limits.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <unistd.h>
46#include "un-namespace.h"
47#include "local.h"
48
49/*
50 * Small standard I/O/seek/close functions.
51 */
52int
38
39#include "namespace.h"
40#include <errno.h>
41#include <fcntl.h>
42#include <limits.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <unistd.h>
46#include "un-namespace.h"
47#include "local.h"
48
49/*
50 * Small standard I/O/seek/close functions.
51 */
52int
53__sread(cookie, buf, n)
54 void *cookie;
55 char *buf;
56 int n;
53__sread(void *cookie, char *buf, int n)
57{
58 FILE *fp = cookie;
59
60 return(_read(fp->_file, buf, (size_t)n));
61}
62
63int
54{
55 FILE *fp = cookie;
56
57 return(_read(fp->_file, buf, (size_t)n));
58}
59
60int
64__swrite(cookie, buf, n)
65 void *cookie;
66 char const *buf;
67 int n;
61__swrite(void *cookie, char const *buf, int n)
68{
69 FILE *fp = cookie;
70
71 return (_write(fp->_file, buf, (size_t)n));
72}
73
74fpos_t
62{
63 FILE *fp = cookie;
64
65 return (_write(fp->_file, buf, (size_t)n));
66}
67
68fpos_t
75__sseek(cookie, offset, whence)
76 void *cookie;
77 fpos_t offset;
78 int whence;
69__sseek(void *cookie, fpos_t offset, int whence)
79{
80 FILE *fp = cookie;
81
82 return (lseek(fp->_file, (off_t)offset, whence));
83}
84
85int
70{
71 FILE *fp = cookie;
72
73 return (lseek(fp->_file, (off_t)offset, whence));
74}
75
76int
86__sclose(cookie)
87 void *cookie;
77__sclose(void *cookie)
88{
89
90 return (_close(((FILE *)cookie)->_file));
91}
92
93/*
94 * Higher level wrappers.
95 */
96int
78{
79
80 return (_close(((FILE *)cookie)->_file));
81}
82
83/*
84 * Higher level wrappers.
85 */
86int
97_sread(fp, buf, n)
98 FILE *fp;
99 char *buf;
100 int n;
87_sread(FILE *fp, char *buf, int n)
101{
102 int ret;
103
104 ret = (*fp->_read)(fp->_cookie, buf, n);
105 if (ret > 0) {
106 if (fp->_flags & __SOFF) {
107 if (fp->_offset <= OFF_MAX - ret)
108 fp->_offset += ret;
109 else
110 fp->_flags &= ~__SOFF;
111 }
112 } else if (ret < 0)
113 fp->_flags &= ~__SOFF;
114 return (ret);
115}
116
117int
88{
89 int ret;
90
91 ret = (*fp->_read)(fp->_cookie, buf, n);
92 if (ret > 0) {
93 if (fp->_flags & __SOFF) {
94 if (fp->_offset <= OFF_MAX - ret)
95 fp->_offset += ret;
96 else
97 fp->_flags &= ~__SOFF;
98 }
99 } else if (ret < 0)
100 fp->_flags &= ~__SOFF;
101 return (ret);
102}
103
104int
118_swrite(fp, buf, n)
119 FILE *fp;
120 char const *buf;
121 int n;
105_swrite(FILE *fp, char const *buf, int n)
122{
123 int ret;
124 int serrno;
125
126 if (fp->_flags & __SAPP) {
127 serrno = errno;
128 if (_sseek(fp, (fpos_t)0, SEEK_END) == -1 &&
129 (fp->_flags & __SOPT))

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

140 fp->_flags &= ~__SOFF;
141
142 } else if (ret < 0)
143 fp->_flags &= ~__SOFF;
144 return (ret);
145}
146
147fpos_t
106{
107 int ret;
108 int serrno;
109
110 if (fp->_flags & __SAPP) {
111 serrno = errno;
112 if (_sseek(fp, (fpos_t)0, SEEK_END) == -1 &&
113 (fp->_flags & __SOPT))

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

124 fp->_flags &= ~__SOFF;
125
126 } else if (ret < 0)
127 fp->_flags &= ~__SOFF;
128 return (ret);
129}
130
131fpos_t
148_sseek(fp, offset, whence)
149 FILE *fp;
150 fpos_t offset;
151 int whence;
132_sseek(FILE *fp, fpos_t offset, int whence)
152{
153 fpos_t ret;
154 int serrno, errret;
155
156 serrno = errno;
157 errno = 0;
158 ret = (*fp->_seek)(fp->_cookie, offset, whence);
159 errret = errno;

--- 28 unchanged lines hidden ---
133{
134 fpos_t ret;
135 int serrno, errret;
136
137 serrno = errno;
138 errno = 0;
139 ret = (*fp->_seek)(fp->_cookie, offset, whence);
140 errret = errno;

--- 28 unchanged lines hidden ---