getopt-core.h 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /* Declarations for getopt (basic, portable features only).
  2. Copyright (C) 1989-2017 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library and is also part of gnulib.
  4. Patches to this file should be submitted to both projects.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public
  7. License as published by the Free Software Foundation; either
  8. version 3 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public
  14. License along with the GNU C Library; if not, see
  15. <http://www.gnu.org/licenses/>. */
  16. #ifndef _GETOPT_CORE_H
  17. #define _GETOPT_CORE_H 1
  18. /* This header should not be used directly; include getopt.h or
  19. unistd.h instead. Unlike most bits headers, it does not have
  20. a protective #error, because the guard macro for getopt.h in
  21. gnulib is not fixed. */
  22. __BEGIN_DECLS
  23. /* For communication from 'getopt' to the caller.
  24. When 'getopt' finds an option that takes an argument,
  25. the argument value is returned here.
  26. Also, when 'ordering' is RETURN_IN_ORDER,
  27. each non-option ARGV-element is returned here. */
  28. extern char *optarg;
  29. /* Index in ARGV of the next element to be scanned.
  30. This is used for communication to and from the caller
  31. and for communication between successive calls to 'getopt'.
  32. On entry to 'getopt', zero means this is the first call; initialize.
  33. When 'getopt' returns -1, this is the index of the first of the
  34. non-option elements that the caller should itself scan.
  35. Otherwise, 'optind' communicates from one call to the next
  36. how much of ARGV has been scanned so far. */
  37. extern int optind;
  38. /* Callers store zero here to inhibit the error message 'getopt' prints
  39. for unrecognized options. */
  40. extern int opterr;
  41. /* Set to an option character which was unrecognized. */
  42. extern int optopt;
  43. /* Get definitions and prototypes for functions to process the
  44. arguments in ARGV (ARGC of them, minus the program name) for
  45. options given in OPTS.
  46. Return the option character from OPTS just read. Return -1 when
  47. there are no more options. For unrecognized options, or options
  48. missing arguments, 'optopt' is set to the option letter, and '?' is
  49. returned.
  50. The OPTS string is a list of characters which are recognized option
  51. letters, optionally followed by colons, specifying that that letter
  52. takes an argument, to be placed in 'optarg'.
  53. If a letter in OPTS is followed by two colons, its argument is
  54. optional. This behavior is specific to the GNU 'getopt'.
  55. The argument '--' causes premature termination of argument
  56. scanning, explicitly telling 'getopt' that there are no more
  57. options.
  58. If OPTS begins with '-', then non-option arguments are treated as
  59. arguments to the option '\1'. This behavior is specific to the GNU
  60. 'getopt'. If OPTS begins with '+', or POSIXLY_CORRECT is set in
  61. the environment, then do not permute arguments.
  62. For standards compliance, the 'argv' argument has the type
  63. char *const *, but this is inaccurate; if argument permutation is
  64. enabled, the argv array (not the strings it points to) must be
  65. writable. */
  66. extern int getopt (int ___argc, char *const *___argv, const char *__shortopts)
  67. __THROW _GL_ARG_NONNULL ((2, 3));
  68. __END_DECLS
  69. #endif /* _GETOPT_CORE_H */