X-Git-Url: https://diplodocus.org/git/nmh/blobdiff_plain/8a14191c0a0ad15bb8f35b49748c75c1e0a8c2f4..ec173fd2c:/uip/mkstemp.c?ds=sidebyside diff --git a/uip/mkstemp.c b/uip/mkstemp.c index 6933a3fd..b7fa5ae0 100644 --- a/uip/mkstemp.c +++ b/uip/mkstemp.c @@ -1,5 +1,4 @@ -/* - * mkstemp.c -- create a temporary file +/* mkstemp.c -- create a temporary file * * This code is Copyright (c) 2014 by the authors of nmh. * See the COPYRIGHT file in the root directory of the nmh @@ -12,10 +11,11 @@ #endif /* ! NMH */ #ifdef HAVE_CONFIG_H -# include +# include "config.h" #endif /* HAVE_CONFIG_H */ #include #include +#include #include #include @@ -23,8 +23,8 @@ # define HAVE_MKSTEMPS 0 #endif /* ! HAVE_MKSTEMPS */ -char *build_template(const char *, const char *, const char *); -void process_args(int, char **, const char **, const char **, const char **); +static char *build_template(const char *, const char *, const char *); +static void process_args(int, char **, const char **, const char **, const char **); /* * Use a template of the form: @@ -34,7 +34,8 @@ void process_args(int, char **, const char **, const char **, const char **); */ int -main(int argc, char *argv[]) { +main(int argc, char *argv[]) +{ const char *directory = "", *prefix = "", *suffix = ""; size_t suffix_len; int fd; @@ -42,7 +43,7 @@ main(int argc, char *argv[]) { process_args(argc, argv, &directory, &prefix, &suffix); if ((template = build_template(directory, prefix, suffix)) == NULL) { - return -1; + return 1; } if ((suffix_len = strlen(suffix)) > 0) { @@ -62,12 +63,13 @@ main(int argc, char *argv[]) { free(template); - return fd >= 0 ? 0 : -1; + return fd >= 0 ? 0 : 1; } -char * -build_template(const char *directory, const char *prefix, const char *suffix) { +static char * +build_template(const char *directory, const char *prefix, const char *suffix) +{ const char pattern[] = "XXXXXX"; size_t len, directory_len, pathsep_len, prefix_len, suffix_len; char *template; @@ -117,7 +119,15 @@ build_template(const char *directory, const char *prefix, const char *suffix) { #if NMH -#include +#include "h/mh.h" +#include "sbr/getarguments.h" +#include "sbr/smatch.h" +#include "sbr/ambigsw.h" +#include "sbr/print_version.h" +#include "sbr/print_help.h" +#include "sbr/error.h" +#include "h/done.h" +#include "h/utils.h" #if HAVE_MKSTEMPS # define MHFIXMSG_SWITCHES \ @@ -142,15 +152,16 @@ DEFINE_SWITCH_ENUM(MHFIXMSG); DEFINE_SWITCH_ARRAY(MHFIXMSG, switches); #undef X -void +static void process_args(int argc, char **argv, const char **directory, - const char **prefix, const char **suffix) { + const char **prefix, const char **suffix) +{ char **argp, **arguments, *cp, buf[100]; # if ! HAVE_MKSTEMPS NMH_UNUSED(suffix); # endif /* ! HAVE_MKSTEMPS */ - if (nmh_init(argv[0], 2)) { done(NOTOK); } + if (nmh_init(argv[0], true, false)) { done(1); } arguments = getarguments (invo_name, argc, argv, 1); argp = arguments; @@ -162,12 +173,12 @@ process_args(int argc, char **argv, const char **directory, switch (smatch(++cp, switches)) { case AMBIGSW: ambigsw(cp, switches); - done(NOTOK); + done(1); case UNKWNSW: inform("-%s unknown", cp); (void) snprintf(buf, sizeof buf, "%s [switches]", invo_name); print_help(buf, switches, 1); - done(NOTOK); + done(1); case HELPSW: (void) snprintf(buf, sizeof buf, "%s [switches]", invo_name); print_help(buf, switches, 1); @@ -179,7 +190,7 @@ process_args(int argc, char **argv, const char **directory, case DIRECTORYSW: /* Allow the directory to start with '-'. */ if ((cp = *argp++) == NULL) { - adios(NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); } *directory = cp; continue; @@ -187,7 +198,7 @@ process_args(int argc, char **argv, const char **directory, case PREFIXSW: /* Allow the prefix to start with '-'. */ if ((cp = *argp++) == NULL) { - adios(NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); } *prefix = cp; continue; @@ -196,7 +207,7 @@ process_args(int argc, char **argv, const char **directory, case SUFFIXSW: /* Allow the suffix to start with '-'. */ if ((cp = *argp++) == NULL) { - adios(NULL, "missing argument to %s", argp[-2]); + die("missing argument to %s", argp[-2]); } *suffix = cp; continue; @@ -206,9 +217,10 @@ process_args(int argc, char **argv, const char **directory, } } #else /* ! NMH */ -void +static void process_args(int argc, char **argv, const char **directory, - const char **prefix, const char **suffix) { + const char **prefix, const char **suffix) +{ # if HAVE_MKSTEMPS const char usage[] = "usage: %s [-h] [-d directory] [-p prefix] [-s suffix]\n"; @@ -235,7 +247,7 @@ process_args(int argc, char **argv, const char **directory, exit(0); default: (void) fprintf(stderr, usage, argv[0]); - exit(-1); + exit(1); } } }