Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cygwin.com/git/newlib-cygwin.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Johnston <jjohnstn@redhat.com>2008-03-01 00:11:57 +0300
committerJeff Johnston <jjohnstn@redhat.com>2008-03-01 00:11:57 +0300
commit76ff710cfaa54aa7a85b15d2d2b0303a53afe83d (patch)
tree8444c7c9f61800989d7c913ec682e3b0bbe46cb7 /newlib/libc/include/getopt.h
parent86a4b0c733dab174b9eb1b556b881f565d7bd819 (diff)
2008-02-29 Gregory Pietsch <gpietsch@comcast.net>
* libc/stdlib/getopt.c (getopt_internal): Rewrite to accept data area so as to support reentrant calls. Change all callers to fill in data area with global values and restore any changes to the global values after call. (__getopt_r, __getopt_long_r, __getopt_long_only_r): New routines to support reentrancy that add a data area argument. * libc/include/getopt.h: Add new _r routines and provide macros so they can be called with using double-underscores.
Diffstat (limited to 'newlib/libc/include/getopt.h')
-rw-r--r--newlib/libc/include/getopt.h86
1 files changed, 62 insertions, 24 deletions
diff --git a/newlib/libc/include/getopt.h b/newlib/libc/include/getopt.h
index 7179298ae..7861ec300 100644
--- a/newlib/libc/include/getopt.h
+++ b/newlib/libc/include/getopt.h
@@ -82,6 +82,7 @@ Gregory Pietsch's current e-mail address:
gpietsch@comcast.net
****************************************************************************/
+
#ifndef GETOPT_H
#define GETOPT_H
@@ -90,30 +91,46 @@ gpietsch@comcast.net
/* include files needed by this include file */
/* macros defined by this include file */
-#define NO_ARG 0
-#define REQUIRED_ARG 1
-#define OPTIONAL_ARG 2
-
-/* types defined by this include file */
-
-struct option
-{
- char *name; /* the name of the long option */
- int has_arg; /* one of the above macros */
- int *flag; /* determines if getopt_long() returns a
- * value for a long option; if it is
- * non-NULL, 0 is returned as a function
- * value and the value of val is stored in
- * the area pointed to by flag. Otherwise,
- * val is returned. */
- int val; /* determines the value to return if flag is
- * NULL. */
-};
+#define NO_ARG 0
+#define REQUIRED_ARG 1
+#define OPTIONAL_ARG 2
+ /* The GETOPT_DATA_INITIALIZER macro is used to initialize a statically-
+ allocated variable of type struct getopt_data. */
+#define GETOPT_DATA_INITIALIZER {0,0,0,0,0}
+ /* These #defines are to keep the namespace clear... */
+#define getopt_r __getopt_r
+#define getopt_long_r __getopt_long_r
+#define getopt_long_only_r __getopt_long_only_r
#ifdef __cplusplus
extern "C"
{
-#endif
+
+#endif /* __cplusplus */
+
+/* types defined by this include file */
+ struct option
+ {
+ char *name; /* the name of the long option */
+ int has_arg; /* one of the above macros */
+ int *flag; /* determines if getopt_long() returns a
+ * value for a long option; if it is
+ * non-NULL, 0 is returned as a function
+ * value and the value of val is stored in
+ * the area pointed to by flag. Otherwise,
+ * val is returned. */
+ int val; /* determines the value to return if flag is
+ * NULL. */
+
+ };
+
+ /* The getopt_data structure is for reentrancy. Its members are similar to
+ the externally-defined variables. */
+ typedef struct getopt_data
+ {
+ char *optarg;
+ int optind, opterr, optopt, optwhere;
+ } getopt_data;
/* externally-defined variables */
extern char *optarg;
@@ -122,14 +139,35 @@ extern "C"
extern int optopt;
/* function prototypes */
- int _EXFUN (getopt, (int __argc, char *const __argv[], const char *__optstring));
- int _EXFUN (getopt_long, (int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind));
- int _EXFUN (getopt_long_only, (int __argc, char *const __argv[], const char *__shortopts, const struct option *__longopts, int *__longind));
+ int _EXFUN (getopt,
+ (int __argc, char *const __argv[], const char *__optstring));
+
+ int _EXFUN (getopt_long,
+ (int __argc, char *const __argv[], const char *__shortopts,
+ const struct option * __longopts, int *__longind));
+
+ int _EXFUN (getopt_long_only,
+ (int __argc, char *const __argv[], const char *__shortopts,
+ const struct option * __longopts, int *__longind));
+
+ int _EXFUN (__getopt_r,
+ (int __argc, char *const __argv[], const char *__optstring,
+ struct getopt_data * __data));
+
+ int _EXFUN (__getopt_long_r,
+ (int __argc, char *const __argv[], const char *__shortopts,
+ const struct option * __longopts, int *__longind,
+ struct getopt_data * __data));
+
+ int _EXFUN (__getopt_long_only_r,
+ (int __argc, char *const __argv[], const char *__shortopts,
+ const struct option * __longopts, int *__longind,
+ struct getopt_data * __data));
#ifdef __cplusplus
};
-#endif
+#endif /* __cplusplus */
#endif /* GETOPT_H */