getopt.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. #ifndef __GETOPT_H__
  2. /**
  3. * DISCLAIMER
  4. * This file has no copyright assigned and is placed in the Public Domain.
  5. * This file is part of the mingw-w64 runtime package.
  6. *
  7. * The mingw-w64 runtime package and its code is distributed in the hope that it
  8. * will be useful but WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESSED OR
  9. * IMPLIED ARE HEREBY DISCLAIMED. This includes but is not limited to
  10. * warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  11. */
  12. #define __GETOPT_H__
  13. /* All the headers include this file. */
  14. #include <crtdefs.h>
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. extern int optind; /* index of first non-option in argv */
  19. extern int optopt; /* single option character, as parsed */
  20. extern int opterr; /* flag to enable built-in diagnostics... */
  21. /* (user may set to zero, to suppress) */
  22. extern char *optarg; /* pointer to argument of current option */
  23. extern int getopt(int nargc, char * const *nargv, const char *options);
  24. #ifdef _BSD_SOURCE
  25. /*
  26. * BSD adds the non-standard `optreset' feature, for reinitialisation
  27. * of `getopt' parsing. We support this feature, for applications which
  28. * proclaim their BSD heritage, before including this header; however,
  29. * to maintain portability, developers are advised to avoid it.
  30. */
  31. # define optreset __mingw_optreset
  32. extern int optreset;
  33. #endif
  34. #ifdef __cplusplus
  35. }
  36. #endif
  37. /*
  38. * POSIX requires the `getopt' API to be specified in `unistd.h';
  39. * thus, `unistd.h' includes this header. However, we do not want
  40. * to expose the `getopt_long' or `getopt_long_only' APIs, when
  41. * included in this manner. Thus, close the standard __GETOPT_H__
  42. * declarations block, and open an additional __GETOPT_LONG_H__
  43. * specific block, only when *not* __UNISTD_H_SOURCED__, in which
  44. * to declare the extended API.
  45. */
  46. #endif /* !defined(__GETOPT_H__) */
  47. #if !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__)
  48. #define __GETOPT_LONG_H__
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. struct option /* specification for a long form option... */
  53. {
  54. const char *name; /* option name, without leading hyphens */
  55. int has_arg; /* does it take an argument? */
  56. int *flag; /* where to save its status, or NULL */
  57. int val; /* its associated status value */
  58. };
  59. enum /* permitted values for its `has_arg' field... */
  60. {
  61. no_argument = 0, /* option never takes an argument */
  62. required_argument, /* option always requires an argument */
  63. optional_argument /* option may take an argument */
  64. };
  65. extern int getopt_long(int nargc, char * const *nargv, const char *options,
  66. const struct option *long_options, int *idx);
  67. extern int getopt_long_only(int nargc, char * const *nargv, const char *options,
  68. const struct option *long_options, int *idx);
  69. /*
  70. * Previous MinGW implementation had...
  71. */
  72. #ifndef HAVE_DECL_GETOPT
  73. /*
  74. * ...for the long form API only; keep this for compatibility.
  75. */
  76. # define HAVE_DECL_GETOPT 1
  77. #endif
  78. #ifdef __cplusplus
  79. }
  80. #endif
  81. #endif /* !defined(__UNISTD_H_SOURCED__) && !defined(__GETOPT_LONG_H__) */