#ifndef STRING_H #define STRING_H #include #include static inline bool is_absolute_path(const char* path) { if (!path || !*path) return false; #ifdef _WIN32 // 1) Drive-letter paths: "C:\…", "D:/…" if (isalpha((unsigned char)path[0]) && path[1] == ':' && (path[2] == '\\' || path[2] == '/')) { return true; } // 2) UNC paths: "\\server\share\…" if (path[0] == '\\' && path[1] == '\\') { return true; } return false; #else // POSIX: anything starting with '/' return path[0] == '/'; #endif } static inline void get_path_directory(const char* path, char* out, size_t out_size) { if (path == NULL || out == NULL || out_size == 0) { if (out && out_size > 0) { out[0] = '\0'; // ensure output is empty on invalid input } return; } const char* last_slash = strrchr(path, '/'); if (!last_slash) { if (out_size > 0) out[0] = '\0'; return; } size_t dir_len = (size_t)(last_slash - path); if (dir_len >= out_size) { dir_len = out_size - 1; } memcpy(out, path, dir_len); out[dir_len] = '/'; out[dir_len + 1] = '\0'; } static inline void string_join(const char* a, const char* b, char* out, size_t out_size) { if (a == NULL || b == NULL || out == NULL || out_size == 0) return; size_t a_len = strlen(a); size_t b_len = strlen(b); if (a_len + b_len + 1 >= out_size) return; // +1 for null terminator strcpy(out, a); strcat(out, b); } #endif // STRING_H