master ohmu/fastfetch-openbsd / src / common / path.h
ohmu  ·  2026-10-15
 1#pragma once
 2
 3#include "common/FFstrbuf.h"
 4#include "common/strutil.h"
 5#include "fastfetch_config.h"
 6
 7[[gnu::nonnull(1, 2), nodiscard]] const char* ffFindExecutableInPath(const char* name, FFstrbuf* result);
 8[[gnu::nonnull(1), gnu::pure, nodiscard]] static inline bool ffIsAbsolutePath(const char* path) {
 9#ifdef _WIN32
10    return (ffCharIsEnglishAlphabet(path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) // drive letter path
11        || (path[0] == '\\' && path[1] == '\\');                                                       // UNC path
12#else
13    return path[0] == '/';
14#endif
15}
16
17#if _WIN32
18char* frealpath(void* __restrict hFile, char* __restrict resolved_name /*MAX_PATH*/);
19char* realpath(const char* __restrict file_name, char* __restrict resolved_name /*MAX_PATH*/);
20ssize_t freadlink(void* hFile, char* buf, size_t bufsiz);
21ssize_t readlink(const char* path, char* buf, size_t bufsiz);
22#endif
23
24#ifdef __FreeBSD__
25    #include <paths.h>
26    #ifdef _PATH_LOCALBASE
27        #define FF_PATH_PKG_BASE _PATH_LOCALBASE
28    #else
29        #define FF_PATH_PKG_BASE "/usr/local"
30    #endif
31#elif __OpenBSD__
32    #define FF_PATH_PKG_BASE "/usr/local"
33#elif __NetBSD__
34    #define FF_PATH_PKG_BASE "/usr/pkg"
35#else
36    #define FF_PATH_PKG_BASE FASTFETCH_TARGET_DIR_USR
37#endif