From eebb03a681273e699f09162aa8d2b670f093a74a Mon Sep 17 00:00:00 2001 From: Gabriele Baldassarre Date: Tue, 26 May 2020 08:17:32 +0000 Subject: More general error handling diff --git a/reloc.h b/reloc.h index bc18e52..ff9930c 100644 --- a/reloc.h +++ b/reloc.h @@ -1,10 +1,16 @@ #ifndef __RELOC_H #define __RELOC_H +#ifdef HAVE_CONFIG_H +# include +#endif + #include #include +#ifndef HAVE_CONFIG_H #define RELEASE "1.0" +#endif /* Represent bytes as 8-bit values tagged with meta-information. */ /* List nodes (struct source) are arena-allocated; no need to track the references. */ diff --git a/sidreloc.c b/sidreloc.c index 7714af5..f6d69f2 100644 --- a/sidreloc.c +++ b/sidreloc.c @@ -20,15 +20,23 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "reloc.h" + #include #include #include #include -#include #include #include -#include "reloc.h" +#ifdef HAVE_ERR_H +#include +#endif + +#ifndef HAVE_ERRX +#include +#include +#endif struct sidheader { uint8_t rsid; @@ -73,6 +81,34 @@ static int nmi_reported; static struct core oldcore, newcore; +#ifndef HAVE_ERRX +/* Some posix haven't this error function + so, we define a rough equivalent */ +static void errx(int eval, const char *fmt, ...){ + va_list arglist; + va_start(arglist, fmt); + fprintf(stderr,"%s: ", "sidreloc"); + vfprintf(stderr,fmt, arglist); + fprintf(stderr,"\n"); + va_end(arglist); + exit(eval); +} +#endif + +#ifndef HAVE_ERR +/* Some posix haven't this error function + so, we define a rough equivalent */ +static void err(int eval, const char *fmt, ...){ + va_list arglist; + va_start(arglist, fmt); + fprintf(stderr, " %s: ", "sidreloc"); + vfprintf(stderr, fmt, arglist); + fprintf(stderr, ": %s\n", strerror(errno)); + va_end(arglist); + exit(eval); +} +#endif + static int readheader(struct sidheader *head, uint8_t *data, int filesize) { if(filesize <= 0x80) return 1; if(data[0] == 'P') { @@ -817,3 +853,4 @@ int main(int argc, char **argv) { return RET_SUCCESS | exitbits; } + diff --git a/solver.c b/solver.c index 7b9fcb6..5323add 100644 --- a/solver.c +++ b/solver.c @@ -20,15 +20,19 @@ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "reloc.h" + #include #include #include #include #include + +#ifdef HAVE_ERR_H #include -#include +#endif -#include "reloc.h" +#include #define HASHSIZE 8192 -- 2.26.0