aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/def_parser
diff options
context:
space:
mode:
authorGravatar Yun Peng <pcloudy@google.com>2017-11-15 10:50:14 +0100
committerGravatar Yun Peng <pcloudy@google.com>2017-12-18 10:54:17 +0100
commitf203db0644fd522e43a4b4ddfa410f95aef49ec3 (patch)
tree19fad59dd57ffc558d88699b1f77714ed656ef57 /third_party/def_parser
parent3d7b730344ede83931f558b4268b4f9558f47e5c (diff)
Windows DefParser: Remove dependency on //src/main/cpp/util:file
Change-Id: Ifc4a00d5bfef974f82c06eebc9553edad7b8145e
Diffstat (limited to 'third_party/def_parser')
-rw-r--r--third_party/def_parser/BUILD3
-rw-r--r--third_party/def_parser/def_parser.cc37
-rw-r--r--third_party/def_parser/def_parser.h2
-rw-r--r--third_party/def_parser/def_parser_main.cc6
4 files changed, 38 insertions, 10 deletions
diff --git a/third_party/def_parser/BUILD b/third_party/def_parser/BUILD
index 47ac3e3472..2d28bbb3a3 100644
--- a/third_party/def_parser/BUILD
+++ b/third_party/def_parser/BUILD
@@ -4,9 +4,6 @@ cc_library(
name = "def_parser_lib",
srcs = ["def_parser.cc"],
hdrs = ["def_parser.h"],
- deps = [
- "//src/main/cpp/util:file",
- ],
)
cc_binary(
diff --git a/third_party/def_parser/def_parser.cc b/third_party/def_parser/def_parser.cc
index 07cb727b71..2ed2db6cd1 100644
--- a/third_party/def_parser/def_parser.cc
+++ b/third_party/def_parser/def_parser.cc
@@ -61,12 +61,12 @@
* Author: Valery Fine 16/09/96 (E-mail: fine@vxcern.cern.ch)
*----------------------------------------------------------------------
*/
-#include "src/main/cpp/util/file_platform.h"
#include "third_party/def_parser/def_parser.h"
#include <algorithm>
#include <iostream>
#include <fstream>
+#include <memory> // unique_ptr
#include <sstream>
#include <windows.h>
@@ -77,6 +77,7 @@
using std::string;
using std::wstring;
using std::stringstream;
+using std::unique_ptr;
typedef struct cmANON_OBJECT_HEADER_BIGOBJ {
/* same as ANON_OBJECT_HEADER_V2 */
@@ -303,6 +304,37 @@ void PrintLastError() {
LocalFree(message_buffer);
}
+wstring StringToWString(const string& s) {
+ SetLastError(ERROR_SUCCESS);
+ DWORD len = MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, NULL, 0);
+ if (len == 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+ PrintLastError();
+ return L"";
+ }
+ unique_ptr<WCHAR[]> wstr(new WCHAR[len]);
+ MultiByteToWideChar(CP_ACP, 0, s.c_str(), -1, wstr.get(), len);
+ return wstring(wstr.get());
+}
+
+wstring AsAbsoluteWindowsPath(const string& path) {
+ wstring wpath = StringToWString(path);
+ // Get the buffer length we need for the full path.
+ SetLastError(ERROR_SUCCESS);
+ DWORD len = GetFullPathNameW(wpath.c_str(), 0, NULL, NULL);
+ if (len == 0 && GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
+ PrintLastError();
+ return L"";
+ }
+ SetLastError(ERROR_SUCCESS);
+ unique_ptr<WCHAR[]> buffer(new WCHAR[len]);
+ GetFullPathNameW(wpath.c_str(), len, buffer.get(), NULL);
+ if (GetLastError() != ERROR_SUCCESS) {
+ PrintLastError();
+ return L"";
+ }
+ return wstring(L"\\\\?\\") + wstring(buffer.get());
+}
+
bool DumpFile(const char* filename, std::set<string>& symbols,
std::set<string>& dataSymbols) {
HANDLE hFile;
@@ -310,8 +342,7 @@ bool DumpFile(const char* filename, std::set<string>& symbols,
LPVOID lpFileBase;
PIMAGE_DOS_HEADER dosHeader;
- wstring filenameW;
- blaze_util::AsAbsoluteWindowsPath(filename, &filenameW);
+ wstring filenameW = AsAbsoluteWindowsPath(filename);
hFile = CreateFileW(filenameW.c_str(), GENERIC_READ,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_ATTRIBUTE_NORMAL, 0);
diff --git a/third_party/def_parser/def_parser.h b/third_party/def_parser/def_parser.h
index 2c200b3215..3785914e56 100644
--- a/third_party/def_parser/def_parser.h
+++ b/third_party/def_parser/def_parser.h
@@ -8,6 +8,8 @@
#include <stdio.h>
#include <string>
+std::wstring AsAbsoluteWindowsPath(const std::string& path);
+
class DefParser{
public:
DefParser() {}
diff --git a/third_party/def_parser/def_parser_main.cc b/third_party/def_parser/def_parser_main.cc
index 5268b0ced5..35762d7ca4 100644
--- a/third_party/def_parser/def_parser_main.cc
+++ b/third_party/def_parser/def_parser_main.cc
@@ -5,7 +5,6 @@
#include <iostream>
#include <string>
-#include "src/main/cpp/util/file_platform.h"
#include "third_party/def_parser/def_parser.h"
static const char* ws = " \t\n\r\f\v";
@@ -38,8 +37,7 @@ int main(int argc, char* argv[]) {
return 1;
}
- std::wstring filenameW;
- blaze_util::AsAbsoluteWindowsPath(argv[1], &filenameW);
+ std::wstring filenameW = AsAbsoluteWindowsPath(argv[1]);
FILE* fout = _wfopen(filenameW.c_str(), L"w+");
if (!fout) {
std::cerr << "Could not open output .def file: " << argv[1] << "\n";
@@ -53,7 +51,7 @@ int main(int argc, char* argv[]) {
for (int i = 3; i < argc; i++) {
// If the argument starts with @, then treat it as a parameter file.
if (argv[i][0] == '@') {
- blaze_util::AsAbsoluteWindowsPath(argv[i] + 1, &filenameW);
+ filenameW = AsAbsoluteWindowsPath(argv[i] + 1);
std::ifstream paramfile(filenameW.c_str(), std::ios::in | std::ios::binary);
if (!paramfile) {
std::cerr << "Could not open parameter file: " << argv[i] << "\n";