aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/compiler/importer.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/google/protobuf/compiler/importer.cc')
-rw-r--r--src/google/protobuf/compiler/importer.cc40
1 files changed, 21 insertions, 19 deletions
diff --git a/src/google/protobuf/compiler/importer.cc b/src/google/protobuf/compiler/importer.cc
index 0d9093c0..c3831e72 100644
--- a/src/google/protobuf/compiler/importer.cc
+++ b/src/google/protobuf/compiler/importer.cc
@@ -33,7 +33,7 @@
// Sanjay Ghemawat, Jeff Dean, and others.
#ifdef _MSC_VER
-#include <io.h>
+#include <direct.h>
#else
#include <unistd.h>
#endif
@@ -44,9 +44,6 @@
#include <algorithm>
#include <memory>
-#ifndef _SHARED_PTR_H
-#include <google/protobuf/stubs/shared_ptr.h>
-#endif
#include <google/protobuf/compiler/importer.h>
@@ -55,15 +52,22 @@
#include <google/protobuf/io/zero_copy_stream_impl.h>
#include <google/protobuf/stubs/strutil.h>
+
+#include <google/protobuf/stubs/io_win32.h>
+
+#ifdef _WIN32
+#include <ctype.h>
+#endif
+
namespace google {
namespace protobuf {
namespace compiler {
#ifdef _WIN32
-#ifndef F_OK
-#define F_OK 00 // not defined by MSVC for whatever reason
-#endif
-#include <ctype.h>
+// DO NOT include <io.h>, instead create functions in io_win32.{h,cc} and import
+// them like we do below.
+using google::protobuf::internal::win32::access;
+using google::protobuf::internal::win32::open;
#endif
// Returns true if the text looks like a Windows-style absolute path, starting
@@ -125,7 +129,7 @@ SourceTreeDescriptorDatabase::~SourceTreeDescriptorDatabase() {}
bool SourceTreeDescriptorDatabase::FindFileByName(
const string& filename, FileDescriptorProto* output) {
- google::protobuf::scoped_ptr<io::ZeroCopyInputStream> input(source_tree_->Open(filename));
+ std::unique_ptr<io::ZeroCopyInputStream> input(source_tree_->Open(filename));
if (input == NULL) {
if (error_collector_ != NULL) {
error_collector_->AddError(filename, -1, 0,
@@ -222,6 +226,7 @@ void Importer::ClearUnusedImportTrackFiles() {
pool_.ClearUnusedImportTrackFiles();
}
+
// ===================================================================
SourceTree::~SourceTree() {}
@@ -270,8 +275,8 @@ static string CanonicalizePath(string path) {
}
#endif
- vector<string> canonical_parts;
- vector<string> parts = Split(
+ std::vector<string> canonical_parts;
+ std::vector<string> parts = Split(
path, "/", true); // Note: Removes empty parts.
for (int i = 0; i < parts.size(); i++) {
if (parts[i] == ".") {
@@ -294,10 +299,8 @@ static string CanonicalizePath(string path) {
}
static inline bool ContainsParentReference(const string& path) {
- return path == ".." ||
- HasPrefixString(path, "../") ||
- HasSuffixString(path, "/..") ||
- path.find("/../") != string::npos;
+ return path == ".." || HasPrefixString(path, "../") ||
+ HasSuffixString(path, "/..") || path.find("/../") != string::npos;
}
// Maps a file from an old location to a new one. Typically, old_prefix is
@@ -327,8 +330,7 @@ static bool ApplyMapping(const string& filename,
// We do not allow the file name to use "..".
return false;
}
- if (HasPrefixString(filename, "/") ||
- IsWindowsAbsolutePath(filename)) {
+ if (HasPrefixString(filename, "/") || IsWindowsAbsolutePath(filename)) {
// This is an absolute path, so it isn't matched by the empty string.
return false;
}
@@ -416,7 +418,7 @@ DiskSourceTree::DiskFileToVirtualFile(
// Verify that we can open the file. Note that this also has the side-effect
// of verifying that we are not canonicalizing away any non-existent
// directories.
- google::protobuf::scoped_ptr<io::ZeroCopyInputStream> stream(OpenDiskFile(disk_file));
+ std::unique_ptr<io::ZeroCopyInputStream> stream(OpenDiskFile(disk_file));
if (stream == NULL) {
return CANNOT_OPEN;
}
@@ -426,7 +428,7 @@ DiskSourceTree::DiskFileToVirtualFile(
bool DiskSourceTree::VirtualFileToDiskFile(const string& virtual_file,
string* disk_file) {
- google::protobuf::scoped_ptr<io::ZeroCopyInputStream> stream(
+ std::unique_ptr<io::ZeroCopyInputStream> stream(
OpenVirtualFile(virtual_file, disk_file));
return stream != NULL;
}