Date: Wed, 20 Oct 1999 22:10:08 +0200 From: Jeroen Ruigrok/Asmodai <asmodai@wxs.nl> To: hackers@freebsd.org Cc: Bill Fumerola <billf@freebsd.org>, Bruce Evans <bde@freebsd.org> Subject: getopt.h Message-ID: <19991020221007.A90211@daemon.ninth-circle.org>
next in thread | raw e-mail | index | archive | help
Well I searched the mailinglists and didn't really got further than discovering that unistd.h goes a little way to provide functionality which getopt.h from glibc provides. And seeing that a question of Bill early 1999 never got answered correctly. I cc:'d Bruce on this since I value his stylistic mindset on this issue. I am starting on this topic since I need to port the source of an application and I found the support of some part of getopt.h and lack of support for the other part a kind of an oddity in the source tree. That, plus a lot of our ports depend on it. And it would be a waste for using ports/devel/libgnugetopt when the solution is pretty small. In unistd.h we have definitions for getopt, optarg, optind, opterr, and optopt. However this means we still have this to worry about: [hacked up version of linux/glibc/posix/getopt.h] #if !defined __GNU_LIBRARY__ #include <ctype.h> #endif struct option { #if defined __STDC__ && __STDC__ const char *name; #else char *name; #endif int has_arg; int *flag; int val; }; #define no_argument 0 #define required_argument 1 #define optional_argument 2 #if defined __STDC__ && __STDC__ extern int getopt_long (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int getopt_long_only (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind); extern int _getopt_internal (int __argc, char *const *__argv, const char *__shortopts, const struct option *__longopts, int *__longind, int __long_only); #endif /* __STDC__ */ I think the above inclusion of ctype.h can be forgotten about when we include sys/types.h and sys/cdefs.h such as unistd.h does. So that effectively leaves us with one struct, three defines and three functions. The things I propose to add to unistd.h are the following: struct option { char *name; int has_arg; int *flag; int val; }; #define no_argument 0 #define required_argument 1 #define optional_argument 2 extern int getopt_long (int, char *const [], const char *, const struct option *, int *); extern int getopt_long_only (int, char *const [], const char *, const struct option *, int *); extern int _getopt_internal (int, char *const [], const char *, const struct option *, int *, int ); This should enable us to compile programs which require getopt.h by simply including unistd.h. I would like to hear any constructive comments on this. Mostly on the three #define's. regards, -- Jeroen Ruigrok van der Werven/Asmodai asmodai(at)wxs.nl The BSD Programmer's Documentation Project <http://home.wxs.nl/~asmodai> Network/Security Specialist BSD: Technical excellence at its best For country, children, hearth, and home. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991020221007.A90211>