X-Recipient: archive-cygwin AT delorie DOT com X-SWARE-Spam-Status: No, hits=-3.0 required=5.0 tests=AWL,BAYES_00,SPF_HELO_PASS,SPF_PASS X-Spam-Check-By: sourceware.org To: cygwin AT cygwin DOT com From: Eric Blake Subject: Re: fcntl bug Date: Mon, 24 Aug 2009 15:15:59 +0000 (UTC) Lines: 42 Message-ID: References: <4A8F0944 DOT 5020004 AT byu DOT net> <4A8F1819 DOT 9060209 AT sipxx DOT com> <4A8F19DC DOT 8060104 AT byu DOT net> <20090822001027 DOT GB8375 AT ednor DOT casa DOT cgf DOT cx> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit User-Agent: Loom/3.14 (http://gmane.org/) X-IsSubscribed: yes Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Christopher Faylor cygwin.com> writes: > >But POSIX does (and Linux at least obeys this part of POSIX, whether or > >not its man page says so): > > I checked in a fix for this a while ago. It's in the latest snapshot. While we're at it, fcntl and dup2 both have another minor bug. POSIX states that fcntl(0,F_DUPFD,10000000) should fail with EINVAL (not EBADF) and the similar dup2(0,10000000) should fail with EBADF (not EMFILE). Gotta love the inconsistency of historical interfaces. (This assumes, of course, that OPEN_MAX is less than 10000000). dup2 should never fail with EMFILE, and fcntl (F_DUPFD) should fail with EMFILE only if the target is within the range of the current OPEN_MAX (aka sysconf(_SC_OPEN_MAX)) but all fds from that point to the end of the table are currently open. #include #include #include #include #include int main() { int i = dup2 (0, 10000000); printf ("%d %d %s\n", i, errno, strerror (errno)); i = fcntl (0, F_DUPFD, 10000000); printf ("%d %d %s\n", i, errno, strerror (errno)); return 0; } Solaris: % ./foo -1 9 Bad file number -1 22 Invalid argument Cygwin 1.7: $ ./foo -1 24 Too many open files -1 9 Bad file descriptor -- Eric Blake -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple