Subject: Re: CVS commit: src/bin/dd
To: David Laight <firstname.lastname@example.org>
From: Dave Sainty <email@example.com>
Date: 11/16/2003 03:39:38
David Laight writes:
> > > What is wrong with:
> > > new_fd = fcntl(fd, F_DUPFD, 3);
> > > close(fd);
> > > fd = newfd;
> > I did consider that, but it seems more error-prone.
> > E.g. "dd if=foo of=/dev/fd/3" would break.
> > Also, the fcntl(F_DUPFD)/dup2() would implicitly close the file
> > descriptor on 3. Not usually a problem, but certainly new behaviour.
> > Who knows, someone somewhere might use closure of fd 3 as an awful way
> > to determine if "dd" has exited or not :)
> fcntl(F_DUPFD) gives you the next free fd number great than or equal to
> to the one given - unlike dup2() which gives a fixed number and might close
> whathever was there before.
Hmmm, I had it in my head that it was synonymous with dup2(). I'm
sure I've seen it documented that way in the past.
But in that case there's nothing wrong with fcntl(F_DUPFD) at all!
I'll make that change.