GetOptInc.h 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. //===-- GetOptInc.h ---------------------------------------------*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLDB_HOST_COMMON_GETOPTINC_H
  9. #define LLDB_HOST_COMMON_GETOPTINC_H
  10. #include "lldb/lldb-defines.h"
  11. #if defined(_MSC_VER)
  12. #define REPLACE_GETOPT
  13. #define REPLACE_GETOPT_LONG
  14. #endif
  15. #if defined(_MSC_VER) || defined(__NetBSD__)
  16. #define REPLACE_GETOPT_LONG_ONLY
  17. #endif
  18. #if defined(REPLACE_GETOPT)
  19. // from getopt.h
  20. #define no_argument 0
  21. #define required_argument 1
  22. #define optional_argument 2
  23. // option structure
  24. struct option {
  25. const char *name;
  26. // has_arg can't be an enum because some compilers complain about type
  27. // mismatches in all the code that assumes it is an int.
  28. int has_arg;
  29. int *flag;
  30. int val;
  31. };
  32. int getopt(int argc, char *const argv[], const char *optstring);
  33. // from getopt.h
  34. extern char *optarg;
  35. extern int optind;
  36. extern int opterr;
  37. extern int optopt;
  38. // defined in unistd.h
  39. extern int optreset;
  40. #else
  41. #include <getopt.h>
  42. #include <unistd.h>
  43. #endif
  44. #if defined(REPLACE_GETOPT_LONG)
  45. int getopt_long(int argc, char *const *argv, const char *optstring,
  46. const struct option *longopts, int *longindex);
  47. #endif
  48. #if defined(REPLACE_GETOPT_LONG_ONLY)
  49. int getopt_long_only(int argc, char *const *argv, const char *optstring,
  50. const struct option *longopts, int *longindex);
  51. #endif
  52. #endif // LLDB_HOST_COMMON_GETOPTINC_H