Skip to content

Commit 90359d2

Browse files
committed
Global: don't require sysinfo.h globally
... which is Linux specific
1 parent 6ff67e8 commit 90359d2

File tree

14 files changed

+25
-54
lines changed

14 files changed

+25
-54
lines changed

CMakeLists.txt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -497,12 +497,6 @@ add_library(libfastfetch OBJECT
497497

498498
target_compile_definitions(libfastfetch PUBLIC _GNU_SOURCE)
499499

500-
CHECK_INCLUDE_FILE("sys/sysinfo.h" HAVE_SYSINFO_H)
501-
if(HAVE_SYSINFO_H)
502-
# needs to be public, because changes fastfech.h ABI
503-
target_compile_definitions(libfastfetch PUBLIC FF_HAVE_SYSINFO_H)
504-
endif()
505-
506500
CHECK_INCLUDE_FILE("utmpx.h" HAVE_UTMPX_H)
507501
if(HAVE_UTMPX_H)
508502
target_compile_definitions(libfastfetch PRIVATE FF_HAVE_UTMPX_H)

src/common/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ static void initState(FFstate* state)
112112
#endif
113113
uname(&state->utsname);
114114

115-
#if FF_HAVE_SYSINFO_H
116-
sysinfo(&state->sysinfo);
117-
#endif
118-
119115
initConfigDirs(state);
120116
}
121117

src/detection/cpu/cpu_linux.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "common/properties.h"
44
#include "detection/temps/temps_linux.h"
55

6+
#include <sys/sysinfo.h>
67
#include <stdlib.h>
78
#include <unistd.h>
89

@@ -99,13 +100,8 @@ void ffDetectCPUImpl(const FFinstance* instance, FFCPUResult* cpu)
99100

100101
cpu->coresPhysical = ffStrbufToUInt16(&physicalCoresBuffer, 1);
101102

102-
#ifdef FF_HAVE_SYSINFO_H
103-
cpu->coresLogical = (uint16_t) get_nprocs_conf();
104-
cpu->coresOnline = (uint16_t) get_nprocs();
105-
#else
106-
cpu->coresLogical = 1;
107-
cpu->coresOnline = 1;
108-
#endif
103+
cpu->coresLogical = (uint16_t) get_nprocs_conf();
104+
cpu->coresOnline = (uint16_t) get_nprocs();
109105

110106
#define BP "/sys/devices/system/cpu/cpufreq/policy0/"
111107
if(ffFileExists(BP, S_IFDIR))

src/detection/processes/processes.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
#include "fastfetch.h"
77

8-
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error);
8+
uint32_t ffDetectProcesses(FFstrbuf* error);
99

1010
#endif

src/detection/processes/processes_bsd.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@
66
#include <sys/user.h>
77
#endif
88

9-
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
9+
uint32_t ffDetectProcesses(FFstrbuf* error)
1010
{
11-
FF_UNUSED(instance);
12-
1311
int request[] = {CTL_KERN, KERN_PROC, KERN_PROC_ALL};
1412
size_t length;
1513

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#include "processes.h"
22

3-
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
3+
#include <sys/sysinfo.h>
4+
5+
uint32_t ffDetectProcesses(FFstrbuf* error)
46
{
5-
#if FF_HAVE_SYSINFO_H
6-
FF_UNUSED(error);
7-
return (uint32_t) instance->state.sysinfo.procs;
8-
#else
9-
ffStrbufAppendS(error, "Unimplemented");
10-
return 0;
11-
#endif
7+
struct sysinfo info;
8+
if(sysinfo(&info) != 0)
9+
ffStrbufAppendS(error, "sysinfo() failed");
10+
return (uint32_t) info.procs;
1211
}

src/detection/processes/processes_windows.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@ extern "C" {
88
#include <ntstatus.h>
99
#include <winternl.h>
1010

11-
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
11+
uint32_t ffDetectProcesses(FFstrbuf* error)
1212
{
13-
FF_UNUSED(instance);
14-
1513
ULONG size = 0;
1614
if(NtQuerySystemInformation(SystemProcessInformation, nullptr, 0, &size) != STATUS_INFO_LENGTH_MISMATCH)
1715
{
@@ -44,7 +42,7 @@ uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
4442

4543
#include "util/windows/wmi.hpp"
4644

47-
uint32_t ffDetectProcesses(FFinstance* instance, FFstrbuf* error)
45+
uint32_t ffDetectProcesses(FFstrbuf* error)
4846
{
4947
FFWmiQuery query(L"SELECT NumberOfProcesses FROM Win32_OperatingSystem", error);
5048
if(!query)

src/detection/uptime/uptime.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@
55

66
#include "fastfetch.h"
77

8-
uint64_t ffDetectUptime(const FFinstance* instance);
8+
uint64_t ffDetectUptime();
99

1010
#endif

src/detection/uptime/uptime_bsd.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,8 @@
44
#include <sys/sysctl.h>
55
#include <sys/time.h>
66

7-
uint64_t ffDetectUptime(const FFinstance* instance)
7+
uint64_t ffDetectUptime()
88
{
9-
FF_UNUSED(instance)
109
struct timeval bootTime;
1110
size_t bootTimeSize = sizeof(bootTime);
1211
if(sysctl(
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
#include "uptime.h"
22

3-
uint64_t ffDetectUptime(const FFinstance* instance)
3+
#include <sys/sysinfo.h>
4+
5+
uint64_t ffDetectUptime()
46
{
5-
#if FF_HAVE_SYSINFO_H
6-
return (uint64_t) instance->state.sysinfo.uptime;
7-
#else
8-
FF_UNUSED(instance)
7+
struct sysinfo info;
8+
if(sysinfo(&info) != 0)
99
return 0;
10-
#endif
10+
return (uint32_t) info.uptime;
1111
}

0 commit comments

Comments
 (0)