@@ -308,6 +308,7 @@ my %FILES_CREATED_BY_OBJECT;
308308# Usually irrelevant on unix
309309# "use_exlock" => Indicates that O_EXLOCK should be used. Default is false.
310310# "file_permissions" => file permissions for sysopen(). Default is 0600.
311+ # "write_only" => Indicates that O_WRONLY should be used. Default is false.
311312
312313# Optionally a reference to a scalar can be passed into the function
313314# On error this will be used to store the reason for the error
@@ -506,13 +507,16 @@ sub _gettemp {
506507 # Attempt to open the file
507508 my $open_success = undef ;
508509 if ( $^O eq ' VMS' and $options {" unlink_on_close" } && !$KEEP_ALL ) {
510+ my $flags = $OPENFLAGS ;
511+ $flags = ($flags & ~O_RDWR) | O_WRONLY if $options {write_only };
509512 # make it auto delete on close by setting FAB$V_DLT bit
510- $fh = VMS::Stdio::vmssysopen($path , $OPENFLAGS , $perms , ' fop=dlt' );
513+ $fh = VMS::Stdio::vmssysopen($path , $flags , $perms , ' fop=dlt' );
511514 $open_success = $fh ;
512515 } else {
513516 my $flags = ( ($options {" unlink_on_close" } && !$KEEP_ALL ) ?
514517 $OPENTEMPFLAGS :
515518 $OPENFLAGS );
519+ $flags = ($flags & ~O_RDWR) | O_WRONLY if $options {write_only };
516520 $flags |= $LOCKFLAG if (defined $LOCKFLAG && $options {use_exlock });
517521 $open_success = sysopen ($fh , $path , $flags , $perms );
518522 }
@@ -1053,7 +1057,7 @@ that the temporary file is removed by the object destructor
10531057if UNLINK is set to true (the default).
10541058
10551059Supported arguments are the same as for C<tempfile > : UNLINK
1056- (defaulting to true), DIR, EXLOCK, PERMS and SUFFIX.
1060+ (defaulting to true), DIR, EXLOCK, PERMS, WRITE_ONLY and SUFFIX.
10571061Additionally, the filename
10581062template is specified using the TEMPLATE option. The OPEN option
10591063is not supported (the file is always opened).
@@ -1370,6 +1374,11 @@ Use C<PERMS> to change this:
13701374
13711375 ($fh, $filename) = tempfile($template, PERMS => 0666);
13721376
1377+ Normally, the temporary filehandle is opened for both reading
1378+ and writing. To open for writing only, use C<WRITE_ONLY > .
1379+
1380+ ($fh, $filename) = tempfile($template, WRITE_ONLY => 1);
1381+
13731382Options can be combined as required.
13741383
13751384Will croak() if there is an error.
@@ -1384,6 +1393,8 @@ EXLOCK flag available since 0.19.
13841393
13851394PERMS flag available since 0.24.
13861395
1396+ WRITE_ONLY flag available since 0.24.
1397+
13871398=cut
13881399
13891400sub tempfile {
@@ -1402,6 +1413,7 @@ sub tempfile {
14021413 " TMPDIR" => 0, # Place tempfile in tempdir if template specified
14031414 " EXLOCK" => 0, # Open file with O_EXLOCK
14041415 " PERMS" => undef , # File permissions
1416+ " WRITE_ONLY" => 0, # Open file with O_WRONLY
14051417 );
14061418
14071419 # Check to see whether we have an odd or even number of arguments
@@ -1485,6 +1497,7 @@ sub tempfile {
14851497 " ErrStr" => \$errstr ,
14861498 " use_exlock" => $options {EXLOCK },
14871499 " file_permissions" => $options {PERMS },
1500+ " write_only" => $options {WRITE_ONLY },
14881501 ) );
14891502
14901503 # Set up an exit handler that can do whatever is right for the
0 commit comments