Skip to content

Commit d90e078

Browse files
committed
Trying to port to MacOS
Signed-off-by: kernaltrap <[email protected]>
1 parent 9024d28 commit d90e078

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

src/config.h

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/*
2+
* Autogenerated by the Meson build system.
3+
* Do not edit, your changes will be lost.
4+
*/
5+
6+
#pragma once
7+
8+
#define PCI_DETECTION 1
9+

src/tinyfetch

38.3 KB
Binary file not shown.

src/tinyfetch.c

+12-12
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include <linux/kernel.h>
2020
#include <sys/sysinfo.h>
2121
#endif
22-
#ifdef __FreeBSD__
22+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
2323
#include <kvm.h>
2424
#include <sys/sysctl.h>
2525
#include <sys/types.h>
@@ -142,7 +142,7 @@ char *get_hostname(void) {
142142
FreeBSD sysctl calling
143143
*/
144144

145-
#ifdef __FreeBSD__
145+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
146146
char *freebsd_sysctl_str(char *ctlname) {
147147
char buf[1024];
148148
size_t buf_size = sizeof(buf);
@@ -219,7 +219,7 @@ char *get_parent_shell(void) {
219219
return strdup(cmdline); // return the contents of cmdline
220220
}
221221
#endif
222-
#ifdef __FreeBSD__
222+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
223223
char *get_parent_shell_noproc(void) {
224224
char *shell_path = getenv("SHELL");
225225
if (shell_path == NULL) {
@@ -256,7 +256,7 @@ long int get_uptime(void) {
256256
return s_info.uptime; // return uptime
257257
}
258258
#endif
259-
#ifdef __FreeBSD__
259+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
260260
long int get_uptime_freebsd(void) {
261261
int mib[2];
262262
size_t len;
@@ -429,7 +429,7 @@ int get_swap_status(void) {
429429
return 0; // No swap available
430430
}
431431
#endif
432-
#ifdef __FreeBSD__
432+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
433433
long long total, used, free;
434434
if (get_swap_stats(&total, &used, &free) != 0) {
435435
return -1; // Error in fetching swap stats
@@ -445,14 +445,14 @@ int get_cpu_count(void) {
445445
#ifdef __linux__
446446
return sysconf(_SC_NPROCESSORS_ONLN);
447447
#endif
448-
#ifdef __FreeBSD__
448+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
449449
int cpu_count = 0;
450450
freebsd_sysctl("hw.ncpu", cpu_count);
451451
return cpu_count;
452452
#endif
453453
}
454454

455-
#ifdef __FreeBSD__
455+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
456456
int get_swap_stats(long long *total, long long *used, long long *free) {
457457
(*total) = -1;
458458
(*used) = -1;
@@ -615,7 +615,7 @@ void tinyshell(void) {
615615
#ifdef __linux__
616616
char *shell = get_parent_shell();
617617
#endif
618-
#ifdef __FreeBSD__
618+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
619619
char *shell = get_parent_shell_noproc();
620620
#endif
621621
printf("%s\n", shell);
@@ -626,7 +626,7 @@ void tinyuptime(void) {
626626
#ifdef __linux__
627627
long int uptime = get_uptime();
628628
#endif
629-
#ifdef __FreeBSD__
629+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
630630
long int uptime = get_uptime_freebsd();
631631
#endif
632632
if (uptime == -1) {
@@ -698,7 +698,7 @@ void tinyram(void) {
698698
}
699699
#endif
700700

701-
#ifdef __FreeBSD__
701+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
702702
size_t total_ram_bytes;
703703
freebsd_sysctl("hw.physmem", total_ram_bytes);
704704
size_t cached_pages;
@@ -762,7 +762,7 @@ void tinycpu(void) {
762762
free(cpu_fallback);
763763
}
764764
#endif
765-
#ifdef __FreeBSD__
765+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
766766
char *cpu = freebsd_sysctl_str("hw.model");
767767
trim_spaces(cpu);
768768
int cpu_count = get_cpu_count();
@@ -829,7 +829,7 @@ void tinyswap(void) {
829829
}
830830
}
831831
#endif
832-
#ifdef __FreeBSD__
832+
#ifdef defined(__FreeBSD__) || defined(__MacOS__)
833833
long long total_swap = -1;
834834
long long used_swap = -1;
835835
long long free_swap = -1;

0 commit comments

Comments
 (0)