diff options
Diffstat (limited to 'src/build')
-rw-r--r-- | src/build/cmeta.c | 15 | ||||
-rw-r--r-- | src/build/codegen.c | 13 |
2 files changed, 16 insertions, 12 deletions
diff --git a/src/build/cmeta.c b/src/build/cmeta.c index 7f314c7..40aba3a 100644 --- a/src/build/cmeta.c +++ b/src/build/cmeta.c @@ -1,5 +1,5 @@ /* - * Copyright © 2022 Michael Smith <mikesmiffy128@gmail.com> + * Copyright © 2023 Michael Smith <mikesmiffy128@gmail.com> * * Permission to use, copy, modify, and/or distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -111,15 +111,7 @@ static void die2(const char *s1, const char *s2) { static char *readsource(const os_char *f) { int fd = os_open(f, O_RDONLY); -#ifndef _WIN32 - if (fd == -1) die2("couldn't open ", f); -#else - // XXX: this is dumb and bad - if (fd == -1) { - fprintf(stderr, "cmeta: fatal: couldn't open %S", f); - exit(100); - } -#endif + if (fd == -1) return 0; uint bufsz = 8192; char *buf = malloc(bufsz); if (!buf) die1("couldn't allocate memory"); @@ -146,6 +138,7 @@ struct cmeta; const struct cmeta *cmeta_loadfile(const os_char *f) { char *buf = readsource(f); + if (!buf) return 0; #ifdef _WIN32 char *realname = malloc(wcslen(f) + 1); if (!realname) die1("couldn't allocate memory"); @@ -163,7 +156,7 @@ const struct cmeta *cmeta_loadfile(const os_char *f) { // NOTE: we don't care about conditional includes, nor do we expand macros. We // just parse the minimum info to get what we need for SST. Also, there's not // too much in the way of syntax checking; if an error gets ignored the compiler -// picks it anyway, and gives far better diagnostics. +// picks it up anyway, and gives far better diagnostics. void cmeta_includes(const struct cmeta *cm, void (*cb)(const char *f, bool issys, void *ctxt), void *ctxt) { const Token *tp = (const Token *)cm; diff --git a/src/build/codegen.c b/src/build/codegen.c index e24a096..bb25395 100644 --- a/src/build/codegen.c +++ b/src/build/codegen.c @@ -24,8 +24,14 @@ #include "skiplist.h" #include "vec.h" +#ifdef _WIN32 +#define fS "S" +#else +#define fS "s" +#endif + static void die(const char *s) { - fprintf(stderr, "codegen: %s\n", s); + fprintf(stderr, "codegen: fatal: %s\n", s); exit(100); } @@ -275,6 +281,11 @@ F( " has_%s = status_%s == FEAT_OK;", f->modname, f->modname) int OS_MAIN(int argc, os_char *argv[]) { for (++argv; *argv; ++argv) { const struct cmeta *cm = cmeta_loadfile(*argv); + if (!cm) { + fprintf(stderr, "codegen: fatal: couldn't load file %" fS "\n", + *argv); + exit(100); + } cmeta_conmacros(cm, &oncondef); cmeta_evdefmacros(cm, &onevdef); if (!vec_push(&pass2, ((struct passinfo){cm, *argv}))) { |