From: Ralph Corderoy Date: Sun, 27 Aug 2017 10:34:50 +0000 (+0100) Subject: Add die(fmt, ...). Equivalent to adios(NULL, fmt, ...). X-Git-Url: https://diplodocus.org/git/nmh/commitdiff_plain/751542a19198f2efa957b77ce41d82479952af62?ds=inline Add die(fmt, ...). Equivalent to adios(NULL, fmt, ...). Avoids the noise of the `NULL' first parameter that's used in over 70% of adios() calls. Removes the possibility of it being omitted and `fmt' being used instead. `die' is already in use in nmh's shell scripts. Had to rename post.c's existing die() to avoid it clashing. --- diff --git a/h/prototypes.h b/h/prototypes.h index 92ed8ef5..0b40c0d5 100644 --- a/h/prototypes.h +++ b/h/prototypes.h @@ -18,6 +18,7 @@ struct msgs_array; void add_profile_entry (const char *, const char *); void inform(char *fmt, ...) CHECK_PRINTF(1, 2); void adios (const char *, const char *, ...) CHECK_PRINTF(2, 3) NORETURN; +void die(const char *, ...) CHECK_PRINTF(1, 2) NORETURN; void admonish (char *, char *, ...) CHECK_PRINTF(2, 3); void advertise (const char *, char *, const char *, va_list) CHECK_PRINTF(3, 0); void advise (const char *, const char *, ...) CHECK_PRINTF(2, 3); diff --git a/sbr/error.c b/sbr/error.c index 96c89f58..5a5808c2 100644 --- a/sbr/error.c +++ b/sbr/error.c @@ -58,6 +58,21 @@ adios (const char *what, const char *fmt, ...) } +/* die is the same as adios(), but without the what as that's commonly + * NULL. */ +void NORETURN +die(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + advertise(NULL, NULL, fmt, ap); + va_end(ap); + done(1); + abort(); +} + + /* admonish calls advertise() with a tail indicating the program * continues. * Thus "[invo_name: ]fmt[[ what]: errno], continuing...\n" results. */ diff --git a/uip/post.c b/uip/post.c index 11170615..a02b0711 100644 --- a/uip/post.c +++ b/uip/post.c @@ -306,7 +306,7 @@ static void sigon (void); static void sigoff (void); static void p_refile (char *); static void fcc (char *, char *); -static void die (char *, char *, ...) CHECK_PRINTF(2, 3); +static void fatal (char *, char *, ...) CHECK_PRINTF(2, 3); static void post (char *, int, int, int, char *, int, char *); static void do_text (char *file, int fd); static void do_an_address (struct mailname *, int); @@ -1606,12 +1606,12 @@ static void chkadr (void) { if (badadr && unkadr) - die (NULL, "%d address%s unparsable, %d addressee%s undeliverable", + fatal (NULL, "%d address%s unparsable, %d addressee%s undeliverable", badadr, PLURALS(badadr), unkadr, PLURALS(badadr)); if (badadr) - die (NULL, "%d address%s unparsable", badadr, PLURALS(badadr)); + fatal (NULL, "%d address%s unparsable", badadr, PLURALS(badadr)); if (unkadr) - die (NULL, "%d addressee%s undeliverable", unkadr, PLURALS(unkadr)); + fatal (NULL, "%d addressee%s undeliverable", unkadr, PLURALS(unkadr)); } @@ -1652,7 +1652,7 @@ do_addresses (int bccque, int talk) chkadr (); if (rp_isbad (retval = sm_waend ())) - die (NULL, "problem ending addresses; %s", rp_string (retval)); + fatal (NULL, "problem ending addresses; %s", rp_string (retval)); } @@ -1718,7 +1718,7 @@ post (char *file, int bccque, int talk, int eai, char *envelope, int eightbit = 0; if (fd == NOTOK) { - die (file, "unable to re-open"); + fatal (file, "unable to re-open"); } if (msgflags & MMIM && cte != UNKNOWN) { @@ -1728,7 +1728,7 @@ post (char *file, int bccque, int talk, int eai, char *envelope, } else { if (scan_input (fd, &eightbit) == NOTOK) { close (fd); - die (file, "problem reading from"); + fatal (file, "problem reading from"); } } @@ -1737,7 +1737,7 @@ post (char *file, int bccque, int talk, int eai, char *envelope, oauth_flag ? auth_svc : NULL, tlsflag)) || rp_isbad (retval = sm_winit (envelope, eai, eightbit))) { close (fd); - die (NULL, "problem initializing server; %s", rp_string (retval)); + fatal (NULL, "problem initializing server; %s", rp_string (retval)); } do_addresses (bccque, talk && verbose); @@ -1780,7 +1780,7 @@ verify_all_addresses (int talk, int eai, char *envelope, int oauth_flag, verbose, snoop, sasl, saslmech, user, oauth_flag ? auth_svc : NULL, tlsflag)) || rp_isbad (retval = sm_winit (envelope, eai, eightbit))) { - die (NULL, "problem initializing server; %s", rp_string (retval)); + fatal (NULL, "problem initializing server; %s", rp_string (retval)); } } @@ -1870,7 +1870,7 @@ do_an_address (struct mailname *lp, int talk) default: if (!talk) fprintf (stderr, " %s: ", addr); - die (NULL, "unexpected response; %s", rp_string (retval)); + fatal (NULL, "unexpected response; %s", rp_string (retval)); } fflush (stdout); @@ -1887,11 +1887,11 @@ do_text (char *file, int fd) while ((state = read (fd, buf, sizeof(buf))) > 0) { if (rp_isbad (retval = sm_wtxt (buf, state))) - die (NULL, "problem writing text; %s\n", rp_string (retval)); + fatal (NULL, "problem writing text; %s\n", rp_string (retval)); } if (state == NOTOK) - die (file, "problem reading from"); + fatal (file, "problem reading from"); switch (retval = sm_wtend ()) { case RP_OK: @@ -1899,11 +1899,11 @@ do_text (char *file, int fd) case RP_NO: case RP_NDEL: - die (NULL, "posting failed; %s", rp_string (retval)); + fatal (NULL, "posting failed; %s", rp_string (retval)); break; default: - die (NULL, "unexpected response; %s", rp_string (retval)); + fatal (NULL, "unexpected response; %s", rp_string (retval)); } } @@ -2037,7 +2037,7 @@ fcc (char *file, char *folder) */ static void -die (char *what, char *fmt, ...) +fatal (char *what, char *fmt, ...) { int err; va_list ap;