This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Croak on unimplemented already at import time
[perl5.git] / ext / POSIX / lib / POSIX.pm
CommitLineData
a0d0e21e 1package POSIX;
e9b37efe
NC
2use strict;
3use warnings;
a0d0e21e 4
122efcc9 5our ($AUTOLOAD, %SIGRT);
73c78b0a 6
19fc2965 7our $VERSION = '1.68';
d5a0d2f9 8
da4061d3 9require XSLoader;
a0d0e21e 10
33fb14dc
NC
11use Fcntl qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK F_SETFD
12 F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK O_ACCMODE O_APPEND
13 O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC
a5d75221 14 O_WRONLY SEEK_CUR SEEK_END SEEK_SET
9b68a132 15 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG
a5d75221
NC
16 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU S_ISGID S_ISUID
17 S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR);
33fb14dc 18
66fbe9e2
GS
19my $loaded;
20
66fbe9e2 21sub croak { require Carp; goto &Carp::croak }
122efcc9 22sub usage { croak "Usage: POSIX::$_[0]" }
4633a7c4 23
da4061d3 24XSLoader::load();
4633a7c4 25
8fe37eed
AP
26my %replacement = (
27 atexit => 'END {}',
28 atof => undef,
29 atoi => undef,
30 atol => undef,
31 bsearch => \'not supplied',
32 calloc => undef,
33 clearerr => 'IO::Handle::clearerr',
34 div => '/, % and int',
35 execl => undef,
36 execle => undef,
37 execlp => undef,
38 execv => undef,
39 execve => undef,
40 execvp => undef,
41 fclose => 'IO::Handle::close',
42 fdopen => 'IO::Handle::new_from_fd',
43 feof => 'IO::Handle::eof',
44 ferror => 'IO::Handle::error',
45 fflush => 'IO::Handle::flush',
46 fgetc => 'IO::Handle::getc',
47 fgetpos => 'IO::Seekable::getpos',
48 fgets => 'IO::Handle::gets',
49 fileno => 'IO::Handle::fileno',
50 fopen => 'IO::File::open',
51 fprintf => 'printf',
52 fputc => 'print',
53 fputs => 'print',
54 fread => 'read',
55 free => undef,
56 freopen => 'open',
57 fscanf => '<> and regular expressions',
58 fseek => 'IO::Seekable::seek',
59 fsetpos => 'IO::Seekable::setpos',
60 fsync => 'IO::Handle::sync',
61 ftell => 'IO::Seekable::tell',
62 fwrite => 'print',
63 labs => 'abs',
64 ldiv => '/, % and int',
65 longjmp => 'die',
66 malloc => undef,
67 memchr => 'index()',
68 memcmp => 'eq',
69 memcpy => '=',
70 memmove => '=',
71 memset => 'x',
72 offsetof => undef,
73 putc => 'print',
74 putchar => 'print',
75 puts => 'print',
76 qsort => 'sort',
77 rand => \'non-portable, use Perl\'s rand instead',
78 realloc => undef,
79 scanf => '<> and regular expressions',
80 setbuf => 'IO::Handle::setbuf',
81 setjmp => 'eval {}',
82 setvbuf => 'IO::Handle::setvbuf',
83 siglongjmp => 'die',
84 sigsetjmp => 'eval {}',
96927498 85 srand => \'not supplied; refer to Perl\'s srand documentation',
8fe37eed
AP
86 sscanf => 'regular expressions',
87 strcat => '.=',
88 strchr => 'index()',
89 strcmp => 'eq',
90 strcpy => '=',
91 strcspn => 'regular expressions',
92 strlen => 'length',
93 strncat => '.=',
94 strncmp => 'eq',
95 strncpy => '=',
96 strpbrk => undef,
97 strrchr => 'rindex()',
98 strspn => undef,
99 strtok => undef,
100 tmpfile => 'IO::File::new_tmpfile',
f914a2ba 101 tmpnam => 'use File::Temp',
8fe37eed
AP
102 ungetc => 'IO::Handle::ungetc',
103 vfprintf => undef,
104 vprintf => undef,
105 vsprintf => undef,
106);
107
122efcc9 108my %reimpl = (
c60f3449
JH
109 abs => 'x => CORE::abs($_[0])',
110 alarm => 'seconds => CORE::alarm($_[0])',
122efcc9 111 assert => 'expr => croak "Assertion failed" if !$_[0]',
122efcc9 112 atan2 => 'x, y => CORE::atan2($_[0], $_[1])',
c60f3449
JH
113 chdir => 'directory => CORE::chdir($_[0])',
114 chmod => 'mode, filename => CORE::chmod($_[0], $_[1])',
115 chown => 'uid, gid, filename => CORE::chown($_[0], $_[1], $_[2])',
116 closedir => 'dirhandle => CORE::closedir($_[0])',
122efcc9 117 cos => 'x => CORE::cos($_[0])',
c60f3449
JH
118 creat => 'filename, mode => &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1])',
119 errno => '$! + 0',
120 exit => 'status => CORE::exit($_[0])',
122efcc9
AP
121 exp => 'x => CORE::exp($_[0])',
122 fabs => 'x => CORE::abs($_[0])',
c60f3449
JH
123 fcntl => 'filehandle, cmd, arg => CORE::fcntl($_[0], $_[1], $_[2])',
124 fork => 'CORE::fork',
125 fstat => 'fd => CORE::open my $dup, "<&", $_[0]; CORE::stat($dup)', # Gross.
122efcc9
AP
126 getc => 'handle => CORE::getc($_[0])',
127 getchar => 'CORE::getc(STDIN)',
122efcc9 128 getegid => '$) + 0',
c60f3449 129 getenv => 'name => $ENV{$_[0]}',
122efcc9
AP
130 geteuid => '$> + 0',
131 getgid => '$( + 0',
c60f3449
JH
132 getgrgid => 'gid => CORE::getgrgid($_[0])',
133 getgrnam => 'name => CORE::getgrnam($_[0])',
122efcc9
AP
134 getgroups => 'my %seen; grep !$seen{$_}++, split " ", $)',
135 getlogin => 'CORE::getlogin()',
136 getpgrp => 'CORE::getpgrp',
137 getpid => '$$',
138 getppid => 'CORE::getppid',
c60f3449
JH
139 getpwnam => 'name => CORE::getpwnam($_[0])',
140 getpwuid => 'uid => CORE::getpwuid($_[0])',
141 gets => 'scalar <STDIN>',
122efcc9 142 getuid => '$<',
c60f3449 143 gmtime => 'time => CORE::gmtime($_[0])',
122efcc9 144 isatty => 'filehandle => -t $_[0]',
c60f3449 145 kill => 'pid, sig => CORE::kill $_[1], $_[0]',
122efcc9 146 link => 'oldfilename, newfilename => CORE::link($_[0], $_[1])',
c60f3449
JH
147 localtime => 'time => CORE::localtime($_[0])',
148 log => 'x => CORE::log($_[0])',
149 mkdir => 'directoryname, mode => CORE::mkdir($_[0], $_[1])',
150 opendir => 'directory => my $dh; CORE::opendir($dh, $_[0]) ? $dh : undef',
151 pow => 'x, exponent => $_[0] ** $_[1]',
152 raise => 'sig => CORE::kill $_[0], $$; # Is this good enough',
153 readdir => 'dirhandle => CORE::readdir($_[0])',
154 remove => 'filename => (-d $_[0]) ? CORE::rmdir($_[0]) : CORE::unlink($_[0])',
155 rename => 'oldfilename, newfilename => CORE::rename($_[0], $_[1])',
156 rewind => 'filehandle => CORE::seek($_[0],0,0)',
157 rewinddir => 'dirhandle => CORE::rewinddir($_[0])',
122efcc9 158 rmdir => 'directoryname => CORE::rmdir($_[0])',
c60f3449
JH
159 sin => 'x => CORE::sin($_[0])',
160 sqrt => 'x => CORE::sqrt($_[0])',
161 stat => 'filename => CORE::stat($_[0])',
162 strerror => 'errno => BEGIN { local $!; require locale; locale->import} my $e = $_[0] + 0; local $!; $! = $e; "$!"',
163 strstr => 'big, little => CORE::index($_[0], $_[1])',
164 system => 'command => CORE::system($_[0])',
165 time => 'CORE::time',
166 tolower => 'string => lc($_[0])',
167 toupper => 'string => uc($_[0])',
168 umask => 'mask => CORE::umask($_[0])',
122efcc9
AP
169 unlink => 'filename => CORE::unlink($_[0])',
170 utime => 'filename, atime, mtime => CORE::utime($_[1], $_[2], $_[0])',
c60f3449
JH
171 wait => 'CORE::wait()',
172 waitpid => 'pid, options => CORE::waitpid($_[0], $_[1])',
122efcc9 173);
8fe37eed 174
19fc2965
JH
175sub import {
176 my $pkg = shift;
177
178 load_imports() unless $loaded++;
179
180 # Grandfather old foo_h form to new :foo_h form
181 s/^(?=\w+_h$)/:/ for my @list = @_;
182
183 my @unimpl = sort grep { exists $replacement{$_} } @list;
184 if (@unimpl) {
185 for my $u (@unimpl) {
186 warn "Unimplemented: POSIX::$u(): ", unimplemented_message($u);
187 }
188 croak(sprintf("Unimplemented: %s",
189 join(" ", map { "POSIX::$_()" } @unimpl)));
190 }
191
192 local $Exporter::ExportLevel = 1;
193 Exporter::import($pkg,@list);
194}
195
122efcc9 196eval join ';', map "sub $_", keys %replacement, keys %reimpl;
8fe37eed 197
19fc2965
JH
198sub unimplemented_message {
199 my $func = shift;
200 my $how = $replacement{$func};
201 return "C-specific, stopped" unless defined $how;
202 return "$$how" if ref $how;
203 return "$how instead" if $how =~ /^use /;
204 return "Use method $how() instead" if $how =~ /::/;
205 return "C-specific: use $how instead";
206}
207
122efcc9 208sub AUTOLOAD {
8fe37eed
AP
209 my ($func) = ($AUTOLOAD =~ /.*::(.*)/);
210
c448c124
AP
211 die "POSIX.xs has failed to load\n" if $func eq 'constant';
212
8dad66f8 213 if (my $code = $reimpl{$func}) {
122efcc9
AP
214 my ($num, $arg) = (0, '');
215 if ($code =~ s/^(.*?) *=> *//) {
216 $arg = $1;
217 $num = 1 + $arg =~ tr/,//;
218 }
219 # no warnings to be consistent with the old implementation, where each
220 # function was in its own little AutoSplit world:
221 eval qq{ sub $func {
222 no warnings;
223 usage "$func($arg)" if \@_ != $num;
224 $code
225 } };
226 no strict;
227 goto &$AUTOLOAD;
228 }
8fe37eed 229 if (exists $replacement{$func}) {
19fc2965 230 croak "Unimplemented: POSIX::$func(): ", unimplemented_message($func);
8fe37eed
AP
231 }
232
8fe37eed 233 constant($func);
a0d0e21e
LW
234}
235
a0d0e21e
LW
236sub perror {
237 print STDERR "@_: " if @_;
238 print STDERR $!,"\n";
239}
240
241sub printf {
242 usage "printf(pattern, args...)" if @_ < 1;
b56ec344 243 CORE::printf STDOUT @_;
a0d0e21e
LW
244}
245
a0d0e21e 246sub sprintf {
c43a6b96 247 usage "sprintf(pattern, args...)" if @_ == 0;
b56ec344 248 CORE::sprintf(shift,@_);
a0d0e21e
LW
249}
250
66fbe9e2 251sub load_imports {
fa44d961 252my %default_export_tags = ( # cf. exports policy below
66fbe9e2
GS
253
254 assert_h => [qw(assert NDEBUG)],
255
256 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
257 isprint ispunct isspace isupper isxdigit tolower toupper)],
258
d4742b2c 259 dirent_h => [],
66fbe9e2 260
c3fa0c84
SH
261 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT EAGAIN
262 EALREADY EBADF EBADMSG EBUSY ECANCELED ECHILD ECONNABORTED
263 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT EEXIST
264 EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EIDRM EILSEQ EINPROGRESS
265 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK EMSGSIZE
266 ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH ENFILE ENOBUFS
267 ENODATA ENODEV ENOENT ENOEXEC ENOLCK ENOLINK ENOMEM ENOMSG
268 ENOPROTOOPT ENOSPC ENOSR ENOSTR ENOSYS ENOTBLK ENOTCONN ENOTDIR
269 ENOTEMPTY ENOTRECOVERABLE ENOTSOCK ENOTSUP ENOTTY ENXIO
270 EOPNOTSUPP EOTHER EOVERFLOW EOWNERDEAD EPERM EPFNOSUPPORT EPIPE
271 EPROCLIM EPROTO EPROTONOSUPPORT EPROTOTYPE ERANGE EREMOTE
272 ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT ESPIPE ESRCH ESTALE
273 ETIME ETIMEDOUT ETOOMANYREFS ETXTBSY EUSERS EWOULDBLOCK EXDEV
274 errno)],
66fbe9e2
GS
275
276 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
277 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
278 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
279 O_RDONLY O_RDWR O_TRUNC O_WRONLY
280 creat
281 SEEK_CUR SEEK_END SEEK_SET
282 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
283 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
284 S_IWGRP S_IWOTH S_IWUSR)],
285
286 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
287 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
288 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
289 FLT_DIG FLT_EPSILON FLT_MANT_DIG
290 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
291 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
292 FLT_RADIX FLT_ROUNDS
293 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
294 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
295 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
296
d4742b2c 297 grp_h => [],
66fbe9e2
GS
298
299 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
300 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
301 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
302 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
303 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
304 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
305 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
306 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
307 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
308 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
309
83f427f7
JH
310 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
311 LC_MONETARY LC_NUMERIC LC_TIME NULL
312 localeconv setlocale)],
66fbe9e2 313
7658eeca
AP
314 math_h => [qw(FP_ILOGB0 FP_ILOGBNAN FP_INFINITE FP_NAN FP_NORMAL
315 FP_SUBNORMAL FP_ZERO
316 M_1_PI M_2_PI M_2_SQRTPI M_E M_LN10 M_LN2 M_LOG10E M_LOG2E
317 M_PI M_PI_2 M_PI_4 M_SQRT1_2 M_SQRT2
318 HUGE_VAL INFINITY NAN
319 acos asin atan ceil cosh fabs floor fmod
320 frexp ldexp log10 modf pow sinh tan tanh)],
66fbe9e2 321
d4742b2c 322 pwd_h => [],
66fbe9e2
GS
323
324 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
325
326 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
327 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
328 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
3609ea0d 329 SIGPIPE %SIGRT SIGRTMIN SIGRTMAX SIGQUIT SIGSEGV SIGSTOP
ee25ad77
FR
330 SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIGBUS
331 SIGPOLL SIGPROF SIGSYS SIGTRAP SIGURG SIGVTALRM SIGXCPU SIGXFSZ
3609ea0d
JH
332 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
333 raise sigaction signal sigpending sigprocmask sigsuspend)],
66fbe9e2 334
d4742b2c 335 stdarg_h => [],
66fbe9e2
GS
336
337 stddef_h => [qw(NULL offsetof)],
338
339 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
340 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
341 STREAM_MAX TMP_MAX stderr stdin stdout
342 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
343 fgets fopen fprintf fputc fputs fread freopen
344 fscanf fseek fsetpos ftell fwrite getchar gets
345 perror putc putchar puts remove rewind
346 scanf setbuf setvbuf sscanf tmpfile tmpnam
347 ungetc vfprintf vprintf vsprintf)],
348
349 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
350 abort atexit atof atoi atol bsearch calloc div
351 free getenv labs ldiv malloc mblen mbstowcs mbtowc
7658eeca 352 qsort realloc strtod strtol strtoul wcstombs wctomb)],
66fbe9e2
GS
353
354 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
355 strchr strcmp strcoll strcpy strcspn strerror strlen
356 strncat strncmp strncpy strpbrk strrchr strspn strstr
357 strtok strxfrm)],
358
359 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
360 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
361 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
362 fstat mkfifo)],
363
d4742b2c 364 sys_times_h => [],
66fbe9e2 365
d4742b2c 366 sys_types_h => [],
66fbe9e2
GS
367
368 sys_utsname_h => [qw(uname)],
369
370 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
371 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
372
373 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
374 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
375 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
376 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
377 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
378 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
379 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
380 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
381 VSTOP VSUSP VTIME
382 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
383 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
384
385 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
ce0afe25 386 difftime mktime strftime tzset tzname)],
66fbe9e2
GS
387
388 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
b250498f 389 STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
66fbe9e2
GS
390 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
391 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
392 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
393 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
394 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
395 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
d61b6859 396 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
66fbe9e2
GS
397 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
398 _exit access ctermid cuserid
399 dup2 dup execl execle execlp execv execve execvp
f0709b24 400 fpathconf fsync getcwd getegid geteuid getgid getgroups
66fbe9e2
GS
401 getpid getuid isatty lseek pathconf pause setgid setpgid
402 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
403
d4742b2c 404 utime_h => [],
66fbe9e2
GS
405);
406
a28fff51
SH
407if ($^O eq 'MSWin32') {
408 $default_export_tags{winsock_h} = [qw(
409 WSAEINTR WSAEBADF WSAEACCES WSAEFAULT WSAEINVAL WSAEMFILE WSAEWOULDBLOCK
410 WSAEINPROGRESS WSAEALREADY WSAENOTSOCK WSAEDESTADDRREQ WSAEMSGSIZE
411 WSAEPROTOTYPE WSAENOPROTOOPT WSAEPROTONOSUPPORT WSAESOCKTNOSUPPORT
412 WSAEOPNOTSUPP WSAEPFNOSUPPORT WSAEAFNOSUPPORT WSAEADDRINUSE
413 WSAEADDRNOTAVAIL WSAENETDOWN WSAENETUNREACH WSAENETRESET WSAECONNABORTED
414 WSAECONNRESET WSAENOBUFS WSAEISCONN WSAENOTCONN WSAESHUTDOWN
415 WSAETOOMANYREFS WSAETIMEDOUT WSAECONNREFUSED WSAELOOP WSAENAMETOOLONG
416 WSAEHOSTDOWN WSAEHOSTUNREACH WSAENOTEMPTY WSAEPROCLIM WSAEUSERS
417 WSAEDQUOT WSAESTALE WSAEREMOTE WSAEDISCON WSAENOMORE WSAECANCELLED
418 WSAEINVALIDPROCTABLE WSAEINVALIDPROVIDER WSAEPROVIDERFAILEDINIT
419 WSAEREFUSED)];
420}
421
fa44d961 422my %other_export_tags = ( # cf. exports policy below
7658eeca
AP
423 fenv_h => [qw(
424 FE_DOWNWARD FE_TONEAREST FE_TOWARDZERO FE_UPWARD fegetround fesetround
425 )],
426
427 math_h_c99 => [ @{$default_export_tags{math_h}}, qw(
428 Inf NaN acosh asinh atanh cbrt copysign erf erfc exp2 expm1 fdim fma
429 fmax fmin fpclassify hypot ilogb isfinite isgreater isgreaterequal
430 isinf isless islessequal islessgreater isnan isnormal isunordered j0 j1
431 jn lgamma log1p log2 logb lrint nan nearbyint nextafter nexttoward
432 remainder remquo rint round scalbn signbit tgamma trunc y0 y1 yn
433 )],
434
435 stdlib_h_c99 => [ @{$default_export_tags{stdlib_h}}, 'strtold' ],
07bb61ac
JH
436
437 nan_payload => [ qw(getpayload setpayload setpayloadsig issignaling) ],
34e79b75
DIM
438
439 signal_h_si_code => [qw(
440 ILL_ILLOPC ILL_ILLOPN ILL_ILLADR ILL_ILLTRP ILL_PRVOPC ILL_PRVREG
441 ILL_COPROC ILL_BADSTK
442 FPE_INTDIV FPE_INTOVF FPE_FLTDIV FPE_FLTOVF FPE_FLTUND
443 FPE_FLTRES FPE_FLTINV FPE_FLTSUB
444 SEGV_MAPERR SEGV_ACCERR
445 BUS_ADRALN BUS_ADRERR BUS_OBJERR
446 TRAP_BRKPT TRAP_TRACE
447 CLD_EXITED CLD_KILLED CLD_DUMPED CLD_TRAPPED CLD_STOPPED CLD_CONTINUED
448 POLL_IN POLL_OUT POLL_MSG POLL_ERR POLL_PRI POLL_HUP
449 SI_USER SI_QUEUE SI_TIMER SI_ASYNCIO SI_MESGQ
450 )],
7658eeca
AP
451);
452
fa44d961
AP
453# exports policy:
454# - new functions may not be added to @EXPORT, only to @EXPORT_OK
455# - new SHOUTYCONSTANTS are OK to add to @EXPORT
456
85a5de57
NC
457{
458 # De-duplicate the export list:
7658eeca
AP
459 my ( %export, %export_ok );
460 @export {map {@$_} values %default_export_tags} = ();
461 @export_ok{map {@$_} values %other_export_tags} = ();
ce0afe25
AB
462 # Doing the de-dup with a temporary hash has the advantage that the SVs in
463 # @EXPORT are actually shared hash key scalars, which will save some memory.
464 our @EXPORT = keys %export;
66fbe9e2 465
fa44d961 466 # you do not want to add symbols to the following list. add a new tag instead
a387c53a 467 our @EXPORT_OK = (qw(close lchown nice open pipe read sleep times write
25a9f0e7 468 printf sprintf lround),
255a3e7b
AP
469 # lround() should really be in the :math_h_c99 tag, but
470 # we're too far into the 5.24 code freeze for that to be
471 # done now. This can be revisited in the 5.25.x cycle.
7658eeca
AP
472 grep {!exists $export{$_}} keys %reimpl, keys %replacement, keys %export_ok);
473
474 our %EXPORT_TAGS = ( %default_export_tags, %other_export_tags );
8dad66f8 475}
66fbe9e2
GS
476
477require Exporter;
478}
557c0de7
BD
479
480package POSIX::SigAction;
481
fc8b6fe2 482sub new { bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0, SAFE => 0}, $_[0] }
557c0de7
BD
483sub handler { $_[0]->{HANDLER} = $_[1] if @_ > 1; $_[0]->{HANDLER} };
484sub mask { $_[0]->{MASK} = $_[1] if @_ > 1; $_[0]->{MASK} };
485sub flags { $_[0]->{FLAGS} = $_[1] if @_ > 1; $_[0]->{FLAGS} };
d36b6582 486sub safe { $_[0]->{SAFE} = $_[1] if @_ > 1; $_[0]->{SAFE} };
3609ea0d 487
0e9a7888
RS
488{
489package POSIX::SigSet;
490# This package is here entirely to make sure that POSIX::SigSet is seen by the
491# PAUSE indexer, so that it will always be clearly indexed in core. This is to
492# prevent the accidental case where a third-party distribution can accidentally
493# claim the POSIX::SigSet package, as occurred in 2011-12. -- rjbs, 2011-12-30
494}
495
983cc415
NC
496package POSIX::SigRt;
497
122efcc9
AP
498require Tie::Hash;
499
500our @ISA = 'Tie::StdHash';
501
502our ($_SIGRTMIN, $_SIGRTMAX, $_sigrtn);
503
504our $SIGACTION_FLAGS = 0;
505
983cc415
NC
506sub _init {
507 $_SIGRTMIN = &POSIX::SIGRTMIN;
508 $_SIGRTMAX = &POSIX::SIGRTMAX;
509 $_sigrtn = $_SIGRTMAX - $_SIGRTMIN;
510}
511
512sub _croak {
513 &_init unless defined $_sigrtn;
514 die "POSIX::SigRt not available" unless defined $_sigrtn && $_sigrtn > 0;
515}
516
517sub _getsig {
518 &_croak;
519 my $rtsig = $_[0];
520 # Allow (SIGRT)?MIN( + n)?, a common idiom when doing these things in C.
521 $rtsig = $_SIGRTMIN + ($1 || 0)
522 if $rtsig =~ /^(?:(?:SIG)?RT)?MIN(\s*\+\s*(\d+))?$/;
523 return $rtsig;
524}
525
526sub _exist {
527 my $rtsig = _getsig($_[1]);
528 my $ok = $rtsig >= $_SIGRTMIN && $rtsig <= $_SIGRTMAX;
529 ($rtsig, $ok);
530}
531
532sub _check {
533 my ($rtsig, $ok) = &_exist;
534 die "No POSIX::SigRt signal $_[1] (valid range SIGRTMIN..SIGRTMAX, or $_SIGRTMIN..$_SIGRTMAX)"
535 unless $ok;
536 return $rtsig;
537}
538
539sub new {
540 my ($rtsig, $handler, $flags) = @_;
541 my $sigset = POSIX::SigSet->new($rtsig);
b0ac411b 542 my $sigact = POSIX::SigAction->new($handler, $sigset, $flags);
983cc415
NC
543 POSIX::sigaction($rtsig, $sigact);
544}
545
546sub EXISTS { &_exist }
547sub FETCH { my $rtsig = &_check;
548 my $oa = POSIX::SigAction->new();
549 POSIX::sigaction($rtsig, undef, $oa);
550 return $oa->{HANDLER} }
551sub STORE { my $rtsig = &_check; new($rtsig, $_[2], $SIGACTION_FLAGS) }
552sub DELETE { delete $SIG{ &_check } }
553sub CLEAR { &_exist; delete @SIG{ &POSIX::SIGRTMIN .. &POSIX::SIGRTMAX } }
554sub SCALAR { &_croak; $_sigrtn + 1 }
122efcc9
AP
555
556tie %POSIX::SIGRT, 'POSIX::SigRt';
557# and the expression on the line above is true, so we return true.