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
74 RCSID("$OpenBSD: scp.c,v 1.132 2006/02/10 01:44:26 stevesk Exp $");
76 #include <sys/types.h>
83 #include "pathnames.h"
86 #include "progressmeter.h"
88 extern char *__progname;
92 /* Struct for addargs */
98 /* Name of current file being transferred. */
101 /* This is set to non-zero to enable verbose mode. */
102 int verbose_mode = 0;
104 /* This is set to zero if the progressmeter is not desired. */
105 int showprogress = 1;
107 /* This is the program to execute for the secured connection. ("ssh" or -S) */
108 char *ssh_program = _PATH_SSH_PROGRAM;
110 /* This is used to store the pid of ssh_program */
111 pid_t do_cmd_pid = -1;
116 if (do_cmd_pid > 1) {
117 kill(do_cmd_pid, signo ? signo : SIGTERM);
118 waitpid(do_cmd_pid, NULL, 0);
127 do_local_cmd(arglist *a)
134 fatal("do_local_cmd: no arguments");
137 fprintf(stderr, "Executing:");
138 for (i = 0; i < a->num; i++)
139 fprintf(stderr, " %s", a->list[i]);
140 fprintf(stderr, "\n");
142 if ((pid = fork()) == -1)
143 fatal("do_local_cmd: fork: %s", strerror(errno));
146 execvp(a->list[0], a->list);
152 signal(SIGTERM, killchild);
153 signal(SIGINT, killchild);
154 signal(SIGHUP, killchild);
156 while (waitpid(pid, &status, 0) == -1)
158 fatal("do_local_cmd: waitpid: %s", strerror(errno));
162 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
169 * This function executes the given command as the specified user on the
170 * given host. This returns < 0 if execution fails, and >= 0 otherwise. This
171 * assigns the input and output file descriptors on success.
175 do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
177 int pin[2], pout[2], reserved[2];
181 "Executing: program %s host %s, user %s, command %s\n",
183 remuser ? remuser : "(unspecified)", cmd);
186 * Reserve two descriptors so that the real pipes won't get
187 * descriptors 0 and 1 because that will screw up dup2 below.
191 /* Create a socket pair for communicating with ssh. */
193 fatal("pipe: %s", strerror(errno));
195 fatal("pipe: %s", strerror(errno));
197 /* Free the reserved descriptors. */
201 /* Fork a child to execute the command on the remote host using ssh. */
203 if (do_cmd_pid == 0) {
212 replacearg(&args, 0, "%s", ssh_program);
214 addargs(&args, "-l%s", remuser);
215 addargs(&args, "%s", host);
216 addargs(&args, "%s", cmd);
218 execvp(ssh_program, args.list);
221 } else if (do_cmd_pid == -1) {
222 fatal("fork: %s", strerror(errno));
224 /* Parent. Close the other side, and return the local side. */
229 signal(SIGTERM, killchild);
230 signal(SIGINT, killchild);
231 signal(SIGHUP, killchild);
240 BUF *allocbuf(BUF *, int, int);
244 void run_err(const char *,...);
245 void verifydir(char *);
249 int errs, remin, remout;
250 int pflag, iamremote, iamrecursive, targetshouldbedirectory;
253 char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
256 void rsource(char *, struct stat *);
257 void sink(int, char *[]);
258 void source(int, char *[]);
259 void tolocal(int, char *[]);
260 void toremote(char *, int, char *[]);
264 main(int argc, char **argv)
266 int ch, fflag, tflag, status;
272 /* Ensure that fds 0, 1 and 2 are open or directed to /dev/null */
275 __progname = ssh_get_progname(argv[0]);
277 memset(&args, '\0', sizeof(args));
279 addargs(&args, "%s", ssh_program);
280 addargs(&args, "-x");
281 addargs(&args, "-oForwardAgent no");
282 addargs(&args, "-oPermitLocalCommand no");
283 addargs(&args, "-oClearAllForwardings yes");
286 while ((ch = getopt(argc, argv, "dfl:prtvBCc:i:P:q1246S:o:F:")) != -1)
288 /* User-visible flags. */
294 addargs(&args, "-%c", ch);
300 addargs(&args, "-%c%s", ch, optarg);
303 addargs(&args, "-p%s", optarg);
306 addargs(&args, "-oBatchmode yes");
309 speed = strtod(optarg, &endp);
310 if (speed <= 0 || *endp != '\0')
312 limit_rate = speed * 1024;
321 ssh_program = xstrdup(optarg);
324 addargs(&args, "-v");
328 addargs(&args, "-q");
332 /* Server options. */
334 targetshouldbedirectory = 1;
336 case 'f': /* "from" */
344 setmode(0, O_BINARY);
353 if ((pwd = getpwuid(userid = getuid())) == NULL)
354 fatal("unknown user %u", (u_int) userid);
356 if (!isatty(STDERR_FILENO))
359 remin = STDIN_FILENO;
360 remout = STDOUT_FILENO;
363 /* Follow "protocol", send data. */
376 targetshouldbedirectory = 1;
380 /* Command to be executed on remote system using "ssh". */
381 (void) snprintf(cmd, sizeof cmd, "scp%s%s%s%s",
382 verbose_mode ? " -v" : "",
383 iamrecursive ? " -r" : "", pflag ? " -p" : "",
384 targetshouldbedirectory ? " -d" : "");
386 (void) signal(SIGPIPE, lostconn);
388 if ((targ = colon(argv[argc - 1]))) /* Dest is remote host. */
389 toremote(targ, argc, argv);
391 if (targetshouldbedirectory)
392 verifydir(argv[argc - 1]);
393 tolocal(argc, argv); /* Dest is local host. */
396 * Finally check the exit status of the ssh process, if one was forked
397 * and no error has occured yet
399 if (do_cmd_pid != -1 && errs == 0) {
403 (void) close(remout);
404 if (waitpid(do_cmd_pid, &status, 0) == -1)
407 if (!WIFEXITED(status) || WEXITSTATUS(status) != 0)
415 toremote(char *targ, int argc, char **argv)
418 char *bp, *host, *src, *suser, *thost, *tuser, *arg;
421 memset(&alist, '\0', sizeof(alist));
428 arg = xstrdup(argv[argc - 1]);
429 if ((thost = strrchr(arg, '@'))) {
440 if (tuser != NULL && !okname(tuser)) {
445 for (i = 0; i < argc - 1; i++) {
446 src = colon(argv[i]);
447 if (src) { /* remote to remote */
449 addargs(&alist, "%s", ssh_program);
451 addargs(&alist, "-v");
452 addargs(&alist, "-x");
453 addargs(&alist, "-oClearAllForwardings yes");
454 addargs(&alist, "-n");
459 host = strrchr(argv[i], '@');
463 host = cleanhostname(host);
466 suser = pwd->pw_name;
467 else if (!okname(suser))
469 addargs(&alist, "-l");
470 addargs(&alist, "%s", suser);
472 host = cleanhostname(argv[i]);
474 addargs(&alist, "%s", host);
475 addargs(&alist, "%s", cmd);
476 addargs(&alist, "%s", src);
477 addargs(&alist, "%s%s%s:%s",
478 tuser ? tuser : "", tuser ? "@" : "",
480 if (do_local_cmd(&alist) != 0)
482 } else { /* local to remote */
484 len = strlen(targ) + CMDNEEDS + 20;
486 (void) snprintf(bp, len, "%s -t %s", cmd, targ);
487 host = cleanhostname(thost);
488 if (do_cmd(host, tuser, bp, &remin,
501 tolocal(int argc, char **argv)
504 char *bp, *host, *src, *suser;
507 memset(&alist, '\0', sizeof(alist));
510 for (i = 0; i < argc - 1; i++) {
511 if (!(src = colon(argv[i]))) { /* Local to local. */
513 addargs(&alist, "%s", _PATH_CP);
515 addargs(&alist, "-r");
517 addargs(&alist, "-p");
518 addargs(&alist, "%s", argv[i]);
519 addargs(&alist, "%s", argv[argc-1]);
520 if (do_local_cmd(&alist))
527 if ((host = strrchr(argv[i], '@')) == NULL) {
534 suser = pwd->pw_name;
536 host = cleanhostname(host);
537 len = strlen(src) + CMDNEEDS + 20;
539 (void) snprintf(bp, len, "%s -f %s", cmd, src);
540 if (do_cmd(host, suser, bp, &remin, &remout, argc) < 0) {
546 sink(1, argv + argc - 1);
553 source(int argc, char **argv)
558 off_t i, amt, statbytes;
560 int fd = -1, haderr, indx;
561 char *last, *name, buf[2048];
564 for (indx = 0; indx < argc; ++indx) {
568 while (len > 1 && name[len-1] == '/')
570 if (strchr(name, '\n') != NULL) {
571 run_err("%s: skipping, filename contains a newline",
575 if ((fd = open(name, O_RDONLY, 0)) < 0)
577 if (fstat(fd, &stb) < 0) {
578 syserr: run_err("%s: %s", name, strerror(errno));
581 switch (stb.st_mode & S_IFMT) {
591 run_err("%s: not a regular file", name);
594 if ((last = strrchr(name, '/')) == NULL)
601 * Make it compatible with possible future
602 * versions expecting microseconds.
604 (void) snprintf(buf, sizeof buf, "T%lu 0 %lu 0\n",
605 (u_long) stb.st_mtime,
606 (u_long) stb.st_atime);
607 (void) atomicio(vwrite, remout, buf, strlen(buf));
611 #define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
612 snprintf(buf, sizeof buf, "C%04o %lld %s\n",
613 (u_int) (stb.st_mode & FILEMODEMASK),
614 (long long)stb.st_size, last);
616 fprintf(stderr, "Sending file modes: %s", buf);
618 (void) atomicio(vwrite, remout, buf, strlen(buf));
621 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
622 next: if (fd != -1) {
629 start_progress_meter(curfile, stb.st_size, &statbytes);
630 /* Keep writing after an error so that we stay sync'd up. */
631 for (haderr = i = 0; i < stb.st_size; i += bp->cnt) {
633 if (i + amt > stb.st_size)
634 amt = stb.st_size - i;
636 result = atomicio(read, fd, bp->buf, amt);
641 (void) atomicio(vwrite, remout, bp->buf, amt);
643 result = atomicio(vwrite, remout, bp->buf, amt);
652 stop_progress_meter();
655 if (close(fd) < 0 && !haderr)
660 (void) atomicio(vwrite, remout, "", 1);
662 run_err("%s: %s", name, strerror(haderr));
668 rsource(char *name, struct stat *statp)
672 char *last, *vect[1], path[1100];
674 if (!(dirp = opendir(name))) {
675 run_err("%s: %s", name, strerror(errno));
678 last = strrchr(name, '/');
684 (void) snprintf(path, sizeof(path), "T%lu 0 %lu 0\n",
685 (u_long) statp->st_mtime,
686 (u_long) statp->st_atime);
687 (void) atomicio(vwrite, remout, path, strlen(path));
688 if (response() < 0) {
693 (void) snprintf(path, sizeof path, "D%04o %d %.1024s\n",
694 (u_int) (statp->st_mode & FILEMODEMASK), 0, last);
696 fprintf(stderr, "Entering directory: %s", path);
697 (void) atomicio(vwrite, remout, path, strlen(path));
698 if (response() < 0) {
702 while ((dp = readdir(dirp)) != NULL) {
705 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
707 if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) {
708 run_err("%s/%s: name too long", name, dp->d_name);
711 (void) snprintf(path, sizeof path, "%s/%s", name, dp->d_name);
715 (void) closedir(dirp);
716 (void) atomicio(vwrite, remout, "E\n", 2);
723 static struct timeval bwstart, bwend;
724 static int lamt, thresh = 16384;
726 struct timespec ts, rm;
728 if (!timerisset(&bwstart)) {
729 gettimeofday(&bwstart, NULL);
737 gettimeofday(&bwend, NULL);
738 timersub(&bwend, &bwstart, &bwend);
739 if (!timerisset(&bwend))
743 waitlen = (double)1000000L * lamt / limit_rate;
745 bwstart.tv_sec = waitlen / 1000000L;
746 bwstart.tv_usec = waitlen % 1000000L;
748 if (timercmp(&bwstart, &bwend, >)) {
749 timersub(&bwstart, &bwend, &bwend);
751 /* Adjust the wait time */
756 } else if (bwend.tv_usec < 100) {
762 TIMEVAL_TO_TIMESPEC(&bwend, &ts);
763 while (nanosleep(&ts, &rm) == -1) {
771 gettimeofday(&bwstart, NULL);
775 sink(int argc, char **argv)
785 int amt, exists, first, mask, mode, ofd, omode;
786 off_t size, statbytes;
787 int setimes, targisdir, wrerrno = 0;
788 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
789 struct timeval tv[2];
793 #define SCREWUP(str) { why = str; goto screwup; }
795 setimes = targisdir = 0;
800 run_err("ambiguous target");
804 if (targetshouldbedirectory)
807 (void) atomicio(vwrite, remout, "", 1);
808 if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
810 for (first = 1;; first = 0) {
812 if (atomicio(read, remin, cp, 1) != 1)
815 SCREWUP("unexpected <newline>");
817 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
818 SCREWUP("lost connection");
820 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
823 fprintf(stderr, "Sink: %s", buf);
825 if (buf[0] == '\01' || buf[0] == '\02') {
827 (void) atomicio(vwrite, STDERR_FILENO,
828 buf + 1, strlen(buf + 1));
835 (void) atomicio(vwrite, remout, "", 1);
845 mtime.tv_sec = strtol(cp, &cp, 10);
846 if (!cp || *cp++ != ' ')
847 SCREWUP("mtime.sec not delimited");
848 mtime.tv_usec = strtol(cp, &cp, 10);
849 if (!cp || *cp++ != ' ')
850 SCREWUP("mtime.usec not delimited");
851 atime.tv_sec = strtol(cp, &cp, 10);
852 if (!cp || *cp++ != ' ')
853 SCREWUP("atime.sec not delimited");
854 atime.tv_usec = strtol(cp, &cp, 10);
855 if (!cp || *cp++ != '\0')
856 SCREWUP("atime.usec not delimited");
857 (void) atomicio(vwrite, remout, "", 1);
860 if (*cp != 'C' && *cp != 'D') {
862 * Check for the case "rcp remote:foo\* local:bar".
863 * In this case, the line "No match." can be returned
864 * by the shell before the rcp command on the remote is
865 * executed so the ^Aerror_message convention isn't
872 SCREWUP("expected control record");
875 for (++cp; cp < buf + 5; cp++) {
876 if (*cp < '0' || *cp > '7')
878 mode = (mode << 3) | (*cp - '0');
881 SCREWUP("mode not delimited");
883 for (size = 0; isdigit(*cp);)
884 size = size * 10 + (*cp++ - '0');
886 SCREWUP("size not delimited");
887 if ((strchr(cp, '/') != NULL) || (strcmp(cp, "..") == 0)) {
888 run_err("error: unexpected filename: %s", cp);
892 static char *namebuf;
893 static size_t cursize;
896 need = strlen(targ) + strlen(cp) + 250;
897 if (need > cursize) {
900 namebuf = xmalloc(need);
903 (void) snprintf(namebuf, need, "%s%s%s", targ,
904 strcmp(targ, "/") ? "/" : "", cp);
909 exists = stat(np, &stb) == 0;
911 int mod_flag = pflag;
913 SCREWUP("received directory without -r");
915 if (!S_ISDIR(stb.st_mode)) {
920 (void) chmod(np, mode);
922 /* Handle copying from a read-only
925 if (mkdir(np, mode | S_IRWXU) < 0)
928 vect[0] = xstrdup(np);
932 if (utimes(vect[0], tv) < 0)
933 run_err("%s: set times: %s",
934 vect[0], strerror(errno));
937 (void) chmod(vect[0], mode);
944 if ((ofd = open(np, O_WRONLY|O_CREAT, mode)) < 0) {
945 bad: run_err("%s: %s", np, strerror(errno));
948 (void) atomicio(vwrite, remout, "", 1);
949 if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
958 start_progress_meter(curfile, size, &statbytes);
959 for (count = i = 0; i < size; i += 4096) {
965 j = atomicio(read, remin, cp, amt);
967 run_err("%s", j ? strerror(errno) :
968 "dropped connection");
979 if (count == bp->cnt) {
980 /* Keep reading so we stay sync'd up. */
982 if (atomicio(vwrite, ofd, bp->buf,
993 stop_progress_meter();
994 if (count != 0 && wrerr == NO &&
995 atomicio(vwrite, ofd, bp->buf, count) != count) {
999 if (wrerr == NO && ftruncate(ofd, size) != 0) {
1000 run_err("%s: truncate: %s", np, strerror(errno));
1004 if (exists || omode != mode)
1006 if (fchmod(ofd, omode)) {
1007 #else /* HAVE_FCHMOD */
1008 if (chmod(np, omode)) {
1009 #endif /* HAVE_FCHMOD */
1010 run_err("%s: set mode: %s",
1011 np, strerror(errno));
1015 if (!exists && omode != mode)
1017 if (fchmod(ofd, omode & ~mask)) {
1018 #else /* HAVE_FCHMOD */
1019 if (chmod(np, omode & ~mask)) {
1020 #endif /* HAVE_FCHMOD */
1021 run_err("%s: set mode: %s",
1022 np, strerror(errno));
1026 if (close(ofd) == -1) {
1031 if (setimes && wrerr == NO) {
1033 if (utimes(np, tv) < 0) {
1034 run_err("%s: set times: %s",
1035 np, strerror(errno));
1041 run_err("%s: %s", np, strerror(wrerrno));
1044 (void) atomicio(vwrite, remout, "", 1);
1051 run_err("protocol error: %s", why);
1058 char ch, *cp, resp, rbuf[2048];
1060 if (atomicio(read, remin, &resp, sizeof(resp)) != sizeof(resp))
1070 case 1: /* error, followed by error msg */
1071 case 2: /* fatal error, "" */
1073 if (atomicio(read, remin, &ch, sizeof(ch)) != sizeof(ch))
1076 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
1079 (void) atomicio(vwrite, STDERR_FILENO, rbuf, cp - rbuf);
1091 (void) fprintf(stderr,
1092 "usage: scp [-1246BCpqrv] [-c cipher] [-F ssh_config] [-i identity_file]\n"
1093 " [-l limit] [-o ssh_option] [-P port] [-S program]\n"
1094 " [[user@]host1:]file1 [...] [[user@]host2:]file2\n");
1099 run_err(const char *fmt,...)
1105 if (fp == NULL && !(fp = fdopen(remout, "w")))
1107 (void) fprintf(fp, "%c", 0x01);
1108 (void) fprintf(fp, "scp: ");
1110 (void) vfprintf(fp, fmt, ap);
1112 (void) fprintf(fp, "\n");
1117 vfprintf(stderr, fmt, ap);
1119 fprintf(stderr, "\n");
1128 if (!stat(cp, &stb)) {
1129 if (S_ISDIR(stb.st_mode))
1133 run_err("%s: %s", cp, strerror(errno));
1148 if (!isalpha(c) && !isdigit(c)) {
1163 bad: fprintf(stderr, "%s: invalid user name\n", cp0);
1168 allocbuf(BUF *bp, int fd, int blksize)
1171 #ifdef HAVE_STRUCT_STAT_ST_BLKSIZE
1174 if (fstat(fd, &stb) < 0) {
1175 run_err("fstat: %s", strerror(errno));
1178 size = roundup(stb.st_blksize, blksize);
1181 #else /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1183 #endif /* HAVE_STRUCT_STAT_ST_BLKSIZE */
1184 if (bp->cnt >= size)
1186 if (bp->buf == NULL)
1187 bp->buf = xmalloc(size);
1189 bp->buf = xrealloc(bp->buf, size);
1190 memset(bp->buf, 0, size);
1199 write(STDERR_FILENO, "lost connection\n", 16);