Only care about POSIX platforms

This commit is contained in:
kamkow1
2025-06-01 21:36:35 +02:00
parent f2aa836d4f
commit 3cbe43eec4

48
gebs.h
View File

@ -73,19 +73,8 @@ int main(int argc, char ** argv)
#ifndef GEBS_H_ #ifndef GEBS_H_
#define GEBS_H_ #define GEBS_H_
#if !(defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)))
// ---------------------------------------------------------------------------- # error "gebs works only on posix platforms"
// Platform macros
// ----------------------------------------------------------------------------
#define GEBS_PLATFORM_POSIX 0
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__))
# define GEBS_PLATFORM GEBS_PLATFORM_POSIX
#endif
#ifndef GEBS_PLATFORM
# error "GEBS_PLATFORM is undefined!"
#endif #endif
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -100,15 +89,11 @@ int main(int argc, char ** argv)
#include <stdarg.h> #include <stdarg.h>
#include <string.h> #include <string.h>
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
#include <unistd.h> #include <unistd.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/wait.h> #include <sys/wait.h>
#include <sys/mman.h> #include <sys/mman.h>
#else
# error "Unknown GEBS_PLATFORM"
#endif
#define discard __attribute__((unused)) #define discard __attribute__((unused))
@ -402,7 +387,6 @@ int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd)
gebs_sb_finish_alloc(alloc, &sb); gebs_sb_finish_alloc(alloc, &sb);
GEBS_LOGI("cmd `%s`\n", sb.items); GEBS_LOGI("cmd `%s`\n", sb.items);
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
// Clone the list // Clone the list
Gebs_Cmd new_cmd = {0}; Gebs_Cmd new_cmd = {0};
defer { gebs_cmd_free_alloc(alloc, &new_cmd); } defer { gebs_cmd_free_alloc(alloc, &new_cmd); }
@ -438,9 +422,6 @@ int gebs_cmd_run_sync_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd)
} while(!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); } while(!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus));
} }
} }
#else
# error "gebs_cmd_run_sync_alloc unknown command"
#endif
} }
int gebs_cmd_run_sync_collect_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd, Gebs_String_Builder *sb_out) int gebs_cmd_run_sync_collect_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd, Gebs_String_Builder *sb_out)
@ -450,7 +431,6 @@ int gebs_cmd_run_sync_collect_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd, Gebs_S
gebs_sb_finish_alloc(alloc, &sb); gebs_sb_finish_alloc(alloc, &sb);
GEBS_LOGI("cmd `%s`\n", sb.items); GEBS_LOGI("cmd `%s`\n", sb.items);
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
// Clone the list // Clone the list
Gebs_Cmd new_cmd = {0}; Gebs_Cmd new_cmd = {0};
defer { gebs_cmd_free_alloc(alloc, &new_cmd); } defer { gebs_cmd_free_alloc(alloc, &new_cmd); }
@ -502,9 +482,6 @@ int gebs_cmd_run_sync_collect_alloc(Gebs_Allocator *alloc, Gebs_Cmd *cmd, Gebs_S
} while(!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus)); } while(!WIFEXITED(wstatus) && !WIFSIGNALED(wstatus));
} }
} }
#else
# error "gebs_cmd_run_sync_alloc unknown command"
#endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -667,41 +644,26 @@ void gebs_scratch_arena_reset(void)
bool gebs_mkdir(const char *p) bool gebs_mkdir(const char *p)
{ {
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX GEBS_LOGO("mkdir %s\n", p);
return mkdir(p, 0777) == 0; return mkdir(p, 0777) == 0;
#else
# error "gebs_mkdir unknown platform"
#endif
} }
bool gebs_exists(const char *p) bool gebs_exists(const char *p)
{ {
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
struct stat st; struct stat st;
return stat(p, &st) == 0; return stat(p, &st) == 0;
#else
# error "gebs_exists unknown platform"
#endif
} }
bool gebs_rename(const char *a, const char *b) bool gebs_rename(const char *a, const char *b)
{ {
GEBS_LOGO("rename %s -> %s\n", a, b); GEBS_LOGO("rename %s -> %s\n", a, b);
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
return rename(a, b) == 0; return rename(a, b) == 0;
#else
# error "gebs_rename unknown platform"
#endif
} }
bool gebs_remove(const char *p) bool gebs_remove(const char *p)
{ {
GEBS_LOGO("remove %s\n", p); GEBS_LOGO("remove %s\n", p);
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
return remove(p) == 0; return remove(p) == 0;
#else
# error "gebs_remove unknown platform"
#endif
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
@ -710,7 +672,6 @@ bool gebs_remove(const char *p)
bool gebs_needs_rebuild(const char *out, const char *in) bool gebs_needs_rebuild(const char *out, const char *in)
{ {
#if GEBS_PLATFORM == GEBS_PLATFORM_POSIX
time_t out_mtime = 0; time_t out_mtime = 0;
time_t in_mtime = 0; time_t in_mtime = 0;
@ -720,9 +681,6 @@ bool gebs_needs_rebuild(const char *out, const char *in)
if (stat(in, &attr2) == 0) { in_mtime = attr2.st_mtime; } if (stat(in, &attr2) == 0) { in_mtime = attr2.st_mtime; }
return in_mtime > out_mtime; return in_mtime > out_mtime;
#else
# error "gebs_needs_rebuild unknown platform"
#endif
} }
void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv, void gebs_rebuild_self1_alloc(Gebs_Allocator *alloc, int argc, char ** argv,