Open
Description
Description
Opening a file in append write only mode (>>
) and attepting to read from it puts the file handle in some kind of invalid state. Following writes will have the intended effect, i.e. append bytes to the file, but return errors.
This behaviour started with 5.38 and broke the tests in Win32::LongPath rdboisvert/Win32-LongPath#14.
cc @shawnlaffan
Steps to Reproduce
open(my $fh, '>>', 'append') or die 'cannot open';
my $line = readline $fh;
print $fh 'append only' or die 'cannot write'; # perl >=5.38 will die here
close $fh or die 'cannot close';
Expected behavior
The code should run successfully as it did before.
Note that using sysread and syswrite does not trigger the issue.
Perl configuration
Observed on multiple platforms (Linux, Windows, macOS), for instance:
Summary of my perl5 (revision 5 version 38 subversion 2) configuration:
Platform:
osname=darwin
osvers=24.2.0
archname=darwin-thread-multi-2level
uname='nixpkgs'
config_args='-de -Dprefix=/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2 -Dman1dir=/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/share/man/man1 -Dman3dir=/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/share/man/man3 -Dcc=cc -Duseshrplib -Uinstallusrbinperl -Dinstallstyle=lib/perl5 -Dlocincpth=/no-such-path/include -Dloclibpth=/no-such-path/lib -Dusethreads'
hint=recommended
useposix=true
d_sigaction=define
useithreads=define
usemultiplicity=define
use64bitint=define
use64bitall=define
uselongdouble=undef
usemymalloc=n
default_inc_excludes_dot=define
Compiler:
cc='cc'
ccflags ='-fno-common -DPERL_DARWIN -mmacosx-version-min=11.3 -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong -I/no-such-path/include'
optimize='-O3'
cppflags='-fno-common -DPERL_DARWIN -mmacosx-version-min=11.3 -DNO_POSIX_2008_LOCALE -fno-strict-aliasing -pipe -fstack-protector-strong -I/no-such-path/include'
ccversion=''
gccversion='Clang 19.1.7'
gccosandvers=''
intsize=4
longsize=8
ptrsize=8
doublesize=8
byteorder=12345678
doublekind=3
d_longlong=define
longlongsize=8
d_longdbl=define
longdblsize=16
longdblkind=3
ivtype='long'
ivsize=8
nvtype='double'
nvsize=8
Off_t='off_t'
lseeksize=8
alignbytes=8
prototype=define
Linker and Libraries:
ld='cc'
ldflags =' -mmacosx-version-min=11.3 -fstack-protector-strong -L/no-such-path/lib'
libpth=
libs=-lcrypt
perllibs=-lcrypt
libc=
so=dylib
useshrplib=true
libperl=libperl.dylib
gnulibc_version=''
Dynamic Linking:
dlsrc=dl_dlopen.xs
dlext=bundle
d_dlsymun=undef
ccdlflags=' '
cccdlflags=' '
lddlflags=' -mmacosx-version-min=11.3 -bundle -undefined dynamic_lookup -L/no-such-path/lib -fstack-protector-strong'
Characteristics of this binary (from libperl):
Compile-time options:
HAS_LONG_DOUBLE
HAS_STRTOLD
HAS_TIMES
MULTIPLICITY
PERLIO_LAYERS
PERL_COPY_ON_WRITE
PERL_DONT_CREATE_GVSV
PERL_HASH_FUNC_SIPHASH13
PERL_HASH_USE_SBOX32
PERL_MALLOC_WRAP
PERL_OP_PARENT
PERL_PRESERVE_IVUV
PERL_USE_SAFE_PUTENV
USE_64_BIT_ALL
USE_64_BIT_INT
USE_ITHREADS
USE_LARGE_FILES
USE_LOCALE
USE_LOCALE_COLLATE
USE_LOCALE_CTYPE
USE_LOCALE_NUMERIC
USE_LOCALE_TIME
USE_PERLIO
USE_PERL_ATOF
USE_REENTRANT_API
Built under darwin
Compiled at Nov 28 2023 14:04:47
%ENV:
PERL5LIB="/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl"
@INC:
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl/5.38.2/darwin-thread-multi-2level
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl/5.38.2
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl/5.38.2/darwin-thread-multi-2level
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/site_perl/5.38.2
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/5.38.2/darwin-thread-multi-2level
/nix/store/waf13fynkk30napkvzljabgsqg0fjck6-perl-5.38.2/lib/perl5/5.38.2