open '>:encoding(UTF-8)' masking write errors?

Consider the following code:

    my $data = 'x' x 1024;
    my $file = '/dev/full';

    open my $out, '>:encoding(UTF-8)', $file
        or die "Error: can't open '$file' for writing: $!\n";
    print $out $data or die "Error: writing to file '$file': $!\n";
    close $out       or die "Error: closing file '$file': $!\n";

It runs without error, which I find surprising and disturbing.
Changing the open line to

    open my $out, '>', $file

gives the error I expect:

    Error: closing file '/dev/full': No space left on device

Is this a bug or do I have unrealistic expectations?

An strace shows that in both cases, the OS is returning an error:

    write(4, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..., 1024) = -1 ENOSPC (No space left on device)




-- 
Justice is when you get what you deserve.
Law is when you get what you pay for.
0
davem
6/17/2017 2:25:59 PM
perl.perl5.porters 46527 articles. 0 followers. Follow

2 Replies
18 Views

Similar Articles

[PageSpeed] 15


On 06/17/2017 10:25 AM, Dave Mitchell wrote:
> Consider the following code:
>
>     my $data = 'x' x 1024;
>     my $file = '/dev/full';
>
>     open my $out, '>:encoding(UTF-8)', $file
>         or die "Error: can't open '$file' for writing: $!\n";
>     print $out $data or die "Error: writing to file '$file': $!\n";
>     close $out       or die "Error: closing file '$file': $!\n";
>
> It runs without error, which I find surprising and disturbing.
> Changing the open line to
>
>     open my $out, '>', $file
>
> gives the error I expect:
>
>     Error: closing file '/dev/full': No space left on device
>
> Is this a bug or do I have unrealistic expectations?

I would consider it wrong. Is the OS error swallowed by the encoding IO
layer?
0
xsawyerx
6/20/2017 6:09:08 PM
On Sat, Jun 17, 2017 at 03:25:59PM +0100, Dave Mitchell wrote:
> Consider the following code:
> 
>     my $data = 'x' x 1024;
>     my $file = '/dev/full';
> 
>     open my $out, '>:encoding(UTF-8)', $file
>         or die "Error: can't open '$file' for writing: $!\n";
>     print $out $data or die "Error: writing to file '$file': $!\n";
>     close $out       or die "Error: closing file '$file': $!\n";
> 
> It runs without error, which I find surprising and disturbing.
> Changing the open line to
> 
>     open my $out, '>', $file
> 
> gives the error I expect:
> 
>     Error: closing file '/dev/full': No space left on device
> 
> Is this a bug or do I have unrealistic expectations?
> 
> An strace shows that in both cases, the OS is returning an error:
> 
>     write(4, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"..., 1024) = -1 ENOSPC (No space left on device)

That looks like a bug to me.

Tony
0
tony
6/21/2017 1:00:30 AM
Reply: