Skip to content

Commit 75176eb

Browse files
SteveL-MSFTadityapatwardhan
authored andcommitted
Update to not rely on sysctl.h if sysconf is available (#41)
1 parent 8098ca6 commit 75176eb

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

src/libpsl-native/src/CMakeLists.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
include(CheckIncludeFiles)
2+
include(CheckFunctionExists)
23

34
add_library(psl-native SHARED
45
getstat.cpp
@@ -28,8 +29,10 @@ add_library(psl-native SHARED
2829
createprocess.cpp
2930
nativesyslog.cpp)
3031

32+
check_function_exists(sysconf HAVE_SYSCONF)
33+
3134
check_include_files(
32-
"sys/types.h;sys/sysctl.h"
35+
"sys/sysctl.h"
3336
HAVE_SYS_SYSCTL_H)
3437

3538
configure_file(

src/libpsl-native/src/getppid.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
#include <sys/user.h>
88
#include <sys/param.h>
99

10-
#if HAVE_SYS_SYSCTL_H
10+
#if HAVE_SYSCONF
11+
// do nothing
12+
#elif HAVE_SYS_SYSCTL_H
1113
#include <sys/sysctl.h>
1214
#endif
1315

src/libpsl-native/src/getuserfrompid.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111
#include <sstream>
1212
#include <errno.h>
1313

14-
#if HAVE_SYS_SYSCTL_H
14+
#if __APPLE__
15+
#include <sys/sysctl.h>
16+
#elif HAVE_SYSCONF
17+
// do nothing
18+
#elif HAVE_SYS_SYSCTL_H
1519
#include <sys/sysctl.h>
1620
#endif
1721

src/libpsl-native/src/pal_config.h.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
#pragma once
22

33
#cmakedefine01 HAVE_SYS_SYSCTL_H
4+
#cmakedefine01 HAVE_SYSCONF

0 commit comments

Comments
 (0)