Subject: Re: CVS commit: src/bin/dd
To: Dave Sainty <email@example.com>
From: David Laight <firstname.lastname@example.org>
Date: 11/15/2003 14:15:53
> > 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.
David Laight: email@example.com