www.digitalmars.com         C & C++   DMDScript  

c++.idde - _O_NOINHERIT

reply Riccardo Cohen <rcohen articque.com> writes:
Hi,

I use metakit library, and in a call to "_open()" they use flag _O_NOINHERIT

This flag is not documented (could not find in winhelp), but it exists and is
set to 128 (I made a 
printf). When running the code below, the file is not created. I have to remove
the flag, then it 
works. (DigitalMars compiler (8.37) )

With MS DevStudio the flag is also set to 128 but that does not change behavior
and the file is created.

I would like to know if this is a bug or if there is something I dont
understand.
Thanks

-- 
Riccardo Cohen

Articque
Les Roches
37230 Fondettes
France
web = http://www.articque.com
tel: +33 02 47 49 90 49
fax: +33 02 47 49 91 49
========================================================
#include <io.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <stdio.h>
int main()
{
   printf("%d\n",_O_NOINHERIT);
   int flags = _O_BINARY | _O_NOINHERIT |  _O_RDWR ;
   int  fd = _open("d:\\zdrop\\testfile.out", flags | _O_CREAT, _S_IREAD |
_S_IWRITE);
   if (fd!=1)
   {
     _write (fd,"ok",2);
     _close(fd);
   }
   char tmp[100];
   gets(tmp);
   return(0);
}
Nov 19 2003
parent reply Arjan Knepper <arjan ask.me> writes:
How is _open() implemented in the metakit lib? With CreateFile ? The 128 
(decimal) == 80(hex) == FILE_ATTRIBUTE_NORMAL which is the only 
exclusive flag for the file attribute arg in CreateFile.

Arjan

Riccardo Cohen wrote:
 Hi,
 
 I use metakit library, and in a call to "_open()" they use flag 
 _O_NOINHERIT
 
 This flag is not documented (could not find in winhelp), but it exists 
 and is set to 128 (I made a printf). When running the code below, the 
 file is not created. I have to remove the flag, then it works. 
 (DigitalMars compiler (8.37) )
 
 With MS DevStudio the flag is also set to 128 but that does not change 
 behavior and the file is created.
 
 I would like to know if this is a bug or if there is something I dont 
 understand.
 Thanks
 
Nov 19 2003
parent reply Riccardo Cohen <rcohen articque.com> writes:
Thanks for your quick answer.
The code is :

   int flags = _O_BINARY | _O_NOINHERIT | (mode_ > 0 ? _O_RDWR : _O_RDONLY);
   int fd = _open(fname_, flags);

I dont really understand your question. _open() is not implemented by metakit
library, but by win32sdk.
The function CreateFile is not called by the metakit library.

Arjan Knepper wrote:

 How is _open() implemented in the metakit lib? With CreateFile ? The 128 
 (decimal) == 80(hex) == FILE_ATTRIBUTE_NORMAL which is the only 
 exclusive flag for the file attribute arg in CreateFile.
 
 Arjan
 
 Riccardo Cohen wrote:
 
 Hi,

 I use metakit library, and in a call to "_open()" they use flag 
 _O_NOINHERIT

 This flag is not documented (could not find in winhelp), but it exists 
 and is set to 128 (I made a printf). When running the code below, the 
 file is not created. I have to remove the flag, then it works. 
 (DigitalMars compiler (8.37) )

 With MS DevStudio the flag is also set to 128 but that does not change 
 behavior and the file is created.

 I would like to know if this is a bug or if there is something I dont 
 understand.
 Thanks
-- Riccardo Cohen Articque Les Roches 37230 Fondettes France web = http://www.articque.com tel: +33 02 47 49 90 49 fax: +33 02 47 49 91 49
Nov 19 2003
parent reply Arjan Knepper <arjan ask.me> writes:
OK you are just using the c-runtime '_open (..)'.

Take a look at the source file which implements _open (..) in the 
compiler src directory. That way you can see how the _O_NOINHERIT is 
affecting the file open api call (which will probably use CreateFile).

I would not use the "undocumented" _O_NOINHERIT. Has problaby something 
to do with the HANDLE returned from CreateFile not being inheritable by 
child processes or threads or DuplicateHandle.

Arjan

Riccardo Cohen wrote:

 Thanks for your quick answer.
 The code is :
 
   int flags = _O_BINARY | _O_NOINHERIT | (mode_ > 0 ? _O_RDWR : _O_RDONLY);
   int fd = _open(fname_, flags);
 
 I dont really understand your question. _open() is not implemented by 
 metakit library, but by win32sdk.
 The function CreateFile is not called by the metakit library.
 
 Arjan Knepper wrote:
 
 How is _open() implemented in the metakit lib? With CreateFile ? The 
 128 (decimal) == 80(hex) == FILE_ATTRIBUTE_NORMAL which is the only 
 exclusive flag for the file attribute arg in CreateFile.

 Arjan

 Riccardo Cohen wrote:

 Hi,

 I use metakit library, and in a call to "_open()" they use flag 
 _O_NOINHERIT

 This flag is not documented (could not find in winhelp), but it 
 exists and is set to 128 (I made a printf). When running the code 
 below, the file is not created. I have to remove the flag, then it 
 works. (DigitalMars compiler (8.37) )

 With MS DevStudio the flag is also set to 128 but that does not 
 change behavior and the file is created.

 I would like to know if this is a bug or if there is something I dont 
 understand.
 Thanks
Nov 19 2003
parent Riccardo Cohen <rcohen articque.com> writes:
I found that _open() function is defined as open(), but could not find open()
except in 
IOS/FILESYS.H definition.
Anyway I understand that this undocumented flag should not be used.
Thanks for the info.

Arjan Knepper wrote:

 OK you are just using the c-runtime '_open (..)'.
 
 Take a look at the source file which implements _open (..) in the 
 compiler src directory. That way you can see how the _O_NOINHERIT is 
 affecting the file open api call (which will probably use CreateFile).
 
 I would not use the "undocumented" _O_NOINHERIT. Has problaby something 
 to do with the HANDLE returned from CreateFile not being inheritable by 
 child processes or threads or DuplicateHandle.
 
 Arjan
 
 Riccardo Cohen wrote:
 
 Thanks for your quick answer.
 The code is :

   int flags = _O_BINARY | _O_NOINHERIT | (mode_ > 0 ? _O_RDWR : 
 _O_RDONLY);
   int fd = _open(fname_, flags);

 I dont really understand your question. _open() is not implemented by 
 metakit library, but by win32sdk.
 The function CreateFile is not called by the metakit library.

 Arjan Knepper wrote:

 How is _open() implemented in the metakit lib? With CreateFile ? The 
 128 (decimal) == 80(hex) == FILE_ATTRIBUTE_NORMAL which is the only 
 exclusive flag for the file attribute arg in CreateFile.

 Arjan

 Riccardo Cohen wrote:

 Hi,

 I use metakit library, and in a call to "_open()" they use flag 
 _O_NOINHERIT

 This flag is not documented (could not find in winhelp), but it 
 exists and is set to 128 (I made a printf). When running the code 
 below, the file is not created. I have to remove the flag, then it 
 works. (DigitalMars compiler (8.37) )

 With MS DevStudio the flag is also set to 128 but that does not 
 change behavior and the file is created.

 I would like to know if this is a bug or if there is something I 
 dont understand.
 Thanks
-- Riccardo Cohen Articque Les Roches 37230 Fondettes France web = http://www.articque.com tel: +33 02 47 49 90 49 fax: +33 02 47 49 91 49
Nov 20 2003