util: add #ifdefs for windows
Suggested by Joseph Atzinger <joe.atzinger.dev@gmail.com>.
Change-Id: I32de34ba9281c24ece813906db6a80a7b0b737a3
Reviewed-on: https://code-review.googlesource.com/1340
Reviewed-by: Russ Cox <rsc@google.com>
Reviewed-by: Russ Cox <rsc@swtch.com>
diff --git a/util/test.cc b/util/test.cc
index 0644829..220bfb0 100644
--- a/util/test.cc
+++ b/util/test.cc
@@ -3,7 +3,9 @@
// license that can be found in the LICENSE file.
#include <stdio.h>
+#ifndef WIN32
#include <sys/resource.h>
+#endif
#include "util/test.h"
DEFINE_string(test_tmpdir, "/var/tmp", "temp directory");
@@ -23,9 +25,13 @@
namespace re2 {
int64 VirtualProcessSize() {
+#ifdef WIN32
+ return 0;
+#else
struct rusage ru;
getrusage(RUSAGE_SELF, &ru);
return (int64)ru.ru_maxrss*1024;
+#endif
}
} // namespace re2
diff --git a/util/util.h b/util/util.h
index a31b8e4..9a67dee 100644
--- a/util/util.h
+++ b/util/util.h
@@ -12,11 +12,11 @@
#include <stddef.h> // For size_t
#include <assert.h>
#include <stdarg.h>
-#include <sys/time.h>
#include <time.h>
#include <ctype.h> // For isdigit, isalpha.
// C++
+#include <ctime>
#include <vector>
#include <string>
#include <algorithm>
@@ -58,8 +58,19 @@
#endif
#ifdef WIN32
-// Disable C4800 warning about conversion from int to bool.
-#pragma warning(disable: 4800)
+
+#define snprintf _snprintf_s
+#define sprintf sprintf_s
+#define stricmp _stricmp
+#define strtof strtod /* not really correct but best we can do */
+#define strtoll _strtoi64
+#define strtoull _strtoui64
+#define vsnprintf vsnprintf_s
+
+#pragma warning(disable: 4018) // signed/unsigned mismatch
+#pragma warning(disable: 4244) // possible data loss in int conversion
+#pragma warning(disable: 4800) // conversion from int to bool
+
#endif
namespace re2 {
diff --git a/util/valgrind.cc b/util/valgrind.cc
index 7115c8e..ee257d0 100644
--- a/util/valgrind.cc
+++ b/util/valgrind.cc
@@ -3,7 +3,9 @@
// license that can be found in the LICENSE file.
#include "util/util.h"
+#ifndef WIN32
#include "util/valgrind.h"
+#endif
namespace re2 {