logo

oasis

Own branch of Oasis Linux (upstream: <https://git.sr.ht/~mcf/oasis/>) git clone https://anongit.hacktivis.me/git/oasis.git

0001-Always-use-prototype-for-getopt-and-getenv.patch (2272B)


  1. From c83c5ddf95c8fb3f39e03a206d34f46faadb2fe7 Mon Sep 17 00:00:00 2001
  2. From: Michael Forney <mforney@mforney.org>
  3. Date: Thu, 2 Apr 2026 17:54:53 -0700
  4. Subject: [PATCH] Always use prototype for getopt and getenv
  5. ---
  6. src/getopt.c | 15 ++-------------
  7. src/getopt.h | 7 -------
  8. 2 files changed, 2 insertions(+), 20 deletions(-)
  9. diff --git a/src/getopt.c b/src/getopt.c
  10. index 7a792de8..3673aecf 100644
  11. --- a/src/getopt.c
  12. +++ b/src/getopt.c
  13. @@ -39,6 +39,8 @@ this program. If not, see <https://www.gnu.org/licenses/>. */
  14. #endif
  15. #include <stdio.h>
  16. +#include <stdlib.h>
  17. +#include <unistd.h>
  18. /* Comment out all this code if we are using the GNU C Library, and are not
  19. actually compiling the library itself. This code is part of the GNU C
  20. @@ -59,15 +61,6 @@ this program. If not, see <https://www.gnu.org/licenses/>. */
  21. #ifndef ELIDE_CODE
  22. -/* This needs to come after some library #include
  23. - to get __GNU_LIBRARY__ defined. */
  24. -#ifdef __GNU_LIBRARY__
  25. -/* Don't include stdlib.h for non-GNU C libraries because some of them
  26. - contain conflicting prototypes for getopt. */
  27. -# include <stdlib.h>
  28. -# include <unistd.h>
  29. -#endif /* GNU C library. */
  30. -
  31. #ifdef VMS
  32. # include <unixlib.h>
  33. # if HAVE_STRING_H - 0
  34. @@ -201,10 +194,6 @@ static char *posixly_correct;
  35. /* Avoid depending on library functions or files
  36. whose names are inconsistent. */
  37. -#ifndef getenv
  38. -extern char *getenv ();
  39. -#endif
  40. -
  41. static char *
  42. my_index (const char *str, int chr)
  43. {
  44. diff --git a/src/getopt.h b/src/getopt.h
  45. index df18ceeb..a6cc6217 100644
  46. --- a/src/getopt.h
  47. +++ b/src/getopt.h
  48. @@ -96,14 +96,7 @@ struct option
  49. #define optional_argument 2
  50. #if defined (__STDC__) && __STDC__
  51. -#ifdef __GNU_LIBRARY__
  52. -/* Many other libraries have conflicting prototypes for getopt, with
  53. - differences in the consts, in stdlib.h. To avoid compilation
  54. - errors, only prototype getopt for the GNU C library. */
  55. extern int getopt (int argc, char *const *argv, const char *shortopts);
  56. -#else /* not __GNU_LIBRARY__ */
  57. -extern int getopt ();
  58. -#endif /* __GNU_LIBRARY__ */
  59. extern int getopt_long (int argc, char *const *argv, const char *shortopts,
  60. const struct option *longopts, int *longind);
  61. extern int getopt_long_only (int argc, char *const *argv,
  62. --
  63. 2.49.0