From 4d6dd9d28130105ec6c0814364435ad36b6386ca Mon Sep 17 00:00:00 2001 From: Romain Vimont Date: Thu, 9 Sep 2021 10:24:08 +0200 Subject: [PATCH] Compute scrcpy directory manually The function dirname() does not work correctly everywhere with non-ASCII characters. Fixes #2619 --- app/src/server.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/app/src/server.c b/app/src/server.c index e1db2f0c..e3c8c344 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -60,7 +60,20 @@ get_server_path(void) { // not found, use current directory return strdup(SERVER_FILENAME); } - char *dir = dirname(executable_path); + + // dirname() does not work correctly everywhere, so get the parent + // directory manually. + // See + char *p = strrchr(executable_path, PATH_SEPARATOR); + if (!p) { + LOGE("Unexpected executable path: \"%s\" (it should contain a '%c')", + executable_path, PATH_SEPARATOR); + free(executable_path); + return strdup(SERVER_FILENAME); + } + + *p = '\0'; // modify executable_path in place + char *dir = executable_path; size_t dirlen = strlen(dir); // sizeof(SERVER_FILENAME) gives statically the size including the null byte