From owner-freebsd-chat Thu May 16 16:49:23 1996 Return-Path: owner-chat Received: (from root@localhost) by freefall.freebsd.org (8.7.3/8.7.3) id QAA17340 for chat-outgoing; Thu, 16 May 1996 16:49:23 -0700 (PDT) Received: from eac.iafrica.com (h196-7-192-148.iafrica.com [196.7.192.148]) by freefall.freebsd.org (8.7.3/8.7.3) with SMTP id QAA17302 for ; Thu, 16 May 1996 16:49:15 -0700 (PDT) Received: (from rnordier@localhost) by eac.iafrica.com (8.6.12/8.6.12) id BAA00727 for chat@freebsd.org; Fri, 17 May 1996 01:49:02 +0200 From: Robert Nordier Message-Id: <199605162349.BAA00727@eac.iafrica.com> Subject: SYSV, *BSD, and getopt(3) To: chat@freebsd.org Date: Fri, 17 May 1996 01:49:01 +0200 (SAT) X-Mailer: ELM [version 2.4 PL24 ME8a] Content-Type: text Sender: owner-chat@freebsd.org X-Loop: FreeBSD.org Precedence: bulk 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