diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-09-06 20:03:16 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-09-06 20:03:16 +0200 |
commit | 56e0e6be56f4109139bcc2e4b4accd5fd76567cb (patch) | |
tree | e50a69b8e7b0f6d8378ff6911d387cc7696d68e9 /Libraries/LibC/getopt.h | |
parent | 6ab498edf798a2b749f38bfb78e67a55327a4ec1 (diff) | |
download | serenity-56e0e6be56f4109139bcc2e4b4accd5fd76567cb.zip |
LibC: Borrow a slightly more functional getopt()
We were already borrowing a getopt() from the BSD family until the day
we write our own. This patch borrows a slightly more modern one so we
also get getopt_long().
Fixes #190.
See also #91 for the desire to eventually NIH our own getopt()..
Diffstat (limited to 'Libraries/LibC/getopt.h')
-rw-r--r-- | Libraries/LibC/getopt.h | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/Libraries/LibC/getopt.h b/Libraries/LibC/getopt.h index a55f06df52..caad05366e 100644 --- a/Libraries/LibC/getopt.h +++ b/Libraries/LibC/getopt.h @@ -2,12 +2,35 @@ #include <sys/cdefs.h> +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +struct option { + const char *name; + int has_arg; + int* flag; + int val; +}; + __BEGIN_DECLS -int getopt(int argc, char* const argv[], const char* optstring); -extern char* optarg; +int getopt_long(int, char* const*, const char*, const struct option*, int*); +int getopt_long_only(int, char* const*, const char*, const struct option*, int*); + +#ifndef _GETOPT_DECLARED +#define _GETOPT_DECLARED +int getopt(int, char * const [], const char *); +extern char *optarg; extern int optind; extern int opterr; extern int optopt; +#endif + +#ifndef _OPTRESET_DECLARED +#define _OPTRESET_DECLARED +extern int optreset; +#endif __END_DECLS + |