getopt.h 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. /* Copyright (C) 2010-2018 The RetroArch team
  2. *
  3. * ---------------------------------------------------------------------------------------
  4. * The following license statement only applies to this file (getopt.h).
  5. * ---------------------------------------------------------------------------------------
  6. *
  7. * Permission is hereby granted, free of charge,
  8. * to any person obtaining a copy of this software and associated documentation files (the "Software"),
  9. * to deal in the Software without restriction, including without limitation the rights to
  10. * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
  11. * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
  16. * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  18. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  19. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  21. */
  22. #ifndef __LIBRETRO_SDK_COMPAT_GETOPT_H
  23. #define __LIBRETRO_SDK_COMPAT_GETOPT_H
  24. #if defined(RARCH_INTERNAL) && defined(HAVE_CONFIG_H)
  25. #include "../../../config.h"
  26. #endif
  27. /* Custom implementation of the GNU getopt_long for portability.
  28. * Not designed to be fully compatible, but compatible with
  29. * the features RetroArch uses. */
  30. #ifdef HAVE_GETOPT_LONG
  31. #include <getopt.h>
  32. #else
  33. /* Avoid possible naming collisions during link since we
  34. * prefer to use the actual name. */
  35. #define getopt_long(argc, argv, optstring, longopts, longindex) __getopt_long_retro(argc, argv, optstring, longopts, longindex)
  36. #include <retro_common_api.h>
  37. RETRO_BEGIN_DECLS
  38. struct option
  39. {
  40. const char *name;
  41. int has_arg;
  42. int *flag;
  43. int val;
  44. };
  45. /* argv[] is declared with char * const argv[] in GNU,
  46. * but this makes no sense, as non-POSIX getopt_long
  47. * mutates argv (non-opts are moved to the end). */
  48. int getopt_long(int argc, char *argv[],
  49. const char *optstring, const struct option *longopts, int *longindex);
  50. extern char *optarg;
  51. extern int optind, opterr, optopt;
  52. RETRO_END_DECLS
  53. /* If these are variously #defined, then we have bigger problems */
  54. #ifndef no_argument
  55. #define no_argument 0
  56. #define required_argument 1
  57. #define optional_argument 2
  58. #endif
  59. /* HAVE_GETOPT_LONG */
  60. #endif
  61. /* pragma once */
  62. #endif