Added some MSVC required functions in Windows.cpp. Moved MSVC specific getopt code inside its own folder.

llvm-svn: 190238
This commit is contained in:
Virgile Bello 2013-09-07 05:05:49 +00:00
parent 3613fd7a35
commit d87fc157d2
4 changed files with 142 additions and 3 deletions

View File

@ -40,4 +40,42 @@ char* realpath(const char * name, char * resolved);
#define S_IRWXG 0 #define S_IRWXG 0
#define S_IRWXO 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_ #endif // LLDB_lldb_win32_h_

View File

@ -10,7 +10,7 @@
#include "lldb/Host/OptionParser.h" #include "lldb/Host/OptionParser.h"
#ifdef _MSC_VER #ifdef _MSC_VER
#include "../windows/getopt.inc" #include "../windows/msvc/getopt.inc"
#else #else
#ifdef _WIN32 #ifdef _WIN32
#define _BSD_SOURCE // Required so that getopt.h defines optreset #define _BSD_SOURCE // Required so that getopt.h defines optreset

View File

@ -46,7 +46,7 @@ int vasprintf(char **ret, const char *fmt, va_list ap)
return len; return len;
} }
char * strcasestr(const char *s, const char* find) char* strcasestr(const char *s, const char* find)
{ {
char c, sc; char c, sc;
size_t len; size_t len;
@ -144,3 +144,66 @@ char* realpath(const char * name, char * resolved)
return retname; 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

View File

@ -50,7 +50,44 @@
*/ */
#ifdef _MSC_VER #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 <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.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, return (getopt_internal(nargc, nargv, options, long_options, idx,
FLAG_PERMUTE|FLAG_LONGONLY)); FLAG_PERMUTE|FLAG_LONGONLY));
} }
#endif #endif