8/27/03 18:12:59, Craig Berry <[EMAIL PROTECTED]> wrote:
>
>On Tuesday, August 26, 2003, at 05:29PM, Alan Winston - SSRL Central Computing
><[EMAIL PROTECTED]> wrote:
>
>
>
>>WINSTON>type tryit.pl
>>use Fcntl;
>>$path = "x.;1";
>> sysopen(X, $path, O_WRONLY|O_TRUNC|O_CREAT, 0666) || die $!;
>>printf X "blabla";
>>WINSTON>perl tryit.pl
>>WINSTON>perl tryit.pl
>>file exists at tryit.pl line 3.
>>%RMS-E-FEX, file already exists, not superseded
>>
>>
>>So, still no help, but this does seem to be 5.6.1 on VMS (from the prebuilt,
>>incidentally) not behaving as documented in this area.
>
>FWIW, I'm pretty sure we just inherit whatever the CRTL does. Look at the CRTL docs
>for creat() and/or open().
I just did:
The following values are defined in the <file.h> header file:
O_RDONLY Open for reading only
O_WRONLY Open for writing only
O_RDWR Open for reading and writing
O_NDELAY Open for asynchronous input
O_APPEND Append on each write
O_CREAT Create a file if it does not exist
O_TRUNC Create a new version of this file
O_EXCL Error if attempting to create existing file
These flags are set using the bitwise OR operator (|) to separate specified flags.
Opening a file with O_APPEND causes each write on the file to be appended to the end.
(In contrast, with the VAX C RTL the behavior of files
opened in append mode was to start at EOF and, thereafter, write at the current file
position.)
If O_TRUNC is specified and the file exists, open creates a new file by incrementing
the version number by 1, leaving the old version in
existence.
If O_CREAT is set and the named file does not exist, the Compaq C RTL creates it with
any attributes specified in the fourth and subsequent
arguments (...). If O_EXCL is set with O_CREAT and the named file exists, the
attempted open returns an error.
So this code does what I want:
use Fcntl;
$path = "x.;1";
sysopen(X, $path, O_WRONLY|O_CREAT, 0666) || die $!;
printf X scalar localtime;
Now can someone confirm that open(FH, "> $path") will always create a new version?
Reading the C docs about fopen it seems like it should (if open is implemented via
fopen):
These access modes have the following effects:
"r" opens an existing file for reading.
"w" creates a new file, if necessary, and opens the file for writing. If the file
exists, it creates a new file with the same name and a higher version
number.
"a" opens the file for append access. An existing file is positioned at the
end-of-file, and data is written there. If the file does not exist, the
Compaq C RTL creates it.
The update access modes allow a file to be opened for both reading and writing. When
used with existing files, "r+" and "a+" differ only in the
initial positioning within the file. The modes are as follows:
"r+" opens an existing file for read update access. It is opened for reading,
positioned first at the beginning-of- file, but writing is also allowed.
"w+" opens a new file for write update access.
"a+" opens a file for append update access. The file is first positioned at the
end-of-file (writing). If the file does not exist, the Compaq C RTL
creates it.
"b" means binary access mode. In this case, no conversion of carriage-control
information is attempted.
If I get the above right I can't do what I want with fopen (not that I want right
now). Strange.
Hm, the section Winston quoted should be corrected then, shouldn't it?
Michael