X-Git-Url: http://git.marmaro.de/?p=mmh;a=blobdiff_plain;f=sbr%2Ffmt_new.c;h=c1386d4c710bb4de354bbbbc9d219b6753ccc5eb;hp=9fd34c8e1b4350782be1164cbb544ab81469f4fb;hb=18591f8e001ecedbee48a51c1d1f08ebaa1c15c8;hpb=f51956be123db66b00138f80464d06f030dbb88d diff --git a/sbr/fmt_new.c b/sbr/fmt_new.c index 9fd34c8..c1386d4 100644 --- a/sbr/fmt_new.c +++ b/sbr/fmt_new.c @@ -8,6 +8,9 @@ #include #include +#include +#include +#include static char *formats = NULL; @@ -24,42 +27,42 @@ char * new_fs(char *form, char *def_form) { struct stat st; - register FILE *fp; + 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(form, "unable to open format file"); + adios(EX_IOERR, form, "unable to open format file"); } if (fstat(fileno(fp), &st) == -1) { - adios(form, "unable to stat format file"); + 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(form, "error reading format file"); + adios(EX_IOERR, form, "error reading format file"); } formats[st.st_size] = '\0'; fclose(fp); } } 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(def_form, "unable to open format file"); + adios(EX_IOERR, def_form, "unable to open format file"); } if (fstat(fileno(fp), &st) == -1) { - adios(def_form, "unable to stat format file"); + 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(def_form, "error reading format file"); + adios(EX_IOERR, def_form, "error reading format file"); } formats[st.st_size] = '\0'; fclose(fp);