summaryrefslogtreecommitdiffstats
path: root/base/trace_event.cc
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-01 17:40:13 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2008-10-01 17:40:13 +0000
commit836f134c56bfa714217ca12a73482205c1480774 (patch)
tree5c5b9d938a712e09831bdd32022e1b3716c5fbdf /base/trace_event.cc
parentd46d6f3b80099ce0c630185a2e86b649bba49254 (diff)
downloadchromium_src-836f134c56bfa714217ca12a73482205c1480774.zip
chromium_src-836f134c56bfa714217ca12a73482205c1480774.tar.gz
chromium_src-836f134c56bfa714217ca12a73482205c1480774.tar.bz2
Cross-platform wrappers for fopen, _wfopen_s, etc.
Patch by Paweł Hajdan jr <phajdan.jr@gmail.com>. http://codereview.chromium.org/6005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@2760 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/trace_event.cc')
-rw-r--r--base/trace_event.cc32
1 files changed, 5 insertions, 27 deletions
diff --git a/base/trace_event.cc b/base/trace_event.cc
index 92939d5..972f17c 100644
--- a/base/trace_event.cc
+++ b/base/trace_event.cc
@@ -78,11 +78,7 @@ void TraceLog::Heartbeat() {
void TraceLog::CloseLogFile() {
if (log_file_) {
-#if defined(OS_WIN)
- ::CloseHandle(log_file_);
-#elif defined(OS_POSIX)
- fclose(log_file_);
-#endif
+ file_util::CloseFile(log_file_);
}
}
@@ -92,26 +88,14 @@ bool TraceLog::OpenLogFile() {
std::wstring log_file_name;
PathService::Get(base::DIR_EXE, &log_file_name);
file_util::AppendToPath(&log_file_name, pid_filename);
-#if defined(OS_WIN)
- log_file_ = ::CreateFile(log_file_name.c_str(), GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (log_file_ == INVALID_HANDLE_VALUE || log_file_ == NULL) {
+ log_file_ = file_util::OpenFile(log_file_name, "a");
+ if (!log_file_) {
// try the current directory
- log_file_ = ::CreateFile(pid_filename.c_str(), GENERIC_WRITE,
- FILE_SHARE_READ | FILE_SHARE_WRITE, NULL,
- OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if (log_file_ == INVALID_HANDLE_VALUE || log_file_ == NULL) {
- log_file_ = NULL;
+ log_file_ = file_util::OpenFile(pid_filename, "a");
+ if (!log_file_) {
return false;
}
}
- ::SetFilePointer(log_file_, 0, 0, FILE_END);
-#elif defined(OS_POSIX)
- log_file_ = fopen(WideToUTF8(log_file_name).c_str(), "a");
- if (log_file_ == NULL)
- return false;
-#endif
return true;
}
@@ -162,13 +146,7 @@ void TraceLog::Trace(const std::string& name,
void TraceLog::Log(const std::string& msg) {
AutoLock lock(file_lock_);
-#if defined (OS_WIN)
- SetFilePointer(log_file_, 0, 0, SEEK_END);
- DWORD num;
- WriteFile(log_file_, (void*)msg.c_str(), (DWORD)msg.length(), &num, NULL);
-#elif defined (OS_POSIX)
fprintf(log_file_, "%s", msg.c_str());
-#endif
}
} // namespace base