summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2015-09-04 09:06:15 +0000
committerPavel Labath <labath@google.com>2015-09-04 09:06:15 +0000
commita04668ff341a11b4f6b31b186d0c647fc5c198ee (patch)
treeb8cb409ffc2e908eb1ee9307cb259179acc81660
parent9815658332259f146c2c649b3b1a7bf7cfec6560 (diff)
downloadbcm5719-llvm-a04668ff341a11b4f6b31b186d0c647fc5c198ee.tar.gz
bcm5719-llvm-a04668ff341a11b4f6b31b186d0c647fc5c198ee.zip
Move GetOptInc to the common namespace
Summary: GetOptInc provides getopt(), getopt_long() and getopt_long_only(). Windows (for defined(_MSC_VER)) doesn't ship with all of the getopt(3) family members and needs all of them. NetBSD requires only getopt_long_only(3). While there fix the code for clang diagnostics. Author: Kamil Rytarowski Reviewers: joerg Subscribers: labath, zturner, lldb-commits Differential Revision: http://reviews.llvm.org/D12582 llvm-svn: 246843
-rw-r--r--lldb/include/lldb/Host/HostGetOpt.h4
-rw-r--r--lldb/include/lldb/Host/common/GetOptInc.h (renamed from lldb/include/lldb/Host/windows/getopt/GetOptInc.h)17
-rw-r--r--lldb/source/Host/CMakeLists.txt2
-rw-r--r--lldb/source/Host/common/GetOptInc.cpp (renamed from lldb/source/Host/windows/getopt/GetOptInc.cpp)27
-rw-r--r--lldb/tools/lldb-mi/CMakeLists.txt2
5 files changed, 36 insertions, 16 deletions
diff --git a/lldb/include/lldb/Host/HostGetOpt.h b/lldb/include/lldb/Host/HostGetOpt.h
index 761c1a11860..6f512915d33 100644
--- a/lldb/include/lldb/Host/HostGetOpt.h
+++ b/lldb/include/lldb/Host/HostGetOpt.h
@@ -8,7 +8,7 @@
//===----------------------------------------------------------------------===//
#pragma once
-#ifndef _MSC_VER
+#if !defined(_MSC_VER) && !defined(__NetBSD__)
#ifdef _WIN32
#define _BSD_SOURCE // Required so that getopt.h defines optreset
@@ -19,6 +19,6 @@
#else
-#include <lldb/Host/windows/getopt/GetOptInc.h>
+#include <lldb/Host/common/GetOptInc.h>
#endif
diff --git a/lldb/include/lldb/Host/windows/getopt/GetOptInc.h b/lldb/include/lldb/Host/common/GetOptInc.h
index 53ce19daa8a..f79644017ca 100644
--- a/lldb/include/lldb/Host/windows/getopt/GetOptInc.h
+++ b/lldb/include/lldb/Host/common/GetOptInc.h
@@ -2,6 +2,15 @@
#include "lldb/lldb-defines.h"
+#if defined(_MSC_VER)
+#define REPLACE_GETOPT
+#define REPLACE_GETOPT_LONG
+#endif
+#if defined(_MSC_VER) || defined(__NetBSD__)
+#define REPLACE_GETOPT_LONG_ONLY
+#endif
+
+#if defined(REPLACE_GETOPT)
// from getopt.h
#define no_argument 0
#define required_argument 1
@@ -28,7 +37,12 @@ extern int optopt;
// defined in unistd.h
extern int optreset;
+#else
+# include <unistd.h>
+# include <getopt.h>
+#endif
+#if defined(REPLACE_GETOPT_LONG)
int getopt_long
(
int argc,
@@ -37,7 +51,9 @@ int getopt_long
const struct option *longopts,
int *longindex
);
+#endif
+#if defined(REPLACE_GETOPT_LONG_ONLY)
int getopt_long_only
(
int argc,
@@ -46,3 +62,4 @@ int getopt_long_only
const struct option *longopts,
int *longindex
);
+#endif
diff --git a/lldb/source/Host/CMakeLists.txt b/lldb/source/Host/CMakeLists.txt
index 3c4503c3f6b..7632c579229 100644
--- a/lldb/source/Host/CMakeLists.txt
+++ b/lldb/source/Host/CMakeLists.txt
@@ -9,6 +9,7 @@ add_host_subdirectory(common
common/FileCache.cpp
common/FileSpec.cpp
common/FileSystem.cpp
+ common/GetOptInc.cpp
common/Host.cpp
common/HostInfoBase.cpp
common/HostNativeThreadBase.cpp
@@ -67,7 +68,6 @@ if (CMAKE_SYSTEM_NAME MATCHES "Windows")
windows/ProcessRunLock.cpp
windows/ThisThread.cpp
windows/Windows.cpp
- windows/getopt/GetOptInc.cpp
)
else()
add_host_subdirectory(posix
diff --git a/lldb/source/Host/windows/getopt/GetOptInc.cpp b/lldb/source/Host/common/GetOptInc.cpp
index 1101c621c90..7689f36c815 100644
--- a/lldb/source/Host/windows/getopt/GetOptInc.cpp
+++ b/lldb/source/Host/common/GetOptInc.cpp
@@ -1,20 +1,19 @@
-#include "lldb/Host/windows/getopt/GetOptInc.h"
+#include "lldb/Host/common/GetOptInc.h"
+
+#if defined(REPLACE_GETOPT) || defined(REPLACE_GETOPT_LONG) || defined(REPLACE_GETOPT_LONG_ONLY)
// getopt.cpp
#include <errno.h>
#include <stdlib.h>
#include <string.h>
-#if defined(__clang__) && defined(_MSC_VER)
-#pragma clang diagnostic push
-#pragma clang diagnostic ignored "-Wwritable-strings"
-#endif
-
+#if defined(REPLACE_GETOPT)
int opterr = 1; /* if error message should be printed */
int optind = 1; /* index into parent argv vector */
int optopt = '?'; /* character checked for validity */
int optreset; /* reset getopt */
char *optarg; /* argument associated with option */
+#endif
#define PRINT_ERROR ((opterr) && (*options != ':'))
@@ -36,7 +35,7 @@ static int parse_long_options(char * const *, const char *,
static int gcd(int, int);
static void permute_args(int, int, int, char * const *);
-static char *place = EMSG; /* option letter processing */
+static const char *place = EMSG; /* option letter processing */
/* XXX: set optreset to 1 rather than these two */
static int nonopt_start = -1; /* first non option argument (for permute) */
@@ -113,7 +112,7 @@ const struct option *long_options, int *idx, int short_too)
size_t current_argv_len;
int i, match;
- current_argv = place;
+ current_argv = const_cast<char*>(place);
match = -1;
optind++;
@@ -400,7 +399,7 @@ start:
else { /* takes (optional) argument */
optarg = NULL;
if (*place) /* no white space */
- optarg = place;
+ optarg = const_cast<char*>(place);
else if (oli[1] != ':') { /* arg not optional */
if (++optind >= nargc) { /* no arg */
place = EMSG;
@@ -425,6 +424,7 @@ start:
*
* [eventually this will replace the BSD getopt]
*/
+#if defined(REPLACE_GETOPT)
int
getopt(int nargc, char * const *nargv, const char *options)
{
@@ -439,11 +439,13 @@ getopt(int nargc, char * const *nargv, const char *options)
*/
return (getopt_internal(nargc, nargv, options, NULL, NULL, 0));
}
+#endif
/*
* getopt_long --
* Parse argc/argv argument vector.
*/
+#if defined(REPLACE_GETOPT_LONG)
int
getopt_long(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
@@ -451,11 +453,13 @@ const struct option *long_options, int *idx)
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE));
}
+#endif
/*
* getopt_long_only --
* Parse argc/argv argument vector.
*/
+#if defined(REPLACE_GETOPT_LONG_ONLY)
int
getopt_long_only(int nargc, char * const *nargv, const char *options,
const struct option *long_options, int *idx)
@@ -464,7 +468,6 @@ const struct option *long_options, int *idx)
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE | FLAG_LONGONLY));
}
+#endif
-#if defined(__clang__) && defined(_MSC_VER)
-#pragma clang diagnostic pop
-#endif \ No newline at end of file
+#endif
diff --git a/lldb/tools/lldb-mi/CMakeLists.txt b/lldb/tools/lldb-mi/CMakeLists.txt
index 1ce08ec20f7..58cb7496585 100644
--- a/lldb/tools/lldb-mi/CMakeLists.txt
+++ b/lldb/tools/lldb-mi/CMakeLists.txt
@@ -81,7 +81,7 @@ set(LLDB_MI_SOURCES
if ( CMAKE_SYSTEM_NAME MATCHES "Windows" )
add_definitions( -DIMPORT_LIBLLDB )
list(APPEND LLDB_MI_SOURCES
- ${LLDB_SOURCE_ROOT}/Host/windows/getopt/GetOptInc.cpp
+ ${LLDB_SOURCE_ROOT}/Host/common/GetOptInc.cpp
)
endif ()
OpenPOWER on IntegriCloud