]> git.notmuchmail.org Git - apitrace/commitdiff
Many fixes to os::Path.
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 30 Oct 2011 00:14:29 +0000 (01:14 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Sun, 30 Oct 2011 00:14:29 +0000 (01:14 +0100)
common/os.hpp
common/os_posix.cpp
common/os_win32.cpp
common/trace_writer_local.cpp

index b9144052d23be24933711c82d75776c97d808992..b97f33070ed5387da0fcdce43a4e0f7a31afbedc 100644 (file)
@@ -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);
     }
index 78fefee52e949893e742a3a205b444eedbeb115b..37dd36431d391eaa90c8ce4df9bc69acea675107 100644 (file)
@@ -95,7 +95,6 @@ getProcessName(void)
         return path;
     }
 #endif
-    szProcessPath[len] = 0;
     path.truncate(len);
 
     return path;
index 66c823263ca9e6dcc44ed640e47562af8f21a395..3bee07012bf6bd8aca04529f57f29dcef055863f 100644 (file)
@@ -68,8 +68,6 @@ getProcessName(void)
     DWORD nWritten = GetModuleFileNameA(NULL, szProcessPath, PATH_MAX);
 
     path.truncate();
-    path.trimExtension();
-    path.trimDirectory();
 
     return path;
 }
index 4d3949037951999563dd6271f7c5b918ab1d1e3b..f50dd21cade4bfe0c49e218904bfb5a424e6f73c 100644 (file)
@@ -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<char *>(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