foxygit / doom Log in
commit 2ecf987df183e01f2e73db001542cfc56a84c6ce
Author:     Ioan Chera <ioan.chera@gmail.com>
AuthorDate: Sun Mar 18 09:42:17 2018 +0200
Commit:     Ioan Chera <ioan.chera@gmail.com>
CommitDate: Sun Mar 18 09:42:17 2018 +0200

    Fix TXT_SelectFile for macOS

    First parameter needed to be const, and the content updated to work under this restriction.
---
 textscreen/txt_fileselect.c | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/textscreen/txt_fileselect.c b/textscreen/txt_fileselect.c
index 8420a3ae..89e51aa5 100644
--- a/textscreen/txt_fileselect.c
+++ b/textscreen/txt_fileselect.c
@@ -463,12 +463,20 @@ int TXT_CanSelectFiles(void)
     return 1;
 }

-char *TXT_SelectFile(char *window_title, char **extensions)
+char *TXT_SelectFile(const char *window_title, char **extensions)
 {
     char *argv[4];
     char *result, *applescript;

-    applescript = GenerateAppleScript(window_title, extensions);
+    // We need to create a temporary copy of window_title because GenerateApple-
+    // Script works with non-const string.
+    char *window_title_copy = strdup(window_title);
+    if (!window_title_copy)
+    {
+        return NULL;
+    }
+
+    applescript = GenerateAppleScript(window_title_copy, extensions);

     argv[0] = "/usr/bin/osascript";
     argv[1] = "-e";
@@ -478,6 +486,7 @@ char *TXT_SelectFile(char *window_title, char **extensions)
     result = ExecReadOutput(argv);

     free(applescript);
+    free(window_title_copy);

     return result;
 }