This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
filecopy.t #3 fails on dos-djgpp
[perl5.git] / t / lib / posix.t
1 #!./perl
2
3 BEGIN {
4     chdir 't' if -d 't';
5     @INC = '../lib';
6     require Config; import Config;
7     if ($^O ne 'VMS' and $Config{'extensions'} !~ /\bPOSIX\b/) {
8         print "1..0\n";
9         exit 0;
10     }
11 }
12
13 use POSIX qw(fcntl_h signal_h limits_h _exit getcwd open read strftime write);
14 use strict subs;
15
16 $| = 1;
17 print "1..18\n";
18
19 $testfd = open("TEST", O_RDONLY, 0) and print "ok 1\n";
20 read($testfd, $buffer, 9) if $testfd > 2;
21 print $buffer eq "#!./perl\n" ? "ok 2\n" : "not ok 2\n";
22
23 write(1,"ok 3\nnot ok 3\n", 5);
24
25 @fds = POSIX::pipe();
26 print $fds[0] > $testfd ? "ok 4\n" : "not ok 4\n";
27 CORE::open($reader = \*READER, "<&=".$fds[0]);
28 CORE::open($writer = \*WRITER, ">&=".$fds[1]);
29 print $writer "ok 5\n";
30 close $writer;
31 print <$reader>;
32 close $reader;
33
34 $sigset = new POSIX::SigSet 1,3;
35 delset $sigset 1;
36 if (!ismember $sigset 1) { print "ok 6\n" }
37 if (ismember $sigset 3) { print "ok 7\n" }
38 $mask = new POSIX::SigSet &SIGINT;
39 $action = new POSIX::SigAction 'main::SigHUP', $mask, 0;
40 sigaction(&SIGHUP, $action);
41 $SIG{'INT'} = 'SigINT';
42 kill 'HUP', $$;
43 sleep 1;
44 print "ok 11\n";
45
46 sub SigHUP {
47     print "ok 8\n";
48     kill 'INT', $$;
49     sleep 2;
50     print "ok 9\n";
51 }
52
53 sub SigINT {
54     print "ok 10\n";
55 }
56
57 print &_POSIX_OPEN_MAX > $fds[1] ? "ok 12\n" : "not ok 12\n";
58
59 print getcwd() =~ m#/t$# ? "ok 13\n" : "not ok 13\n";
60
61 # Check string conversion functions.
62
63 if ($Config{d_strtod}) {
64     $lc = &POSIX::setlocale(&POSIX::LC_NUMERIC, 'C') if $Config{d_setlocale};
65     ($n, $x) = &POSIX::strtod('3.14159_OR_SO');
66     print (($n == 3.14159) && ($x == 6) ? "ok 14\n" : "not ok 14\n");
67     &POSIX::setlocale(&POSIX::LC_NUMERIC, $lc) if $Config{d_setlocale};
68 } else { print "# strtod not present\n", "ok 14\n"; }
69
70 if ($Config{d_strtol}) {
71     ($n, $x) = &POSIX::strtol('21_PENGUINS');
72     print (($n == 21) && ($x == 9) ? "ok 15\n" : "not ok 15\n");
73 } else { print "# strtol not present\n", "ok 15\n"; }
74
75 if ($Config{d_strtoul}) {
76     ($n, $x) = &POSIX::strtoul('88_TEARS');
77     print (($n == 88) && ($x == 6) ? "ok 16\n" : "not ok 16\n");
78 } else { print "# strtoul not present\n", "ok 16\n"; }
79
80 # Pick up whether we're really able to dynamically load everything.
81 print &POSIX::acos(1.0) == 0.0 ? "ok 17\n" : "not ok 17\n";
82
83 # This can coredump if struct tm has a timezone field and we
84 # didn't detect it.  If this fails, try adding
85 # -DSTRUCT_TM_HASZONE to your cflags when compiling ext/POSIX/POSIX.c.
86 # See ext/POSIX/hints/sunos_4.pl and ext/POSIX/hints/linux.pl 
87 print POSIX::strftime("ok 18 # %H:%M, on %D\n", localtime());
88
89 $| = 0;
90 print '@#!*$@(!@#$';
91 _exit(0);