www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/06/02:14:23

Message-Id: <1C6D083001E72A00@iris.ernet.in>
Date: 06 Dec 96 11:15 IST
From: tehmul%NIITPUN AT iris DOT ernet DOT in
Sender: tehmul%niitpun AT iris DOT ernet DOT in
To: djgpp AT delorie DOT com
Subject: Re:Re:v2 funnies
Mime-Version: 1.0

                              
>>>If I call open("filename",mode) with two args to create a new file and 
>>>write to it, even if I use mode O_RDWR, the file is created with its DOS 
>>>readonly attribute set so it can't be altered or deleted afterwards 
>>>(unless I state >>the permission required, as 
>>> open("filename",mode,S_IWUSR)). 
>>>This is unexpected and annoying, and did not happen in v1. Why is this? 
>>I thought that ANSI behaviour specifies that whenever you create a file, 
>>the third parameter to open (the permission) is _mandatory_, not optional.  
>>So not giving the third parameter while creating the file might be a 
>>mistake in the first place. 

> Well, ANSI doesn't specify *anything* for open: it's not part of the 
> standard.  But looking at the man page on a Solaris (POSIX) sytem, it shows 
> the prototype as:
>     int open(const char *path, int oflag, /* mode_t mode */ ...);
>[snip]

Ulp!  I meant Posix. Case of lack of sleep. Posix does mention the 
following for O_CREAT:
  "this option requires a third argument, mode, which is of type mode_t.
   [snip]  When bits in mode other than the file permission bits are set, 
   the effect is implementation defined."

Since it states _requires_, you have to pass a third argument.  If not 
passed, the third argument I guess should be picked off the stack, which 
contains an undefined value at this point.  This would cause the open() call 
to behave in the "implementation defined" manner.

Ciao
TG

- Raw text -


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