refactor: centralize and improve error handling and path construction

This commit is contained in:
sankalp committed 2025-10-08 14:11:45 +05:45
1 parent 176d691007
commit 872cb30721
6 files changed
+162 -149

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
#ifndef KEYVIBE_UTILS_H
#define KEYVIBE_UTILS_H
#include <stddef.h>
#include <sys/types.h>
// Returns 1 on success, 0 on truncation/error
int safe_snprintf(char *dst, size_t dst_sz, const char *fmt, ...);
// fprintf to stderr with printf-style formatting. Returns 1 for convenient
// `return errorf(...)` usage.
int errorf(const char *fmt, ...);
// Common runtime helpers
const char *get_runtime_dir(void);
void build_pidfile_path(char *buffer, size_t buflen);
int read_pidfile(const char *path, pid_t *out_pid);
int write_pidfile(const char *path, pid_t pid);
int process_is_running(pid_t pid);
#endif // KEYVIBE_UTILS_H