PerlIO omission

B

Ben Morrow

Quoth Bo Lindbergh said:
Why is there no truncate operation in PerlIO?

Err...cos PerlIO's broken? :)
There seems to be some sort of abstraction of the operation, but systems
with ftruncate(2) always end up calling it on fileno($FH). :(

Ben
 
C

Charles DeRykus

Charles said:
There is though: perldoc -f truncate

I think there is an emulation even on OS's
which don't have ftruncate(2).

On Win32 for instance, truncate still succeeds:

C:\temp>perl -V:d_truncate
d_truncate='undef';

C:\temp>perl
open my $fh, "+<", "foo" or die "open: $!";
truncate $fh,0 or die "truncate failed";
^D
 
B

Bo Lindbergh

Ben Morrow said:
Err...cos PerlIO's broken? :)
There seems to be some sort of abstraction of the operation, but systems
with ftruncate(2) always end up calling it on fileno($FH). :(

And so truncate fails with EBADF in the example below.

{
open(my $fh,">",\my $buffer)
or die "open: $!";
print $fh "Hello, World!\n"
or die "print: $!";
truncate($fh,5)
or die "truncate: $!";
}

This is sad, because truncating a Perl scalar is a perfectly
reasonable thing to want to do.


/Bo Lindbergh
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,010
Latest member
MerrillEic

Latest Threads

Top