diff options
author | joerg <joerg@FreeBSD.org> | 1996-04-06 11:00:28 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1996-04-06 11:00:28 +0000 |
commit | 434cdc4bf4b1fb5dc0f0a1847805f0af442522e3 (patch) | |
tree | f56ad561aa81e916c3830dd457def2ed838b9f9c /sbin | |
parent | c0988308980a8ddb60e251dfe131084f0ddf387a (diff) | |
download | FreeBSD-src-434cdc4bf4b1fb5dc0f0a1847805f0af442522e3.zip FreeBSD-src-434cdc4bf4b1fb5dc0f0a1847805f0af442522e3.tar.gz |
Don't immediately give up if a single read() or write() wasn't
sufficient to transfer all the data from stdin, or to stdout. Working
on pipes causes further fragmentation.
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/scsi/scsi.c | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/sbin/scsi/scsi.c b/sbin/scsi/scsi.c index df3ade7..52658c3 100644 --- a/sbin/scsi/scsi.c +++ b/sbin/scsi/scsi.c @@ -39,7 +39,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: scsi.c,v 1.9 1995/07/11 09:21:33 dufault Exp $ + * $Id: scsi.c,v 1.10 1995/07/30 12:58:47 joerg Exp $ */ #include <stdio.h> @@ -281,8 +281,8 @@ do_cmd(int fd, char *fmt, int argc, char **argv) struct get_hook h; scsireq_t *scsireq = scsireq_new(); enum data_phase data_phase; - int count; - char *data_fmt; + int count, amount; + char *data_fmt, *bp; h.argc = argc; h.argv = argv; @@ -335,11 +335,26 @@ do_cmd(int fd, char *fmt, int argc, char **argv) { if (strcmp(data_fmt, "-") == 0) /* Read data from stdin */ { - if (read(0, scsireq->databuf, count) != count) + bp = (char *)scsireq->databuf; + while (count > 0 && (amount = read(0, bp, count)) > 0) + { + count -= amount; + bp += amount; + } + if (amount == -1) { perror("read"); exit(errno); } + else if (amount == 0) + { + /* early EOF */ + fprintf(stderr, + "Warning: only read %lu bytes out of %lu.\n", + scsireq->datalen - (u_long)count, + scsireq->datalen); + scsireq->datalen -= (u_long)count; + } } else { @@ -366,11 +381,22 @@ do_cmd(int fd, char *fmt, int argc, char **argv) { if (strcmp(data_fmt, "-") == 0) /* stdout */ { - if (write(1, scsireq->databuf, count) != count) + bp = (char *)scsireq->databuf; + while (count > 0 && (amount = write(1, bp, count)) > 0) + { + count -= amount; + bp += amount; + } + if (amount < 0) { perror("write"); exit(errno); } + else if (amount == 0) + fprintf(stderr, "Warning: wrote only %d bytes out of %d.\n", + scsireq->datalen - count, + scsireq->datalen); + } else { |