mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 14:03:58 +00:00
Unify handling of BSD systems where applicable
This commit is contained in:
parent
4ef6490a26
commit
76faee71a5
2 changed files with 10 additions and 5 deletions
|
@ -34,7 +34,7 @@
|
|||
#include <sys/utsname.h>
|
||||
#endif
|
||||
|
||||
#ifdef __FreeBSD__
|
||||
#ifdef __BSD__
|
||||
#include <sys/sysctl.h>
|
||||
#elif defined(__APPLE__)
|
||||
#include <mach-o/dyld.h>
|
||||
|
@ -1994,10 +1994,10 @@ std::string get_executable_path(const char *argv0) {
|
|||
// https://opensource.apple.com/source/adv_cmds/adv_cmds-163/ps/print.c
|
||||
uint32_t buffSize = sizeof buff;
|
||||
if (_NSGetExecutablePath(buff, &buffSize) == 0) return std::string(buff);
|
||||
#elif defined(__FreeBSD__)
|
||||
// FreeBSD does not have /proc by default, but it can be mounted as procfs via the
|
||||
// Linux compatibility layer. Per sysctl(3), passing in a process ID of -1 returns
|
||||
// the value for the current process.
|
||||
#elif defined(__BSD__)
|
||||
// BSDs do not have /proc by default, (although it can be mounted as procfs via the Linux
|
||||
// compatibility layer). We can use sysctl instead: per sysctl(3), passing in a process ID of -1
|
||||
// returns the value for the current process.
|
||||
size_t buff_size = sizeof buff;
|
||||
int name[] = {CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1};
|
||||
int result = sysctl(name, sizeof(name) / sizeof(int), buff, &buff_size, nullptr, 0);
|
||||
|
|
|
@ -22,6 +22,11 @@
|
|||
#include "fallback.h" // IWYU pragma: keep
|
||||
#include "maybe.h"
|
||||
|
||||
// Create a generic define for all BSD platforms
|
||||
#if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__DragonFly__)
|
||||
#define __BSD__
|
||||
#endif
|
||||
|
||||
// PATH_MAX may not exist.
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX 4096
|
||||
|
|
Loading…
Reference in a new issue