delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2009/08/24/11:17:11

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 <ebb9 AT byu DOT 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 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
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: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
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 <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

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019