aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/from
diff options
context:
space:
mode:
authorJuli Mallett <jmallett@FreeBSD.org>2002-06-30 17:36:54 +0000
committerJuli Mallett <jmallett@FreeBSD.org>2002-06-30 17:36:54 +0000
commitc948c0582cace4ca0a573b94abcbccadcf040131 (patch)
tree7ead791225e68851bfcf7ddf6c48150c2a12b6da /usr.bin/from
parentbff4151c280b4e9083aadb7e54e73e29c093ed4b (diff)
downloadsrc-c948c0582cace4ca0a573b94abcbccadcf040131.tar.gz
src-c948c0582cace4ca0a573b94abcbccadcf040131.zip
Minor cleanup: ANSI C function declarations, use argc after getopt(3) to check
for remaining arguments, rather than checking for *argv being a boolean truth. Instead of using an empty case to check for -f- to mean "read stdin", and have stdin reopned otherwise, use a FILE* for the mbox, and assign it to stdin when we mean to use stdin, otherwise fopen(3). Kill `register' qualifier.
Notes
Notes: svn path=/head/; revision=99143
Diffstat (limited to 'usr.bin/from')
-rw-r--r--usr.bin/from/from.c23
1 files changed, 12 insertions, 11 deletions
diff --git a/usr.bin/from/from.c b/usr.bin/from/from.c
index 5fc726fae434..d42e0bd787fa 100644
--- a/usr.bin/from/from.c
+++ b/usr.bin/from/from.c
@@ -59,10 +59,9 @@ int match(char *, char *);
static void usage(void);
int
-main(argc, argv)
- int argc;
- char **argv;
+main(int argc, char **argv)
{
+ FILE *mbox;
struct passwd *pwd;
int ch, count, newline;
char *file, *sender, *p;
@@ -92,10 +91,11 @@ main(argc, argv)
default:
usage();
}
+ argc -= optind;
argv += optind;
- if (!file) {
- if (*argv) {
+ if (file == NULL) {
+ if (argc) {
(void)snprintf(buf, sizeof(buf), "%s/%s", _PATH_MAILDIR, *argv);
file = buf;
} else {
@@ -112,11 +112,12 @@ main(argc, argv)
/* read from stdin */
if (strcmp(file, "-") == 0) {
+ mbox = stdin;
}
- else if (!freopen(file, "r", stdin)) {
+ else if ((mbox = fopen(file, "r")) == NULL) {
errx(1, "can't read %s", file);
}
- for (newline = 1; fgets(buf, sizeof(buf), stdin);) {
+ for (newline = 1; fgets(buf, sizeof(buf), mbox);) {
if (*buf == '\n') {
newline = 1;
continue;
@@ -133,21 +134,21 @@ main(argc, argv)
if (count != -1)
printf("There %s %d message%s in your incoming mailbox.\n",
count == 1 ? "is" : "are", count, count == 1 ? "" : "s");
+ fclose(mbox);
exit(0);
}
static void
-usage()
+usage(void)
{
fprintf(stderr, "usage: from [-c] [-f file] [-s sender] [user]\n");
exit(1);
}
int
-match(line, sender)
- register char *line, *sender;
+match(char *line, char *sender)
{
- register char ch, pch, first, *p, *t;
+ char ch, pch, first, *p, *t;
for (first = *sender++;;) {
if (isspace(ch = *line))