ascii-chat 0.11.33
Video chat in your terminal
Loading...
Searching...
No Matches
linux/filesystem.c
Go to the documentation of this file.
1
7#ifdef __linux__
8
10#include <ascii-chat/common.h>
12#include <unistd.h>
13#include <string.h>
14#include <errno.h>
15
19bool platform_get_executable_path(char *exe_path, size_t path_size) {
20 if (!exe_path || path_size == 0) {
21 SET_ERRNO(ERROR_INVALID_PARAM, "Invalid parameters: exe_path=%p, path_size=%zu", (void *)exe_path, path_size);
22 return false;
23 }
24
25 ssize_t len = readlink("/proc/self/exe", exe_path, path_size - 1);
26 if (len < 0) {
27 SET_ERRNO_SYS(ERROR_INVALID_STATE, "readlink(\"/proc/self/exe\") failed: %s", SAFE_STRERROR(errno));
28 return false;
29 }
30 if ((size_t)len >= path_size - 1) {
32 "Executable path exceeds buffer size (path length >= %zu bytes, buffer size = %zu bytes)", (size_t)len,
33 path_size);
34 return false;
35 }
36 // NOLINTNEXTLINE(clang-analyzer-security.ArrayBound) - len bounded by path_size check above
37 exe_path[len] = '\0';
38 return true;
39}
40
41#endif
⚠️‼️ Comprehensive thread-local error context system for ascii-chat
⚙️ Common definitions, error codes, macros, and types shared throughout the application
Cross-platform error handling utilities.
Cross-platform filesystem operations.
#define SAFE_STRERROR(errnum)
Definition common.h:465
#define SET_ERRNO_SYS(code, context_msg,...)
Set error code with custom message and system error context, returning the error code.
#define SET_ERRNO(code, context_msg,...)
Set error code with custom context message and log it, returning the error code.
@ ERROR_INVALID_STATE
@ ERROR_INVALID_PARAM
@ ERROR_BUFFER_OVERFLOW
bool platform_get_executable_path(char *exe_path, size_t path_size)
Get the path to the current executable.
Definition filesystem.c:191
int errno