getopt_ext.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. //
  2. // Copyright 2026 Aarav Ravindra Kharade
  3. //
  4. // Licensed under the Apache License, Version 2.0 (the "License");
  5. // you may not use this file except in compliance with the License.
  6. // You may obtain a copy of the License at
  7. //
  8. // http://www.apache.org/licenses/LICENSE-2.0
  9. //
  10. // Unless required by applicable law or agreed to in writing, software
  11. // distributed under the License is distributed on an "AS IS" BASIS,
  12. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. // See the License for the specific language governing permissions and
  14. // limitations under the License.
  15. //
  16. /* Declarations for getopt (GNU extensions).
  17. Copyright (C) 1989-2026 Free Software Foundation, Inc.
  18. This file is part of the GNU C Library and is also part of gnulib.
  19. Patches to this file should be submitted to both projects.
  20. The GNU C Library is free software; you can redistribute it and/or
  21. modify it under the terms of the GNU Lesser General Public
  22. License as published by the Free Software Foundation; either
  23. version 2.1 of the License, or (at your option) any later version.
  24. The GNU C Library is distributed in the hope that it will be useful,
  25. but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. Lesser General Public License for more details.
  28. You should have received a copy of the GNU Lesser General Public
  29. License along with the GNU C Library; if not, see
  30. <https://www.gnu.org/licenses/>. */
  31. #ifndef _GETOPT_EXT_H
  32. #define _GETOPT_EXT_H 1
  33. /* This header should not be used directly; include getopt.h instead.
  34. Unlike most bits headers, it does not have a protective #error,
  35. because the guard macro for getopt.h in gnulib is not fixed. */
  36. __BEGIN_DECLS
  37. /* Describe the long-named options requested by the application.
  38. The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
  39. of 'struct option' terminated by an element containing a name which is
  40. zero.
  41. The field 'has_arg' is:
  42. no_argument (or 0) if the option does not take an argument,
  43. required_argument (or 1) if the option requires an argument,
  44. optional_argument (or 2) if the option takes an optional argument.
  45. If the field 'flag' is not NULL, it points to a variable that is set
  46. to the value given in the field 'val' when the option is found, but
  47. left unchanged if the option is not found.
  48. To have a long-named option do something other than set an 'int' to
  49. a compiled-in constant, such as set a value from 'optarg', set the
  50. option's 'flag' field to zero and its 'val' field to a nonzero
  51. value (the equivalent single-letter option character, if there is
  52. one). For long options that have a zero 'flag' field, 'getopt'
  53. returns the contents of the 'val' field. */
  54. struct option
  55. {
  56. const char *name;
  57. /* has_arg can't be an enum because some compilers complain about
  58. type mismatches in all the code that assumes it is an int. */
  59. int has_arg;
  60. int *flag;
  61. int val;
  62. };
  63. /* Names for the values of the 'has_arg' field of 'struct option'. */
  64. #define no_argument 0
  65. #define required_argument 1
  66. #define optional_argument 2
  67. extern int getopt_long (int ___argc, char *__getopt_argv_const *___argv,
  68. const char *__shortopts,
  69. const struct option *__longopts, int *__longind)
  70. __THROW __nonnull ((2, 3));
  71. extern int getopt_long_only (int ___argc, char *__getopt_argv_const *___argv,
  72. const char *__shortopts,
  73. const struct option *__longopts, int *__longind)
  74. __THROW __nonnull ((2, 3));
  75. __END_DECLS
  76. #endif /* getopt_ext.h */