=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/ftp.c,v retrieving revision 1.68 retrieving revision 1.69 diff -c -r1.68 -r1.69 *** src/usr.bin/ftp/ftp.c 2008/03/10 22:56:43 1.68 --- src/usr.bin/ftp/ftp.c 2008/04/12 21:20:58 1.69 *************** *** 1,4 **** ! /* $OpenBSD: ftp.c,v 1.68 2008/03/10 22:56:43 espie Exp $ */ /* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: ftp.c,v 1.69 2008/04/12 21:20:58 ray Exp $ */ /* $NetBSD: ftp.c,v 1.27 1997/08/18 10:20:23 lukem Exp $ */ /* *************** *** 60,66 **** */ #if !defined(lint) && !defined(SMALL) ! static const char rcsid[] = "$OpenBSD: ftp.c,v 1.68 2008/03/10 22:56:43 espie Exp $"; #endif /* not lint and not SMALL */ #include --- 60,66 ---- */ #if !defined(lint) && !defined(SMALL) ! static const char rcsid[] = "$OpenBSD: ftp.c,v 1.69 2008/04/12 21:20:58 ray Exp $"; #endif /* not lint and not SMALL */ #include *************** *** 541,547 **** volatile off_t hashbytes; char * volatile lmode; char buf[BUFSIZ], *bufp; ! int oprogress; hashbytes = mark; direction = "sent"; --- 541,547 ---- volatile off_t hashbytes; char * volatile lmode; char buf[BUFSIZ], *bufp; ! int oprogress, serrno; hashbytes = mark; direction = "sent"; *************** *** 704,710 **** case TYPE_I: case TYPE_L: ! errno = d = 0; while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) { may_send_noop_char(); bytes += c; --- 704,710 ---- case TYPE_I: case TYPE_L: ! d = 0; while ((c = read(fileno(fin), buf, sizeof(buf))) > 0) { may_send_noop_char(); bytes += c; *************** *** 720,725 **** --- 720,727 ---- (void)fflush(ttyout); } } + if (c == -1 || d == -1) + serrno = errno; if (hash && (!progress || filesize < 0) && bytes > 0) { if (bytes < mark) (void)putc('#', ttyout); *************** *** 727,736 **** (void)fflush(ttyout); } if (c < 0) ! warn("local: %s", local); if (d < 0) { ! if (errno != EPIPE) ! warn("netout"); bytes = -1; } break; --- 729,738 ---- (void)fflush(ttyout); } if (c < 0) ! warnx("local: %s: %s", local, strerror(serrno)); if (d < 0) { ! if (serrno != EPIPE) ! warnx("netout: %s", strerror(serrno)); bytes = -1; } break; *************** *** 759,764 **** --- 761,768 ---- } #endif } + if (ferror(fin) || ferror(dout)) + serrno = errno; if (hash && (!progress || filesize < 0)) { if (bytes < hashbytes) (void)putc('#', ttyout); *************** *** 766,775 **** (void)fflush(ttyout); } if (ferror(fin)) ! warn("local: %s", local); if (ferror(dout)) { if (errno != EPIPE) ! warn("netout"); bytes = -1; } break; --- 770,779 ---- (void)fflush(ttyout); } if (ferror(fin)) ! warnx("local: %s: %s", local, strerror(serrno)); if (ferror(dout)) { if (errno != EPIPE) ! warnx("netout: %s", strerror(serrno)); bytes = -1; } break; *************** *** 834,840 **** FILE * volatile fout, * volatile din; int (* volatile closefunc)(FILE *); volatile sig_t oldinti, oldintr, oldintp; ! int c, d; volatile int is_retr, tcrflag, bare_lfs; static size_t bufsize; static char *buf; --- 838,844 ---- FILE * volatile fout, * volatile din; int (* volatile closefunc)(FILE *); volatile sig_t oldinti, oldintr, oldintp; ! int c, d, serrno; volatile int is_retr, tcrflag, bare_lfs; static size_t bufsize; static char *buf; *************** *** 890,896 **** oldinti = signal(SIGINFO, psummary); if (ignorespecial || (strcmp(local, "-") && *local != '|')) { if (access(local, W_OK) < 0) { ! char *dir = strrchr(local, '/'); if (errno != ENOENT && errno != EACCES) { warn("local: %s", local); --- 894,900 ---- oldinti = signal(SIGINFO, psummary); if (ignorespecial || (strcmp(local, "-") && *local != '|')) { if (access(local, W_OK) < 0) { ! char *dir; if (errno != ENOENT && errno != EACCES) { warn("local: %s", local); *************** *** 899,904 **** --- 903,909 ---- code = -1; return; } + dir = strrchr(local, '/'); if (dir != NULL) *dir = 0; d = access(dir == local ? "/" : dir ? local : ".", W_OK); *************** *** 1048,1053 **** --- 1053,1060 ---- (void)fflush(ttyout); } } + if (c == -1 || d < c) + serrno = errno; if (hash && (!progress || filesize < 0) && bytes > 0) { if (bytes < mark) (void)putc('#', ttyout); *************** *** 1055,1067 **** (void)fflush(ttyout); } if (c < 0) { ! if (errno != EPIPE) ! warn("netin"); bytes = -1; } if (d < c) { if (d < 0) ! warn("local: %s", local); else warnx("%s: short write", local); } --- 1062,1074 ---- (void)fflush(ttyout); } if (c < 0) { ! if (serrno != EPIPE) ! warnx("netin: %s", strerror(serrno)); bytes = -1; } if (d < c) { if (d < 0) ! warnx("local: %s: %s", local, strerror(serrno)); else warnx("%s: short write", local); } *************** *** 1075,1088 **** goto done; n = restart_point; for (i = 0; i++ < n;) { ! if ((ch = fgetc(fout)) == EOF) goto done; if (ch == '\n') i++; } if (fseek(fout, 0L, SEEK_CUR) < 0) { done: ! warn("local: %s", local); progress = oprogress; preserve = opreserve; if (closefunc != NULL) --- 1082,1101 ---- goto done; n = restart_point; for (i = 0; i++ < n;) { ! if ((ch = fgetc(fout)) == EOF) { ! if (!ferror(fout)) ! errno = 0; goto done; + } if (ch == '\n') i++; } if (fseek(fout, 0L, SEEK_CUR) < 0) { done: ! if (errno) ! warn("local: %s", local); ! else ! warnx("local: %s", local); progress = oprogress; preserve = opreserve; if (closefunc != NULL) *************** *** 1119,1124 **** --- 1132,1139 ---- contin2: ; } break2: + if (ferror(din) || ferror(fout)) + serrno = errno; if (bare_lfs) { fprintf(ttyout, "WARNING! %d bare linefeeds received in ASCII mode.\n", bare_lfs); *************** *** 1132,1143 **** (void)fflush(ttyout); } if (ferror(din)) { ! if (errno != EPIPE) ! warn("netin"); bytes = -1; } if (ferror(fout)) ! warn("local: %s", local); break; } progressmeter(1); --- 1147,1158 ---- (void)fflush(ttyout); } if (ferror(din)) { ! if (serrno != EPIPE) ! warnx("netin: %s", strerror(serrno)); bytes = -1; } if (ferror(fout)) ! warnx("local: %s: %s", local, strerror(serrno)); break; } progressmeter(1);