Subject: _open problem using O_EXCL flag and -mno-cygwin
From: "David Ponce" <[email-masked]>
To: <[email-masked]>
Cc: "david" <[email-masked]>
Date: Fri, 15 Dec 2000 10:16:21 +0100 (MET)

Hello,

I am a NT Emacs 21 pretester and I successfully compiled it (with
-mno-cygwin) using the latest (great!) cygwin 1.1.6 (I tried the
20001213 snapshot too).  Emacs works well except a problem using the
O_EXCL flag with the _open function. With this flag _open always
return -1 with errno=22.

Following is a simple test program that isolates the problem:

------------------------
#include <io.h>
#include <stdio.h>
#include <errno.h>
#include <sys/stat.h>
#include <fcntl.h>

int fdesc;

int main(void)
{

  fprintf(stderr, "O_BINARY=%i, _O_BINARY=%i\n", O_BINARY, _O_BINARY);

  fprintf(stderr, "O_WRONLY=%i, _O_WRONLY=%i\n", O_WRONLY, _O_WRONLY);
  fprintf(stderr, "O_CREAT=%i, _O_CREAT=%i\n",  O_CREAT, _O_CREAT);
  fprintf(stderr, "O_EXCL=%i, _O_EXCL=%i\n",   O_EXCL, _O_EXCL);
  fprintf(stderr, "O_TRUNC=%i, _O_TRUNC=%i\n",  O_TRUNC, _O_TRUNC);
  fprintf(stderr, "O_NOINHERIT=%i, _O_NOINHERIT=%i\n",
          O_NOINHERIT, _O_NOINHERIT);
  fprintf(stderr, "S_IREAD=%i, _S_IREAD=%i\n",  S_IREAD, _S_IREAD);
  fprintf(stderr, "S_IWRITE=%i, _S_IWRITE=%i\n", S_IWRITE, _S_IWRITE);

  errno = 0;
  fdesc = _open("testopen.tmp1",
   O_BINARY | O_WRONLY | O_CREAT | O_TRUNC | O_EXCL | _O_NOINHERIT,
   S_IREAD | S_IWRITE);
  fprintf(stderr, "fdesc=%i\n", fdesc);
  fprintf(stderr, "errno=%i\n", errno);

  errno = 0;
  fdesc = _open("testopen.tmp2",
   O_BINARY | O_WRONLY | O_CREAT | O_TRUNC | _O_NOINHERIT,
   S_IREAD | S_IWRITE);
  fprintf(stderr, "fdesc=%i\n", fdesc);
  fprintf(stderr, "errno=%i\n", errno);

}
------------------------

And the transcription of the test case (the testopen.tmp files does not
initially exist)

------------------------
C:\cygwin\tmp>gcc -mno-cygwin testopen.c

C:\cygwin\tmp>a.exe
O_BINARY=32768, _O_BINARY=32768
O_WRONLY=1, _O_WRONLY=1
O_CREAT=256, _O_CREAT=256
O_EXCL=1024, _O_EXCL=1024
O_TRUNC=512, _O_TRUNC=512
O_NOINHERIT=128, _O_NOINHERIT=128
S_IREAD=256,  _S_IREAD=256
S_IWRITE=128,  _S_IWRITE=128
fdesc=-1
errno=22
fdesc=3
errno=0

C:\cygwin\tmp>del testopen.tmp*

C:\cygwin\tmp>gcc testopen.c

C:\cygwin\tmp>a.exe
O_BINARY=65536, _O_BINARY=65536
O_WRONLY=1, _O_WRONLY=1
O_CREAT=512, _O_CREAT=512
O_EXCL=2048, _O_EXCL=2048
O_TRUNC=1024, _O_TRUNC=1024
O_NOINHERIT=262144, _O_NOINHERIT=262144
S_IREAD=256,  _S_IREAD=256
S_IWRITE=128,  _S_IWRITE=128
fdesc=3
errno=0
fdesc=4
errno=0
------------------------

When I compile the same program without -mno-cygwin it works well.

So is the O_EXCL flag supported by the mingw version of _open. Or is
it a bug?

Thank you so much for any help.

Sincerely,
David

--
Want to unsubscribe from this list?
Send a message to [email-masked]