1N/A#!./perl
1N/A
1N/ABEGIN {
1N/A chdir 't' if -d 't';
1N/A @INC = '../lib';
1N/A}
1N/A
1N/A# A modest test: exercises only O_WRONLY, O_CREAT, and O_RDONLY.
1N/A# Have to be modest to be portable: could possibly extend testing
1N/A# also to O_RDWR and O_APPEND, but dunno about the portability of,
1N/A# say, O_TRUNC and O_EXCL, not to mention O_NONBLOCK.
1N/A
1N/Ause Fcntl;
1N/A
1N/Aprint "1..7\n";
1N/A
1N/Aprint "ok 1\n";
1N/A
1N/Aif (sysopen(my $wo, "fcntl$$", O_WRONLY|O_CREAT)) {
1N/A print "ok 2\n";
1N/A if (syswrite($wo, "foo") == 3) {
1N/A print "ok 3\n";
1N/A close($wo);
1N/A if (sysopen(my $ro, "fcntl$$", O_RDONLY)) {
1N/A print "ok 4\n";
1N/A if (sysread($ro, my $read, 3)) {
1N/A print "ok 5\n";
1N/A if ($read eq "foo") {
1N/A print "ok 6\n";
1N/A } else {
1N/A print "not ok 6 # content '$read' not ok\n";
1N/A }
1N/A } else {
1N/A print "not ok 5 # sysread failed: $!\n";
1N/A }
1N/A } else {
1N/A print "not ok 4 # sysopen O_RDONLY failed: $!\n";
1N/A }
1N/A close($ro);
1N/A } else {
1N/A print "not ok 3 # syswrite failed: $!\n";
1N/A }
1N/A close($wo);
1N/A} else {
1N/A print "not ok 2 # sysopen O_WRONLY failed: $!\n";
1N/A}
1N/A
1N/A# Opening of character special devices gets special treatment in doio.c
1N/A# Didn't work as of perl-5.8.0-RC2.
1N/Ause File::Spec; # To portably get /dev/null
1N/A
1N/Amy $devnull = File::Spec->devnull;
1N/Aif (-c $devnull) {
1N/A if (sysopen(my $wo, $devnull, O_WRONLY)) {
1N/A print "ok 7 # open /dev/null O_WRONLY\n";
1N/A close($wo);
1N/A }
1N/A else {
1N/A print "not ok 7 # open /dev/null O_WRONLY\n";
1N/A }
1N/A}
1N/Aelse {
1N/A print "ok 7 # Skipping /dev/null sysopen O_WRONLY test\n";
1N/A}
1N/A
1N/AEND {
1N/A 1 while unlink "fcntl$$";
1N/A}