Lines Matching +full:read +full:- +full:out
1 /*-
2 * SPDX-License-Identifier: BSD-3-Clause
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55 n = io->offset; in seek_offset()
56 sz = io->dbsz; in seek_offset()
58 _Static_assert(sizeof(io->offset) == sizeof(int64_t), "64-bit off_t"); in seek_offset()
65 * Bail out if the calculation of a file offset would overflow. in seek_offset()
67 if ((io->flags & ISCHR) == 0 && (n < 0 || n > OFF_MAX / (ssize_t)sz)) in seek_offset()
70 else if ((io->flags & ISCHR) != 0 && (uint64_t)n > UINT64_MAX / sz) in seek_offset()
94 if (lseek(in.fd, seek_offset(&in), SEEK_CUR) == -1 && in pos_in()
100 /* Don't try to read a really weird amount (like negative). */ in pos_in()
105 * Read the data. If a pipe, read until satisfy the number of bytes in pos_in()
110 if ((nr = read(in.fd, in.db, bcnt)) > 0) { in pos_in()
112 if (!(bcnt -= nr)) { in pos_in()
114 --cnt; in pos_in()
117 --cnt; in pos_in()
127 --files_cnt; in pos_in()
134 * Input error -- either EOF with no more files, or I/O error. in pos_in()
159 * going to fail, but don't protect the user -- they shouldn't in pos_out()
162 if (out.flags & (ISSEEK | ISPIPE)) { in pos_out()
164 if (lseek(out.fd, seek_offset(&out), SEEK_CUR) == -1 && in pos_out()
166 err(1, "%s", out.name); in pos_out()
170 /* Don't try to read a really weird amount (like negative). */ in pos_out()
171 if (out.offset < 0) in pos_out()
174 /* If no read access, try using mtio. */ in pos_out()
175 if (out.flags & NOREAD) { in pos_out()
177 t_op.mt_count = out.offset; in pos_out()
179 if (ioctl(out.fd, MTIOCTOP, &t_op) == -1) in pos_out()
180 err(1, "%s", out.name); in pos_out()
184 /* Read it. */ in pos_out()
185 for (cnt = 0; cnt < out.offset; ++cnt) { in pos_out()
187 n = read(out.fd, out.db, out.dbsz); in pos_out()
191 if (n == -1) in pos_out()
192 err(1, "%s", out.name); in pos_out()
197 * the EOF read does not count as a seek'd block. in pos_out()
201 if (ioctl(out.fd, MTIOCTOP, &t_op) == -1) in pos_out()
202 err(1, "%s", out.name); in pos_out()
204 while (cnt++ < out.offset) { in pos_out()
206 n = write(out.fd, out.db, out.dbsz); in pos_out()
208 if (n == -1) in pos_out()
209 err(1, "%s", out.name); in pos_out()
210 if (n != out.dbsz) in pos_out()
211 errx(1, "%s: write failure", out.name); in pos_out()