=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/ftp/fetch.c,v retrieving revision 1.16 retrieving revision 1.17 diff -c -r1.16 -r1.17 *** src/usr.bin/ftp/fetch.c 1997/09/11 01:55:15 1.16 --- src/usr.bin/ftp/fetch.c 1998/02/17 23:22:54 1.17 *************** *** 1,4 **** ! /* $OpenBSD: fetch.c,v 1.16 1997/09/11 01:55:15 millert Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- --- 1,4 ---- ! /* $OpenBSD: fetch.c,v 1.17 1998/02/17 23:22:54 millert Exp $ */ /* $NetBSD: fetch.c,v 1.14 1997/08/18 10:20:20 lukem Exp $ */ /*- *************** *** 38,44 **** */ #ifndef lint ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.16 1997/09/11 01:55:15 millert Exp $"; #endif /* not lint */ /* --- 38,44 ---- */ #ifndef lint ! static char rcsid[] = "$OpenBSD: fetch.c,v 1.17 1998/02/17 23:22:54 millert Exp $"; #endif /* not lint */ /* *************** *** 56,61 **** --- 56,62 ---- #include #include + #include #include #include #include *************** *** 66,72 **** #include "ftp_var.h" ! static int url_get __P((const char *, const char *, int)); void aborthttp __P((int)); --- 67,73 ---- #include "ftp_var.h" ! static int url_get __P((const char *, const char *, const char *)); void aborthttp __P((int)); *************** *** 86,95 **** * Returns -1 on failure, 0 on success */ static int ! url_get(origline, proxyenv, fd) const char *origline; const char *proxyenv; ! int fd; { struct sockaddr_in sin; int i, out, isftpurl; --- 87,96 ---- * Returns -1 on failure, 0 on success */ static int ! url_get(origline, proxyenv, outfile) const char *origline; const char *proxyenv; ! const char *outfile; { struct sockaddr_in sin; int i, out, isftpurl; *************** *** 138,148 **** goto cleanup_url_get; } ! savefile = strrchr(path, '/'); /* find savefile */ ! if (savefile != NULL) ! savefile++; else ! savefile = path; if (EMPTYSTRING(savefile)) { if (isftpurl) goto noftpautologin; --- 139,149 ---- goto cleanup_url_get; } ! if (outfile) ! savefile = outfile; else ! savefile = basename(path); ! if (EMPTYSTRING(savefile)) { if (isftpurl) goto noftpautologin; *************** *** 302,316 **** } else filesize = -1; ! /* Open the output file. */ ! if (fd == -1) { out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { warn("Can't open %s", savefile); goto cleanup_url_get; } } else ! out = fd; /* Trap signals */ oldintr = NULL; --- 303,317 ---- } else filesize = -1; ! /* Open the output file. */ ! if (strcmp(savefile, "-") != 0) { out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) { warn("Can't open %s", savefile); goto cleanup_url_get; } } else ! out = fileno(stdout); /* Trap signals */ oldintr = NULL; *************** *** 361,367 **** (void)signal(SIGINT, oldintr); close(s); ! if (fd != -1) close(out); if (proxy) free(proxy); --- 362,368 ---- (void)signal(SIGINT, oldintr); close(s); ! if (out != fileno(stdout)) close(out); if (proxy) free(proxy); *************** *** 414,423 **** * Otherwise, 0 is returned if all files retrieved successfully. */ int ! auto_fetch(argc, argv, fd) int argc; char *argv[]; ! int fd; { static char lasthost[MAXHOSTNAMELEN]; char *xargv[5]; --- 415,424 ---- * Otherwise, 0 is returned if all files retrieved successfully. */ int ! auto_fetch(argc, argv, outfile) int argc; char *argv[]; ! char *outfile; { static char lasthost[MAXHOSTNAMELEN]; char *xargv[5]; *************** *** 461,467 **** * Try HTTP URL-style arguments first. */ if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { ! if (url_get(line, httpproxy, fd) == -1) rval = argpos + 1; continue; } --- 462,468 ---- * Try HTTP URL-style arguments first. */ if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) { ! if (url_get(line, httpproxy, outfile) == -1) rval = argpos + 1; continue; } *************** *** 474,480 **** host = line; if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { if (ftpproxy) { ! if (url_get(line, ftpproxy, fd) == -1) rval = argpos + 1; continue; } --- 475,481 ---- host = line; if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) { if (ftpproxy) { ! if (url_get(line, ftpproxy, outfile) == -1) rval = argpos + 1; continue; } *************** *** 638,648 **** mget(xargc, xargv); interactive = ointeractive; } else { ! if (fd != -1) { ! xargv[2] = "-"; xargc++; } - xargv[3] = NULL; get(xargc, xargv); } --- 639,649 ---- mget(xargc, xargv); interactive = ointeractive; } else { ! if (outfile != NULL) { ! xargv[2] = outfile; ! xargv[3] = NULL; xargc++; } get(xargc, xargv); }