make the code, which was supposed to iterate file log number (if no access) and fallback to stderr in worst case rather than segfault, actually work
authorsheepluva
Sat, 29 Nov 2014 15:38:28 +0100
changeset 10573 3b82b4d90eb7
parent 10572 c4e86a2efc55
child 10574 1636b0efa415
make the code, which was supposed to iterate file log number (if no access) and fallback to stderr in worst case rather than segfault, actually work
hedgewars/uUtils.pas
--- a/hedgewars/uUtils.pas	Sat Nov 29 15:25:09 2014 +0100
+++ b/hedgewars/uUtils.pas	Sat Nov 29 15:38:28 2014 +0100
@@ -538,9 +538,6 @@
     InitCriticalSection(logMutex);
 {$ENDIF}
 {$I-}
-{$IFNDEF PAS2C}
-    logFile:= stderr; // if everything fails, write to stderr
-{$ENDIF}
     if (length(UserPathPrefix) > 0) then
         begin
         {$IFNDEF PAS2C}
@@ -553,12 +550,20 @@
         while(i < 7) do
             begin
             assign(logFile, shortstring(UserPathPrefix) + '/Logs/' + logfileBase + inttostr(i) + '.log');
+            Rewrite(logFile);
             if IOResult = 0 then
                 break;
             inc(i)
             end;
         end;
-    Rewrite(logFile);
+
+{$IFNDEF PAS2C}
+    if (length(UserPathPrefix) = 0) or (IOResult = 0) then
+        begin
+        logFile:= stderr; // if everything fails, write to stderr
+        Rewrite(logFile);
+        end;
+{$ENDIF}
 {$I+}
 {$ENDIF}