[MPlayer-dev-eng] [PATCH] Use unrar for open vobsubs if available

Ulion ulion2002 at gmail.com
Fri Dec 7 16:11:45 CET 2007


2007/12/7, Reimar Doeffinger <Reimar.Doeffinger at stud.uni-karlsruhe.de>:
> On Fri, Dec 07, 2007 at 07:24:32PM +0800, Ulion wrote:
> > > No, none of them need to be closed. All you need to do is replace stderr instead of
> > > closing.
> > > So something like
> > > > fd = open("/dev/null", O_WRONLY);
> > > > if (fd < 3) _exit(EXIT_FAILURE);
> > > > dup2(fd, 2);
> > > > close(fd);
> > > should do it.
> > > Note that this will cause MPlayer to fail if it was started without
> > > stdin, stdout or stderr itself (though I don't think we really need
> > > to care about that).
> >
> > dup2() will close target fd if it's openen. So current code looks ok for me:
> >         /* suppress stderr messages */
> >         close(2);
> >         fd = open("/dev/null", O_WRONLY);
> >         if(fd != 2) {
> >             if (dup2(fd, 2))
> >                 _exit(EXIT_FAILURE);
> >             close(fd);
> >         }
> >
> > Is it ok for you?
>
> No, not really. Your code is already like that more complex, but it also handles
> the case that open fails only implicitly, which is more fragile, and with the
> dup2 test removed it is just plain broken.

How about:

        fd = open("/dev/null", O_WRONLY);
        if(fd == -1)
            _exit(EXIT_FAILURE);
        if (fd != 2) {
            dup2(fd, 2);
            close(fd);
        }


-- 
Ulion



More information about the MPlayer-dev-eng mailing list