---
 h/prototypes.h |  2 +-
 sbr/m_gmprot.c | 13 +++++++++++++
 uip/dist.c     | 19 +++++++++----------
 uip/repl.c     | 13 ++-----------
 4 files changed, 25 insertions(+), 22 deletions(-)

diff --git a/h/prototypes.h b/h/prototypes.h
index 69556f9..7febc60 100644
--- a/h/prototypes.h
+++ b/h/prototypes.h
@@ -45,6 +45,7 @@ int execprogl(char *, char *, ...);
 char *expandfol(char *);
 char *expanddir(char *);
 int ext_hook(char *, char *, char *);
+FILE* fcreat_gmprot(char *filepath);
 int folder_addmsg(struct msgs **, char *, int, int, int, int, char *);
 int folder_delmsgs(struct msgs *, int);
 void folder_free(struct msgs *);
@@ -162,4 +163,3 @@ int is_readonly(struct msgs *);
 void set_readonly(struct msgs *);
 int other_files(struct msgs *);
 void set_other_files(struct msgs *);
-
diff --git a/sbr/m_gmprot.c b/sbr/m_gmprot.c
index 377be09..88b533a 100644
--- a/sbr/m_gmprot.c
+++ b/sbr/m_gmprot.c
@@ -7,7 +7,20 @@
 */

 #include <h/mh.h>
+#include <sysexits.h>

+FILE*
+fcreat_gmprot(char *filepath)
+{
+       int mask = umask(~m_gmprot());
+       FILE *out = fopen(filepath, "w");
+
+       if (!out) {
+               adios(EX_CANTCREAT, filepath, "unable to create");
+       }
+       umask(mask);
+       return out;
+}

 int
 m_gmprot(void)
diff --git a/uip/dist.c b/uip/dist.c
index d74e498..72313ff 100644
--- a/uip/dist.c
+++ b/uip/dist.c
@@ -36,13 +36,12 @@ int
 main(int argc, char **argv)
 {
        int anot = 0;
-       int in, out;
+       int in;
        char *cp, *cwd, *maildir, *msgnam;
        char *ed = NULL, *folder = NULL;
        char *form = NULL, *msg = NULL, buf[BUFSIZ], drft[BUFSIZ];
        char **argp, **arguments;
        struct msgs *mp = NULL;
-       char *fmtstr;

        setlocale(LC_ALL, "");
        invo_name = mhbasename(argv[0]);
@@ -115,17 +114,17 @@ main(int argc, char **argv)
        }

        cwd = mh_xstrdup(pwd());
-
        strncpy(drft, m_draft(seq_beyond), sizeof(drft));
-       if ((out = creat(drft, m_gmprot())) == NOTOK) {
-               adios(EX_CANTCREAT, drft, "unable to create");
-       }

-       fmtstr = new_fs(form, distcomps);
-       if (write(out, fmtstr, strlen(fmtstr)) != (int)strlen(fmtstr)) {
-               adios(EX_IOERR, drft, "error writing");
+       {
+               FILE *out = fcreat_gmprot(drft);
+               char *fmtstr = new_fs(form, distcomps);
+
+               if (fwrite(fmtstr, strlen(fmtstr), 1, out) != 1) {
+                       adios(EX_IOERR, drft, "error writing");
+               }
+               fclose(out);
        }
-       close(out);

        if (!msg) {
                msg = seq_cur;
diff --git a/uip/repl.c b/uip/repl.c
index 8a40543..14eee3e 100644
--- a/uip/repl.c
+++ b/uip/repl.c
@@ -370,9 +370,6 @@ docc(char *cp, int ccflag)
        }
 }

-
-
-
 static void
 replout(FILE *inb, char *drft, struct msgs *mp,
        int mime, char *form, char *filter)
@@ -382,16 +379,10 @@ replout(FILE *inb, char *drft, struct msgs *mp,
        int i;
        struct comp *cptr;
        char **ap;
-       int char_read = 0, format_len, mask;
+       int char_read = 0, format_len;
        char *scanl;
        unsigned char *cp;
-       FILE *out;
-
-       mask = umask(~m_gmprot());
-       if ((out = fopen(drft, "w")) == NULL)
-               adios(EX_CANTCREAT, drft, "unable to create");
-
-       umask(mask);
+       FILE *out = fcreat_gmprot(drft);

        /* get new format string */
        cp = new_fs(form, NULL);

Reply via email to