]> git.cworth.org Git - apitrace/commitdiff
Escape double quotes and slashes when outputing C strings.
authorJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 9 Jul 2008 11:33:50 +0000 (20:33 +0900)
committerJosé Fonseca <jrfonseca@tungstengraphics.com>
Wed, 9 Jul 2008 11:33:50 +0000 (20:33 +0900)
log.cpp

diff --git a/log.cpp b/log.cpp
index f4c77465ad2a1851b5d33d7811d7f38db0260272..0c5a09e3315001a8e31c53483173bd35369ccc70 100644 (file)
--- a/log.cpp
+++ b/log.cpp
@@ -69,11 +69,10 @@ static void _ReOpen(void) {
                          NULL);
 }
 
-static void Write(const char *szText) {
+static void Write(const char *sBuffer, DWORD dwBytesToWrite) {
     if(g_hFile == INVALID_HANDLE_VALUE)
         return;
     
-    DWORD dwBytesToWrite = (DWORD)strlen(szText);
     DWORD dwBytesWritten = 0;
     
     while (dwBytesWritten < dwBytesToWrite) {
@@ -85,7 +84,7 @@ static void Write(const char *szText) {
         overlapped.OffsetHigh = 0xffffffff;
         
         if(WriteFile(g_hFile,
-                     szText + dwBytesWritten,
+                     sBuffer + dwBytesWritten,
                      dwBytesToWrite - dwBytesWritten,
                      &dwBytesWritten,
                      &overlapped) == FALSE) {
@@ -96,6 +95,10 @@ static void Write(const char *szText) {
     }
 }
 
+static void Write(const char *szText) {
+    Write(szText, (DWORD)strlen(szText));
+}
+
 void Open(const TCHAR *szName) {
     _Open(szName, TEXT("xml"));
     Write("<?xml version='1.0' encoding='UTF-8'?>");
@@ -227,7 +230,11 @@ void DumpString(const char *str) {
     Log::Text("\"");
     unsigned char c;
     while((c = *p++) != 0) {
-        if(c >= 0x20 && c <= 0x7e)
+        if(c == '\"')
+            Text("\\\"");
+        else if(c == '\\')
+            Text("\\\\");
+        else if(c >= 0x20 && c <= 0x7e)
             TextChar(c);
         else if(c == '\t')
             Text("\\t");