#include <h/utils.h>
#include <signal.h>
#include <fcntl.h>
-
+#include <unistd.h>
+#include <sys/stat.h>
+#include <locale.h>
+#include <sysexits.h>
static struct swit switches[] = {
#define BODYSW 0
/* Without arguments, exit. */
if (argc == 1) {
- adios(NULL, "no interactive mail shell. Use inc/scan/show instead.");
+ adios(EX_USAGE, NULL, "no interactive mail shell. Use inc/scan/show instead.");
}
context_read();
switch (smatch(++cp, switches)) {
case AMBIGSW:
ambigsw(cp, switches);
- /* sysexits.h EX_USAGE */
- exit(1);
+ exit(EX_USAGE);
case UNKWNSW:
- adios(NULL, "-%s unknown", cp);
+ adios(EX_USAGE, NULL, "-%s unknown", cp);
case HELPSW:
snprintf(buf, sizeof(buf),
"%s addrs... [switches]",
invo_name);
print_help(buf, switches, 0);
- exit(0);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
case VERSIONSW:
print_version(invo_name);
- exit(0);
+ exit(argc == 2 ? EX_OK : EX_USAGE);
case FROMSW:
if (!(from = *argp++) || *from == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
continue;
case BODYSW:
if (!(body = *argp++) || *body == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
continue;
case SUBJSW:
if (!(subject = *argp++) || *subject == '-')
- adios(NULL, "missing argument to %s",
+ adios(EX_USAGE, NULL, "missing argument to %s",
argp[-2]);
continue;
}
}
if (iscc)
cclist = cclist ? add(cp, add(", ", cclist)) :
- getcpy(cp);
+ mh_xstrdup(cp);
else
tolist = tolist ? add(cp, add(", ", tolist)) :
- getcpy(cp);
+ mh_xstrdup(cp);
}
if (tolist == NULL)
- adios(NULL, "usage: %s addrs ... [switches]", invo_name);
+ adios(EX_USAGE, NULL, "usage: %s addrs ... [switches]", invo_name);
tfile = m_mktemp2("/tmp/", invo_name, NULL, &out);
if (tfile == NULL)
- adios("mhmail", "unable to create temporary file");
+ adios(EX_CANTCREAT, "mhmail", "unable to create temporary file");
chmod(tfile, 0600);
strncpy(tmpfil, tfile, sizeof(tmpfil));
}
empty = 0;
if (fputs(buf, out) == EOF) {
- adios(tmpfil, "error writing");
+ adios(EX_IOERR, tmpfil, "error writing");
}
}
if (empty) {
unlink(tmpfil);
- adios(NULL, "not sending message with empty body");
+ adios(EX_DATAERR, NULL, "not sending message with empty body");
}
}
fclose(out);
if (in == -1 || out == -1) {
fprintf(stderr, "Letter left at %s.\n",
tmpfil);
- /* sysexits.h exit-status from spost */
- exit(status ? 1 : 0);
+ exit(status);
}
cpydata(in, out, tmpfil, "dead.letter");
close(in);
fprintf(stderr, "Letter saved in dead.letter\n");
}
unlink(tmpfil);
- /* sysexits.h exit status from spost */
- exit(status ? 1 : 0);
+ exit(status);
}
intrser(int i)
{
unlink(tmpfil);
- exit(i != 0 ? 1 : 0);
+ _exit(EX_IOERR);
}