Skip to content

Fix utf-8 char path in windows #1002

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 0 additions & 14 deletions app/src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#include "config.h"
#include "common.h"
Expand Down Expand Up @@ -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);
}
6 changes: 6 additions & 0 deletions app/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#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"
Expand All @@ -20,7 +21,12 @@

static const char *
get_server_path(void) {
#ifndef _WIN32
const char *server_path_env = getenv("SCRCPY_SERVER_PATH");
#else
const wchar_t *wide_server_path_env = _wgetenv(L"SCRCPY_SERVER_PATH");
char *server_path_env = utf8_from_wide_char(wide_server_path_env);
#endif
if (server_path_env) {
LOGD("Using SCRCPY_SERVER_PATH: %s", server_path_env);
// if the envvar is set, use it
Expand Down
12 changes: 12 additions & 0 deletions app/src/sys/unix/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <signal.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <unistd.h>

Expand Down Expand Up @@ -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);
}
23 changes: 23 additions & 0 deletions app/src/sys/win/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include "util/log.h"
#include "util/str_util.h"

#include <sys/stat.h>

static int
build_cmd(char *cmd, size_t len, const char *const argv[]) {
// Windows command-line parsing is WTF:
Expand Down Expand Up @@ -90,3 +92,24 @@ get_executable_path(void) {
buf[len] = '\0';
return utf8_from_wide_char(buf);
}

bool
is_regular_file(const char *path) {
struct _stat path_stat;
int r;
wchar_t *wide_path = utf8_to_wide_char(path);

if (!wide_path) {
LOGE("Failed to allocate memory");
return false;
}

r = _wstat(wide_path, &path_stat);
SDL_free(wide_path);

if (r) {
perror("stat");
return false;
}
return S_ISREG(path_stat.st_mode);
}