[MPlayer-dev-eng] [PATCH] Use unrar for open vobsubs if available
Reimar Doeffinger
Reimar.Doeffinger at stud.uni-karlsruhe.de
Fri Dec 7 16:00:30 CET 2007
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.
Greetings,
Reimar Döffinger
More information about the MPlayer-dev-eng
mailing list