11 plan skip_all => "POSIX is unavailable" if $Config{'extensions'} !~ m!\bPOSIX\b!;
17 use Scalar::Util qw(looks_like_number);
20 grep { eval "&$_;1" or $@!~/vendor has not defined POSIX macro/ } @_
23 my @path_consts = check qw(
24 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_NAME_MAX
25 _PC_NO_TRUNC _PC_PATH_MAX
28 my @path_consts_terminal = check qw(
29 _PC_MAX_CANON _PC_MAX_INPUT _PC_VDISABLE
32 my @path_consts_fifo = check qw(
36 my @sys_consts = check qw(
37 _SC_ARG_MAX _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
38 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
39 _SC_STREAM_MAX _SC_VERSION _SC_TZNAME_MAX
42 my $tests = 2 * 3 * @path_consts +
43 2 * 3 * @path_consts_terminal +
44 2 * 3 * @path_consts_fifo +
48 : (skip_all => "No tests to run on this OS")
51 my $curdir = File::Spec->curdir;
52 $curdir = VMS::Filespec::fileify($curdir) if $^O eq 'VMS';
58 sub _check_and_report {
59 my ($eval_status, $return_val, $description) = @_;
60 my $success = defined($return_val) || $! == 0;
61 is( $eval_status, '', $description );
63 skip "terminal constants set errno on QNX", 1
64 if $^O eq 'nto' and $description =~ $TTY;
65 ok( $success, "\tchecking that the returned value is defined ("
66 . (defined($return_val) ? "yes, it's $return_val)" : "it isn't)"
67 . " or that errno is clear ("
68 . (!($!+0) ? "it is)" : "it isn't, it's $!)"))
72 skip "constant not implemented on $^O or no limit in effect", 1
73 if !defined($return_val);
74 ok( looks_like_number($return_val), "\tchecking that the returned value looks like a number" );
78 # testing fpathconf() on a non-terminal file
80 my $fd = POSIX::open($curdir, O_RDONLY)
81 or skip "could not open current directory ($!)", 3 * @path_consts;
83 for my $constant (@path_consts) {
85 $r = eval { fpathconf( $fd, eval "$constant()" ) };
86 _check_and_report( $@, $r, "calling fpathconf($fd, $constant) " );
92 # testing pathconf() on a non-terminal file
93 for my $constant (@path_consts) {
95 $r = eval { pathconf( $curdir, eval "$constant()" ) };
96 _check_and_report( $@, $r, qq[calling pathconf("$curdir", $constant)] );
100 my $n = 2 * 3 * @path_consts_terminal;
103 or skip("$TTY not a character file", $n);
105 or skip("failed to open $TTY: $!", $n);
107 or skip("TTY ($TTY) not a terminal file", $n);
109 my $fd = fileno(TTY);
111 # testing fpathconf() on a terminal file
112 for my $constant (@path_consts_terminal) {
114 $r = eval { fpathconf( $fd, eval "$constant()" ) };
115 _check_and_report( $@, $r, qq[calling fpathconf($fd, $constant) ($TTY)] );
119 # testing pathconf() on a terminal file
120 for my $constant (@path_consts_terminal) {
122 $r = eval { pathconf( $TTY, eval "$constant()" ) };
123 _check_and_report( $@, $r, qq[calling pathconf($TTY, $constant)] );
130 eval { mkfifo($fifo, 0666) }
131 or skip("could not create fifo $fifo ($!)", 2 * 3 * @path_consts_fifo);
134 my $fd = POSIX::open($fifo, O_RDWR)
135 or skip("could not open $fifo ($!)", 3 * @path_consts_fifo);
137 for my $constant (@path_consts_fifo) {
139 $r = eval { fpathconf( $fd, eval "$constant()" ) };
140 _check_and_report( $@, $r, "calling fpathconf($fd, $constant) ($fifo)" );
146 # testing pathconf() on a fifo file
147 for my $constant (@path_consts_fifo) {
149 $r = eval { pathconf( $fifo, eval "$constant()" ) };
150 _check_and_report( $@, $r, qq[calling pathconf($fifo, $constant)] );
155 1 while unlink($fifo);
159 if($^O eq 'cygwin') {
161 skip("No _SC_TZNAME_MAX on Cygwin", 3);
166 for my $constant (@sys_consts) {
168 $r = eval { sysconf( eval "$constant()" ) };
169 _check_and_report( $@, $r, "calling sysconf($constant)" );