49 lines
2.3 KiB
C
49 lines
2.3 KiB
C
/* Capa de adaptación al sistema operativo (INTERNA). Hay una implementación
|
|
* para Linux (probada) y otra para Windows (escrita, sin compilar ni probar
|
|
* todavía: ver docs/STATUS.md). */
|
|
#ifndef TAHGIBU_PLATFORM_H
|
|
#define TAHGIBU_PLATFORM_H
|
|
|
|
#include <stdbool.h>
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
#include "tahgibu/error.h"
|
|
|
|
/* Rutas estándar de usuario. Cada buffer debe tener al menos 512 bytes. */
|
|
tgb_status tgb_plat_default_dirs(char *config, char *data, char *cache, char *state, size_t cap);
|
|
/* Crea la carpeta y sus padres (como mkdir -p). */
|
|
tgb_status tgb_plat_mkdirs(const char *path);
|
|
bool tgb_plat_exists(const char *path);
|
|
bool tgb_plat_is_dir(const char *path);
|
|
|
|
/* Lee un archivo completo. Falla con TGB_ERR_LIMIT si supera max_bytes. Liberar con free(). */
|
|
tgb_status tgb_plat_read_file(const char *path, uint8_t **out, size_t *len, size_t max_bytes);
|
|
/* Escritura atómica: temporal en la misma carpeta + fsync + rename. Si algo
|
|
* falla, el destino queda intacto y el temporal se borra. */
|
|
tgb_status tgb_plat_write_atomic(const char *path, const void *data, size_t len);
|
|
tgb_status tgb_plat_remove(const char *path); /* TGB_OK también si no existía */
|
|
tgb_status tgb_plat_copy_file(const char *src, const char *dst);
|
|
/* Lista nombres (sin "." ni "..") de una carpeta. Liberar con tgb_plat_free_list. */
|
|
tgb_status tgb_plat_list_dir(const char *dir, char ***names, size_t *count);
|
|
void tgb_plat_free_list(char **names, size_t count);
|
|
|
|
size_t tgb_plat_available_memory(void); /* bytes de RAM disponibles (0 = desconocido) */
|
|
size_t tgb_plat_free_disk(const char *dir); /* bytes libres (0 = desconocido) */
|
|
|
|
long tgb_plat_pid(void);
|
|
/* Marca de inicio del proceso para distinguir PIDs reutilizados (0 = desconocido). */
|
|
int64_t tgb_plat_process_start_token(long pid);
|
|
bool tgb_plat_process_alive(long pid, int64_t start_token);
|
|
int64_t tgb_plat_now_unix(void);
|
|
int64_t tgb_plat_file_mtime(const char *path); /* segundos Unix, 0 si no se puede */
|
|
double tgb_plat_monotonic_seconds(void);
|
|
|
|
/* Bibliotecas dinámicas (extensiones nativas). */
|
|
void *tgb_plat_dlopen(const char *path);
|
|
void *tgb_plat_dlsym(void *lib, const char *name);
|
|
void tgb_plat_dlclose(void *lib);
|
|
const char *tgb_plat_dlerror(void);
|
|
const char *tgb_plat_dll_extension(void); /* ".so" o ".dll" */
|
|
|
|
#endif
|