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

Diff for /src/usr.bin/from/from.c between version 1.19 and 1.20

version 1.19, 2015/06/03 02:35:50 version 1.20, 2015/06/03 18:08:54
Line 39 
Line 39 
 #include <paths.h>  #include <paths.h>
 #include <string.h>  #include <string.h>
 #include <err.h>  #include <err.h>
   #include <errno.h>
   
 int     match(char *, char *);  int     match(char *, char *);
 FILE    *open_mbox(const char *file, const char *user);  char    *mail_spool(char *file, const char *user);
   
 int  int
 main(int argc, char *argv[])  main(int argc, char *argv[])
 {  {
         int ch, newline;          int ch, newline, fflag = 0;
         char *file, *line, *sender, *p;          char *file, *line, *sender, *p;
         size_t linesize = 0;          size_t linesize = 0;
         ssize_t linelen;          ssize_t linelen;
Line 56 
Line 57 
         while ((ch = getopt(argc, argv, "f:s:")) != -1) {          while ((ch = getopt(argc, argv, "f:s:")) != -1) {
                 switch(ch) {                  switch(ch) {
                 case 'f':                  case 'f':
                           fflag = 1;
                         file = optarg;                          file = optarg;
                         break;                          break;
                 case 's':                  case 's':
Line 72 
Line 74 
         }          }
         argv += optind;          argv += optind;
   
         if ((fp = open_mbox(file, *argv)) == NULL)          file = mail_spool(file, *argv);
                 exit(1);          if ((fp = fopen(file, "r")) == NULL) {
                   if (!fflag && errno == ENOENT)
                           exit(EXIT_SUCCESS);
                   err(1, "%s", file);
           }
         for (newline = 1; (linelen = getline(&line, &linesize, fp)) != -1;) {          for (newline = 1; (linelen = getline(&line, &linesize, fp)) != -1;) {
                 if (*line == '\n') {                  if (*line == '\n') {
                         newline = 1;                          newline = 1;
Line 88 
Line 94 
         exit(EXIT_SUCCESS);          exit(EXIT_SUCCESS);
 }  }
   
 FILE *  char *
 open_mbox(const char *file, const char *user)  mail_spool(char *file, const char *user)
 {  {
         struct passwd *pwd;          struct passwd *pwd;
         char *buf = NULL;  
         FILE *fp;  
   
         /*          /*
          * We find the mailbox by:           * We find the mailbox by:
Line 115 
Line 119 
                         }                          }
                 }                  }
                 if (file == NULL) {                  if (file == NULL) {
                         if (asprintf(&buf, "%s/%s", _PATH_MAILDIR, user) == -1)                          if (asprintf(&file, "%s/%s", _PATH_MAILDIR, user) == -1)
                                 err(1, NULL);                                  err(1, NULL);
                         file = buf;  
                 }                  }
         }          }
         if ((fp = fopen(file, "r")) == NULL)          return(file);
                 warn("%s", file);  
         free(buf);  
         return(fp);  
 }  }
   
 int  int

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20