Mail Archives: djgpp/1996/12/06/02:14:23
>>>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 -