diff --git a/lldb/include/lldb/Host/windows/win32.h b/lldb/include/lldb/Host/windows/win32.h index 918c00098b09..e3030d34e311 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 +#include +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 074632641b98..287292ee74af 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 ed886c72123b..8459d80cec19 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 similarity index 95% rename from lldb/source/Host/windows/getopt.inc rename to lldb/source/Host/windows/msvc/getopt.inc index e8722699308d..9af237eb1929 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 #include #include @@ -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