Chromium Code Reviews| Index: tools/crashpad_database_util.cc |
| diff --git a/tools/crashpad_database_util.cc b/tools/crashpad_database_util.cc |
| index cd5a2195bd5b2146a1abb28ee0b3dabfea8c329b..c3d0d899cf3237764c9490a46eff646db7272d6c 100644 |
| --- a/tools/crashpad_database_util.cc |
| +++ b/tools/crashpad_database_util.cc |
| @@ -14,7 +14,6 @@ |
| #include <errno.h> |
| #include <getopt.h> |
| -#include <libgen.h> |
| #include <stdio.h> |
| #include <stdlib.h> |
| #include <string.h> |
| @@ -29,6 +28,9 @@ |
| #include "base/files/file_path.h" |
| #include "base/memory/scoped_ptr.h" |
| #include "base/numerics/safe_conversions.h" |
| +#include "base/strings/string_util.h" |
| +#include "base/strings/utf_string_conversions.h" |
| +#include "build/build_config.h" |
| #include "client/crash_report_database.h" |
| #include "client/settings.h" |
| #include "tools/tool_support.h" |
| @@ -36,9 +38,45 @@ |
| #include "util/file/file_reader.h" |
| #include "util/misc/uuid.h" |
| +#if defined(OS_MACOSX) |
| +#include <libgen.h> |
| +#endif // OS_MACOSX |
| + |
| namespace crashpad { |
| namespace { |
| +#if defined(OS_POSIX) |
| +time_t TimeGM(struct tm* tm) { |
| + return timegm(tm); |
| +} |
| + |
| +std::string Basename(const std::string& path) { |
| + std::string copy(path); |
| + return std::string(basename(©[0])); |
| +} |
| + |
| +const char* Strptime(const char* buf, const char* format, struct tm* tm) { |
| + return strptime(buf, format, tm); |
| +} |
| +#elif defined(OS_WIN) |
| +time_t TimeGM(struct tm* tm) { |
| + return _mkgmtime(tm); |
|
Mark Mentovai
2015/05/04 21:04:29
Write a timegm wrapper in compat/win/time.{cc,h} i
scottmg
2015/05/04 23:26:36
I did timegm and strptime, but basename seems icky
|
| +} |
| + |
| +std::string Basename(const std::string& path) { |
| + char fname[_MAX_FNAME]; |
| + char ext[_MAX_EXT]; |
| + _splitpath(path.c_str(), nullptr, nullptr, fname, ext); |
| + return std::string(fname) + std::string(ext); |
| +} |
| + |
| +const char* Strptime(const char* buf, const char* format, struct tm* tm) { |
| + // TODO(scottmg): strptime implementation. |
| + NOTREACHED(); |
| + return nullptr; |
| +} |
| +#endif // OS_POSIX |
| + |
| void Usage(const std::string& me) { |
| fprintf(stderr, |
| "Usage: %s [OPTION]... PID\n" |
| @@ -104,14 +142,14 @@ bool StringToBool(const char* string, bool* boolean) { |
| }; |
| for (size_t index = 0; index < arraysize(kFalseWords); ++index) { |
| - if (strcasecmp(string, kFalseWords[index]) == 0) { |
| + if (base::strcasecmp(string, kFalseWords[index]) == 0) { |
| *boolean = false; |
| return true; |
| } |
| } |
| for (size_t index = 0; index < arraysize(kTrueWords); ++index) { |
| - if (strcasecmp(string, kTrueWords[index]) == 0) { |
| + if (base::strcasecmp(string, kTrueWords[index]) == 0) { |
| *boolean = true; |
| return true; |
| } |
| @@ -133,7 +171,7 @@ std::string BoolToString(bool boolean) { |
| // when true, causes |string| to be interpreted as a UTC time rather than a |
| // local time when the time zone is ambiguous. |
| bool StringToTime(const char* string, time_t* time, bool utc) { |
| - if (strcasecmp(string, "never") == 0) { |
| + if (base::strcasecmp(string, "never") == 0) { |
| *time = 0; |
| return true; |
| } |
| @@ -148,12 +186,12 @@ bool StringToTime(const char* string, time_t* time, bool utc) { |
| for (size_t index = 0; index < arraysize(kFormats); ++index) { |
| tm time_tm; |
| - const char* strptime_result = strptime(string, kFormats[index], &time_tm); |
| + const char* strptime_result = Strptime(string, kFormats[index], &time_tm); |
| if (strptime_result == end) { |
| if (utc) { |
| - *time = timegm(&time_tm); |
| + *time = TimeGM(&time_tm); |
| } else { |
| - *time = timelocal(&time_tm); |
| + *time = mktime(&time_tm); |
| } |
| return true; |
| @@ -172,7 +210,7 @@ bool StringToTime(const char* string, time_t* time, bool utc) { |
| return false; |
| } |
| -// Converst |time_tt| to a string, and returns it. |utc| determines whether the |
| +// Converts |time_tt| to a string, and returns it. |utc| determines whether the |
| // converted time will reference local time or UTC. If |time_tt| is 0, the |
| // string "never" will be returned as a special case. |
| std::string TimeToString(time_t time_tt, bool utc) { |
| @@ -182,9 +220,17 @@ std::string TimeToString(time_t time_tt, bool utc) { |
| tm time_tm; |
| if (utc) { |
| +#if defined(OS_POSIX) |
| gmtime_r(&time_tt, &time_tm); |
| +#elif defined(OS_WIN) |
| + gmtime_s(&time_tm, &time_tt); |
| +#endif // OS_POSIX |
| } else { |
| +#if defined(OS_POSIX) |
| localtime_r(&time_tt, &time_tm); |
| +#elif defined(OS_WIN) |
| + localtime_s(&time_tm, &time_tt); |
| +#endif // OS_POSIX |
| } |
| char string[64]; |
| @@ -203,7 +249,14 @@ void ShowReport(const CrashReportDatabase::Report& report, |
| bool utc) { |
| std::string spaces(space_count, ' '); |
| - printf("%sPath: %s\n", spaces.c_str(), report.file_path.value().c_str()); |
| + printf("%sPath: %s\n", |
|
Mark Mentovai
2015/05/04 21:04:30
Does it work to use PRFilePath here so that the ar
scottmg
2015/05/04 23:26:36
Done.
|
| + spaces.c_str(), |
| +#if defined(OS_POSIX) |
| + report.file_path.value().c_str() |
| +#elif defined(OS_WIN) |
| + base::UTF16ToUTF8(report.file_path.value()).c_str() |
| +#endif |
| + ); |
| if (!report.id.empty()) { |
| printf("%sRemote ID: %s\n", spaces.c_str(), report.id.c_str()); |
| } |
| @@ -239,7 +292,7 @@ void ShowReports(const std::vector<CrashReportDatabase::Report>& reports, |
| } |
| int DatabaseUtilMain(int argc, char* argv[]) { |
| - const std::string me(basename(argv[0])); |
| + const std::string me(Basename(argv[0])); |
| enum OptionFlags { |
| // “Short” (single-character) options. |
| @@ -349,7 +402,12 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
| break; |
| } |
| case kOptionNewReport: { |
| - options.new_report_paths.push_back(base::FilePath(optarg)); |
| +#if defined(OS_POSIX) |
| + base::FilePath new_report_path(optarg); |
| +#elif defined(OS_WIN) |
| + base::FilePath new_report_path(base::UTF8ToUTF16(optarg)); |
|
Mark Mentovai
2015/05/04 21:04:30
Similarly, when the entry point is main() and not
scottmg
2015/05/04 23:26:36
Yes, that's right. I looked at switching to wmain,
|
| +#endif // OS_POSIX |
| + options.new_report_paths.push_back(new_report_path); |
| break; |
| } |
| case kOptionUTC: { |
| @@ -408,8 +466,13 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
| return EXIT_FAILURE; |
| } |
| +#if defined(OS_POSIX) |
| + base::FilePath database_path(options.database); |
| +#elif defined(OS_WIN) |
| + base::FilePath database_path(base::UTF8ToUTF16(options.database)); |
| +#endif // OS_POSIX |
| scoped_ptr<CrashReportDatabase> database( |
| - CrashReportDatabase::Initialize(base::FilePath(options.database))); |
| + CrashReportDatabase::Initialize(database_path)); |
| if (!database) { |
| return EXIT_FAILURE; |
| } |
| @@ -453,7 +516,7 @@ int DatabaseUtilMain(int argc, char* argv[]) { |
| printf("%s%s (%ld)\n", |
| prefix, |
| TimeToString(last_upload_attempt_time, options.utc).c_str(), |
| - implicit_cast<long>(last_upload_attempt_time)); |
| + static_cast<long>(last_upload_attempt_time)); |
| } |
| if (options.show_pending_reports) { |