2 * scp - secure remote copy. This is basically patched BSD rcp which
3 * uses ssh to do the data transfer (instead of using rcmd).
5 * NOTE: This version should NOT be suid root. (This uses ssh to
6 * do the transfer and ssh has the necessary privileges.)
8 * 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi>
10 * As far as I am concerned, the code I have written for this software
11 * can be used freely for any purpose. Any derived versions of this
12 * software must be clearly marked as such, and if the derived work is
13 * incompatible with the protocol description in the RFC file, it must be
14 * called by a name other than "ssh" or "Secure Shell".
17 * Copyright (c) 1999 Theo de Raadt. All rights reserved.
18 * Copyright (c) 1999 Aaron Campbell. All rights reserved.
20 * Redistribution and use in source and binary forms, with or without
21 * modification, are permitted provided that the following conditions
23 * 1. Redistributions of source code must retain the above copyright
24 * notice, this list of conditions and the following disclaimer.
25 * 2. Redistributions in binary form must reproduce the above copyright
26 * notice, this list of conditions and the following disclaimer in the
27 * documentation and/or other materials provided with the distribution.
29 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
30 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
31 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
32 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
33 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
34 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
38 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
44 * Copyright (c) 1983, 1990, 1992, 1993, 1995
45 * The Regents of the University of California. All rights reserved.
47 * Redistribution and use in source and binary forms, with or without
48 * modification, are permitted provided that the following conditions
50 * 1. Redistributions of source code must retain the above copyright
51 * notice, this list of conditions and the following disclaimer.
52 * 2. Redistributions in binary form must reproduce the above copyright
53 * notice, this list of conditions and the following disclaimer in the
54 * documentation and/or other materials provided with the distribution.
55 * 3. Neither the name of the University nor the names of its contributors
56 * may be used to endorse or promote products derived from this software
57 * without specific prior written permission.
59 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
75 #include <sys/types.h>
76 #ifdef HAVE_SYS_STAT_H
77 # include <sys/stat.h>
87 #include "pathnames.h"
90 #include "progressmeter.h"
92 extern char *__progname;
96 /* Struct for addargs */
100 off_t limit_rate = 0;
102 /* Name of current file being transferred. */
105 /* This is set to non-zero to enable verbose mode. */
106 int verbose_mode = 0;
108 /* This is set to zero if the progressmeter is not desired. */
109 int showprogress = 1;
111 /* This is the program to execute for the secured connection. ("ssh" or -S) */
112 char *ssh_program = _PATH_SSH_PROGRAM;
114 /* This is used to store the pid of ssh_program */
115 pid_t do_cmd_pid = -1;
120 if (do_cmd_pid > 1) {
121 kill(do_cmd_pid, signo ? signo : SIGTERM);
122 waitpid(do_cmd_pid, NULL, 0);
131 do_local_cmd(arglist *a)
138 fatal("do_local_cmd: no arguments");
141 fprintf(stderr, "Executing:");
142 for (i = 0; i < a->num; i++)
143 fprintf(stderr, " %s", a->list[i]);
144 fprintf(stderr, "\n");
146 if ((pid = fork()) == -1)
147 fatal("do_local_cmd: fork: %s", strerror(errno));
150 execvp(a->list[0], a->list);
156 signal(SIGTERM, killchild);
157 signal(SIGINT, killchild);
158 signal(SIGHUP, killchild);
160 while (waitpid(pid, &status, 0) == -1)
162 fatal("do_local_cmd: waitpid: %s", strerror(errno));
166 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
173 * This function executes the given command as the specified user on the
174 * given host. This returns < 0 if execution fails, and >= 0 otherwise. This
175 * assigns the input and output file descriptors on success.
179 do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
181 int pin[2], pout[2], reserved[2];
185 "Executing: program %s host %s, user %s, command %s\n",
187 remuser ? remuser : "(unspecified)", cmd);
190 * Reserve two descriptors so that the real pipes won't get
191 * descriptors 0 and 1 because that will screw up dup2 below.
195 /* Create a socket pair for communicating with ssh. */
197 fatal("pipe: %s", strerror(errno));
199 fatal("pipe: %s", strerror(errno));
201 /* Free the reserved descriptors. */
205 /* Fork a child to execute the command on the remote host using ssh. */
207 if (do_cmd_pid == 0) {
216 replacearg(&args, 0, "%s", ssh_program);
218 addargs(&args, "-l%s", remuser);
219 addargs(&args, "%s", host);
220 addargs(&args, "%s", cmd);
222 execvp(ssh_program, args.list);
225 } else if (do_cmd_pid == -1) {
226 fatal("fork: %s", strerror(errno));
228 /* Parent. Close the other side, and return the local side. */
233 signal(SIGTERM, killchild);
234 signal(SIGINT, killchild);
235 signal(SIGHUP, killchild);
244 BUF *allocbuf(BUF *, int, int);
248 void run_err(const char *,...);
249 void verifydir(char *);
253 int errs, remin, remout;
254 int pflag, iamremote, iamrecursive, targetshouldbedirectory;
257 char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
260 void rsource(char *, struct stat *);
261 void sink(int, char *[]);
262 void source(int, char *[]);
263 void tolocal(int, char *[]);
264 void toremote(char *, int, char *[]);
268 main(int argc, char **argv)
270 int ch, fflag, tflag, status;
276 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
279 __progname = ssh_get_progname(argv[0]);
281 memset(&args, '\0', sizeof(args));
283 addargs(&args, "%s", ssh_program);
284 addargs(&args, "-x");
285 addargs(&args, "-oForwardAgent no");
286 addargs(&args, "-oPermitLocalCommand no");
287 addargs(&args, "-oClearAllForwardings yes");
290 while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:")) != -1)
292 /* User-visible flags. */
298 addargs(&args, "-%c", ch);
304 addargs(&args, "-%c%s", ch, optarg);
307 addargs(&args, "-p%s", optarg);
310 addargs(&args, "-oBatchmode yes");
313 speed = strtod(optarg, &endp);
314 if (speed <= 0 || *endp != '\0')
316 limit_rate = speed * 1024;
325 ssh_program = xstrdup(optarg);
328 addargs(&args, "-v");
332 addargs(&args, "-q");
336 /* Server options. */
338 targetshouldbedirectory = 1;
340 case 'f': /* "from" */
348 setmode(0, O_BINARY);
357 if ((pwd = getpwuid(userid = getuid())) == NULL)
358 fatal("unknown user %u", (u_int) userid);
360 if (!isatty(STDERR_FILENO))
363 remin = STDIN_FILENO;
364 remout = STDOUT_FILENO;
367 /* Follow "protocol", send data. */
380 targetshouldbedirectory = 1;
384 /* Command to be executed on remote system using "ssh". */
385 (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
386 verbose_mode ? " -v" : "",
387 iamrecursive ? " -r" : "", pflag ? " -p" : "",
388 targetshouldbedirectory ? " -d" : "");
390 (void) signal(SIGPIPE, lostconn);
392 if ((targ = colon(argv[argc - 1]))) /* Dest is remote host. */
393 toremote(targ, argc, argv);
395 if (targetshouldbedirectory)
396 verifydir(argv[argc - 1]);
397 tolocal(argc, argv); /* Dest is local host. */
400 * Finally check the exit status of the ssh process, if one was forked
401 * and no error has occured yet
403 if (do_cmd_pid != -1 && errs == 0) {
407 (void) close(remout);
408 if (waitpid(do_cmd_pid, &status, 0) == -1)
411 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
419 toremote(char *targ, int argc, char **argv)
422 char *bp, *host, *src, *suser, *thost, *tuser, *arg;
425 memset(&alist, '\0', sizeof(alist));
432 arg = xstrdup(argv[argc - 1]);
433 if ((thost = strrchr(arg, '@'))) {
444 if (tuser != NULL && !okname(tuser)) {
449 for (i = 0; i < argc - 1; i++) {
450 src = colon(argv[i]);
451 if (src) { /* remote to remote */
453 addargs(&alist, "%s", ssh_program);
455 addargs(&alist, "-v");
456 addargs(&alist, "-x");
457 addargs(&alist, "-oClearAllForwardings yes");
458 addargs(&alist, "-n");
463 host = strrchr(argv[i], '@');
467 host = cleanhostname(host);
470 suser = pwd->pw_name;
471 else if (!okname(suser))
473 addargs(&alist, "-l");
474 addargs(&alist, "%s", suser);
476 host = cleanhostname(argv[i]);
478 addargs(&alist, "%s", host);
479 addargs(&alist, "%s", cmd);
480 addargs(&alist, "%s", src);
481 addargs(&alist, "%s%s%s:%s",
482 tuser ? tuser : "", tuser ? "@" : "",
484 if (do_local_cmd(&alist) != 0)
486 } else { /* local to remote */
488 len = strlen(targ) + CMDNEEDS + 20;
490 (void) snprintf(bp, len, "%s -t %s", cmd, targ);
491 host = cleanhostname(thost);
492 if (do_cmd(host, tuser, bp, &remin,
505 tolocal(int argc, char **argv)
508 char *bp, *host, *src, *suser;
511 memset(&alist, '\0', sizeof(alist));
514 for (i = 0; i < argc - 1; i++) {
515 if (!(src = colon(argv[i]))) { /* Local to local. */
517 addargs(&alist, "%s", _PATH_CP);
519 addargs(&alist, "-r");
521 addargs(&alist, "-p");
522 addargs(&alist, "%s", argv[i]);
523 addargs(&alist, "%s", argv[argc-1]);
524 if (do_local_cmd(&alist))
531 if ((host = strrchr(argv[i], '@')) == NULL) {
538 suser = pwd->pw_name;
540 host = cleanhostname(host);
541 len = strlen(src) + CMDNEEDS + 20;
543 (void) snprintf(bp, len, "%s -f %s", cmd, src);
544 if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
550 sink(1, argv + argc - 1);
557 source(int argc, char **argv)
562 off_t i, amt, statbytes;
564 int fd = -1, haderr, indx;
565 char *last, *name, buf[2048];
568 for (indx = 0; indx < argc; ++indx) {
572 while (len > 1 && name[len-1] == '/')
574 if (strchr(name, '\n') != NULL) {
575 run_err("%s: skipping, filename contains a newline",
579 if ((fd = open(name, O_RDONLY, 0)) < 0)
581 if (fstat(fd, &stb) < 0) {
582 syserr: run_err("%s: %s", name, strerror(errno));
585 switch (stb.st_mode & S_IFMT) {
595 run_err("%s: not a regular file", name);
598 if ((last = strrchr(name, '/')) == NULL)
605 * Make it compatible with possible future
606 * versions expecting microseconds.
608 (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
609 (u_long) stb.st_mtime,
610 (u_long) stb.st_atime);
611 (void) atomicio(vwrite, remout, buf, strlen(buf));
615 #define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
616 snprintf(buf, sizeof buf, "C%04o %lld %s\n",
617 (u_int) (stb.st_mode & FILEMODEMASK),
618 (long long)stb.st_size, last);
620 fprintf(stderr, "Sending file modes: %s", buf);
622 (void) atomicio(vwrite, remout, buf, strlen(buf));
625 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
626 next: if (fd != -1) {
633 start_progress_meter(curfile, stb.st_size, &statbytes);
634 /* Keep writing after an error so that we stay sync'd up. */
635 for (haderr = i = 0; i < stb.st_size; i += bp->cnt) {
637 if (i + amt > stb.st_size)
638 amt = stb.st_size - i;
640 result = atomicio(read, fd, bp->buf, amt);
645 (void) atomicio(vwrite, remout, bp->buf, amt);
647 result = atomicio(vwrite, remout, bp->buf, amt);
656 stop_progress_meter();
659 if (close(fd) < 0 && !haderr)
664 (void) atomicio(vwrite, remout, "", 1);
666 run_err("%s: %s", name, strerror(haderr));
672 rsource(char *name, struct stat *statp)
676 char *last, *vect[1], path[1100];
678 if (!(dirp = opendir(name))) {
679 run_err("%s: %s", name, strerror(errno));
682 last = strrchr(name, '/');
688 (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
689 (u_long) statp->st_mtime,
690 (u_long) statp->st_atime);
691 (void) atomicio(vwrite, remout, path, strlen(path));
692 if (response() < 0) {
697 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
698 (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
700 fprintf(stderr, "Entering directory: %s", path);
701 (void) atomicio(vwrite, remout, path, strlen(path));
702 if (response() < 0) {
706 while ((dp = readdir(dirp)) != NULL) {
709 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
711 if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) {
712 run_err("%s/%s: name too long", name, dp->d_name);
715 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);
719 (void) closedir(dirp);
720 (void) atomicio(vwrite, remout, "E\n", 2);
727 static struct timeval bwstart, bwend;
728 static int lamt, thresh = 16384;
730 struct timespec ts, rm;
732 if (!timerisset(&bwstart)) {
733 gettimeofday(&bwstart, NULL);
741 gettimeofday(&bwend, NULL);
742 timersub(&bwend, &bwstart, &bwend);
743 if (!timerisset(&bwend))
747 waitlen = (double)1000000L * lamt / limit_rate;
749 bwstart.tv_sec = waitlen / 1000000L;
750 bwstart.tv_usec = waitlen % 1000000L;
752 if (timercmp(&bwstart, &bwend, >)) {
753 timersub(&bwstart, &bwend, &bwend);
755 /* Adjust the wait time */
760 } else if (bwend.tv_usec < 100) {
766 TIMEVAL_TO_TIMESPEC(&bwend, &ts);
767 while (nanosleep(&ts, &rm) == -1) {
775 gettimeofday(&bwstart, NULL);
779 sink(int argc, char **argv)
789 int amt, exists, first, mask, mode, ofd, omode;
790 off_t size, statbytes;
791 int setimes, targisdir, wrerrno = 0;
792 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
793 struct timeval tv[2];
797 #define SCREWUP(str) { why = str; goto screwup; }
799 setimes = targisdir = 0;
804 run_err("ambiguous target");
808 if (targetshouldbedirectory)
811 (void) atomicio(vwrite, remout, "", 1);
812 if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
814 for (first = 1;; first = 0) {
816 if (atomicio(read, remin, cp, 1) != 1)
819 SCREWUP("unexpected <newline>");
821 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
822 SCREWUP("lost connection");
824 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
827 fprintf(stderr, "Sink: %s", buf);
829 if (buf[0] == '\01' || buf[0] == '\02') {
831 (void) atomicio(vwrite, STDERR_FILENO,
832 buf + 1, strlen(buf + 1));
839 (void) atomicio(vwrite, remout, "", 1);
849 mtime.tv_sec = strtol(cp, &cp, 10);
850 if (!cp || *cp++ != ' ')
851 SCREWUP("mtime.sec not delimited");
852 mtime.tv_usec = strtol(cp, &cp, 10);
853 if (!cp || *cp++ != ' ')
854 SCREWUP("mtime.usec not delimited");
855 atime.tv_sec = strtol(cp, &cp, 10);
856 if (!cp || *cp++ != ' ')
857 SCREWUP("atime.sec not delimited");
858 atime.tv_usec = strtol(cp, &cp, 10);
859 if (!cp || *cp++ != '\0')
860 SCREWUP("atime.usec not delimited");
861 (void) atomicio(vwrite, remout, "", 1);
864 if (*cp != 'C' && *cp != 'D') {
866 * Check for the case "rcp remote:foo\* local:bar".
867 * In this case, the line "No match." can be returned
868 * by the shell before the rcp command on the remote is
869 * executed so the ^Aerror_message convention isn't
876 SCREWUP("expected control record");
879 for (++cp; cp < buf + 5; cp++) {
880 if (*cp < '0' || *cp > '7')
882 mode = (mode << 3) | (*cp - '0');
885 SCREWUP("mode not delimited");
887 for (size = 0; isdigit(*cp);)
888 size = size * 10 + (*cp++ - '0');
890 SCREWUP("size not delimited");
891 if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
892 run_err("error: unexpected filename: %s", cp);
896 static char *namebuf;
897 static size_t cursize;
900 need = strlen(targ) + strlen(cp) + 250;
901 if (need > cursize) {
904 namebuf = xmalloc(need);
907 (void) snprintf(namebuf, need, "%s%s%s", targ,
908 strcmp(targ, "/") ? "/" : "", cp);
913 exists = stat(np, &stb) == 0;
915 int mod_flag = pflag;
917 SCREWUP("received directory without -r");
919 if (!S_ISDIR(stb.st_mode)) {
924 (void) chmod(np, mode);
926 /* Handle copying from a read-only
929 if (mkdir(np, mode | S_IRWXU) < 0)
932 vect[0] = xstrdup(np);
936 if (utimes(vect[0], tv) < 0)
937 run_err("%s: set times: %s",
938 vect[0], strerror(errno));
941 (void) chmod(vect[0], mode);
948 if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) {
949 bad: run_err("%s: %s", np, strerror(errno));
952 (void) atomicio(vwrite, remout, "", 1);
953 if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
962 start_progress_meter(curfile, size, &statbytes);
963 for (count = i = 0; i < size; i += 4096) {
969 j = atomicio(read, remin, cp, amt);
971 run_err("%s", j ? strerror(errno) :
972 "dropped connection");
983 if (count == bp->cnt) {
984 /* Keep reading so we stay sync'd up. */
986 if (atomicio(vwrite, ofd, bp->buf,
997 stop_progress_meter();
998 if (count != 0 && wrerr == NO &&
999 atomicio(vwrite, ofd, bp->buf, count) != count) {
1003 if (wrerr == NO && ftruncate(ofd, size) != 0) {
1004 run_err("%s: truncate: %s", np, strerror(errno));
1008 if (exists || omode != mode)
1010 if (fchmod(ofd, omode)) {
1011 #else /* HAVE_FCHMOD */
1012 if (chmod(np, omode)) {
1013 #endif /* HAVE_FCHMOD */
1014 run_err("%s: set mode: %s",
1015 np, strerror(errno));
1019 if (!exists && omode != mode)
1021 if (fchmod(ofd, omode & ~mask)) {
1022 #else /* HAVE_FCHMOD */
1023 if (chmod(np, omode & ~mask)) {
1024 #endif /* HAVE_FCHMOD */
1025 run_err("%s: set mode: %s",
1026 np, strerror(errno));
1030 if (close(ofd) == -1) {
1035 if (setimes && wrerr == NO) {
1037 if (utimes(np, tv) < 0) {
1038 run_err("%s: set times: %s",
1039 np, strerror(errno));
1045 run_err("%s: %s", np, strerror(wrerrno));
1048 (void) atomicio(vwrite, remout, "", 1);
1055 run_err("protocol error: %s", why);
1062 char ch, *cp, resp, rbuf[2048];
1064 if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
1074 case 1: /* error, followed by error msg */
1075 case 2: /* fatal error, "" */
1077 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
1080 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
1083 (void) atomicio(vwrite, STDERR_FILENO, rbuf, cp - rbuf);
1095 (void) fprintf(stderr,
1096 "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
1097 " [-l limit] [-o ssh_option] [-P port] [-S program]\n"
1098 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
1103 run_err(const char *fmt,...)
1109 if (fp != NULL || (remout != -1 && (fp = fdopen(remout, "w")))) {
1110 (void) fprintf(fp, "%c", 0x01);
1111 (void) fprintf(fp, "scp: ");
1113 (void) vfprintf(fp, fmt, ap);
1115 (void) fprintf(fp, "\n");
1121 vfprintf(stderr, fmt, ap);
1123 fprintf(stderr, "\n");
1132 if (!stat(cp, &stb)) {
1133 if (S_ISDIR(stb.st_mode))
1137 run_err("%s: %s", cp, strerror(errno));
1152 if (!isalpha(c) && !isdigit(c)) {
1167 bad: fprintf(stderr, "%s: invalid user name\n", cp0);
1172 allocbuf(BUF *bp, int fd, int blksize)
1175 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1178 if (fstat(fd, &stb) < 0) {
1179 run_err("fstat: %s", strerror(errno));
1182 size = roundup(stb.st_blksize, blksize);
1185 #else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1187 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1188 if (bp->cnt >= size)
1190 if (bp->buf == NULL)
1191 bp->buf = xmalloc(size);
1193 bp->buf = xrealloc(bp->buf, size);
1194 memset(bp->buf, 0, size);
1203 write(STDERR_FILENO, "lost connection\n", 16);