diff --git a/Makefile b/Makefile index e73c883..cbe920f 100644 --- a/Makefile +++ b/Makefile @@ -19,12 +19,14 @@ PROGRAM=em SRC=ansi.c basic.c bind.c buffer.c crypt.c display.c eval.c exec.c \ file.c fileio.c ibmpc.c input.c isearch.c line.c lock.c main.c \ pklock.c posix.c random.c region.c search.c spawn.c tcap.c \ - termio.c vmsvt.c vt52.c window.c word.c names.c globals.c version.c + termio.c vmsvt.c vt52.c window.c word.c names.c globals.c version.c \ + usage.c wrapper.c OBJ=ansi.o basic.o bind.o buffer.o crypt.o display.o eval.o exec.o \ file.o fileio.o ibmpc.o input.o isearch.o line.o lock.o main.o \ pklock.o posix.o random.o region.o search.o spawn.o tcap.o \ - termio.o vmsvt.o vt52.o window.o word.o names.o globals.o version.o + termio.o vmsvt.o vt52.o window.o word.o names.o globals.o version.o \ + usage.o wrapper.o HDR=ebind.h edef.h efunc.h epath.h estruct.h evar.h util.h version.h diff --git a/input.c b/input.c index 154c2c9..28d6ada 100644 --- a/input.c +++ b/input.c @@ -1,4 +1,4 @@ -/* INPUT.C +/* input.c * * Various input routines * @@ -6,11 +6,13 @@ * modified by Petri Kutvonen */ -#include -#include -#include "estruct.h" -#include "edef.h" -#include "efunc.h" +#include +#include + +#include "estruct.h" +#include "edef.h" +#include "efunc.h" +#include "wrapper.h" #if PKCODE #if MSDOS && TURBO @@ -587,7 +589,7 @@ int getstring(char *prompt, char *buf, int nbuf, int eolchar) if (!iswild) strcat(ffbuf, "*"); strcat(ffbuf, " >"); - mkstemp(tmp); + xmkstemp(tmp); strcat(ffbuf, tmp); strcat(ffbuf, " 2>&1"); system(ffbuf); diff --git a/usage.c b/usage.c new file mode 100644 index 0000000..0ae18ce --- /dev/null +++ b/usage.c @@ -0,0 +1,22 @@ +#include "usage.h" + +#include +#include +#include + +static void report(const char* prefix, const char *err, va_list params) +{ + char msg[4096]; + vsnprintf(msg, sizeof(msg), err, params); + fprintf(stderr, "%s%s\n", prefix, msg); +} + +void die(const char* err, ...) +{ + va_list params; + + va_start(params, err); + report("fatal: ", err, params); + va_end(params); + exit(128); +} diff --git a/usage.h b/usage.h new file mode 100644 index 0000000..bb6b40e --- /dev/null +++ b/usage.h @@ -0,0 +1,6 @@ +#ifndef USAGE_H_ +#define USAGE_H_ + +extern void die(const char* err, ...); + +#endif /* USAGE_H_ */ diff --git a/wrapper.c b/wrapper.c new file mode 100644 index 0000000..4bf8d7e --- /dev/null +++ b/wrapper.c @@ -0,0 +1,14 @@ +#include "usage.h" + +#include + +/* Function copyright: git */ +int xmkstemp(char *template) +{ + int fd; + + fd = mkstemp(template); + if (fd < 0) + die("Unable to create temporary file"); + return fd; +} diff --git a/wrapper.h b/wrapper.h new file mode 100644 index 0000000..0db3b8f --- /dev/null +++ b/wrapper.h @@ -0,0 +1,6 @@ +#ifndef WRAPPER_H_ +#define WRAPPER_H_ + +extern int xmkstemp(char *template); + +#endif /* WRAPPER_H_ */