re2 fixes for Windows

This commit is contained in:
Matt Hill
2015-07-21 19:53:36 -04:00
parent b8456987d0
commit d5bc315744
4 changed files with 18 additions and 5 deletions

View File

@@ -11,7 +11,9 @@
#include <stdio.h> #include <stdio.h>
#include <string> #include <string>
#ifndef WIN32
#include <pthread.h> #include <pthread.h>
#endif
#include <errno.h> #include <errno.h>
#include "util/atomicops.h" #include "util/atomicops.h"
#include "util/util.h" #include "util/util.h"

View File

@@ -14,8 +14,10 @@
namespace re2 { namespace re2 {
#ifndef WIN32
#define HAVE_PTHREAD 1 #define HAVE_PTHREAD 1
#define HAVE_RWLOCK 1 #define HAVE_RWLOCK 1
#endif
#if defined(NO_THREADS) #if defined(NO_THREADS)
typedef int MutexType; // to keep a lock-count typedef int MutexType; // to keep a lock-count

View File

@@ -38,7 +38,11 @@ static void StringAppendV(string* dst, const char* format, va_list ap) {
// Restore the va_list before we use it again // Restore the va_list before we use it again
va_copy(backup_ap, ap); va_copy(backup_ap, ap);
#ifdef WIN32
result = vsnprintf_s(buf, length, length, format, backup_ap);
#else
result = vsnprintf(buf, length, format, backup_ap); result = vsnprintf(buf, length, format, backup_ap);
#endif
va_end(backup_ap); va_end(backup_ap);
if ((result >= 0) && (result < length)) { if ((result >= 0) && (result < length)) {

View File

@@ -1,7 +1,7 @@
// Copyright 1999-2005 The RE2 Authors. All Rights Reserved. // Copyright 1999-2005 The RE2 Authors. All Rights Reserved.
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
#include <stdio.h>
#include "re2/util/util.h" #include "re2/util/util.h"
#include "re2/stringpiece.h" #include "re2/stringpiece.h"
@@ -38,7 +38,12 @@ int CEscapeString(const char* src, int src_len, char* dest,
if (c < ' ' || c > '~') { if (c < ' ' || c > '~') {
if (dest_len - used < 5) // space for four-character escape + \0 if (dest_len - used < 5) // space for four-character escape + \0
return -1; return -1;
sprintf(dest + used, "\\%03o", c); #ifdef WIN32
sprintf_s(dest + used, dest_len, "\\%03o", c);
#else
std::sprintf(dest + used, "\\%03o", c);
#endif
used += 4; used += 4;
} else { } else {
dest[used++] = c; break; dest[used++] = c; break;