Skip to content

Commit e3d5aac

Browse files
authored
Implement getexepath for OpenBSD (#129103)
Contributes to #124911.
1 parent 826a0c6 commit e3d5aac

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

src/native/minipal/getexepath.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#include <sys/types.h>
1616
#include <sys/param.h>
1717
#include <sys/sysctl.h>
18+
#elif defined(__OpenBSD__)
19+
#include <string.h>
20+
#include <unistd.h>
21+
#include <sys/sysctl.h>
1822
#elif defined(_WIN32)
1923
#include <windows.h>
2024
#elif defined(__HAIKU__)
@@ -57,6 +61,16 @@ static inline char* minipal_getexepath(void)
5761
}
5862

5963
return strdup(path);
64+
#elif defined(__OpenBSD__)
65+
const int name[] = { CTL_KERN, KERN_PROC_ARGS, getpid(), KERN_PROC_ARGV };
66+
void *argv[PATH_MAX];
67+
size_t len = sizeof(argv);
68+
if (sysctl(name, 4, argv, &len, NULL, 0) != 0)
69+
{
70+
return NULL;
71+
}
72+
73+
return realpath((char *)argv[0], NULL);
6074
#elif defined(__sun)
6175
const char* path = getexecname();
6276
if (path == NULL)

0 commit comments

Comments
 (0)