[tyndur-devel] [PATCH] libc: getopt muss in die unistd.h
Kevin Wolf ·
! libc: Sowohl getopt.h als auch unistd.h stellen die grundlegende getopt-Funkionalität bereit. Signed-off-by: Kevin Wolf <kevin at tyndur.org> --- src/modules/include/getopt.h | 74 ++++++++++++++++++++++------------------- src/modules/include/unistd.h | 4 ++ 2 files changed, 44 insertions(+), 34 deletions(-) diff --git a/src/modules/include/getopt.h b/src/modules/include/getopt.h index 84717b3..b381947 100644 --- a/src/modules/include/getopt.h +++ b/src/modules/include/getopt.h @@ -27,41 +27,10 @@ */ #ifndef _GETOPT_H_ -#define _GETOPT_H_ - -// Fuer den has_arg-Member in der option-struct -#define no_argument 0 -#define required_argument 1 -#define optional_argument 2 - -/** - * Struktur die eine lange Option fuer getopt_long oder getopt_long_only - * beschreibt - */ -struct option { - /** Name der Option (der Text wie sie benutzt wird) */ - const char* name; - - /** - * 0 oder no_argument wenn die Option kein Argument nimmt - * 1 oder required_argument wenn die Option ein Argument haben muss - * 2 oder optional_argument wenn die Option ein Argument haben kann, aber - * nicht muss - */ - int has_arg; - - /** - * Ist dieser Pointer != NULL, wird an dieser Speicherstelle der Wert val - * abgelegt, wenn diese Option gefunden wird. - */ - int* flag; - - /** - * Wert den die Funktionen zurueckgeben oder allenfalls ind *flag ablegen - * */ - int val; -}; +#ifndef __unistd_only +#define _GETOPT_H_ +#endif /** Pointer auf den aktuellen argumentstring zur aktuellen Option oder NULL */ extern char* optarg; @@ -104,6 +73,41 @@ extern int optreset; */ int getopt(int argc, char* const argv[], const char* optstring); +#ifndef __unistd_only + +// Fuer den has_arg-Member in der option-struct +#define no_argument 0 +#define required_argument 1 +#define optional_argument 2 + +/** + * Struktur die eine lange Option fuer getopt_long oder getopt_long_only + * beschreibt + */ +struct option { + /** Name der Option (der Text wie sie benutzt wird) */ + const char* name; + + /** + * 0 oder no_argument wenn die Option kein Argument nimmt + * 1 oder required_argument wenn die Option ein Argument haben muss + * 2 oder optional_argument wenn die Option ein Argument haben kann, aber + * nicht muss + */ + int has_arg; + + /** + * Ist dieser Pointer != NULL, wird an dieser Speicherstelle der Wert val + * abgelegt, wenn diese Option gefunden wird. + */ + int* flag; + + /** + * Wert den die Funktionen zurueckgeben oder allenfalls ind *flag ablegen + * */ + int val; +}; + /** * Diese Funktion arbeitet gleich wie getopt, akzeptiert aber auch lange * Optionen, die mit zwei Minuszeichen eingeleitet werden. Argumente koennen @@ -147,4 +151,6 @@ int getopt_long(int argc, char* const argv[], const char* optstring, int getopt_long_only(int argc, char* const argv[], const char* optstring, const struct option* longopts, int* longindex); +#endif /* !defined(__unistd_only) */ + #endif diff --git a/src/modules/include/unistd.h b/src/modules/include/unistd.h index 2949dfb..100e3b7 100644 --- a/src/modules/include/unistd.h +++ b/src/modules/include/unistd.h @@ -31,6 +31,10 @@ #include <sys/types.h> #include <lost/config.h> +#define __unistd_only +#include <getopt.h> +#undef __unistd_only + /// Nummer der des Posix-Deskriptors fuer stdin #define STDIN_FILENO 0 -- 1.6.0.2