From 759484bacdbfd748c4c3c9beb6b94bf5c9779476 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Wed, 29 May 2002 13:14:51 +0000 Subject: [PATCH] Use getopt() to reject any options and skip "--" arguments. --- usr.bin/write/write.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/usr.bin/write/write.c b/usr.bin/write/write.c index 5144507b7c09..b21233bda3b7 100644 --- a/usr.bin/write/write.c +++ b/usr.bin/write/write.c @@ -86,6 +86,11 @@ main(argc, argv) (void)setlocale(LC_CTYPE, ""); + while (getopt(argc, argv, "") != -1) + usage(); + argc -= optind; + argv += optind; + /* check that sender has write enabled */ if (isatty(fileno(stdin))) myttyfd = fileno(stdin); @@ -108,20 +113,20 @@ main(argc, argv) /* check args */ switch (argc) { - case 2: - search_utmp(argv[1], tty, mytty, myuid); + case 1: + search_utmp(argv[0], tty, mytty, myuid); do_write(tty, mytty, myuid); break; - case 3: - if (!strncmp(argv[2], _PATH_DEV, strlen(_PATH_DEV))) - argv[2] += strlen(_PATH_DEV); - if (utmp_chk(argv[1], argv[2])) - errx(1, "%s is not logged in on %s", argv[1], argv[2]); - if (term_chk(argv[2], &msgsok, &atime, 1)) + case 2: + if (!strncmp(argv[1], _PATH_DEV, strlen(_PATH_DEV))) + argv[1] += strlen(_PATH_DEV); + if (utmp_chk(argv[0], argv[1])) + errx(1, "%s is not logged in on %s", argv[0], argv[1]); + if (term_chk(argv[1], &msgsok, &atime, 1)) exit(1); if (myuid && !msgsok) - errx(1, "%s has messages disabled on %s", argv[1], argv[2]); - do_write(argv[2], mytty, myuid); + errx(1, "%s has messages disabled on %s", argv[0], argv[1]); + do_write(argv[1], mytty, myuid); break; default: usage();