in reply to Re: Testing for read() failures on different platforms
in thread Testing for read() failures on different platforms
I suppose you could create the file, open it successfully, then delete it and try to read from it. That might generate a read error.
Not on UNIX. It is perfectly possible to open a file, unlink it from the file system, and still be able to read from or write to it. The file is actually deleted when the last open filehandle to it is closed. This is a common way to create a temporary file that no other process can open.
#!/usr/bin/perl my $tf = 'tmpfile'; open FH, ">$tf" or die $!; print FH "Test data\n"; close FH; open FH, "<$tf" or die $!; unlink $tf; print "File deleted!\n" unless -e $tf; print 'File contents: ', <FH>;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Testing for read() failures on different platforms
by hbo (Monk) on Jul 27, 2004 at 15:29 UTC |