From e261132db00dd88ff2f7ddf8cc70dd04ade1690d Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Wed, 17 Aug 2022 16:32:09 -0400 Subject: [PATCH] - use char* get_current_dir_name() in Mac/Linux to save the cwd in the shell open function --- src/common/platform/posix/cocoa/i_system.mm | 24 +++++++++++---------- src/common/platform/posix/sdl/i_system.cpp | 24 +++++++++++---------- 2 files changed, 26 insertions(+), 22 deletions(-) diff --git a/src/common/platform/posix/cocoa/i_system.mm b/src/common/platform/posix/cocoa/i_system.mm index 58617cd812..971e7aad70 100644 --- a/src/common/platform/posix/cocoa/i_system.mm +++ b/src/common/platform/posix/cocoa/i_system.mm @@ -186,18 +186,20 @@ bool I_ChDir(const char* path) return chdir(path) == 0; } -void I_OpenShellFolder(const char* folder) +void I_OpenShellFolder(const char* infolder) { - char curdir[PATH_MAX]; - if (!getcwd (curdir, countof(curdir))) - { - Printf ("Current path too long\n"); - return; - } + char* curdir = get_current_dir_name(); - chdir(folder); - Printf("Opening folder: %s\n", folder); - std::system("open ."); - chdir(curdir); + if (!chdir(infolder)) + { + Printf("Opening folder: %s\n", infolder); + system("open ."); + chdir(curdir); + } + else + { + Printf("Unable to open directory '%s\n", infolder); + } + free(curdir); } diff --git a/src/common/platform/posix/sdl/i_system.cpp b/src/common/platform/posix/sdl/i_system.cpp index 53fc55836d..2f3e3e75ec 100644 --- a/src/common/platform/posix/sdl/i_system.cpp +++ b/src/common/platform/posix/sdl/i_system.cpp @@ -447,18 +447,20 @@ unsigned int I_MakeRNGSeed() return seed; } -void I_OpenShellFolder(const char* folder) +void I_OpenShellFolder(const char* infolder) { - char curdir[PATH_MAX]; - if (!getcwd (curdir, countof(curdir))) - { - Printf ("Current path too long\n"); - return; - } + char* curdir = get_current_dir_name(); - chdir(folder); - Printf("Opening folder: %s\n", folder); - std::system("xdg-open ."); - chdir(curdir); + if (!chdir(infolder)) + { + Printf("Opening folder: %s\n", infolder); + system("xdg-open ."); + chdir(curdir); + } + else + { + Printf("Unable to open directory '%s\n", infolder); + } + free(curdir); }