| 1 | // SPDX-License-Identifier: GPL-3.0-or-later |
| 2 | |
| 3 | #ifndef NETDATA_OS_H |
| 4 | #define NETDATA_OS_H |
| 5 | |
| 6 | #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_MACOS) |
| 7 | #include <sys/syscall.h> |
| 8 | #endif |
| 9 | |
| 10 | #include "system_memory.h" |
| 11 | #include "random.h" |
| 12 | #include "timestamps.h" |
| 13 | #include "setproctitle.h" |
| 14 | #include "close_range.h" |
| 15 | #include "setresuid.h" |
| 16 | #include "setresgid.h" |
| 17 | #include "getgrouplist.h" |
| 18 | #include "adjtimex.h" |
| 19 | #include "gettid.h" |
| 20 | #include "get_pid_max.h" |
| 21 | #include "get_system_cpus.h" |
| 22 | #include "get_system_pagesize.h" |
| 23 | #include "sleep.h" |
| 24 | #include "uuid_generate.h" |
| 25 | #include "setenv.h" |
| 26 | #include "hostname.h" |
| 27 | #include "os-freebsd-wrappers.h" |
| 28 | #include "os-macos-wrappers.h" |
| 29 | #include "os-windows-wrappers.h" |
| 30 | #include "system-maps/cached-uid-username.h" |
| 31 | #include "system-maps/cached-gid-groupname.h" |
| 32 | #include "system-maps/cache-host-users-and-groups.h" |
| 33 | #include "system-maps/cached-sid-username.h" |
| 34 | #include "windows-perflib/perflib.h" |
| 35 | #include "disk_space.h" |
| 36 | #include "file_metadata.h" |
| 37 | #include "process_path.h" |
| 38 | #include "boottime.h" |
| 39 | #include "boot_id.h" |
| 40 | #include "run_dir.h" |
| 41 | #include "file_lock.h" |
| 42 | #include "mmap_limit.h" |
| 43 | #include "machine_id.h" |
| 44 | #include "process_memory.h" |
| 45 | #include "dir_size.h" |
| 46 | |
| 47 | // this includes windows.h to the whole of netdata |
| 48 | // so various conflicts arise |
| 49 | // #include "windows-wmi/windows-wmi.h" |
| 50 | |
| 51 | // ===================================================================================================================== |
| 52 | // common defs for Apple/FreeBSD/Linux |
| 53 | |
| 54 | extern const char *os_type; |
| 55 | |
| 56 | extern unsigned int system_hz; |
| 57 | void os_get_system_HZ(void); |
| 58 | |
| 59 | // Forward declaration needed because this header uses strncpyz() before inlined.h is included. |
| 60 | static char *strncpyz(char *dst, const char *src, size_t dst_size_minus_1); |
| 61 | |
| 62 | #if defined(OS_WINDOWS) |
| 63 | char *os_translate_path(char *dst, const char *src, size_t dst_size); |
| 64 | char *os_translate_msys_to_windows_path(const char *src); |
| 65 | // Returns newly allocated POSIX-style storage; caller must free. |
| 66 | char *os_translate_windows_to_msys_path(const char *src); |
| 67 | #else |
| 68 | // No translation needed on non-Windows; copy src into dst for consistent semantics. |
| 69 | static inline char *os_translate_path(char *dst, const char *src, size_t dst_size) { |
| 70 | if (!dst || !dst_size) |
| 71 | return dst; |
| 72 | if (!src) { |
| 73 | dst[0] = '\0'; |
| 74 | return dst; |
| 75 | } |
| 76 | strncpyz(dst, src, dst_size - 1); |
| 77 | return dst; |
| 78 | } |
| 79 | static inline char *os_translate_windows_to_msys_path(const char *src) { |
| 80 | return strdupz(src ? src : ""); |
| 81 | } |
| 82 | #endif |
| 83 | |
| 84 | #endif //NETDATA_OS_H |