Subject: pkg/7434: mit-pthreads lacks getopt() declarations
To: None <gnats-bugs@gnats.netbsd.org>
From: Andreas Gustafsson <gson@araneus.fi>
List: netbsd-bugs
Date: 04/21/1999 07:51:10
>Number:         7434
>Category:       pkg
>Synopsis:       mit-pthreads <unistd.h> lacks getopt() declarations
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager (NetBSD software packages system manager)
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Wed Apr 21 07:50:01 1999
>Last-Modified:
>Originator:     Andreas Gustafsson
>Organization:
Araneus Information Systems Oy
>Release:        1.3.2
>Environment:

System: NetBSD guava.araneus.fi 1.3.2 NetBSD 1.3.2 (GUAVA) #0: Wed Feb 17 10:21:50 EET 1999 gson@guava.araneus.fi:/z/src-1.3/sys/arch/i386/compile/GUAVA i386


>Description:

The file /usr/pkg/pthreads/include/unistd.h, installed as part of the
devel/mit-pthreads package, lacks a function prototype for the
getopt function as well as declarations for getopt's external variables.

>How-To-Repeat:

    $ cat getopt-test.c
    #include <unistd.h>
    int main(int argc, char **argv) {
	int ch;
	while ((ch = getopt(argc, argv, "a")) != -1) {
	    /* body uninteresting */
	}
	argc -= optind;
	argv += optind;
	return 0;
    }
    $ /usr/pkg/pthreads/bin/pgcc -Wall getopt-test.c
    getopt-test.c: In function `main':
    getopt-test.c:4: warning: implicit declaration of function `getopt'
    getopt-test.c:7: `optind' undeclared (first use this function)
    getopt-test.c:7: (Each undeclared identifier is reported only once
    getopt-test.c:7: for each function it appears in.)

>Fix:

Add the following patch to the the
/usr/pkgsrc/devel/mit-pthreads/patches directory:

--- include/unistd.h.orig	Wed Apr 21 12:11:13 1999
+++ include/unistd.h	Wed Apr 21 12:10:50 1999
@@ -176,6 +176,11 @@
 unsigned	 ualarm __P((unsigned, unsigned));
 void	 usleep __P((unsigned));
 int	 vfork __P((void));
+int	 getopt __P((int, char * const *, const char *));
+extern	 char *optarg;			/* getopt(3) external variables */
+extern	 int opterr;
+extern	 int optind;
+extern	 int optopt;
 
 #endif /* !_POSIX_SOURCE */
 __END_DECLS

The pthreads package actually installs both a <unistd.h> and a
slightly different <pthreads/unistd.h>.  I have no idea what the
latter is for.  Depending on its purpose, perhaps it should also
have the getopt declarations added.
>Audit-Trail:
>Unformatted: