]> diplodocus.org Git - nmh/blobdiff - sbr/fmt_new.c
Don't need to cast to `char *' for free(3) these days.
[nmh] / sbr / fmt_new.c
index effd06f1ae98323a93f3c81b97a64ef256897088..18f48987fb890fae7a4be8b7268fe62fb5c507a0 100644 (file)
@@ -2,14 +2,13 @@
 /*
  * fmt_new.c -- read format file/string and normalize
  *
- * $Id$
- *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  * complete copyright information.
  */
 
 #include <h/mh.h>
+#include <h/utils.h>
 
 #define QUOTE '\\'
 
@@ -29,10 +28,9 @@ char *
 new_fs (char *form, char *format, char *default_fs)
 {
     struct stat st;
-    register FILE *fp;
+    FILE *fp;
 
-    if (formats)
-       free (formats);
+    mh_xfree(formats);
 
     if (form) {
        if ((fp = fopen (etcpath (form), "r")) == NULL)
@@ -41,8 +39,7 @@ new_fs (char *form, char *format, char *default_fs)
        if (fstat (fileno (fp), &st) == -1)
            adios (form, "unable to stat format file");
 
-       if (!(formats = malloc ((size_t) st.st_size + 1)))
-           adios (form, "unable to allocate space for format");
+       formats = mh_xmalloc ((size_t) st.st_size + 1);
 
        if (read (fileno(fp), formats, (int) st.st_size) != st.st_size)
            adios (form, "error reading format file");
@@ -60,6 +57,13 @@ new_fs (char *form, char *format, char *default_fs)
 }
 
 
+void
+free_fs (){
+    free (formats);
+    formats = 0;
+}
+
+
 /*
  * Expand escapes in format strings
  */