From: Alex Riesen Date: Wed, 27 Jun 2007 13:18:47 GMT Subject: Re: [PATCH] git-log: detect dup and fdopen failure Message-ID: <81b0412b0706270618p850df2dy41b2b797d82e3276@mail.gmail.com> In-Reply-To: <87r6nxo8iq.fsf_-_@rho.meyering.net> On 6/27/07, Jim Meyering wrote: > I didn't see that fdopen could fail with ENOMEM. > That'll teach me to trust the man page. I see POSIX does mention it. I wouldn't trust Linux man pages nor POSIX, if I were you. Check if this works in some exotic but common environments (like MacOSX, Cygwin or HP-UX). (And yes, they probably are broken, and no, you can't fix them, and no, people are not going to stop using them). > + if (!use_stdout) { > + int fd = dup(1); > + if (fd < 0 || (realstdout = fdopen(fd, "w")) == NULL) > + die("failed to duplicate standard output: %s", > + strerror(errno)); > + } Kinda stuffed in here. What's wrong with plain realstdout = fdopen(dup(1), "w"); if (!realstdout) die("%s", strerror(errno)); (Yes, I do think that "duplicate standard output" is useless, except for debugging. Exactly as strerror is, but that is shorter).