Author | Jamozed <[email protected]> |
Date | 2022-02-09 00:44:14 |
Commit | 83240070661c0e6c147aa2fdafe09c327944f790 |
Parent | 0a8f8638a20c1b465ebb108f2ef89fd47936a7d4 |
Update libutil
Diffstat
M | src/bltns/eval.c | | | 3 | ++- |
M | src/conf.c | | | 5 | +++-- |
M | src/eval.c | | | 3 | ++- |
M | src/lex.c | | | 4 | ++-- |
M | src/lex.h | | | 4 | ++-- |
M | src/lineread.c | | | 3 | ++- |
M | src/main.c | | | 10 | +++++----- |
M | src/parse.c | | | 3 | ++- |
M | src/parse.h | | | 6 | +++--- |
A | src/util/alloc.c | | | 48 | ++++++++++++++++++++++++++++++++++++++++++++++++ |
M | src/util/stack.c | | | 3 | ++- |
M | src/util/strconv.h | | | 20 | ++++++++++---------- |
R | src/util/strtoi.c -> src/util/strtos.c | | | 37 | +++++++++++++++++++------------------ |
M | src/util/strtou.c | | | 37 | +++++++++++++++++++------------------ |
R | src/util/util.c -> src/util/alloc.h | | | 30 | +++++++++--------------------- |
M | src/util/util.h | | | 49 | +++++++++++++++++++++++++++++++++++++++++-------- |
16 files changed, 171 insertions, 94 deletions
diff --git a/src/bltns/eval.c b/src/bltns/eval.c index aafff88..de8dd30 100644 --- a/src/bltns/eval.c +++ b/src/bltns/eval.c @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ #include "../esh.h" +#include "../util/alloc.h" #include "../util/optget.h" #include "../util/util.h" @@ -60,7 +61,7 @@ int bltn_eval(int ac, char *av[]) { size += (strlen(av[opt.ind + i]) + 1); } - args = assert_calloc(size, sizeof (*args)); dest = args; + args = xcalloc(size, sizeof (*args)); dest = args; for (UINT i = 0; i != ac - opt.ind; i += 1) { if (i != 0) { strncat(dest, " ", 1); dest += 1; } diff --git a/src/conf.c b/src/conf.c index 1528203..e6e70a8 100644 --- a/src/conf.c +++ b/src/conf.c @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "conf.h" #include "esh.h" +#include "util/alloc.h" #include "util/error.h" #include "util/util.h" @@ -52,12 +53,12 @@ void confread(void) { free(base); char *home = getenv("HOME"); if (!home || !home[0]) { warn("$HOME is unset or empty"); return; } - base = assert_malloc(strlen(home) + strlen("/.config") + 1); + base = xmalloc(strlen(home) + strlen("/.config") + 1); strcpy(base, home); strcat(base, "./config"); } /* Allocate and construct the full eshrc path */ - path = assert_malloc(strlen(base) + strlen("/esh/eshrc") + 1); + path = xmalloc(strlen(base) + strlen("/esh/eshrc") + 1); strcpy(path, base); strcat(path, "/esh/eshrc"); free(base); /* If the eshrc file exists, then evaluate it */ diff --git a/src/eval.c b/src/eval.c index 605cce0..6bb8c8f 100644 --- a/src/eval.c +++ b/src/eval.c @@ -31,6 +31,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ #include "esh.h" +#include "util/alloc.h" #include "util/error.h" #include "util/util.h" @@ -65,7 +66,7 @@ extern void eval_file(const char *file) { fseek(fi, 0, SEEK_END); fl = ftell(fi); rewind(fi); - fb = assert_malloc((fl + 1) * sizeof (*fb)); + fb = xmalloc((fl + 1) * sizeof (*fb)); fread(fb, 1, fl, fi); fb[fl] = 0; fclose(fi); eval(fb, fl); free(fb); return; diff --git a/src/lex.c b/src/lex.c index d70cfe4..09f41a1 100644 --- a/src/lex.c +++ b/src/lex.c @@ -41,8 +41,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include <string.h> char *tok_ks[] = { - "NULL", "EOF", "WORD", "END", - "PIPE", "RIN", "ROUT", "RERR", + "NULL", "EOF", "WORD", "END", + "PIPE", "RIN", "ROUT", "RERR", }; /* Initialise a lexer. */ diff --git a/src/lex.h b/src/lex.h index 6f158fa..f1f1d19 100644 --- a/src/lex.h +++ b/src/lex.h @@ -36,8 +36,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "util/util.h" typedef enum { - TK_NULL, TK_EOF, TK_WORD, TK_END, - TK_PIPE, TK_RIN, TK_ROUT, TK_RERR, + TK_NULL, TK_EOF, TK_WORD, TK_END, + TK_PIPE, TK_RIN, TK_ROUT, TK_RERR, } tok_k; typedef struct { tok_k k; char *s; } tok; diff --git a/src/lineread.c b/src/lineread.c index d2066bf..1ab27b9 100644 --- a/src/lineread.c +++ b/src/lineread.c @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "conf.h" #include "lineread.h" +#include "util/alloc.h" #include "util/error.h" #include "util/util.h" @@ -375,7 +376,7 @@ static void line_delete_end(line *l) { /* Initialise history */ static int hist_init(hist *h) { h->ap = 0; h->ah = 0; h->at = 0; h->al = 0; h->ac = conf_histsize + 1; - if (!(h->a = assert_calloc(h->ac, sizeof (*h->a)))) { return 1; } + if (!(h->a = xcalloc(h->ac, sizeof (*h->a)))) { return 1; } /* TODO load history from file */ return 0; } diff --git a/src/main.c b/src/main.c index 940c1bc..7b0b456 100644 --- a/src/main.c +++ b/src/main.c @@ -77,8 +77,8 @@ static void ver(void); int main(int ac, char *av[]) { (void)(ac); A0 = av[0]; struct opt opt = OPTGET_INIT; opt.str = ""; opt.lops = lops; for (int o; (o = optget(&opt, av, 1)) != -1;) switch (o) { - case 256: { hlp(); return 0; } - case 257: { ver(); return 0; } + case 256: { hlp(); } return 0; + case 257: { ver(); } return 0; case 258: { Lflag = true; } break; case 259: { Pflag = true; } break; default: { return 1; } @@ -93,7 +93,7 @@ int main(int ac, char *av[]) { (void)(ac); A0 = av[0]; if (sigsetjmp(jmp, 1)) { fputc('\n', stdout); } jmpflag = true; char *line = lineread(); - if (!line) { if (errno) { warn("%s, %d", serr(), errno); } break; } + if (!line) { if (errno) { warn("lineread: %s", serr()); } break; } eval(line, strlen((char *)line)); free(line); } while (_loop); @@ -105,19 +105,19 @@ static void reset(int signo) { (void)(signo); if (jmpflag) { siglongjmp(jmp, 1); } } +/* Print help information. */ static void hlp(void) { puts("ESH - Executive Shell\n"); puts("Usage: esh\n"); puts("Options:"); puts(" --help Display help information"); puts(" --version Display version information"); - return; } +/* Print version information. */ static void ver(void) { puts("ESH, version " PROJECT_VERSION); puts("Copyright (C) 2020, Jakob Wakeling"); puts("All rights reserved."); puts("OMKOV Permissive Licence (https://www.omkov.net/OLPE)"); - return; } diff --git a/src/parse.c b/src/parse.c index 882ee26..d85766f 100644 --- a/src/parse.c +++ b/src/parse.c @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #include "esh.h" #include "lex.h" +#include "util/alloc.h" #include "util/error.h" #include "util/stack.h" #include "util/util.h" @@ -47,7 +48,7 @@ static ast parse_comm(lex *l); static ast parse_pipe(lex *l, ast lc); /* Initialise an AST node. */ -ast ast_init(void) { return assert_calloc(1, sizeof (struct ast_s)); } +ast ast_init(void) { return xcalloc(1, sizeof (struct ast_s)); } /* Uninitialise an AST node and its children. */ void ast_free(ast a) { diff --git a/src/parse.h b/src/parse.h index 0f9331f..501a8ac 100644 --- a/src/parse.h +++ b/src/parse.h @@ -43,9 +43,9 @@ typedef struct ast_s *ast; struct ast_s { ast_k k; char *s; ast lc, rc; stack c; - struct { char *s; bool a; } ri; - struct { char *s; bool a; } ro; - struct { char *s; bool a; } re; + struct { char *s; bool a; } ri; /* stdin */ + struct { char *s; bool a; } ro; /* stdout */ + struct { char *s; bool a; } re; /* stderr */ }; extern char *ast_ks[]; diff --git a/src/util/util.c b/src/util/alloc.c similarity index 77% rename from src/util/util.c rename to src/util/alloc.c index c38d2bd..be1ec97 100644 --- a/src/util/util.c +++ b/src/util/alloc.c @@ -1,5 +1,5 @@ -// util/util.c -// Common utility source file for ESH +// util/alloc.h, version 1.0.0 +// Memory allocation source file from libutil // Copyright (C) 2021, Jakob Wakeling // All rights reserved. @@ -30,25 +30,19 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ -#include "util.h" +#include "alloc.h" +#include "error.h" -#include <assert.h> #include <stdlib.h> -/* Allocate and assert memory. */ -void *assert_malloc(UINT l) { - register void *r = malloc(l); - assert(r); return r; +void *xmalloc(UINT l) { + void *q = malloc(l); if (!q) { error(1, "%s", SERR); } return q; } -/* Allocate and assert memory. */ -void *assert_calloc(UINT n, UINT l) { - register void *r = calloc(n, l); - assert(r); return r; +void *xcalloc(UINT n, UINT l) { + void *q = calloc(n, l); if (!q) { error(1, "%s", SERR); } return q; } -/* Reallocate and assert memory. */ -void *assert_realloc(void *p, UINT l) { - register void *r = realloc(p, l); - assert(r); return r; +void *xrealloc(void *p, UINT l) { + void *q = realloc(p, l); if (!q) { error(1, "%s", SERR); } return q; } diff --git a/src/util/alloc.h b/src/util/alloc.h new file mode 100644 index 0000000..f58e3ab --- /dev/null +++ b/src/util/alloc.h @@ -0,0 +1,42 @@ +// util/alloc.h, version 1.0.0 +// Memory allocation header file from libutil +// Copyright (C) 2021, Jakob Wakeling +// All rights reserved. + +/* +OMKOV Permissive Licence, version 1.0 + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal with +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +* Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimers. +* Redistributions in binary form must reproduce the above copyright notice, this + list of conditions and the following disclaimers in the documentation and/or + other materials provided with the distribution. +* Neither the names of the copyright holders, nor the names of its contributors + may be used to endorse or promote products derived from this Software without + specific prior written permission. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE COPYRIGHT +HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. +*/ + +#ifndef UTIL_ALLOC_H_M0UWQ8LT +#define UTIL_ALLOC_H_M0UWQ8LT + +#include "util.h" + +extern void *xmalloc(UINT l); +extern void *xcalloc(UINT n, UINT l); +extern void *xrealloc(void *p, UINT l); + +#endif // UTIL_ALLOC_H_M0UWQ8LT diff --git a/src/util/stack.c b/src/util/stack.c index 5a66f24..61524b9 100644 --- a/src/util/stack.c +++ b/src/util/stack.c @@ -30,6 +30,7 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ +#include "alloc.h" #include "stack.h" #include "util.h" @@ -54,7 +55,7 @@ extern void stack_free(stack *s) { /* Push a pointer to the top of a stack. */ extern void stack_push(stack *s, void *e) { - s->a = assert_realloc(s->a, (s->ac += 1) * s->el); + s->a = xrealloc(s->a, (s->ac += 1) * s->el); memcpy(s->a + (s->al * s->el), &e, s->el); s->al += 1; } diff --git a/src/util/strconv.h b/src/util/strconv.h index 655ef06..5901fcb 100644 --- a/src/util/strconv.h +++ b/src/util/strconv.h @@ -1,4 +1,4 @@ -// util/strconv.h, version 1.1.1 +// util/strconv.h, version 1.1.2 // String conversion header file from libutil // Copyright (C) 2021, Jakob Wakeling // All rights reserved. @@ -33,16 +33,16 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. #ifndef UTIL_STRCONV_H_3EQMSZZK #define UTIL_STRCONV_H_3EQMSZZK -#include <stdint.h> +#include "util.h" -int8_t strtoi8(const char *nptr, char **endptr, register int base); -int16_t strtoi16(const char *nptr, char **endptr, register int base); -int32_t strtoi32(const char *nptr, char **endptr, register int base); -int64_t strtoi64(const char *nptr, char **endptr, register int base); +s8 strtos8(const char *nptr, char **endptr, register int base); +s16 strtos16(const char *nptr, char **endptr, register int base); +s32 strtos32(const char *nptr, char **endptr, register int base); +s64 strtos64(const char *nptr, char **endptr, register int base); -uint8_t strtou8(const char *nptr, char **endptr, register int base); -uint16_t strtou16(const char *nptr, char **endptr, register int base); -uint32_t strtou32(const char *nptr, char **endptr, register int base); -uint64_t strtou64(const char *nptr, char **endptr, register int base); +u8 strtou8(const char *nptr, char **endptr, register int base); +u16 strtou16(const char *nptr, char **endptr, register int base); +u32 strtou32(const char *nptr, char **endptr, register int base); +u64 strtou64(const char *nptr, char **endptr, register int base); #endif // UTIL_STRCONV_H_3EQMSZZK diff --git a/src/util/strtoi.c b/src/util/strtos.c similarity index 80% rename from src/util/strtoi.c rename to src/util/strtos.c index b3d94dc..c09c2e3 100644 --- a/src/util/strtoi.c +++ b/src/util/strtos.c @@ -1,4 +1,4 @@ -// util/strtoi.c, version 1.1.1 +// util/strtos.c, version 1.1.2 // String conversion source file from libutil // Copyright (C) 2021, Jakob Wakeling // All rights reserved. @@ -30,14 +30,15 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ +#include "util.h" + #include <ctype.h> #include <errno.h> #include <stdbool.h> -#include <stdint.h> /* Convert a string to a signed 8-bit integer */ -int8_t strtoi8(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint8_t i = 0, c; bool neg = false; +s8 strtos8(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u8 i = 0, c; bool neg = false; for (; isspace(*s); ++s); @@ -56,8 +57,8 @@ int8_t strtoi8(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (neg ? -INT8_MIN : INT8_MAX - c) / base) { - errno = ERANGE; i = neg ? INT8_MIN : INT8_MAX; goto end; + if (i > (neg ? -(S8_MIN + 1) : S8_MAX - c) / base) { + errno = ERANGE; i = neg ? S8_MIN : S8_MAX; goto end; } i = i * base + c; @@ -68,8 +69,8 @@ end:; } /* Convert a string to a signed 16-bit integer */ -int16_t strtoi16(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint16_t i = 0, c; bool neg = false; +s16 strtos16(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u16 i = 0, c; bool neg = false; for (; isspace(*s); ++s); @@ -88,8 +89,8 @@ int16_t strtoi16(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (neg ? -INT16_MIN : INT16_MAX - c) / base) { - errno = ERANGE; i = neg ? INT16_MIN : INT16_MAX; goto end; + if (i > (neg ? -(S16_MIN + 1) : S16_MAX - c) / base) { + errno = ERANGE; i = neg ? S16_MIN : S16_MAX; goto end; } i = i * base + c; @@ -100,8 +101,8 @@ end:; } /* Convert a string to a signed 32-bit integer */ -int32_t strtoi32(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint32_t i = 0, c; bool neg = false; +s32 strtos32(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u32 i = 0, c; bool neg = false; for (; isspace(*s); ++s); @@ -120,8 +121,8 @@ int32_t strtoi32(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (neg ? -INT32_MIN : INT32_MAX - c) / base) { - errno = ERANGE; i = neg ? INT32_MIN : INT32_MAX; goto end; + if (i > (neg ? -(S32_MIN + 1) : S32_MAX - c) / base) { + errno = ERANGE; i = neg ? S32_MIN : S32_MAX; goto end; } i = i * base + c; @@ -132,8 +133,8 @@ end:; } /* Convert a string to a signed 64-bit integer */ -int64_t strtoi64(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint64_t i = 0, c; bool neg = false; +s64 strtos64(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u64 i = 0, c; bool neg = false; for (; isspace(*s); ++s); @@ -152,8 +153,8 @@ int64_t strtoi64(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (neg ? -INT64_MIN : INT64_MAX - c) / base) { - errno = ERANGE; i = neg ? INT64_MIN : INT64_MAX; goto end; + if (i > (neg ? -(S64_MIN + 1) : S64_MAX - c) / base) { + errno = ERANGE; i = neg ? S64_MIN : S64_MAX; goto end; } i = i * base + c; diff --git a/src/util/strtou.c b/src/util/strtou.c index 7e9acf0..e865866 100644 --- a/src/util/strtou.c +++ b/src/util/strtou.c @@ -1,4 +1,4 @@ -// util/strtou.c, version 1.1.1 +// util/strtou.c, version 1.1.2 // String conversion source file from libutil // Copyright (C) 2021, Jakob Wakeling // All rights reserved. @@ -30,13 +30,14 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ +#include "util.h" + #include <ctype.h> #include <errno.h> -#include <stdint.h> /* Convert a string to an unsigned 8-bit integer */ -uint8_t strtou8(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint8_t i = 0, c; +u8 strtou8(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u8 i = 0, c; for (; isspace(*s); ++s); @@ -55,8 +56,8 @@ uint8_t strtou8(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (UINT8_MAX - c) / base) { - errno = ERANGE; i = UINT8_MAX; goto end; + if (i > (U8_MAX - c) / base) { + errno = ERANGE; i = U8_MAX; goto end; } i = i * base + c; @@ -67,8 +68,8 @@ end:; } /* Convert a string to an unsigned 16-bit integer */ -uint16_t strtou16(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint16_t i = 0, c; +u16 strtou16(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u16 i = 0, c; for (; isspace(*s); ++s); @@ -87,8 +88,8 @@ uint16_t strtou16(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (UINT16_MAX - c) / base) { - errno = ERANGE; i = UINT16_MAX; goto end; + if (i > (U16_MAX - c) / base) { + errno = ERANGE; i = U16_MAX; goto end; } i = i * base + c; @@ -99,8 +100,8 @@ end:; } /* Convert a string to an unsigned 32-bit integer */ -uint32_t strtou32(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint32_t i = 0, c; +u32 strtou32(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u32 i = 0, c; for (; isspace(*s); ++s); @@ -119,8 +120,8 @@ uint32_t strtou32(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (UINT32_MAX - c) / base) { - errno = ERANGE; i = UINT32_MAX; goto end; + if (i > (U32_MAX - c) / base) { + errno = ERANGE; i = U32_MAX; goto end; } i = i * base + c; @@ -131,8 +132,8 @@ end:; } /* Convert a string to an unsigned 64-bit integer */ -uint64_t strtou64(const char *nptr, char **endptr, register int base) { - register const char *s = nptr; register uint64_t i = 0, c; +u64 strtou64(const char *nptr, char **endptr, register int base) { + register const char *s = nptr; register u64 i = 0, c; for (; isspace(*s); ++s); @@ -151,8 +152,8 @@ uint64_t strtou64(const char *nptr, char **endptr, register int base) { else { break; } if (c >= base) { break; } - if (i > (UINT64_MAX - c) / base) { - errno = ERANGE; i = UINT64_MAX; goto end; + if (i > (U64_MAX - c) / base) { + errno = ERANGE; i = U64_MAX; goto end; } i = i * base + c; diff --git a/src/util/util.h b/src/util/util.h index 18d3015..3b3d167 100644 --- a/src/util/util.h +++ b/src/util/util.h @@ -1,5 +1,5 @@ -// util/util.h -// Common utility header file for ESH +// util/util.h, version 1.0.0 +// Utility header file from libutil // Copyright (C) 2021, Jakob Wakeling // All rights reserved. @@ -30,12 +30,16 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE. */ -#ifndef ESH_UTIL_UTIL_H_KP8NS9DC -#define ESH_UTIL_UTIL_H_KP8NS9DC +#ifndef UTIL_UTIL_H_KP8NS9DC +#define UTIL_UTIL_H_KP8NS9DC +#include <assert.h> +#include <float.h> #include <stdbool.h> +#include <stddef.h> #include <stdint.h> +/* Type Definitions */ typedef uint8_t u8; typedef uint16_t u16; typedef uint32_t u32; @@ -52,8 +56,37 @@ typedef float f32; typedef double f64; typedef long double f128; -extern void *assert_malloc(UINT l); -extern void *assert_calloc(UINT n, UINT l); -extern void *assert_realloc(void * p, UINT l); +/* Type Limits */ +#define U8_MIN UINT8_MIN +#define U8_MAX UINT8_MAX +#define U16_MIN UINT16_MIN +#define U16_MAX UINT16_MAX +#define U32_MIN UINT32_MIN +#define U32_MAX UINT32_MAX +#define U64_MIN UINT64_MIN +#define U64_MAX UINT64_MAX +#define UINT_MIN UINTPTR_MIN +#define UINT_MAX UINTPTR_MAX -#endif // ESH_UTIL_UTIL_H_KP8NS9DC +#define S8_MIN INT8_MIN +#define S8_MAX INT8_MAX +#define S16_MIN INT16_MIN +#define S16_MAX INT16_MAX +#define S32_MIN INT32_MIN +#define S32_MAX INT32_MAX +#define S64_MIN INT64_MIN +#define S64_MAX INT64_MAX +#define SINT_MIN INTPTR_MIN +#define SINT_MAX INTPTR_MAX + +#define F32_MIN FLT_MIN +#define F32_MAX FLT_MAX +#define F64_MIN DBL_MIN +#define F64_MAX DBL_MAX +#define F128_MIN LDBL_MIN +#define F128_MAX LDBL_MAX + +/* Miscellaneous */ +#define BIT(x) (1 << (x)) + +#endif // UTIL_UTIL_H_KP8NS9DC