Skip to content

Commit 2761122

Browse files
authored
Merge pull request #3868 from pherl/3.5.x
Support win32 long path for cross compiled build
2 parents 188f180 + 9c197b7 commit 2761122

13 files changed

+22
-29
lines changed

src/google/protobuf/compiler/command_line_interface.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ namespace compiler {
100100
#endif
101101

102102
namespace {
103-
#if defined(_MSC_VER)
103+
#if defined(_WIN32)
104104
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
105105
// them like we do below.
106106
using google::protobuf::internal::win32::access;

src/google/protobuf/compiler/command_line_interface_unittest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ namespace google {
7070
namespace protobuf {
7171
namespace compiler {
7272

73-
#if defined(_MSC_VER)
73+
#if defined(_WIN32)
7474
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
7575
// them like we do below.
7676
using google::protobuf::internal::win32::access;

src/google/protobuf/compiler/importer.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ namespace google {
6565
namespace protobuf {
6666
namespace compiler {
6767

68-
#ifdef _MSC_VER
68+
#ifdef _WIN32
6969
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
7070
// them like we do below.
7171
using google::protobuf::internal::win32::access;

src/google/protobuf/compiler/objectivec/objectivec_helpers.cc

+11-6
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,6 @@
5050
#include <google/protobuf/stubs/io_win32.h>
5151
#include <google/protobuf/stubs/strutil.h>
5252

53-
#if defined(_MSC_VER)
54-
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
55-
// them like we do below.
56-
using google::protobuf::internal::win32::open;
57-
#endif
5853

5954
// NOTE: src/google/protobuf/compiler/plugin.cc makes use of cerr for some
6055
// error cases, so it seems to be ok to use as a back door for errors.
@@ -64,6 +59,16 @@ namespace protobuf {
6459
namespace compiler {
6560
namespace objectivec {
6661

62+
// <io.h> is transitively included in this file. Import the functions explicitly
63+
// in this port namespace to avoid ambiguous definition.
64+
namespace posix {
65+
#ifdef _WIN32
66+
using ::google::protobuf::internal::win32::open;
67+
#else
68+
using ::open;
69+
#endif
70+
} // namespace port
71+
6772
Options::Options() {
6873
// Default is the value of the env for the package prefixes.
6974
const char* file_path = getenv("GPB_OBJC_EXPECTED_PACKAGE_PREFIXES");
@@ -1469,7 +1474,7 @@ bool ParseSimpleFile(
14691474
const string& path, LineConsumer* line_consumer, string* out_error) {
14701475
int fd;
14711476
do {
1472-
fd = open(path.c_str(), O_RDONLY);
1477+
fd = posix::open(path.c_str(), O_RDONLY);
14731478
} while (fd < 0 && errno == EINTR);
14741479
if (fd < 0) {
14751480
*out_error =

src/google/protobuf/compiler/plugin.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ namespace google {
5454
namespace protobuf {
5555
namespace compiler {
5656

57-
#if defined(_MSC_VER)
57+
#if defined(_WIN32)
5858
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
5959
// them like we do below.
6060
using google::protobuf::internal::win32::setmode;

src/google/protobuf/io/zero_copy_stream_impl.cc

-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,6 @@ namespace io {
5656
// Win32 lseek is broken: If invoked on a non-seekable file descriptor, its
5757
// return value is undefined. We re-define it to always produce an error.
5858
#define lseek(fd, offset, origin) ((off_t)-1)
59-
#endif
60-
61-
#ifdef _MSC_VER
6259
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
6360
// them like we do below.
6461
using google::protobuf::internal::win32::access;

src/google/protobuf/io/zero_copy_stream_unittest.cc

-3
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ namespace {
8383

8484
#ifdef _WIN32
8585
#define pipe(fds) _pipe(fds, 4096, O_BINARY)
86-
#endif
87-
88-
#ifdef _MSC_VER
8986
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
9087
// them like we do below.
9188
using google::protobuf::internal::win32::access;

src/google/protobuf/message_unittest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@
6363
namespace google {
6464
namespace protobuf {
6565

66-
#if defined(_MSC_VER)
66+
#if defined(_WIN32)
6767
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
6868
// them like we do below.
6969
using google::protobuf::internal::win32::close;

src/google/protobuf/stubs/io_win32.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
//
4040
// This file is only used on Windows, it's empty on other platforms.
4141

42-
#if defined(_MSC_VER)
42+
#if defined(_WIN32)
4343

4444
// Comment this out to fall back to using the ANSI versions (open, mkdir, ...)
4545
// instead of the Unicode ones (_wopen, _wmkdir, ...). Doing so can be useful to
@@ -358,5 +358,5 @@ wstring testonly_path_to_winpath(const string& path) {
358358
} // namespace protobuf
359359
} // namespace google
360360

361-
#endif // defined(_MSC_VER)
361+
#endif // defined(_WIN32)
362362

src/google/protobuf/stubs/io_win32.h

-6
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252

5353
// Compilers on Windows other than MSVC (e.g. Cygwin, MinGW32) define the
5454
// following functions already, except for mkdir.
55-
#ifdef _MSC_VER
5655
namespace google {
5756
namespace protobuf {
5857
namespace internal {
@@ -77,9 +76,6 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath(
7776
} // namespace internal
7877
} // namespace protobuf
7978
} // namespace google
80-
#else // _MSC_VER
81-
#define mkdir(name, mode) mkdir(name)
82-
#endif // !_MSC_VER
8379

8480
#ifndef W_OK
8581
#define W_OK 02 // not defined by MSVC for whatever reason
@@ -100,5 +96,3 @@ LIBPROTOBUF_EXPORT std::wstring testonly_path_to_winpath(
10096
#endif // defined(_WIN32)
10197

10298
#endif // GOOGLE_PROTOBUF_STUBS_IO_WIN32_H__
103-
104-

src/google/protobuf/stubs/io_win32_unittest.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//
3535
// This file is only used on Windows, it's empty on other platforms.
3636

37-
#if defined(_MSC_VER)
37+
#if defined(_WIN32)
3838

3939
#define WIN32_LEAN_AND_MEAN
4040
#include <errno.h>
@@ -369,5 +369,5 @@ TEST_F(IoWin32Test, AsWindowsPathTest) {
369369
} // namespace protobuf
370370
} // namespace google
371371

372-
#endif // defined(_MSC_VER)
372+
#endif // defined(_WIN32)
373373

src/google/protobuf/testing/file.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ namespace protobuf {
5757
// them like we do below.
5858
#endif
5959

60-
#ifdef _MSC_VER
60+
#ifdef _WIN32
6161
using google::protobuf::internal::win32::access;
6262
using google::protobuf::internal::win32::chdir;
6363
using google::protobuf::internal::win32::fopen;

src/google/protobuf/testing/googletest.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
namespace google {
5353
namespace protobuf {
5454

55-
#ifdef _MSC_VER
55+
#ifdef _WIN32
5656
// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
5757
// them like we do below.
5858
using google::protobuf::internal::win32::close;

0 commit comments

Comments
 (0)