mirror of
https://github.com/panda3d/panda3d.git
synced 2025-10-01 17:35:34 -04:00
Use sysctl on FreeBSD
This commit is contained in:
parent
0e54f8b85b
commit
bd5e89e4a5
@ -38,6 +38,10 @@
|
||||
|
||||
#ifdef IS_FREEBSD
|
||||
extern char **environ;
|
||||
|
||||
// This is for sysctl.
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysctl.h>
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_PYTHON
|
||||
@ -565,6 +569,26 @@ read_args() {
|
||||
_args.push_back(GLOBAL_ARGV[i]);
|
||||
}
|
||||
|
||||
#elif defined(IS_FREEBSD)
|
||||
// In FreeBSD, we can use sysctl to determine the command-line arguments.
|
||||
|
||||
size_t bufsize = 4096;
|
||||
char buffer[4096];
|
||||
int mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_ARGS, getpid()};
|
||||
if (sysctl(mib, 4, (void*) &buffer, &bufsize, NULL, 0) == -1) {
|
||||
perror("sysctl");
|
||||
} else {
|
||||
if (_binary_name.empty()) {
|
||||
_binary_name = buffer;
|
||||
}
|
||||
int idx = strlen(buffer) + 1;
|
||||
while (idx < bufsize) {
|
||||
_args.push_back((char*)(buffer + idx));
|
||||
int newidx = strlen(buffer + idx);
|
||||
idx += newidx + 1;
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(HAVE_PROC_SELF_CMDLINE) || defined(HAVE_PROC_CURPROC_CMDLINE)
|
||||
// In Linux, and possibly in other systems as well, we might not be
|
||||
// able to use the global ARGC/ARGV variables at static init time.
|
||||
|
Loading…
x
Reference in New Issue
Block a user