Should this be a generic function (included into sbr/)? There probably are other places where we create files with reduced permissions. This patch here does not fully convince me -- it pays the encapsulation of a few lines with an additional lookup --, but it might be a starting point for a larger improvement. Then the deal could be much better.
meillo [2016-09-08 13:04] [email protected] > > From: Dmitry Bogatov <[email protected]> > > --- > uip/repl.c | 22 +++++++++++++--------- > 1 file changed, 13 insertions(+), 9 deletions(-) > > diff --git a/uip/repl.c b/uip/repl.c > index 8a40543..9e39b2a 100644 > --- a/uip/repl.c > +++ b/uip/repl.c > @@ -370,8 +370,18 @@ docc(char *cp, int ccflag) > } > } > > +static FILE* > +fcreate_with_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; > +} > > static void > replout(FILE *inb, char *drft, struct msgs *mp, > @@ -382,16 +392,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 = fcreate_with_gmprot(drft); > > /* get new format string */ > cp = new_fs(form, NULL); > -- > I may be not subscribed. Please, keep me in carbon copy. > > >
