X-Recipient: archive-cygwin@delorie.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@cygwin.com
From: Eric Blake <ebb9@byu.net>
Subject:  Re: fcntl bug
Date: Mon, 24 Aug 2009 15:15:59 +0000 (UTC)
Lines: 42
Message-ID:  <loom.20090824T170139-863@post.gmane.org>
References:  <4A8F0944.5020004@byu.net>  <4A8F1819.9060209@sipxx.com>  <4A8F19DC.8060104@byu.net> <20090822001027.GB8375@ednor.casa.cgf.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@cygwin.com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe@cygwin.com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin@cygwin.com>
List-Help: <mailto:cygwin-help@cygwin.com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner@cygwin.com
Mail-Followup-To: cygwin@cygwin.com
Delivered-To: mailing list cygwin@cygwin.com

Christopher Faylor <cgf-use-the-mailinglist-please <at> 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 <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <errno.h>
#include <stdio.h>
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

