]> diplodocus.org Git - nmh/blobdiff - uip/mkstemp.c
Silence more gcc format-string warnings.
[nmh] / uip / mkstemp.c
index 16ddf644ab88cb4fbeff4df3bfaa9424cf53f86c..b7acbb1460051c7ed103d8c55006ea3f16de2642 100644 (file)
@@ -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
 #endif /* HAVE_CONFIG_H */
 #include <unistd.h>
 #include <stdlib.h>
+#include <stdbool.h>
 #include <string.h>
 #include <stdio.h>
 
+#include <h/utils.h>
+
 #if ! defined HAVE_MKSTEMPS
 #   define HAVE_MKSTEMPS 0
 #endif /* ! HAVE_MKSTEMPS */
@@ -48,7 +50,9 @@ main(int argc, char *argv[]) {
     if ((suffix_len = strlen(suffix)) > 0) {
 #       if HAVE_MKSTEMPS
         if ((fd = mkstemps(template, suffix_len)) < 0) { perror("mkstemps"); }
-#       endif /* HAVE_MKSTEMPS */
+#       else  /* ! HAVE_MKSTEMPS */
+        fd = 0;
+#       endif /* ! HAVE_MKSTEMPS */
     } else {
         if ((fd = mkstemp(template)) < 0) { perror("mkstemp"); }
     }
@@ -102,15 +106,15 @@ build_template(const char *directory, const char *prefix, const char *suffix) {
         tp += sizeof pattern - 1;
 
         (void) strncpy(tp, suffix, suffix_len);
-        tp += suffix_len;
+        /* tp += suffix_len; */
 
         template[len-1] = '\0';
 
         return template;
-    } else {
-        perror("malloc");
-        return NULL;
     }
+
+    perror("malloc");
+    return NULL;
 }
 
 
@@ -148,7 +152,7 @@ process_args(int argc, char **argv, const char **directory,
     NMH_UNUSED(suffix);
 #   endif /* ! HAVE_MKSTEMPS */
 
-    if (nmh_init(argv[0], 1)) { done(NOTOK); }
+    if (nmh_init(argv[0], 2)) { done(NOTOK); }
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -162,7 +166,7 @@ process_args(int argc, char **argv, const char **directory,
                 ambigsw(cp, switches);
                 done(NOTOK);
             case UNKWNSW:
-                advise (NULL, "-%s unknown", cp);
+                inform("-%s unknown", cp);
                 (void) snprintf(buf, sizeof buf, "%s [switches]", invo_name);
                 print_help(buf, switches, 1);
                 done(NOTOK);