From 22c30268664781adae88534fe5e91c10eb58e916 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jos=C3=A9=20Fonseca?= Date: Sun, 30 Oct 2011 01:14:29 +0100 Subject: [PATCH] Many fixes to os::Path. --- common/os.hpp | 11 +++++------ common/os_posix.cpp | 1 - common/os_win32.cpp | 2 -- common/trace_writer_local.cpp | 35 +++++++++++++++++++---------------- 4 files changed, 24 insertions(+), 25 deletions(-) diff --git a/common/os.hpp b/common/os.hpp index b914405..b97f330 100644 --- a/common/os.hpp +++ b/common/os.hpp @@ -119,11 +119,10 @@ public: return size - 1; } - void truncate(size_t size) { - assert(size > 0); - assert(size <= buffer.size()); - assert(buffer[size - 1] == 0); - buffer.resize(size); + void truncate(size_t length) { + assert(length < buffer.size()); + buffer[length] = 0; + buffer.resize(length + 1); } void truncate(void) { @@ -138,7 +137,7 @@ public: void join(const Path & other) { size_t len = length(); if (len > 0 && buffer[len - 1] != PATH_SEP) { - buffer.insert(buffer.begin() + len, PATH_SEP); + buffer.insert(buffer.begin() + len++, PATH_SEP); } buffer.insert(buffer.begin() + len, other.buffer.begin(), other.buffer.end() - 1); } diff --git a/common/os_posix.cpp b/common/os_posix.cpp index 78fefee..37dd364 100644 --- a/common/os_posix.cpp +++ b/common/os_posix.cpp @@ -95,7 +95,6 @@ getProcessName(void) return path; } #endif - szProcessPath[len] = 0; path.truncate(len); return path; diff --git a/common/os_win32.cpp b/common/os_win32.cpp index 66c8232..3bee070 100644 --- a/common/os_win32.cpp +++ b/common/os_win32.cpp @@ -68,8 +68,6 @@ getProcessName(void) DWORD nWritten = GetModuleFileNameA(NULL, szProcessPath, PATH_MAX); path.truncate(); - path.trimExtension(); - path.trimDirectory(); return path; } diff --git a/common/trace_writer_local.cpp b/common/trace_writer_local.cpp index 4d39490..f50dd21 100644 --- a/common/trace_writer_local.cpp +++ b/common/trace_writer_local.cpp @@ -73,30 +73,33 @@ LocalWriter::~LocalWriter() void LocalWriter::open(void) { + os::Path szFileName; - static unsigned dwCounter = 0; + char *lpFileName; - const char *szExtension = "trace"; - char szFileName[PATH_MAX]; - const char *lpFileName; + lpFileName = const_cast(getenv("TRACE_FILE")); + if (!lpFileName) { + lpFileName = szFileName.buf(PATH_MAX); + static unsigned dwCounter = 0; - lpFileName = getenv("TRACE_FILE"); - if (lpFileName) { - strncpy(szFileName, lpFileName, PATH_MAX); - } - else { - os::Path szProcessName = os::getProcessName(); - os::Path szCurrentDir = os::getCurrentDir(); + os::Path process = os::getProcessName(); +#ifdef _WIN32 + process.trimExtension(); +#endif + process.trimDirectory(); + + os::Path prefix = os::getCurrentDir(); + prefix.join(process); for (;;) { FILE *file; if (dwCounter) - snprintf(szFileName, PATH_MAX, "%s%c%s.%u.%s", szCurrentDir.str(), PATH_SEP, szProcessName.str(), dwCounter, szExtension); + snprintf(lpFileName, PATH_MAX, "%s.%u.trace", prefix.str(), dwCounter); else - snprintf(szFileName, PATH_MAX, "%s%c%s.%s", szCurrentDir.str(), PATH_SEP, szProcessName.str(), szExtension); + snprintf(lpFileName, PATH_MAX, "%s.trace", prefix.str()); - file = fopen(szFileName, "rb"); + file = fopen(lpFileName, "rb"); if (file == NULL) break; @@ -106,9 +109,9 @@ LocalWriter::open(void) { } } - os::log("apitrace: tracing to %s\n", szFileName); + os::log("apitrace: tracing to %s\n", lpFileName); - Writer::open(szFileName); + Writer::open(lpFileName); #if 0 // For debugging the exception handler -- 2.7.4