This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: fcntl bug


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]