[BACK]Return to fetch.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ftp

Diff for /src/usr.bin/ftp/fetch.c between version 1.16 and 1.17

version 1.16, 1997/09/11 01:55:15 version 1.17, 1998/02/17 23:22:54
Line 56 
Line 56 
   
 #include <ctype.h>  #include <ctype.h>
 #include <err.h>  #include <err.h>
   #include <libgen.h>
 #include <netdb.h>  #include <netdb.h>
 #include <fcntl.h>  #include <fcntl.h>
 #include <signal.h>  #include <signal.h>
Line 66 
Line 67 
   
 #include "ftp_var.h"  #include "ftp_var.h"
   
 static int      url_get __P((const char *, const char *, int));  static int      url_get __P((const char *, const char *, const char *));
 void            aborthttp __P((int));  void            aborthttp __P((int));
   
   
Line 86 
Line 87 
  * Returns -1 on failure, 0 on success   * Returns -1 on failure, 0 on success
  */   */
 static int  static int
 url_get(origline, proxyenv, fd)  url_get(origline, proxyenv, outfile)
         const char *origline;          const char *origline;
         const char *proxyenv;          const char *proxyenv;
         int fd;          const char *outfile;
 {  {
         struct sockaddr_in sin;          struct sockaddr_in sin;
         int i, out, isftpurl;          int i, out, isftpurl;
Line 138 
Line 139 
                 goto cleanup_url_get;                  goto cleanup_url_get;
         }          }
   
         savefile = strrchr(path, '/');                  /* find savefile */          if (outfile)
         if (savefile != NULL)                  savefile = outfile;
                 savefile++;  
         else          else
                 savefile = path;                  savefile = basename(path);
   
         if (EMPTYSTRING(savefile)) {          if (EMPTYSTRING(savefile)) {
                 if (isftpurl)                  if (isftpurl)
                         goto noftpautologin;                          goto noftpautologin;
Line 302 
Line 303 
         } else          } else
                 filesize = -1;                  filesize = -1;
   
         /* Open the output file. */          /* Open the output file.  */
         if (fd == -1) {          if (strcmp(savefile, "-") != 0) {
                 out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);                  out = open(savefile, O_CREAT | O_WRONLY | O_TRUNC, 0666);
                 if (out < 0) {                  if (out < 0) {
                         warn("Can't open %s", savefile);                          warn("Can't open %s", savefile);
                         goto cleanup_url_get;                          goto cleanup_url_get;
                 }                  }
         } else          } else
                 out = fd;                  out = fileno(stdout);
   
         /* Trap signals */          /* Trap signals */
         oldintr = NULL;          oldintr = NULL;
Line 361 
Line 362 
         (void)signal(SIGINT, oldintr);          (void)signal(SIGINT, oldintr);
   
         close(s);          close(s);
         if (fd != -1)          if (out != fileno(stdout))
                 close(out);                  close(out);
         if (proxy)          if (proxy)
                 free(proxy);                  free(proxy);
Line 414 
Line 415 
  * Otherwise, 0 is returned if all files retrieved successfully.   * Otherwise, 0 is returned if all files retrieved successfully.
  */   */
 int  int
 auto_fetch(argc, argv, fd)  auto_fetch(argc, argv, outfile)
         int argc;          int argc;
         char *argv[];          char *argv[];
         int fd;          char *outfile;
 {  {
         static char lasthost[MAXHOSTNAMELEN];          static char lasthost[MAXHOSTNAMELEN];
         char *xargv[5];          char *xargv[5];
Line 461 
Line 462 
                  * Try HTTP URL-style arguments first.                   * Try HTTP URL-style arguments first.
                  */                   */
                 if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {                  if (strncasecmp(line, HTTP_URL, sizeof(HTTP_URL) - 1) == 0) {
                         if (url_get(line, httpproxy, fd) == -1)                          if (url_get(line, httpproxy, outfile) == -1)
                                 rval = argpos + 1;                                  rval = argpos + 1;
                         continue;                          continue;
                 }                  }
Line 474 
Line 475 
                 host = line;                  host = line;
                 if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {                  if (strncasecmp(line, FTP_URL, sizeof(FTP_URL) - 1) == 0) {
                         if (ftpproxy) {                          if (ftpproxy) {
                                 if (url_get(line, ftpproxy, fd) == -1)                                  if (url_get(line, ftpproxy, outfile) == -1)
                                         rval = argpos + 1;                                          rval = argpos + 1;
                                 continue;                                  continue;
                         }                          }
Line 638 
Line 639 
                         mget(xargc, xargv);                          mget(xargc, xargv);
                         interactive = ointeractive;                          interactive = ointeractive;
                 } else {                  } else {
                         if (fd != -1) {                          if (outfile != NULL) {
                                 xargv[2] = "-";                                  xargv[2] = outfile;
                                   xargv[3] = NULL;
                                 xargc++;                                  xargc++;
                         }                          }
                         xargv[3] = NULL;  
                         get(xargc, xargv);                          get(xargc, xargv);
                 }                  }
   

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17