diff --git a/app/src/command.c b/app/src/command.c index 63afccb4..abaa223d 100644 --- a/app/src/command.c +++ b/app/src/command.c @@ -4,9 +4,6 @@ #include #include #include -#include -#include -#include #include "config.h" #include "common.h" @@ -205,14 +202,3 @@ process_check_success(process_t proc, const char *name) { } return true; } - -bool -is_regular_file(const char *path) { - struct stat path_stat; - int r = stat(path, &path_stat); - if (r) { - perror("stat"); - return false; - } - return S_ISREG(path_stat.st_mode); -} diff --git a/app/src/server.c b/app/src/server.c index 31e09ae3..54813ab8 100644 --- a/app/src/server.c +++ b/app/src/server.c @@ -6,11 +6,13 @@ #include #include #include +#include #include "config.h" #include "command.h" #include "util/log.h" #include "util/net.h" +#include "util/str_util.h" #define SOCKET_NAME "scrcpy" #define SERVER_FILENAME "scrcpy-server" @@ -20,10 +22,18 @@ static char * get_server_path(void) { +#ifdef __WINDOWS__ + const wchar_t *server_path_env = _wgetenv(L"SCRCPY_SERVER_PATH"); +#else const char *server_path_env = getenv("SCRCPY_SERVER_PATH"); +#endif if (server_path_env) { // if the envvar is set, use it +#ifdef __WINDOWS__ + char *server_path = utf8_from_wide_char(server_path_env); +#else char *server_path = SDL_strdup(server_path_env); +#endif if (!server_path) { LOGE("Could not allocate memory"); return NULL; diff --git a/app/src/sys/unix/command.c b/app/src/sys/unix/command.c index fbcf2355..af5d4b2f 100644 --- a/app/src/sys/unix/command.c +++ b/app/src/sys/unix/command.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include @@ -127,3 +128,14 @@ get_executable_path(void) { return NULL; #endif } + +bool +is_regular_file(const char *path) { + struct stat path_stat; + + if (stat(path, &path_stat)) { + perror("stat"); + return false; + } + return S_ISREG(path_stat.st_mode); +} diff --git a/app/src/sys/win/command.c b/app/src/sys/win/command.c index 55edaf8f..3846847e 100644 --- a/app/src/sys/win/command.c +++ b/app/src/sys/win/command.c @@ -4,6 +4,8 @@ #include "util/log.h" #include "util/str_util.h" +#include + static int build_cmd(char *cmd, size_t len, const char *const argv[]) { // Windows command-line parsing is WTF: @@ -90,3 +92,22 @@ get_executable_path(void) { buf[len] = '\0'; return utf8_from_wide_char(buf); } + +bool +is_regular_file(const char *path) { + wchar_t *wide_path = utf8_to_wide_char(path); + if (!wide_path) { + LOGC("Could not allocate wide char string"); + return false; + } + + struct _stat path_stat; + int r = _wstat(wide_path, &path_stat); + SDL_free(wide_path); + + if (r) { + perror("stat"); + return false; + } + return S_ISREG(path_stat.st_mode); +}