3 * scp - secure remote copy. This is basically patched BSD rcp which uses ssh
4 * to do the data transfer (instead of using rcmd).
6 * NOTE: This version should NOT be suid root. (This uses ssh to do the transfer
7 * and ssh has the necessary privileges.)
9 * 1995 Timo Rinne <tri@iki.fi>, Tatu Ylonen <ylo@cs.hut.fi>
14 * Copyright (c) 1983, 1990, 1992, 1993, 1995
15 * The Regents of the University of California. All rights reserved.
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
20 * 1. Redistributions of source code must retain the above copyright
21 * notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 * notice, this list of conditions and the following disclaimer in the
24 * documentation and/or other materials provided with the distribution.
25 * 3. All advertising materials mentioning features or use of this software
26 * must display the following acknowledgement:
27 * This product includes software developed by the University of
28 * California, Berkeley and its contributors.
29 * 4. Neither the name of the University nor the names of its contributors
30 * may be used to endorse or promote products derived from this software
31 * without specific prior written permission.
33 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
34 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
35 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
36 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
37 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
38 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
39 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
40 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
41 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
42 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 /* For progressmeter() -- number of seconds before xfer considered "stalled" */
59 /* Visual statistics about files as they are transferred. */
60 void progressmeter(int);
62 /* Returns width of the terminal (for progress meter calculations). */
63 int getttywidth(void);
65 /* Time a transfer started. */
66 static struct timeval start;
68 /* Number of bytes of current file transferred so far. */
69 volatile unsigned long statbytes;
71 /* Total size of current file. */
74 /* Name of current file being transferred. */
77 /* This is set to non-zero if IPv4 is desired. */
80 /* This is set to non-zero if IPv6 is desired. */
83 /* This is set to non-zero to enable verbose mode. */
86 /* This is set to non-zero if compression is desired. */
87 int compress_flag = 0;
89 /* This is set to zero if the progressmeter is not desired. */
92 /* This is set to non-zero if running in batch mode (that is, password
93 and passphrase queries are not allowed). */
96 /* This is set to the cipher type string if given on the command line. */
99 /* This is set to the RSA authentication identity file name if given on
101 char *identity = NULL;
103 /* This is the port to use in contacting the remote site (is non-NULL). */
107 * This function executes the given command as the specified user on the
108 * given host. This returns < 0 if execution fails, and >= 0 otherwise. This
109 * assigns the input and output file descriptors on success.
113 do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout)
115 int pin[2], pout[2], reserved[2];
118 fprintf(stderr, "Executing: host %s, user %s, command %s\n",
119 host, remuser ? remuser : "(unspecified)", cmd);
122 * Reserve two descriptors so that the real pipes won't get
123 * descriptors 0 and 1 because that will screw up dup2 below.
127 /* Create a socket pair for communicating with ssh. */
129 fatal("pipe: %s", strerror(errno));
131 fatal("pipe: %s", strerror(errno));
133 /* Free the reserved descriptors. */
137 /* For a child to execute the command on the remote host using ssh. */
151 args[i++] = SSH_PROGRAM;
153 args[i++] = "-oFallBackToRsh no";
158 args[i++] = "-oFallBackToRsh no";
164 args[i++] = "-oBatchMode yes";
165 if (cipher != NULL) {
169 if (identity != NULL) {
171 args[i++] = identity;
177 if (remuser != NULL) {
185 execvp(SSH_PROGRAM, args);
189 /* Parent. Close the other side, and return the local side. */
198 fatal(const char *fmt,...)
204 vsnprintf(buf, sizeof(buf), fmt, ap);
206 fprintf(stderr, "%s\n", buf);
210 /* This stuff used to be in BSD rcp extern.h. */
217 extern int iamremote;
219 BUF *allocbuf(BUF *, int, int);
224 void run_err(const char *,...);
225 void verifydir(char *);
227 /* Stuff from BSD rcp.c continues. */
231 int errs, remin, remout;
232 int pflag, iamremote, iamrecursive, targetshouldbedirectory;
235 char cmd[CMDNEEDS]; /* must hold "rcp -r -p -d\0" */
238 void rsource(char *, struct stat *);
239 void sink(int, char *[]);
240 void source(int, char *[]);
241 void tolocal(int, char *[]);
242 void toremote(char *, int, char *[]);
250 int ch, fflag, tflag;
256 while ((ch = getopt(argc, argv, "dfprtvBCc:i:P:q46")) != EOF)
258 /* User-visible flags. */
274 /* Server options. */
276 targetshouldbedirectory = 1;
278 case 'f': /* "from" */
311 if ((pwd = getpwuid(userid = getuid())) == NULL)
312 fatal("unknown user %d", (int) userid);
314 if (!isatty(STDERR_FILENO))
317 remin = STDIN_FILENO;
318 remout = STDOUT_FILENO;
321 /* Follow "protocol", send data. */
334 targetshouldbedirectory = 1;
337 /* Command to be executed on remote system using "ssh". */
338 (void) sprintf(cmd, "scp%s%s%s%s", verbose_mode ? " -v" : "",
339 iamrecursive ? " -r" : "", pflag ? " -p" : "",
340 targetshouldbedirectory ? " -d" : "");
342 (void) signal(SIGPIPE, lostconn);
344 if ((targ = colon(argv[argc - 1]))) /* Dest is remote host. */
345 toremote(targ, argc, argv);
347 tolocal(argc, argv); /* Dest is local host. */
348 if (targetshouldbedirectory)
349 verifydir(argv[argc - 1]);
358 if (*host == '[' && host[strlen(host) - 1] == ']') {
359 host[strlen(host) - 1] = '\0';
366 toremote(targ, argc, argv)
371 char *bp, *host, *src, *suser, *thost, *tuser;
377 if ((thost = strchr(argv[argc - 1], '@'))) {
380 tuser = argv[argc - 1];
383 else if (!okname(tuser))
386 thost = argv[argc - 1];
390 for (i = 0; i < argc - 1; i++) {
391 src = colon(argv[i]);
392 if (src) { /* remote to remote */
396 host = strchr(argv[i], '@');
397 len = strlen(SSH_PROGRAM) + strlen(argv[i]) +
398 strlen(src) + (tuser ? strlen(tuser) : 0) +
399 strlen(thost) + strlen(targ) + CMDNEEDS + 32;
403 host = cleanhostname(host);
406 suser = pwd->pw_name;
407 else if (!okname(suser))
410 "%s%s -x -o'FallBackToRsh no' -n -l %s %s %s %s '%s%s%s:%s'",
411 SSH_PROGRAM, verbose_mode ? " -v" : "",
412 suser, host, cmd, src,
413 tuser ? tuser : "", tuser ? "@" : "",
416 host = cleanhostname(argv[i]);
418 "exec %s%s -x -o'FallBackToRsh no' -n %s %s %s '%s%s%s:%s'",
419 SSH_PROGRAM, verbose_mode ? " -v" : "",
421 tuser ? tuser : "", tuser ? "@" : "",
425 fprintf(stderr, "Executing: %s\n", bp);
428 } else { /* local to remote */
430 len = strlen(targ) + CMDNEEDS + 20;
432 (void) sprintf(bp, "%s -t %s", cmd, targ);
433 host = cleanhostname(thost);
434 if (do_cmd(host, tuser,
435 bp, &remin, &remout) < 0)
452 char *bp, *host, *src, *suser;
454 for (i = 0; i < argc - 1; i++) {
455 if (!(src = colon(argv[i]))) { /* Local to local. */
456 len = strlen(_PATH_CP) + strlen(argv[i]) +
457 strlen(argv[argc - 1]) + 20;
459 (void) sprintf(bp, "exec %s%s%s %s %s", _PATH_CP,
460 iamrecursive ? " -r" : "", pflag ? " -p" : "",
461 argv[i], argv[argc - 1]);
463 fprintf(stderr, "Executing: %s\n", bp);
472 if ((host = strchr(argv[i], '@')) == NULL) {
479 suser = pwd->pw_name;
480 else if (!okname(suser))
483 host = cleanhostname(host);
484 len = strlen(src) + CMDNEEDS + 20;
486 (void) sprintf(bp, "%s -f %s", cmd, src);
487 if (do_cmd(host, suser, bp, &remin, &remout) < 0) {
493 sink(1, argv + argc - 1);
508 int amt, fd, haderr, indx, result;
509 char *last, *name, buf[2048];
511 for (indx = 0; indx < argc; ++indx) {
514 if ((fd = open(name, O_RDONLY, 0)) < 0)
516 if (fstat(fd, &stb) < 0) {
517 syserr: run_err("%s: %s", name, strerror(errno));
520 switch (stb.st_mode & S_IFMT) {
530 run_err("%s: not a regular file", name);
533 if ((last = strrchr(name, '/')) == NULL)
540 * Make it compatible with possible future
541 * versions expecting microseconds.
543 (void) sprintf(buf, "T%lu 0 %lu 0\n",
544 (unsigned long) stb.st_mtime,
545 (unsigned long) stb.st_atime);
546 (void) write(remout, buf, strlen(buf));
550 #define FILEMODEMASK (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
551 (void) sprintf(buf, "C%04o %lu %s\n",
552 (unsigned int) (stb.st_mode & FILEMODEMASK),
553 (unsigned long) stb.st_size,
556 fprintf(stderr, "Sending file modes: %s", buf);
559 (void) write(remout, buf, strlen(buf));
562 if ((bp = allocbuf(&buffer, fd, 2048)) == NULL) {
563 next: (void) close(fd);
567 totalbytes = stb.st_size;
570 /* Keep writing after an error so that we stay sync'd up. */
571 for (haderr = i = 0; i < stb.st_size; i += bp->cnt) {
573 if (i + amt > stb.st_size)
574 amt = stb.st_size - i;
576 result = read(fd, bp->buf, amt);
578 haderr = result >= 0 ? EIO : errno;
581 (void) write(remout, bp->buf, amt);
583 result = atomicio(write, remout, bp->buf, amt);
585 haderr = result >= 0 ? EIO : errno;
592 if (close(fd) < 0 && !haderr)
595 (void) write(remout, "", 1);
597 run_err("%s: %s", name, strerror(haderr));
609 char *last, *vect[1], path[1100];
611 if (!(dirp = opendir(name))) {
612 run_err("%s: %s", name, strerror(errno));
615 last = strrchr(name, '/');
621 (void) sprintf(path, "T%lu 0 %lu 0\n",
622 (unsigned long) statp->st_mtime,
623 (unsigned long) statp->st_atime);
624 (void) write(remout, path, strlen(path));
625 if (response() < 0) {
630 (void) sprintf(path, "D%04o %d %.1024s\n",
631 (unsigned int) (statp->st_mode & FILEMODEMASK),
634 fprintf(stderr, "Entering directory: %s", path);
635 (void) write(remout, path, strlen(path));
636 if (response() < 0) {
640 while ((dp = readdir(dirp))) {
643 if (!strcmp(dp->d_name, ".") || !strcmp(dp->d_name, ".."))
645 if (strlen(name) + 1 + strlen(dp->d_name) >= sizeof(path) - 1) {
646 run_err("%s/%s: name too long", name, dp->d_name);
649 (void) sprintf(path, "%s/%s", name, dp->d_name);
653 (void) closedir(dirp);
654 (void) write(remout, "E\n", 2);
670 int amt, count, exists, first, mask, mode, ofd, omode;
671 int setimes, size, targisdir, wrerrno = 0;
672 char ch, *cp, *np, *targ, *why, *vect[1], buf[2048];
676 #define SCREWUP(str) { why = str; goto screwup; }
678 setimes = targisdir = 0;
683 run_err("ambiguous target");
687 if (targetshouldbedirectory)
690 (void) write(remout, "", 1);
691 if (stat(targ, &stb) == 0 && S_ISDIR(stb.st_mode))
693 for (first = 1;; first = 0) {
695 if (read(remin, cp, 1) <= 0)
698 SCREWUP("unexpected <newline>");
700 if (read(remin, &ch, sizeof(ch)) != sizeof(ch))
701 SCREWUP("lost connection");
703 } while (cp < &buf[sizeof(buf) - 1] && ch != '\n');
706 if (buf[0] == '\01' || buf[0] == '\02') {
708 (void) write(STDERR_FILENO,
709 buf + 1, strlen(buf + 1));
716 (void) write(remout, "", 1);
722 #define getnum(t) (t) = 0; \
723 while (*cp >= '0' && *cp <= '9') (t) = (t) * 10 + (*cp++ - '0');
730 SCREWUP("mtime.sec not delimited");
733 SCREWUP("mtime.usec not delimited");
736 SCREWUP("atime.sec not delimited");
739 SCREWUP("atime.usec not delimited");
740 (void) write(remout, "", 1);
743 if (*cp != 'C' && *cp != 'D') {
745 * Check for the case "rcp remote:foo\* local:bar".
746 * In this case, the line "No match." can be returned
747 * by the shell before the rcp command on the remote is
748 * executed so the ^Aerror_message convention isn't
755 SCREWUP("expected control record");
758 for (++cp; cp < buf + 5; cp++) {
759 if (*cp < '0' || *cp > '7')
761 mode = (mode << 3) | (*cp - '0');
764 SCREWUP("mode not delimited");
766 for (size = 0; *cp >= '0' && *cp <= '9';)
767 size = size * 10 + (*cp++ - '0');
769 SCREWUP("size not delimited");
771 static char *namebuf;
775 need = strlen(targ) + strlen(cp) + 250;
777 namebuf = xmalloc(need);
778 (void) sprintf(namebuf, "%s%s%s", targ,
779 *targ ? "/" : "", cp);
784 exists = stat(np, &stb) == 0;
786 int mod_flag = pflag;
788 if (!S_ISDIR(stb.st_mode)) {
793 (void) chmod(np, mode);
795 /* Handle copying from a read-only
798 if (mkdir(np, mode | S_IRWXU) < 0)
805 if (utime(np, &ut) < 0)
806 run_err("%s: set times: %s",
807 np, strerror(errno));
810 (void) chmod(np, mode);
815 if ((ofd = open(np, O_WRONLY | O_CREAT | O_TRUNC, mode)) < 0) {
816 bad: run_err("%s: %s", np, strerror(errno));
819 (void) write(remout, "", 1);
820 if ((bp = allocbuf(&buffer, ofd, 4096)) == NULL) {
832 for (count = i = 0; i < size; i += 4096) {
838 j = read(remin, cp, amt);
840 run_err("%s", j ? strerror(errno) :
841 "dropped connection");
848 if (count == bp->cnt) {
849 /* Keep reading so we stay sync'd up. */
851 j = write(ofd, bp->buf, count);
854 wrerrno = j >= 0 ? EIO : errno;
863 if (count != 0 && wrerr == NO &&
864 (j = write(ofd, bp->buf, count)) != count) {
866 wrerrno = j >= 0 ? EIO : errno;
869 if (ftruncate(ofd, size)) {
870 run_err("%s: truncate: %s", np, strerror(errno));
875 if (exists || omode != mode)
876 if (fchmod(ofd, omode))
877 run_err("%s: set mode: %s",
878 np, strerror(errno));
880 if (!exists && omode != mode)
881 if (fchmod(ofd, omode & ~mask))
882 run_err("%s: set mode: %s",
883 np, strerror(errno));
887 if (setimes && wrerr == NO) {
889 if (utime(np, &ut) < 0) {
890 run_err("%s: set times: %s",
891 np, strerror(errno));
897 run_err("%s: %s", np, strerror(wrerrno));
900 (void) write(remout, "", 1);
907 run_err("protocol error: %s", why);
914 char ch, *cp, resp, rbuf[2048];
916 if (read(remin, &resp, sizeof(resp)) != sizeof(resp))
926 case 1: /* error, followed by error msg */
927 case 2: /* fatal error, "" */
929 if (read(remin, &ch, sizeof(ch)) != sizeof(ch))
932 } while (cp < &rbuf[sizeof(rbuf) - 1] && ch != '\n');
935 (void) write(STDERR_FILENO, rbuf, cp - rbuf);
947 (void) fprintf(stderr,
948 "usage: scp [-pqrvC46] [-P port] [-c cipher] [-i identity] f1 f2; or:\n scp [options] f1 ... fn directory\n");
953 run_err(const char *fmt,...)
959 if (fp == NULL && !(fp = fdopen(remout, "w")))
961 (void) fprintf(fp, "%c", 0x01);
962 (void) fprintf(fp, "scp: ");
964 (void) vfprintf(fp, fmt, ap);
966 (void) fprintf(fp, "\n");
971 vfprintf(stderr, fmt, ap);
973 fprintf(stderr, "\n");
977 /* Stuff below is from BSD rcp util.c. */
980 * Copyright (c) 1992, 1993
981 * The Regents of the University of California. All rights reserved.
983 * Redistribution and use in source and binary forms, with or without
984 * modification, are permitted provided that the following conditions
986 * 1. Redistributions of source code must retain the above copyright
987 * notice, this list of conditions and the following disclaimer.
988 * 2. Redistributions in binary form must reproduce the above copyright
989 * notice, this list of conditions and the following disclaimer in the
990 * documentation and/or other materials provided with the distribution.
991 * 3. All advertising materials mentioning features or use of this software
992 * must display the following acknowledgement:
993 * This product includes software developed by the University of
994 * California, Berkeley and its contributors.
995 * 4. Neither the name of the University nor the names of its contributors
996 * may be used to endorse or promote products derived from this software
997 * without specific prior written permission.
999 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
1000 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1001 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1002 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
1003 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1004 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1005 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1006 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1007 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1008 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1020 if (*cp == ':') /* Leading colon is part of file name. */
1026 if (*cp == '@' && *(cp+1) == '[')
1028 if (*cp == ']' && *(cp+1) == ':' && flag)
1030 if (*cp == ':' && !flag)
1044 if (!stat(cp, &stb)) {
1045 if (S_ISDIR(stb.st_mode))
1049 run_err("%s: %s", cp, strerror(errno));
1065 if (!isalpha(c) && !isdigit(c) && c != '_' && c != '-')
1070 bad: fprintf(stderr, "%s: invalid user name\n", cp0);
1075 allocbuf(bp, fd, blksize)
1082 if (fstat(fd, &stb) < 0) {
1083 run_err("fstat: %s", strerror(errno));
1086 if (stb.st_blksize == 0)
1089 size = blksize + (stb.st_blksize - blksize % stb.st_blksize) %
1091 if (bp->cnt >= size)
1093 if (bp->buf == NULL)
1094 bp->buf = xmalloc(size);
1096 bp->buf = xrealloc(bp->buf, size);
1106 fprintf(stderr, "lost connection\n");
1112 alarmtimer(int wait)
1114 struct itimerval itv;
1116 itv.it_value.tv_sec = wait;
1117 itv.it_value.tv_usec = 0;
1118 itv.it_interval = itv.it_value;
1119 setitimer(ITIMER_REAL, &itv, NULL);
1123 updateprogressmeter(int ignore)
1125 int save_errno = errno;
1134 static pid_t pgrp = -1;
1140 return ((ioctl(STDOUT_FILENO, TIOCGPGRP, &ctty_pgrp) != -1 &&
1141 ctty_pgrp == pgrp));
1145 progressmeter(int flag)
1147 static const char prefixes[] = " KMGTP";
1148 static struct timeval lastupdate;
1149 static off_t lastsize;
1150 struct timeval now, td, wait;
1151 off_t cursize, abbrevsize;
1153 int ratio, barlength, i, remaining;
1157 (void) gettimeofday(&start, (struct timezone *) 0);
1161 if (foregroundproc() == 0)
1164 (void) gettimeofday(&now, (struct timezone *) 0);
1165 cursize = statbytes;
1166 if (totalbytes != 0) {
1167 ratio = 100.0 * cursize / totalbytes;
1168 ratio = MAX(ratio, 0);
1169 ratio = MIN(ratio, 100);
1173 snprintf(buf, sizeof(buf), "\r%-20.20s %3d%% ", curfile, ratio);
1175 barlength = getttywidth() - 51;
1176 if (barlength > 0) {
1177 i = barlength * ratio / 100;
1178 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1180 "*****************************************************************************"
1181 "*****************************************************************************",
1185 abbrevsize = cursize;
1186 while (abbrevsize >= 100000 && i < sizeof(prefixes)) {
1190 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf), " %5d %c%c ",
1191 (int) abbrevsize, prefixes[i], prefixes[i] == ' ' ? ' ' :
1194 timersub(&now, &lastupdate, &wait);
1195 if (cursize > lastsize) {
1198 if (wait.tv_sec >= STALLTIME) {
1199 start.tv_sec += wait.tv_sec;
1200 start.tv_usec += wait.tv_usec;
1204 timersub(&now, &start, &td);
1205 elapsed = td.tv_sec + (td.tv_usec / 1000000.0);
1207 if (statbytes <= 0 || elapsed <= 0.0 || cursize > totalbytes) {
1208 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1210 } else if (wait.tv_sec >= STALLTIME) {
1211 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1214 remaining = (int) (totalbytes / (statbytes / elapsed) - elapsed);
1215 i = remaining / 3600;
1217 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1220 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1222 i = remaining % 3600;
1223 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
1224 "%02d:%02d ETA", i / 60, i % 60);
1226 atomicio(write, fileno(stdout), buf, strlen(buf));
1229 struct sigaction sa;
1230 sa.sa_handler = updateprogressmeter;
1231 sigemptyset(&sa.sa_mask);
1232 sa.sa_flags = SA_RESTART;
1233 sigaction(SIGALRM, &sa, NULL);
1235 } else if (flag == 1) {
1237 write(fileno(stdout), "\n", 1);
1245 struct winsize winsize;
1247 if (ioctl(fileno(stdout), TIOCGWINSZ, &winsize) != -1)
1248 return (winsize.ws_col ? winsize.ws_col : 80);