system/5000: /usr/share/misc/getopt is broken

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

system/5000: /usr/share/misc/getopt is broken

Ray Lai
>Number:         5000
>Category:       system
>Synopsis:       /usr/share/misc/getopt is broken
>Confidential:   yes
>Severity:       non-critical
>Priority:       low
>Responsible:    bugs
>State:          open
>Quarter:        
>Keywords:      
>Date-Required:
>Class:          doc-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Feb 01 07:20:02 GMT 2006
>Closed-Date:
>Last-Modified:
>Originator:     Ray Lai
>Release:        3.9-beta
>Organization:
net
>Environment:
       
        System      : OpenBSD 3.9
        Architecture: OpenBSD.i386
        Machine     : i386
>Description:
The current /usr/share/misc/getopt example is broken.  It doesn't
even compile!  ('' is not a valid character.)

>How-To-Repeat:

>Fix:
I've fixed and KNFed the example.  I've also included an example
similar to the one found in getopt(3).  Since there is already an
example in getopt(3), perhaps this file is extraneous?

Index: getopt
===================================================================
RCS file: /home/ray/openbsd/src/share/misc/getopt,v
retrieving revision 1.7
diff -u -r1.7 getopt
--- getopt 22 Jul 2002 20:13:14 -0000 1.7
+++ getopt 24 Jan 2006 20:36:00 -0000
@@ -5,26 +5,36 @@
  * from: @(#)getopt 5.3 (Berkeley) 3/28/94
  */
 
-#include <sys/types.h>
+#include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
-void usage(void);
+__dead void usage(void);
 
 int
 main(int argc, char *argv[])
 {
- int ch;
+ int bflag, ch;
+ char *file;
 
- while ((ch = getopt(argc, argv, "abcf:")) != -1)
+ bflag = 0;
+ file = NULL;
+ while ((ch = getopt(argc, argv, "bf:")) != -1)
  switch (ch) {
- case '':
+ case 'b':
+ bflag = 1;
+ break;
+ case 'f':
+ file = optarg;
  break;
- case '?':
  default:
  usage();
+ /* NOTREACHED */
  }
  argc -= optind;
  argv += optind;
+
+ return (0);
 }
 
 void


>Release-Note:
>Audit-Trail:
>Unformatted: