=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/from/from.c,v retrieving revision 1.19 retrieving revision 1.20 diff -c -r1.19 -r1.20 *** src/usr.bin/from/from.c 2015/06/03 02:35:50 1.19 --- src/usr.bin/from/from.c 2015/06/03 18:08:54 1.20 *************** *** 1,4 **** ! /* $OpenBSD: from.c,v 1.19 2015/06/03 02:35:50 millert Exp $ */ /* $NetBSD: from.c,v 1.6 1995/09/01 01:39:10 jtc Exp $ */ /* --- 1,4 ---- ! /* $OpenBSD: from.c,v 1.20 2015/06/03 18:08:54 millert Exp $ */ /* $NetBSD: from.c,v 1.6 1995/09/01 01:39:10 jtc Exp $ */ /* *************** *** 39,52 **** #include #include #include int match(char *, char *); ! FILE *open_mbox(const char *file, const char *user); int main(int argc, char *argv[]) { ! int ch, newline; char *file, *line, *sender, *p; size_t linesize = 0; ssize_t linelen; --- 39,53 ---- #include #include #include + #include int match(char *, char *); ! char *mail_spool(char *file, const char *user); int main(int argc, char *argv[]) { ! int ch, newline, fflag = 0; char *file, *line, *sender, *p; size_t linesize = 0; ssize_t linelen; *************** *** 56,61 **** --- 57,63 ---- while ((ch = getopt(argc, argv, "f:s:")) != -1) { switch(ch) { case 'f': + fflag = 1; file = optarg; break; case 's': *************** *** 72,79 **** } argv += optind; ! if ((fp = open_mbox(file, *argv)) == NULL) ! exit(1); for (newline = 1; (linelen = getline(&line, &linesize, fp)) != -1;) { if (*line == '\n') { newline = 1; --- 74,85 ---- } argv += optind; ! file = mail_spool(file, *argv); ! 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;) { if (*line == '\n') { newline = 1; *************** *** 88,99 **** exit(EXIT_SUCCESS); } ! FILE * ! open_mbox(const char *file, const char *user) { struct passwd *pwd; - char *buf = NULL; - FILE *fp; /* * We find the mailbox by: --- 94,103 ---- exit(EXIT_SUCCESS); } ! char * ! mail_spool(char *file, const char *user) { struct passwd *pwd; /* * We find the mailbox by: *************** *** 115,129 **** } } if (file == NULL) { ! if (asprintf(&buf, "%s/%s", _PATH_MAILDIR, user) == -1) err(1, NULL); - file = buf; } } ! if ((fp = fopen(file, "r")) == NULL) ! warn("%s", file); ! free(buf); ! return(fp); } int --- 119,129 ---- } } if (file == NULL) { ! if (asprintf(&file, "%s/%s", _PATH_MAILDIR, user) == -1) err(1, NULL); } } ! return(file); } int