#!/usr/bin/env perl
use warnings;
use strict;
my $file = $^O eq 'MSWin32' ? "P:\\foo" : '/tmp/foo/bar';
open my $fh, '>', $file or die "$file: $!";
my $data = "\0" x 2_000_000;
print "Writing ", length $data, " bytes to $file\n";
printf $fh "%s", $data or warn "printf: $!";
close $fh or warn "close: $!";
print "Still not fatal\n";
__END__
Windows:
Install https://www.ltr-data.se/opencode.html/#ImDisk
As Administrator:
> imdisk -a -t vm -m P: -s 1M -p "/fs:fat /q /y"
> perl write.pl
Writing 2000000 bytes to P:\foo
printf: No space left on device at write.pl line 9.
close: No space left on device at write.pl line 10.
Still not fatal
> imdisk -D -m P:
Linux:
$ mkdir -vp /tmp/foo
$ sudo mount -t tmpfs -o size=1M,uid=`id -u` tmpfs /tmp/foo
$ perl write.pl
Writing 2000000 bytes to /tmp/foo/bar
printf: No space left on device at write.pl line 9.
close: No space left on device at write.pl line 10.
Still not fatal
$ sudo umount /tmp/foo
| [reply] [Watch: Dir/Any] [d/l] |
I disagree about printf() errors.
It was all about sprintf, not printf. Different cases and conditions (memory exhausted vs. disk full etc, NFS conditions and such).
perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'
| [reply] [Watch: Dir/Any] |
| [reply] [Watch: Dir/Any] |