]> diplodocus.org Git - nmh/blobdiff - uip/mkstemp.c
Add more NORETURN and CHECK_PRINTF function attributes.
[nmh] / uip / mkstemp.c
index 259c3edd39de5b4c28e841de477fb4c6f93a7058..7dc806562a11ea23415157c021c28503947cbaa4 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 */
@@ -42,7 +44,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,7 +64,7 @@ main(int argc, char *argv[]) {
 
     free(template);
 
-    return fd >= 0  ?  0  :  -1;
+    return fd >= 0  ?  0  :  1;
 }
 
 
@@ -109,10 +111,10 @@ build_template(const char *directory, const char *prefix, const char *suffix) {
         template[len-1] = '\0';
 
         return template;
-    } else {
-        perror("malloc");
-        return NULL;
     }
+
+    perror("malloc");
+    return NULL;
 }
 
 
@@ -150,7 +152,7 @@ process_args(int argc, char **argv, const char **directory,
     NMH_UNUSED(suffix);
 #   endif /* ! HAVE_MKSTEMPS */
 
-    if (nmh_init(argv[0], 2)) { done(NOTOK); }
+    if (nmh_init(argv[0], 2)) { done(1); }
     arguments = getarguments (invo_name, argc, argv, 1);
     argp = arguments;
 
@@ -162,12 +164,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:
-                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);
+                done(1);
             case HELPSW:
                 (void) snprintf(buf, sizeof buf, "%s [switches]", invo_name);
                 print_help(buf, switches, 1);
@@ -235,7 +237,7 @@ process_args(int argc, char **argv, const char **directory,
             exit(0);
         default:
             (void) fprintf(stderr, usage, argv[0]);
-            exit(-1);
+            exit(1);
         }
     }
 }