summaryrefslogtreecommitdiff
path: root/scp.c
diff options
context:
space:
mode:
authorDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
committerDamien Miller <djm@mindrot.org>2005-05-26 12:23:44 +1000
commitb253cc42136649e3eac80e02667f8fbc1e43baaa (patch)
treee3824a905c7b12e4901e60e87ecdc968228e645e /scp.c
parent02e754f1f01470c11a175a0d07381361afe37fff (diff)
- avsm@cvs.openbsd.org 2005/05/24 17:32:44
[atomicio.c atomicio.h authfd.c monitor_wrap.c msg.c scp.c sftp-client.c] [ssh-keyscan.c sshconnect.c] Switch atomicio to use a simpler interface; it now returns a size_t (containing number of bytes read/written), and indicates error by returning 0. EOF is signalled by errno==EPIPE. Typical use now becomes: if (atomicio(read, ..., len) != len) err(1,"read"); ok deraadt@, cloder@, djm@
Diffstat (limited to 'scp.c')
-rw-r--r--scp.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/scp.c b/scp.c
index 1d34cc639..1455c18fd 100644
--- a/scp.c
+++ b/scp.c
@@ -71,7 +71,7 @@
71 */ 71 */
72 72
73#include "includes.h" 73#include "includes.h"
74RCSID("$OpenBSD: scp.c,v 1.121 2005/04/02 12:41:16 djm Exp $"); 74RCSID("$OpenBSD: scp.c,v 1.122 2005/05/24 17:32:43 avsm Exp $");
75 75
76#include "xmalloc.h" 76#include "xmalloc.h"
77#include "atomicio.h" 77#include "atomicio.h"
@@ -502,7 +502,8 @@ source(int argc, char **argv)
502 struct stat stb; 502 struct stat stb;
503 static BUF buffer; 503 static BUF buffer;
504 BUF *bp; 504 BUF *bp;
505 off_t i, amt, result, statbytes; 505 off_t i, amt, statbytes;
506 size_t result;
506 int fd, haderr, indx; 507 int fd, haderr, indx;
507 char *last, *name, buf[2048]; 508 char *last, *name, buf[2048];
508 int len; 509 int len;
@@ -578,14 +579,14 @@ next: (void) close(fd);
578 if (!haderr) { 579 if (!haderr) {
579 result = atomicio(read, fd, bp->buf, amt); 580 result = atomicio(read, fd, bp->buf, amt);
580 if (result != amt) 581 if (result != amt)
581 haderr = result >= 0 ? EIO : errno; 582 haderr = errno;
582 } 583 }
583 if (haderr) 584 if (haderr)
584 (void) atomicio(vwrite, remout, bp->buf, amt); 585 (void) atomicio(vwrite, remout, bp->buf, amt);
585 else { 586 else {
586 result = atomicio(vwrite, remout, bp->buf, amt); 587 result = atomicio(vwrite, remout, bp->buf, amt);
587 if (result != amt) 588 if (result != amt)
588 haderr = result >= 0 ? EIO : errno; 589 haderr = errno;
589 statbytes += result; 590 statbytes += result;
590 } 591 }
591 if (limit_rate) 592 if (limit_rate)
@@ -720,7 +721,8 @@ sink(int argc, char **argv)
720 YES, NO, DISPLAYED 721 YES, NO, DISPLAYED
721 } wrerr; 722 } wrerr;
722 BUF *bp; 723 BUF *bp;
723 off_t i, j; 724 off_t i;
725 size_t j;
724 int amt, count, exists, first, mask, mode, ofd, omode; 726 int amt, count, exists, first, mask, mode, ofd, omode;
725 off_t size, statbytes; 727 off_t size, statbytes;
726 int setimes, targisdir, wrerrno = 0; 728 int setimes, targisdir, wrerrno = 0;
@@ -748,7 +750,7 @@ sink(int argc, char **argv)
748 targisdir = 1; 750 targisdir = 1;
749 for (first = 1;; first = 0) { 751 for (first = 1;; first = 0) {
750 cp = buf; 752 cp = buf;
751 if (atomicio(read, remin, cp, 1) <= 0) 753 if (atomicio(read, remin, cp, 1) != 1)
752 return; 754 return;
753 if (*cp++ == '\n') 755 if (*cp++ == '\n')
754 SCREWUP("unexpected <newline>"); 756 SCREWUP("unexpected <newline>");
@@ -902,7 +904,7 @@ bad: run_err("%s: %s", np, strerror(errno));
902 count += amt; 904 count += amt;
903 do { 905 do {
904 j = atomicio(read, remin, cp, amt); 906 j = atomicio(read, remin, cp, amt);
905 if (j <= 0) { 907 if (j == 0) {
906 run_err("%s", j ? strerror(errno) : 908 run_err("%s", j ? strerror(errno) :
907 "dropped connection"); 909 "dropped connection");
908 exit(1); 910 exit(1);
@@ -918,10 +920,10 @@ bad: run_err("%s: %s", np, strerror(errno));
918 if (count == bp->cnt) { 920 if (count == bp->cnt) {
919 /* Keep reading so we stay sync'd up. */ 921 /* Keep reading so we stay sync'd up. */
920 if (wrerr == NO) { 922 if (wrerr == NO) {
921 j = atomicio(vwrite, ofd, bp->buf, count); 923 if (atomicio(vwrite, ofd, bp->buf,
922 if (j != count) { 924 count) != count) {
923 wrerr = YES; 925 wrerr = YES;
924 wrerrno = j >= 0 ? EIO : errno; 926 wrerrno = errno;
925 } 927 }
926 } 928 }
927 count = 0; 929 count = 0;
@@ -931,9 +933,9 @@ bad: run_err("%s: %s", np, strerror(errno));
931 if (showprogress) 933 if (showprogress)
932 stop_progress_meter(); 934 stop_progress_meter();
933 if (count != 0 && wrerr == NO && 935 if (count != 0 && wrerr == NO &&
934 (j = atomicio(vwrite, ofd, bp->buf, count)) != count) { 936 atomicio(vwrite, ofd, bp->buf, count) != count) {
935 wrerr = YES; 937 wrerr = YES;
936 wrerrno = j >= 0 ? EIO : errno; 938 wrerrno = errno;
937 } 939 }
938 if (wrerr == NO && ftruncate(ofd, size) != 0) { 940 if (wrerr == NO && ftruncate(ofd, size) != 0) {
939 run_err("%s: truncate: %s", np, strerror(errno)); 941 run_err("%s: truncate: %s", np, strerror(errno));