summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVirgile Bello <virgile.bello@gmail.com>2013-09-07 05:05:49 +0000
committerVirgile Bello <virgile.bello@gmail.com>2013-09-07 05:05:49 +0000
commitd87fc157d2b791af191de89d460c8cae124b47a8 (patch)
tree16f20d8fd09c662d67e5473dca4e9c7a3e72c1fa
parent3613fd7a35fbdfe03d7a0b2a2aba1812442940cf (diff)
downloadbcm5719-llvm-d87fc157d2b791af191de89d460c8cae124b47a8.tar.gz
bcm5719-llvm-d87fc157d2b791af191de89d460c8cae124b47a8.zip
Added some MSVC required functions in Windows.cpp. Moved MSVC specific getopt code inside its own folder.
llvm-svn: 190238
-rw-r--r--lldb/include/lldb/Host/windows/win32.h38
-rw-r--r--lldb/source/Host/common/OptionParser.cpp2
-rw-r--r--lldb/source/Host/windows/Windows.cpp65
-rw-r--r--lldb/source/Host/windows/msvc/getopt.inc (renamed from lldb/source/Host/windows/getopt.inc)40
4 files changed, 142 insertions, 3 deletions
diff --git a/lldb/include/lldb/Host/windows/win32.h b/lldb/include/lldb/Host/windows/win32.h
index 918c00098b0..e3030d34e31 100644
--- a/lldb/include/lldb/Host/windows/win32.h
+++ b/lldb/include/lldb/Host/windows/win32.h
@@ -40,4 +40,42 @@ char* realpath(const char * name, char * resolved);
#define S_IRWXG 0
#define S_IRWXO 0
+#ifdef _MSC_VER
+
+#include <stdint.h>
+#include <io.h>
+typedef unsigned short mode_t;
+typedef uint32_t pid_t;
+
+int usleep(uint32_t useconds);
+
+char* getcwd(char* path, int max);
+char* basename(char *path);
+char *dirname(char *path);
+
+int strcasecmp(const char* s1, const char* s2);
+int strncasecmp(const char* s1, const char* s2, size_t n);
+
+
+#define PATH_MAX MAX_PATH
+#define STDIN_FILENO 0
+#define STDOUT_FILENO 1
+#define STDERR_FILENO 2
+
+#define __PRETTY_FUNCTION__ __FUNCSIG__
+
+#define S_IFDIR _S_IFDIR
+#define S_ISDIR(mode) (((mode) & S_IFMT) == S_IFDIR)
+
+#define snprintf _snprintf
+
+// timespec
+struct timespec
+{
+ time_t tv_sec;
+ long tv_nsec;
+};
+
+#endif
+
#endif // LLDB_lldb_win32_h_
diff --git a/lldb/source/Host/common/OptionParser.cpp b/lldb/source/Host/common/OptionParser.cpp
index 074632641b9..287292ee74a 100644
--- a/lldb/source/Host/common/OptionParser.cpp
+++ b/lldb/source/Host/common/OptionParser.cpp
@@ -10,7 +10,7 @@
#include "lldb/Host/OptionParser.h"
#ifdef _MSC_VER
-#include "../windows/getopt.inc"
+#include "../windows/msvc/getopt.inc"
#else
#ifdef _WIN32
#define _BSD_SOURCE // Required so that getopt.h defines optreset
diff --git a/lldb/source/Host/windows/Windows.cpp b/lldb/source/Host/windows/Windows.cpp
index ed886c72123..8459d80cec1 100644
--- a/lldb/source/Host/windows/Windows.cpp
+++ b/lldb/source/Host/windows/Windows.cpp
@@ -46,7 +46,7 @@ int vasprintf(char **ret, const char *fmt, va_list ap)
return len;
}
-char * strcasestr(const char *s, const char* find)
+char* strcasestr(const char *s, const char* find)
{
char c, sc;
size_t len;
@@ -144,3 +144,66 @@ char* realpath(const char * name, char * resolved)
return retname;
}
+
+#ifdef _MSC_VER
+
+char* basename(char *path)
+{
+ char* l1 = strrchr(path, '\\');
+ char* l2 = strrchr(path, '/');
+ if (l2 > l1) l1 = l2;
+ if (!l1) return path; // no base name
+ return &l1[1];
+}
+
+char* getcwd(char* path, int max)
+{
+ if (GetCurrentDirectory(max, path) == 0)
+ return path;
+ return NULL;
+}
+
+char *dirname(char *path)
+{
+ char* l1 = strrchr(path, '\\');
+ char* l2 = strrchr(path, '/');
+ if (l2 > l1) l1 = l2;
+ if (!l1) return NULL; // no dir name
+ *l1 = 0;
+ return path;
+}
+
+int strcasecmp(const char* s1, const char* s2)
+{
+ while (*s1 != '\0' && tolower(*s1) == tolower(*s2))
+ {
+ s1++;
+ s2++;
+ }
+
+ return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
+}
+
+int strncasecmp(const char* s1, const char* s2, size_t n)
+{
+ if (n == 0)
+ return 0;
+
+ while (n-- != 0 && tolower(*s1) == tolower(*s2))
+ {
+ if (n == 0 || *s1 == '\0' || *s2 == '\0')
+ break;
+ s1++;
+ s2++;
+ }
+
+ return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
+}
+
+int usleep(uint32_t useconds)
+{
+ Sleep(useconds / 1000);
+ return 0;
+}
+
+#endif // _MSC_VER
diff --git a/lldb/source/Host/windows/getopt.inc b/lldb/source/Host/windows/msvc/getopt.inc
index e8722699308..9af237eb192 100644
--- a/lldb/source/Host/windows/getopt.inc
+++ b/lldb/source/Host/windows/msvc/getopt.inc
@@ -50,7 +50,44 @@
*/
#ifdef _MSC_VER
-#include "lldb/Host/msvc/getopt.h"
+
+// getopt.h
+enum {
+ no_argument = 0,
+ required_argument,
+ optional_argument
+};
+
+struct option {
+ /* name of long option */
+ const char *name;
+ /*
+ * one of no_argument, required_argument, and optional_argument:
+ * whether option takes an argument
+ */
+ int has_arg;
+ /* if not NULL, set *flag to val when option found */
+ int *flag;
+ /* if flag not NULL, value to set *flag to; else return value */
+ int val;
+};
+
+int getopt(int argc, char * const argv[],
+ const char *optstring);
+
+extern char *optarg;
+extern int optind, opterr, optopt;
+
+int getopt_long(int argc, char * const *argv,
+ const char *optstring,
+ const struct option *longopts, int *longindex);
+
+int getopt_long_only(int argc, char * const *argv,
+ const char *optstring,
+ const struct option *longopts, int *longindex);
+extern int optreset;
+
+// getopt.cpp
#include <errno.h>
#include <stdlib.h>
#include <string.h>
@@ -511,4 +548,5 @@ getopt_long_only(int nargc, char * const *nargv, const char *options,
return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE|FLAG_LONGONLY));
}
+
#endif
OpenPOWER on IntegriCloud