begin  quoting Carlos R. Mafra as of Fri, Mar 26, 2010 at 09:36:07PM +0100:
> On Fri, 26 Mar 2010 at 20:35:02 +0100, Tamas TEVESZ wrote:
> > +
> > +#define    RETRY( x )      do {                            \
> > +                           x;                      \
> > +                   } while (errno == EINTR);
> >  

I was under the impression that good C style was to leave off the semicolons
in macros, so that using the macro uses a semicolon like a normal statement.

> [...]
> 
> >  
> > -   if ((src = open(srcFile, O_RDONLY | O_BINARY)) == 0) {
> > +   RETRY( src = fopen(srcFile, "rb") )

Would be instead

        RETRY( src = fopen(srcFile, "rb") );

...and thus not suprise the reader of the code.

> > +   if (src == NULL) {
> >             wsyserror(_("Could not open %s"), srcFile);
> >             return -1;
> >     }
> 
> Using this RETRY() macro is a bit ugly. I didn't like from the look
> of it.

Shouldn't there also be some sort of limit in the loop? If the
function so wrapped manages to have a bug that results in it causing
itself to be interrupted, this construct turns into an infinite loop.

RETRY_ON_EINTR seems like a better name. Still ugly, though.

> So let me ask a question. What bad thing would happen if you don't
> use this RETRY trick and do simply a 
> 
>    src = fopen(srcFile, "rb");
>    if (!src) {
>            wsyserror(_("Could not open %s"), srcFile);
>            return -1;
>    }
> 
> The old code didn't retry, why do you need it now?


Are signals really causing problems? Ignoring a signal errors seems
like a bad policy, especially when it's hidden in a macro.

-S.


-- 
To unsubscribe, send mail to [email protected].

Reply via email to