From b7606be372bff4f434d0e2e06ca8a1edd249cde4 Mon Sep 17 00:00:00 2001
From: Brad Smith <[EMAIL REDACTED]>
Date: Tue, 1 Sep 2026 00:11:39 -0400
Subject: [PATCH] fs: Use getexecpath() on OpenBSD for GetExePath().
---
CMakeLists.txt | 1 +
src/filesystem/unix/SDL_sysfilesystem.c | 10 ++++++++++
2 files changed, 11 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index af7bb774228a6..4cabec1374754 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1225,6 +1225,7 @@ if(SDL_LIBC)
if(NOT WINDOWS)
check_symbol_exists(fdatasync "unistd.h" HAVE_FDATASYNC)
+ check_symbol_exists(getexecpath "unistd.h" HAVE_GETEXECPATH)
check_symbol_exists(gethostname "unistd.h" HAVE_GETHOSTNAME)
check_symbol_exists(getpagesize "unistd.h" HAVE_GETPAGESIZE)
check_symbol_exists(getresgid "unistd.h" HAVE_GETRESGID)
diff --git a/src/filesystem/unix/SDL_sysfilesystem.c b/src/filesystem/unix/SDL_sysfilesystem.c
index 127c285200ff1..d24dff6169b34 100644
--- a/src/filesystem/unix/SDL_sysfilesystem.c
+++ b/src/filesystem/unix/SDL_sysfilesystem.c
@@ -138,6 +138,15 @@ static char *GetExePath(void)
}
#endif
#ifdef SDL_PLATFORM_OPENBSD
+#ifdef HAVE_GETEXECPATH
+ char fullpath[PATH_MAX];
+ if (getexecpath(fullpath, sizeof(fullpath)) == 0) {
+ result = SDL_strdup(fullpath);
+ if (!result) {
+ return NULL;
+ }
+ }
+#else
// Please note that this will fail if the process was launched with a relative path and $PWD + the cwd have changed, or argv is altered. So don't do that. Or add a new sysctl to OpenBSD.
char **cmdline;
size_t len;
@@ -193,6 +202,7 @@ static char *GetExePath(void)
SDL_free(cmdline);
}
+#endif
#endif
// is a Linux-style /proc filesystem available?