From 8d2b222c1a2498081a055167717e503171453f60 Mon Sep 17 00:00:00 2001 From: Brian Fiete Date: Thu, 15 Jul 2021 05:58:59 -0700 Subject: [PATCH] Preserve cwd after spawn --- BeefySysLib/platform/posix/PosixCommon.cpp | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/BeefySysLib/platform/posix/PosixCommon.cpp b/BeefySysLib/platform/posix/PosixCommon.cpp index 426e502e..4fa4c52b 100644 --- a/BeefySysLib/platform/posix/PosixCommon.cpp +++ b/BeefySysLib/platform/posix/PosixCommon.cpp @@ -844,6 +844,8 @@ BFP_EXPORT BfpSpawn* BFP_CALLTYPE BfpSpawn_Create(const char* inTargetPath, cons //printf("BfpSpawn_Create: %s %s %x\n", inTargetPath, args, flags); + char* prevWorkingDir = NULL; + if ((workingDir != NULL) && (workingDir[0] != 0)) { if (chdir(workingDir) != 0) @@ -852,8 +854,19 @@ BFP_EXPORT BfpSpawn* BFP_CALLTYPE BfpSpawn_Create(const char* inTargetPath, cons OUTRESULT(BfpSpawnResult_UnknownError); return NULL; } + + prevWorkingDir = getcwd(NULL, 0); } + defer( + { + if (prevWorkingDir != NULL) + { + chdir(prevWorkingDir); + free(prevWorkingDir); + } + }); + String newArgs; String tempFileName;