[TCPSVCS] Remove hardcoded C drive letter (#800)
[reactos.git] / base / services / tcpsvcs / log.c
index 3b2d467..ef25909 100644 (file)
@@ -12,7 +12,7 @@
 #define DEBUG
 
 static LPWSTR lpEventSource = L"tcpsvcs";
-static LPCWSTR lpLogFileName = L"C:\\tcpsvcs_log.log";
+static WCHAR szLogFileName[MAX_PATH];
 static HANDLE hLogFile = NULL;
 
 static OVERLAPPED olWrite;
@@ -47,7 +47,7 @@ LogToEventLog(LPCWSTR lpMsg,
 static BOOL
 OpenLogFile()
 {
-    hLogFile = CreateFileW(lpLogFileName,
+    hLogFile = CreateFileW(szLogFileName,
                            GENERIC_WRITE,
                            FILE_SHARE_READ,
                            NULL,
@@ -212,13 +212,19 @@ InitLogging()
 #ifdef DEBUG
     BOOL bRet = FALSE;
 
+    if (!GetEnvironmentVariableW(L"SystemDrive", szLogFileName, ARRAYSIZE(szLogFileName)))
+    {
+        StringCchCopyW(szLogFileName, ARRAYSIZE(szLogFileName), L"C:");
+    }
+    StringCchCatW(szLogFileName, ARRAYSIZE(szLogFileName), L"\\tcpsvcs_log.log");
+
     ZeroMemory(&olWrite, sizeof(OVERLAPPED));
     olWrite.Offset = 0xFFFFFFFF;
     olWrite.OffsetHigh = 0xFFFFFFFF;
     olWrite.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
     if (olWrite.hEvent)
     {
-        DeleteFileW(lpLogFileName);
+        DeleteFileW(szLogFileName);
 
         if (OpenLogFile())
         {