mirror of
https://github.com/Genymobile/scrcpy.git
synced 2026-02-16 03:14:28 +01:00
Improve portable builds
In portable builds, scrcpy-server.jar was supposed to be present in the current directory, so in practice it worked only if scrcpy was launched from its own directory. Instead, find the absolute path of the executable and build a suitable path to use scrcpy-server.jar from the same directory.
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
// for portability
|
||||
#define _POSIX_SOURCE // for kill()
|
||||
#define _BSD_SOURCE // for readlink()
|
||||
|
||||
// modern glibc will complain without this
|
||||
#define _DEFAULT_SOURCE
|
||||
|
||||
#include "command.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
#include <limits.h>
|
||||
#include <signal.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
@@ -98,3 +104,15 @@ cmd_simple_wait(pid_t pid, int *exit_code) {
|
||||
}
|
||||
return !code;
|
||||
}
|
||||
|
||||
char *
|
||||
get_executable_path(void) {
|
||||
char buf[PATH_MAX + 1]; // +1 for the null byte
|
||||
ssize_t len = readlink("/proc/self/exe", buf, PATH_MAX);
|
||||
if (len == -1) {
|
||||
perror("readlink");
|
||||
return NULL;
|
||||
}
|
||||
buf[len] = '\0';
|
||||
return SDL_strdup(buf);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user