SDL: haiku: Don't change the cwd on startup if launched from a Terminal.

From 663411ff77c18b7c09b5661af96ffac4805d14e1 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Thu, 11 Jul 2024 11:41:14 -0400
Subject: [PATCH] haiku: Don't change the cwd on startup if launched from a
 Terminal.

This patch was written by @pulkomandy. Thanks!

Reference Issue #7596.
---
 src/main/haiku/SDL_BeApp.cc | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/src/main/haiku/SDL_BeApp.cc b/src/main/haiku/SDL_BeApp.cc
index a736a9f09731e..be41676c7a799 100644
--- a/src/main/haiku/SDL_BeApp.cc
+++ b/src/main/haiku/SDL_BeApp.cc
@@ -118,9 +118,13 @@ static int StartBeLooper()
         } while ((!be_app) || be_app->IsLaunching());
     }
 
-     /* Change working directory to that of executable */
+     /* If started from the GUI, change working directory to that of executable.
+      * This matches behavior on other platforms and may be needed by some SDL software.
+      * Don't do it when started from terminal (TERM environment variable is set), because in that
+      * case, the current directory may be important, and after this there will be no way to know
+      * what it was. */
     app_info info;
-    if (B_OK == be_app->GetAppInfo(&info)) {
+    if (NULL == getenv("TERM") && B_OK == be_app->GetAppInfo(&info)) {
         entry_ref ref = info.ref;
         BEntry entry;
         if (B_OK == entry.SetTo(&ref)) {