Date: Fri, 17 May 1996 01:49:01 +0200 (SAT) From: Robert Nordier <rnordier@iafrica.com> To: chat@freebsd.org Subject: SYSV, *BSD, and getopt(3) Message-ID: <199605162349.BAA00727@eac.iafrica.com>
next in thread | raw e-mail | index | archive | help
This is something I've never really noticed before, but there's an actual - and apparently deliberate - difference between System V and *BSD coding styles when it comes to handling getopt(3) errors. The System V (original?) approach has always been to run through all the options before calling a halt with a usage() message: SYSV$ grep -az grep: illegal option -- a grep: illegal option -- z usage: grep [...] But the *BSD approach is apparently to cut things short at once: FBSD% grep -az grep: illegal option -- a usage: grep [...] A look at both manpages seems to confirm the difference is intentional. /* * System V style */ int main(int argc, char *argv[]) { int err; int c; err = 0; while ((c = getopt(argc, argv, "abc")) != -1) switch (c) { case 'a': /* ... */ break; default: err++; } if (err) usage(); return 0; } /* * BSD style */ int main(int argc, char *argv[]) { int c; while ((c = getopt(argc, argv, "abc")) != EOF) switch (c) { case 'a': /* ... */ break; default: usage(); } return 0; } I guess it's only a very minor point, but evidently sometime, somewhere, someone felt it mattered.... Anyone have any why's or wherefore's on this? Is it even an accepted part of BSD porting procedure to go in and change this stuff around? 8) -- Robert Nordier
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199605162349.BAA00727>