]> diplodocus.org Git - nmh/blobdiff - sbr/utils.c
Document changes to base64 encoder/decoder.
[nmh] / sbr / utils.c
index 8162056796d1a57fa368fdcac27b67276a090e37..d8b060fb13ce5f7a87a949166fe01e6d566c73d6 100644 (file)
@@ -9,9 +9,14 @@
 
 #include <h/mh.h>
 #include <h/utils.h>
-#include <stdlib.h>
 #include <fcntl.h>
-#include <errno.h>
+
+/* sbr/signals.c */
+extern int setup_signal_handlers();
+
+/* sbr/m_mktemp.c */
+extern void remove_registered_files_atexit();
+
 
 /*
  * We allocate space for messages (msgs array)
@@ -319,3 +324,31 @@ nmh_strcasestr (const char *s1, const char *s2) {
 
     return NULL;
 }
+
+
+int
+nmh_init(const char *argv0, int read_context) {
+    setlocale(LC_ALL, "");
+
+    invo_name = r1bindex ((char *) argv0, '/');
+
+    if (setup_signal_handlers()) {
+        admonish("sigaction", "unable to set up signal handlers");
+    }
+
+    /* POSIX atexit() does not define any error conditions. */
+    if (atexit(remove_registered_files_atexit)) {
+        admonish("atexit", "unable to register atexit function");
+    }
+
+    if (read_context) {
+        context_read();
+        return OK;
+    } else {
+        int status = context_foil(NULL);
+        if (status != OK) {
+            advise("", "failed to create minimal profile/conext");
+        }
+        return status;
+    }
+}