Restructure project, add gebs_exists() and gebs_mkdir()

This commit is contained in:
kamkow1
2025-05-19 12:25:08 +02:00
parent 0087c523b5
commit c905379d14
6 changed files with 45 additions and 14 deletions

25
gebs.h
View File

@ -164,6 +164,8 @@ typedef struct {
bool gebs_rename(const char *a, const char *b);
bool gebs_remove(const char *p);
bool gebs_mkdir(const char *p);
bool gebs_exists(const char *p);
// ----------------------------------------------------------------------------
// Commands
@ -216,6 +218,10 @@ void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,
int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd)
{
Gebs_String_Builder sb = {0};
gebs_nsl_join_alloc(alloc, cmd, &sb, " ");
GEBS_LOGI("cmd `%s`\n", sb.items);
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
// Clone the list
Gebs_Cmd new_cmd = {0};
@ -287,6 +293,25 @@ void *gebs_default_allocator_realloc(void *memory, size_t prev_size, size_t new_
// Filesystem operations
// ----------------------------------------------------------------------------
bool gebs_mkdir(const char *p)
{
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
return mkdir(p, 0777) == 0;
#else
# error "gebs_mkdir unknown platform"
#endif
}
bool gebs_exists(const char *p)
{
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
struct stat st;
return stat(p, &st) == 0;
#else
# error "gebs_exists unknown platform"
#endif
}
bool gebs_rename(const char *a, const char *b)
{
GEBS_LOGO("rename %s -> %s\n", a, b);