From fdd97359c96b35faf1fa8003e1f3e61eb1625ef0 Mon Sep 17 00:00:00 2001 From: "Michael D. Lowis" Date: Tue, 1 Nov 2022 14:39:05 -0400 Subject: [PATCH] move standard library functions to helper header so i can work toward their removal --- bin/dial.c | 1 + bin/init.c | 2 +- bin/listen.c | 3 +- bin/screenlock.c | 1 + bin/shell.c | 1 + inc/liba.h | 84 ++++++++++++++++--------------------- inc/std.h | 29 +++++++++++++ lib/a/Net.c | 27 ++++++------ lib/a/Options.c | 27 ++++++------ lib/a/UTF8.c | 22 +++++----- lib/a/defaults/options.c | 2 +- lib/a/defaults/set_option.c | 2 +- lib/a/gc.c | 42 ++++++++++--------- lib/a/stdlib/ecalloc.c | 3 +- lib/a/stdlib/efopen.c | 1 + lib/a/stdlib/efreadline.c | 5 ++- lib/a/stdlib/emalloc.c | 3 +- lib/a/stdlib/eraise.c | 1 + lib/a/stdlib/erealloc.c | 3 +- lib/a/stdlib/esignal.c | 1 + lib/a/stdlib/estrdup.c | 1 + lib/a/stdlib/fatal.c | 3 +- lib/a/stdlib/forkexec.c | 1 + lib/a/stdlib/smprintf.c | 5 ++- lib/a/stdlib/strmcat.c | 5 ++- lib/a/stdlib/warn.c | 1 + lib/ui/font_load.c | 3 +- lib/ui/window_create.c | 1 + 28 files changed, 161 insertions(+), 119 deletions(-) create mode 100644 inc/std.h diff --git a/bin/dial.c b/bin/dial.c index 507241b..27baa44 100644 --- a/bin/dial.c +++ b/bin/dial.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/bin/init.c b/bin/init.c index 0e276ef..5092574 100644 --- a/bin/init.c +++ b/bin/init.c @@ -1,4 +1,4 @@ -#define _XOPEN_SOURCE 700 +#include #include #include diff --git a/bin/listen.c b/bin/listen.c index d205875..7525543 100644 --- a/bin/listen.c +++ b/bin/listen.c @@ -1,10 +1,11 @@ +#include #include #include char* Usage = "listen DIALSTR CMD [ARG...]"; char** Command = NULL; -void OnNewClient(int cfd) +void OnNewClient(Int cfd) { int pid = fork(); if (pid < 0) diff --git a/bin/screenlock.c b/bin/screenlock.c index 6b66458..3fea960 100644 --- a/bin/screenlock.c +++ b/bin/screenlock.c @@ -1,3 +1,4 @@ +#include #include #include diff --git a/bin/shell.c b/bin/shell.c index 52fe958..5b467f4 100644 --- a/bin/shell.c +++ b/bin/shell.c @@ -1,3 +1,4 @@ +#include #include #include #include diff --git a/inc/liba.h b/inc/liba.h index 6e5a038..ec96541 100644 --- a/inc/liba.h +++ b/inc/liba.h @@ -1,22 +1,31 @@ -/* Standard Macros and Types */ -#include -#define _XOPEN_SOURCE 700 - -#include -#include -#include -#include #include - -/* Useful Standard Functions */ -#include -#include -#include #include -#include +#include -/* we're only targeting unixes */ -#include +typedef unsigned char Byte; +typedef long Int; +typedef unsigned long Uint; +typedef double Real; +typedef Int Rune; +typedef _Bool Bool; + +#ifndef true +#define true ((Bool)1) +#endif + +#ifndef false +#define false ((Bool)0) +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +#ifndef EOF +#define EOF ((Int)-1) +#endif + +void exit(int status); /* Miscellaneous Macros ******************************************************************************/ @@ -27,13 +36,13 @@ #ifndef container_of #define container_of(obj, type, member) \ - (type*)((uintptr_t)obj - offsetof(type, member)) + (type*)((uIntptr_t)obj - offsetof(type, member)) #endif /* Garbage Collector Interface */ -void* GC_Allocate(size_t sz); +void* GC_Allocate(Int sz); void GC_AddRef(void* p); void GC_DelRef(void* p); @@ -44,37 +53,20 @@ typedef struct { char* l; char* d; char s; - unsigned int a : 1; + Uint a : 1; } Option_T; -int Options_Parse(int argc, char** argv); +Int Options_Parse(Int argc, char** argv); void Options_PrintHelp(void); -/* - Standard Library Helpers -*/ -void fatal(const char* fmt, ...); -void warn(const char* fmt, ...); -void esignal(int sig, void (*func)(int)); -int eraise(int sig); -void* ecalloc(size_t num, size_t size); -void* emalloc(size_t size); -void* erealloc(void* ptr, size_t size); -char* smprintf(const char* fmt, ...); -FILE* efopen(const char* filename, const char* mode); -char* efreadline(FILE* input); -char* estrdup(const char *s); -int forkexec(char** cmd); -char* strmcat(char* first, ...); - /* Networking */ -int Net_Announce(char* dialstr); -int Net_Listen(int fd, int backlog); -int Net_Accept(int fd); -int Net_Dial(char* dialstr); -void Net_Serve(char* dialstr, void (*on_client)(int cfd)); +Int Net_Announce(char* dialstr); +Int Net_Listen(Int fd, Int backlog); +Int Net_Accept(Int fd); +Int Net_Dial(char* dialstr); +void Net_Serve(char* dialstr, void (*on_client)(Int cfd)); /* UTF8 Encoding and Decoding @@ -85,10 +77,8 @@ void Net_Serve(char* dialstr, void (*on_client)(int cfd)); #define RUNE_MAX ((Rune)0x10FFFF) #define RUNE_EOF ((Rune)EOF) -typedef uint32_t Rune; - -size_t UTF8_Encode(char str[UTF_MAX], Rune rune); -bool UTF8_Decode(Rune* rune, size_t* length, int byte); +Int UTF8_Encode(Byte str[UTF_MAX], Rune rune); +Bool UTF8_Decode(Rune* rune, Int* length, Int byte); /* Basic Runtime Facilities @@ -98,7 +88,7 @@ bool UTF8_Decode(Rune* rune, size_t* length, int byte); #define main usermain extern int usermain(int argc, char** argv); -extern void set_option(int sname, char* lname, char* arg); +extern void set_option(Int sname, char* lname, char* arg); extern char* ARGV0; extern char* Usage; diff --git a/inc/std.h b/inc/std.h new file mode 100644 index 0000000..7f9c1ef --- /dev/null +++ b/inc/std.h @@ -0,0 +1,29 @@ +#define _XOPEN_SOURCE 700 + +/* Standard Macros and Types */ +#include +#include + +/* Useful Standard Functions */ +#include +#include +#include +#include +#include + +/* we're only targeting unixes */ +#include + +void fatal(const char* fmt, ...); +void warn(const char* fmt, ...); +void esignal(int sig, void (*func)(int)); +int eraise(int sig); +void* ecalloc(int num, int size); +void* emalloc(int size); +void* erealloc(void* ptr, int size); +char* smprintf(const char* fmt, ...); +FILE* efopen(const char* filename, const char* mode); +char* efreadline(FILE* input); +char* estrdup(const char *s); +int forkexec(char** cmd); +char* strmcat(char* first, ...); diff --git a/lib/a/Net.c b/lib/a/Net.c index 0eea143..922e9a5 100644 --- a/lib/a/Net.c +++ b/lib/a/Net.c @@ -1,3 +1,4 @@ +#include #include #include #include @@ -13,7 +14,7 @@ typedef struct { } conn_t; struct socket_t { - int fd; + Int fd; union { struct sockaddr_in in; struct sockaddr_un un; @@ -38,7 +39,7 @@ struct in_addr ResolveAddress(char *hostname) return addr; } -int MakeSocket(char* dialstr, struct socket_t* sock) +Int MakeSocket(char* dialstr, struct socket_t* sock) { size_t i; /* make a local copy of dial string */ @@ -63,7 +64,7 @@ int MakeSocket(char* dialstr, struct socket_t* sock) sock->addr.in.sin_port = htons(strtol(conn.service, NULL, 0)); sock->addr.in.sin_addr = ResolveAddress(conn.address); sock->fd = socket(AF_INET, SOCK_STREAM, 0); - setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); + setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &(Int){1}, sizeof(Int)); } else if (!strcmp("udp", conn.network)) { @@ -71,7 +72,7 @@ int MakeSocket(char* dialstr, struct socket_t* sock) sock->addr.in.sin_port = htons(strtol(conn.service, NULL, 0)); sock->addr.in.sin_addr = ResolveAddress(conn.address); sock->fd = socket(AF_INET, SOCK_DGRAM, 0); - setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &(int){1}, sizeof(int)); + setsockopt(sock->fd, SOL_SOCKET, SO_REUSEADDR, &(Int){1}, sizeof(Int)); } else if (!strcmp("unix", conn.network)) { @@ -86,12 +87,12 @@ int MakeSocket(char* dialstr, struct socket_t* sock) return sock->fd; } -int Net_Announce(char* dialstr) +Int Net_Announce(char* dialstr) { struct socket_t sock = { .fd = -1 }; if (MakeSocket(dialstr, &sock)) { - int rv = -1; + Int rv = -1; switch (sock.addr.in.sin_family) { case AF_INET: @@ -118,19 +119,19 @@ int Net_Announce(char* dialstr) return sock.fd; } -int Net_Listen(int fd, int backlog) +Int Net_Listen(Int fd, Int backlog) { return listen(fd, backlog); } -int Net_Accept(int fd) +Int Net_Accept(Int fd) { return accept(fd, 0, 0); } -int Net_Dial(char* dialstr) +Int Net_Dial(char* dialstr) { - int rv = -1; + Int rv = -1; struct socket_t sock = { .fd = -1 }; if (MakeSocket(dialstr, &sock)) { @@ -148,14 +149,14 @@ int Net_Dial(char* dialstr) return (rv == 0 ? sock.fd : rv); } -void Net_Serve(char* dialstr, void (*on_client)(int cfd)) +void Net_Serve(char* dialstr, void (*on_client)(Int cfd)) { - int sfd = Net_Announce(dialstr); + Int sfd = Net_Announce(dialstr); if (sfd >= 0) { while (!Net_Listen(sfd, 5)) { - int cfd; + Int cfd; if ((cfd = Net_Accept(sfd)) >= 0) { on_client(cfd); diff --git a/lib/a/Options.c b/lib/a/Options.c index 72c4cf1..5a54aac 100644 --- a/lib/a/Options.c +++ b/lib/a/Options.c @@ -1,6 +1,7 @@ +#include #include -static void HandleOption(int s, char* l, char* arg) +static void HandleOption(Int s, char* l, char* arg) { if (s == 'h') { @@ -17,9 +18,9 @@ static Option_T* LookupOption(char* flag) { Option_T* opt = NULL; - for (int i = 0; Options[i].s || Options[i].l; i++) + for (Int i = 0; Options[i].s || Options[i].l; i++) { - int match = ( + Int match = ( (flag[1] && !strcmp(Options[i].l, flag)) || (!flag[1] && flag[0] == Options[i].s) ); @@ -33,7 +34,7 @@ static Option_T* LookupOption(char* flag) return opt; } -static inline void ParseLongOption(int* currp, char** argv) +static inline void ParseLongOption(Int* currp, char** argv) { /* get the option and the arg if there is one */ char* flag = argv[*currp] + 2; @@ -77,7 +78,7 @@ static inline void ParseLongOption(int* currp, char** argv) *currp += 1; } -static inline void ParseShortOption(int* currp, char** argv) +static inline void ParseShortOption(Int* currp, char** argv) { char* argstr = argv[*currp]+1; char flag[] = "\0\0"; @@ -123,13 +124,13 @@ static inline void ParseShortOption(int* currp, char** argv) *currp += 1; } -int Options_Parse(int argc, char** argv) +Int Options_Parse(Int argc, char** argv) { /* Record the program name */ ARGV0 = argv[0]; - int new_argc = 0; - int curr_arg = 1; + Int new_argc = 0; + Int curr_arg = 1; /* now parse the arguments */ for (; curr_arg < argc;) { @@ -168,10 +169,10 @@ int Options_Parse(int argc, char** argv) void Options_PrintHelp(void) { /* calculate padding */ - size_t padding = 0; - for (int i = 0; Options[i].s || Options[i].l; i++) + Int padding = 0; + for (Int i = 0; Options[i].s || Options[i].l; i++) { - size_t pad = 4; + Int pad = 4; if (Options[i].s) { pad += 2; @@ -195,8 +196,8 @@ void Options_PrintHelp(void) printf("usage: %s\n\n", Usage); } - /* print option help messages */ - for (int i = 0; Options[i].s || Options[i].l; i++) + /* prInt option help messages */ + for (Int i = 0; Options[i].s || Options[i].l; i++) { int remain = padding; if (Options[i].s) diff --git a/lib/a/UTF8.c b/lib/a/UTF8.c index 5a39bb8..428c0c9 100644 --- a/lib/a/UTF8.c +++ b/lib/a/UTF8.c @@ -1,17 +1,17 @@ #include -static const uint8_t UTF8_SeqBits[] = { 0x00u, 0x80u, 0xC0u, 0xE0u, 0xF0u, 0xF8u, 0xFCu, 0xFEu }; -static const uint8_t UTF8_SeqMask[] = { 0x00u, 0xFFu, 0x1Fu, 0x0Fu, 0x07u, 0x03u, 0x01u, 0x00u }; -static const uint8_t UTF8_SeqLens[] = { 0x01u, 0x00u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x00u }; +static const Byte UTF8_SeqBits[] = { 0x00u, 0x80u, 0xC0u, 0xE0u, 0xF0u, 0xF8u, 0xFCu, 0xFEu }; +static const Byte UTF8_SeqMask[] = { 0x00u, 0xFFu, 0x1Fu, 0x0Fu, 0x07u, 0x03u, 0x01u, 0x00u }; +static const Byte UTF8_SeqLens[] = { 0x01u, 0x00u, 0x02u, 0x03u, 0x04u, 0x05u, 0x06u, 0x00u }; -static bool runevalid(Rune val) { +static Bool runevalid(Rune val) { return (val <= RUNE_MAX) && ((val & 0xFFFEu) != 0xFFFEu) && ((val < 0xD800u) || (val > 0xDFFFu)) && ((val < 0xFDD0u) || (val > 0xFDEFu)); } -static size_t runelen(Rune rune) { +static Int runelen(Rune rune) { if(!runevalid(rune)) return 0; else if(rune <= 0x7F) @@ -24,26 +24,26 @@ static size_t runelen(Rune rune) { return 4; } -static uint8_t utfseq(uint8_t byte) { - for (int i = 1; i < 8; i++) +static Byte utfseq(Byte byte) { + for (Int i = 1; i < 8; i++) if ((byte & UTF8_SeqBits[i]) == UTF8_SeqBits[i-1]) return UTF8_SeqLens[i-1]; return 0; } -size_t UTF8_Encode(char str[UTF_MAX], Rune rune) +Int UTF8_Encode(Byte str[UTF_MAX], Rune rune) { - size_t len = runelen(rune); + Int len = runelen(rune); str[0] = (len == 1 ? 0x00 : UTF8_SeqBits[len]) | (UTF8_SeqMask[len] & (rune >> (6 * (len-1)))); - for (size_t i = 1; i < len; i++) + for (Int i = 1; i < len; i++) { str[i] = 0x80u | (0x3Fu & (rune >> (6 * (len-i-1)))); } return len; } -bool UTF8_Decode(Rune* rune, size_t* length, int byte) +Bool UTF8_Decode(Rune* rune, Int* length, Int byte) { /* Handle the start of a new rune */ if (*length == 0) diff --git a/lib/a/defaults/options.c b/lib/a/defaults/options.c index 03c70f0..359b487 100644 --- a/lib/a/defaults/options.c +++ b/lib/a/defaults/options.c @@ -1,6 +1,6 @@ #include Option_T Options[] = { - { .s = 'h', .l = "help", .a = 0, .d = "print this help message" }, + { .s = 'h', .l = "help", .a = 0, .d = "prInt this help message" }, {0} }; \ No newline at end of file diff --git a/lib/a/defaults/set_option.c b/lib/a/defaults/set_option.c index 7d7df2f..3cc16ec 100644 --- a/lib/a/defaults/set_option.c +++ b/lib/a/defaults/set_option.c @@ -1,6 +1,6 @@ #include -void set_option(int sname, char* lname, char* arg) +void set_option(Int sname, char* lname, char* arg) { (void)sname; (void)lname; diff --git a/lib/a/gc.c b/lib/a/gc.c index 7ca71da..2406e2a 100644 --- a/lib/a/gc.c +++ b/lib/a/gc.c @@ -7,6 +7,8 @@ /* the real main lives here */ #undef main +#include + /* TODO: * Process all increments *then* all decrements */ @@ -14,7 +16,7 @@ #define THOLD 0.65 #define DELETED ((void*)(intptr_t)-1) #define LOG_SIZE 1023u -#define NUM_PRIMES (sizeof(Primes)/sizeof(unsigned int)) +#define NUM_PRIMES (sizeof(Primes)/sizeof(unsigned Int)) enum { INCREMENT = 0, @@ -34,24 +36,24 @@ typedef struct { static void obj_addref(object_t* obj); static void obj_delref(object_t* obj); static void gc_collect(void); -static void log_add(object_t* obj, int op); +static void log_add(object_t* obj, Int op); typedef struct { - size_t size; - size_t nslots; - size_t thold; + Int size; + Int nslots; + Int thold; void** slots; } hash_t; -static void hash_init(hash_t* hash, int nslots); +static void hash_init(hash_t* hash, Int nslots); static void hash_grow(hash_t* hash); static void hash_add(hash_t* hash, void* entry); -static int hash_del(hash_t* hash, void* entry); +static Int hash_del(hash_t* hash, void* entry); static intptr_t* Stack_Bot = 0; static buffer_t Log = {0}; static hash_t ZCT; -static unsigned int Primes[] = { +static Int Primes[] = { 1543, 3079, 6151, 12289, 24593, 49157, 98317, 196613, 393241, 786433, 1572869, 3145739, 6291469, 12582917, 25165843, 50331653, 100663319, 201326611, 402653189, @@ -60,7 +62,7 @@ static unsigned int Primes[] = { /* Public Routines ***************************************/ -void* GC_Allocate(size_t sz) +void* GC_Allocate(Int sz) { sz = (sz / sizeof(intptr_t)) + ((sz % sizeof(intptr_t)) ? 1 : 0); object_t* obj = ecalloc(1, sizeof(object_t) + sz); @@ -167,9 +169,9 @@ static void gc_collect(void) gc_scan_globals(&oldzct); /* free the rest as they are dead for sure */ - size_t nslots = Primes[oldzct.nslots]; + Int nslots = Primes[oldzct.nslots]; void** slots = oldzct.slots; - for (size_t i = 0; i < nslots; i++) + for (Int i = 0; i < nslots; i++) { if (slots[i] != NULL && slots[i] != DELETED) { @@ -179,7 +181,7 @@ static void gc_collect(void) free(slots); } -static void log_add(object_t* obj, int op) +static void log_add(object_t* obj, Int op) { Log.log[Log.index++] = (((uintptr_t)obj) | op); if (Log.index >= ((sizeof(Log)/sizeof(uintptr_t))-1)) @@ -221,24 +223,24 @@ static uint64_t hash64(uint64_t key) return key; } -static void hash_init(hash_t* hash, int nslots) +static void hash_init(hash_t* hash, Int nslots) { memset(hash, 0, sizeof(hash_t)); hash->nslots = nslots; - hash->thold = (size_t)(Primes[hash->nslots] * THOLD); + hash->thold = (Int)(Primes[hash->nslots] * THOLD); hash->slots = calloc(Primes[hash->nslots], sizeof(void*)); } static void hash_grow(hash_t* hash) { - size_t nslots = Primes[hash->nslots]; + Int nslots = Primes[hash->nslots]; void** slots = hash->slots; hash->size = 0; hash->nslots++; - hash->thold = (size_t)(Primes[hash->nslots] * THOLD); + hash->thold = (Int)(Primes[hash->nslots] * THOLD); hash->slots = calloc(Primes[hash->nslots], sizeof(void*)); - for (size_t i = 0; i < nslots; i++) + for (Int i = 0; i < nslots; i++) { if (slots[i] != NULL) { @@ -258,7 +260,7 @@ static void hash_add(hash_t* hash, void* entry) /* now hash and add the new item */ uint64_t hcode = hash64((uint64_t)entry); - size_t index = (hcode % Primes[hash->nslots]); + Int index = (hcode % Primes[hash->nslots]); while (1) { if (hash->slots[index] == entry) @@ -278,10 +280,10 @@ static void hash_add(hash_t* hash, void* entry) } } -static int hash_del(hash_t* hash, void* entry) +static Int hash_del(hash_t* hash, void* entry) { uint64_t hcode = hash64((uint64_t)entry); - size_t index = (hcode % Primes[hash->nslots]); + Int index = (hcode % Primes[hash->nslots]); while (1) { diff --git a/lib/a/stdlib/ecalloc.c b/lib/a/stdlib/ecalloc.c index f6ad21c..7756325 100644 --- a/lib/a/stdlib/ecalloc.c +++ b/lib/a/stdlib/ecalloc.c @@ -1,6 +1,7 @@ #include +#include -void* ecalloc(size_t num, size_t size) +void* ecalloc(int num, int size) { void* ret; if (NULL == (ret = calloc(num,size))) diff --git a/lib/a/stdlib/efopen.c b/lib/a/stdlib/efopen.c index aa459f9..1b47115 100644 --- a/lib/a/stdlib/efopen.c +++ b/lib/a/stdlib/efopen.c @@ -1,4 +1,5 @@ #include +#include FILE* efopen(const char* filename, const char* mode) { diff --git a/lib/a/stdlib/efreadline.c b/lib/a/stdlib/efreadline.c index c9cef61..6d506e2 100644 --- a/lib/a/stdlib/efreadline.c +++ b/lib/a/stdlib/efreadline.c @@ -1,9 +1,10 @@ #include +#include char* efreadline(FILE* input) { - size_t size = 32; - size_t index = 0; + Int size = 32; + Int index = 0; char* str = (char*)emalloc(size); memset(str, 0, size); if (feof(input)) diff --git a/lib/a/stdlib/emalloc.c b/lib/a/stdlib/emalloc.c index 9e7470d..ac4cd85 100644 --- a/lib/a/stdlib/emalloc.c +++ b/lib/a/stdlib/emalloc.c @@ -1,6 +1,7 @@ #include +#include -void* emalloc(size_t size) +void* emalloc(int size) { void* ret; if (NULL == (ret = malloc(size))) diff --git a/lib/a/stdlib/eraise.c b/lib/a/stdlib/eraise.c index 6a3bd50..a6b1e75 100644 --- a/lib/a/stdlib/eraise.c +++ b/lib/a/stdlib/eraise.c @@ -1,4 +1,5 @@ #include +#include int eraise(int sig) { diff --git a/lib/a/stdlib/erealloc.c b/lib/a/stdlib/erealloc.c index 3d0db4a..47c4835 100644 --- a/lib/a/stdlib/erealloc.c +++ b/lib/a/stdlib/erealloc.c @@ -1,6 +1,7 @@ #include +#include -void* erealloc(void* ptr, size_t size) +void* erealloc(void* ptr, int size) { void* ret; if (NULL == (ret = realloc(ptr,size))) diff --git a/lib/a/stdlib/esignal.c b/lib/a/stdlib/esignal.c index f31b0c5..042039e 100644 --- a/lib/a/stdlib/esignal.c +++ b/lib/a/stdlib/esignal.c @@ -1,4 +1,5 @@ #include +#include void esignal(int sig, void (*func)(int)) { diff --git a/lib/a/stdlib/estrdup.c b/lib/a/stdlib/estrdup.c index 4945c47..210c636 100644 --- a/lib/a/stdlib/estrdup.c +++ b/lib/a/stdlib/estrdup.c @@ -1,4 +1,5 @@ #include +#include char* estrdup(const char *s) { diff --git a/lib/a/stdlib/fatal.c b/lib/a/stdlib/fatal.c index 384c981..7ddfa83 100644 --- a/lib/a/stdlib/fatal.c +++ b/lib/a/stdlib/fatal.c @@ -1,4 +1,5 @@ #include +#include void fatal(const char* fmt, ...) { @@ -16,5 +17,5 @@ void fatal(const char* fmt, ...) fprintf(stderr, " %s", strerror(errno)); } fprintf(stderr, "\n"); - exit(EXIT_FAILURE); + exit(1); } diff --git a/lib/a/stdlib/forkexec.c b/lib/a/stdlib/forkexec.c index 62d6c4a..24de21f 100644 --- a/lib/a/stdlib/forkexec.c +++ b/lib/a/stdlib/forkexec.c @@ -1,4 +1,5 @@ #include +#include #include #include #include diff --git a/lib/a/stdlib/smprintf.c b/lib/a/stdlib/smprintf.c index 5ff127a..1045cbe 100644 --- a/lib/a/stdlib/smprintf.c +++ b/lib/a/stdlib/smprintf.c @@ -1,10 +1,11 @@ #include +#include -char* smprintf(const char* fmt, ...) +char* smprIntf(const char* fmt, ...) { va_list args; va_start(args, fmt); - int strsz = vsnprintf(NULL, 0, fmt, args); + Int strsz = vsnprintf(NULL, 0, fmt, args); va_end(args); char* str = emalloc(strsz+1); va_start(args, fmt); diff --git a/lib/a/stdlib/strmcat.c b/lib/a/stdlib/strmcat.c index 1cefc62..b08afe2 100644 --- a/lib/a/stdlib/strmcat.c +++ b/lib/a/stdlib/strmcat.c @@ -1,17 +1,18 @@ #include +#include char* strmcat(char* first, ...) { va_list args; /* calculate the length of the final string */ - size_t len = strlen(first); + Int len = strlen(first); va_start(args, first); for (char* s = NULL; (s = va_arg(args, char*));) { len += strlen(s); } va_end(args); - /* allocate the final string and copy the args into it */ + /* allocate the final string and copy the args Into it */ char *str = malloc(len+1), *curr = str; while (first && *first) { diff --git a/lib/a/stdlib/warn.c b/lib/a/stdlib/warn.c index d9011da..23960c2 100644 --- a/lib/a/stdlib/warn.c +++ b/lib/a/stdlib/warn.c @@ -1,4 +1,5 @@ #include +#include void warn(const char* fmt, ...) { diff --git a/lib/ui/font_load.c b/lib/ui/font_load.c index cbb286b..24163ef 100644 --- a/lib/ui/font_load.c +++ b/lib/ui/font_load.c @@ -1,10 +1,11 @@ +#include #include #include #include UIFont font_load(char* patt) { - static bool inited = false; + static Bool inited = false; if (!inited && !FcInit()) { fatal("failed to initialize fontconfig"); diff --git a/lib/ui/window_create.c b/lib/ui/window_create.c index 6d16209..83db56a 100644 --- a/lib/ui/window_create.c +++ b/lib/ui/window_create.c @@ -1,3 +1,4 @@ +#include #include #include #include -- 2.52.0