Factor trim format function out
[mmh] / sbr / fmt_new.c
index 9a7988e..c1386d4 100644 (file)
@@ -30,12 +30,12 @@ new_fs(char *form, char *def_form)
        FILE *fp;
 
        if (formats) {
-               free(formats);
+               mh_free0(&formats);
        }
 
        if (form) {
                if (*form == '=') {
-                       formats = getcpy(form+1);
+                       formats = mh_xstrdup(form+1);
                } else {
                        if ((fp = fopen(etcpath(form), "r")) == NULL) {
                                adios(EX_IOERR, form, "unable to open format file");
@@ -43,7 +43,7 @@ new_fs(char *form, char *def_form)
                        if (fstat(fileno(fp), &st) == -1) {
                                adios(EX_IOERR, form, "unable to stat format file");
                        }
-                       formats = mh_xmalloc((size_t) st.st_size + 1);
+                       formats = mh_xcalloc(st.st_size + 1, sizeof(char));
                        if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
                                adios(EX_IOERR, form, "error reading format file");
                        }
@@ -52,7 +52,7 @@ new_fs(char *form, char *def_form)
                }
        } else if (def_form) {
                if (*def_form == '=') {
-                       formats = getcpy(def_form+1);
+                       formats = mh_xstrdup(def_form+1);
                } else {
                        if ((fp = fopen(etcpath(def_form), "r")) == NULL) {
                                adios(EX_IOERR, def_form, "unable to open format file");
@@ -60,7 +60,7 @@ new_fs(char *form, char *def_form)
                        if (fstat(fileno(fp), &st) == -1) {
                                adios(EX_IOERR, def_form, "unable to stat format file");
                        }
-                       formats = mh_xmalloc((size_t) st.st_size + 1);
+                       formats = mh_xcalloc(st.st_size + 1, sizeof(char));
                        if (read(fileno(fp), formats, (int)st.st_size) != st.st_size) {
                                adios(EX_IOERR, def_form, "error reading format file");
                        }