#include "util.h" #include #include int ecex_file_exists(const char *path) { if (!path || !path[0]) return 0; FILE *file = fopen(path, "rb"); if (!file) return 0; fclose(file); return 1; } char *ecex_read_entire_file(const char *path, size_t *out_size) { FILE *file = fopen(path, "rb"); if (!file) return NULL; if (fseek(file, 0, SEEK_END) != 0) { fclose(file); return NULL; } long size = ftell(file); if (size < 0) { fclose(file); return NULL; } rewind(file); char *data = malloc((size_t)size + 1); if (!data) { fclose(file); return NULL; } size_t read_count = fread(data, 1, (size_t)size, file); fclose(file); if (read_count != (size_t)size) { free(data); return NULL; } data[size] = '\0'; if (out_size) { *out_size = (size_t)size; } return data; } char *ecex_strdup(const char *s) { if (!s) return NULL; size_t len = 0; while (s[len]) len++; char *out = malloc(len + 1); if (!out) return NULL; for (size_t i = 0; i <= len; i++) { out[i] = s[i]; } return out; }