This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
In POSIX, improve the diagnostic for the "use $method" instead.
[perl5.git] / ext / POSIX / lib / POSIX.pm
CommitLineData
a0d0e21e 1package POSIX;
e9b37efe
NC
2use strict;
3use warnings;
a0d0e21e 4
e9b37efe 5our(@ISA, %EXPORT_TAGS, @EXPORT_OK, @EXPORT, $AUTOLOAD, %SIGRT) = ();
73c78b0a 6
c43a6b96 7our $VERSION = '1.25';
d5a0d2f9 8
3b35bae3 9use AutoLoader;
c07a80fd 10
da4061d3 11require XSLoader;
a0d0e21e 12
33fb14dc
NC
13use Fcntl qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK F_SETFD
14 F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK O_ACCMODE O_APPEND
15 O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC
a5d75221 16 O_WRONLY SEEK_CUR SEEK_END SEEK_SET
9b68a132 17 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG
a5d75221
NC
18 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU S_ISGID S_ISUID
19 S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR);
33fb14dc 20
66fbe9e2
GS
21my $loaded;
22
a0d0e21e 23sub import {
8fe37eed
AP
24 my $pkg = shift;
25
66fbe9e2 26 load_imports() unless $loaded++;
8fe37eed
AP
27
28 # Grandfather old foo_h form to new :foo_h form
29 s/^(?=\w+_h$)/:/ for my @list = @_;
30
a0d0e21e 31 local $Exporter::ExportLevel = 1;
8fe37eed 32 Exporter::import($pkg,@list);
a0d0e21e
LW
33}
34
66fbe9e2 35sub croak { require Carp; goto &Carp::croak }
f2b27c0e
NIS
36# declare usage to assist AutoLoad
37sub usage;
4633a7c4 38
da4061d3 39XSLoader::load();
4633a7c4 40
8fe37eed
AP
41my %replacement = (
42 atexit => 'END {}',
43 atof => undef,
44 atoi => undef,
45 atol => undef,
46 bsearch => \'not supplied',
47 calloc => undef,
48 clearerr => 'IO::Handle::clearerr',
49 div => '/, % and int',
50 execl => undef,
51 execle => undef,
52 execlp => undef,
53 execv => undef,
54 execve => undef,
55 execvp => undef,
56 fclose => 'IO::Handle::close',
57 fdopen => 'IO::Handle::new_from_fd',
58 feof => 'IO::Handle::eof',
59 ferror => 'IO::Handle::error',
60 fflush => 'IO::Handle::flush',
61 fgetc => 'IO::Handle::getc',
62 fgetpos => 'IO::Seekable::getpos',
63 fgets => 'IO::Handle::gets',
64 fileno => 'IO::Handle::fileno',
65 fopen => 'IO::File::open',
66 fprintf => 'printf',
67 fputc => 'print',
68 fputs => 'print',
69 fread => 'read',
70 free => undef,
71 freopen => 'open',
72 fscanf => '<> and regular expressions',
73 fseek => 'IO::Seekable::seek',
74 fsetpos => 'IO::Seekable::setpos',
75 fsync => 'IO::Handle::sync',
76 ftell => 'IO::Seekable::tell',
77 fwrite => 'print',
78 labs => 'abs',
79 ldiv => '/, % and int',
80 longjmp => 'die',
81 malloc => undef,
82 memchr => 'index()',
83 memcmp => 'eq',
84 memcpy => '=',
85 memmove => '=',
86 memset => 'x',
87 offsetof => undef,
88 putc => 'print',
89 putchar => 'print',
90 puts => 'print',
91 qsort => 'sort',
92 rand => \'non-portable, use Perl\'s rand instead',
93 realloc => undef,
94 scanf => '<> and regular expressions',
95 setbuf => 'IO::Handle::setbuf',
96 setjmp => 'eval {}',
97 setvbuf => 'IO::Handle::setvbuf',
98 siglongjmp => 'die',
99 sigsetjmp => 'eval {}',
100 srand => \'not supplied, refer to Perl\'s srand documentation',
101 sscanf => 'regular expressions',
102 strcat => '.=',
103 strchr => 'index()',
104 strcmp => 'eq',
105 strcpy => '=',
106 strcspn => 'regular expressions',
107 strlen => 'length',
108 strncat => '.=',
109 strncmp => 'eq',
110 strncpy => '=',
111 strpbrk => undef,
112 strrchr => 'rindex()',
113 strspn => undef,
114 strtok => undef,
115 tmpfile => 'IO::File::new_tmpfile',
116 ungetc => 'IO::Handle::ungetc',
117 vfprintf => undef,
118 vprintf => undef,
119 vsprintf => undef,
120);
121
122eval "sub $_;" for keys %replacement;
123
a0d0e21e 124sub AUTOLOAD {
2ae48df0 125 no warnings 'uninitialized';
8fe37eed
AP
126
127 my ($func) = ($AUTOLOAD =~ /.*::(.*)/);
128
129 if (exists $replacement{$func}) {
130 my $how = $replacement{$func};
131 croak "Unimplemented: POSIX::$func() is C-specific, stopped"
132 unless defined $how;
133 croak "Unimplemented: POSIX::$func() is $$how" if ref $how;
11e7c26f 134 croak "Use method $how() instead of POSIX::$func()" if $how =~ /::/;
8fe37eed
AP
135 croak "Unimplemented: POSIX::$func() is C-specific, use $how instead";
136 }
137
138 if ($func =~ /^_?[a-z]/) {
a0d0e21e
LW
139 $AutoLoader::AUTOLOAD = $AUTOLOAD;
140 goto &AutoLoader::AUTOLOAD
141 }
8fe37eed
AP
142
143 constant($func);
a0d0e21e
LW
144}
145
557c0de7
BD
146package POSIX::SigAction;
147
148use AutoLoader 'AUTOLOAD';
557c0de7 149
3609ea0d
JH
150package POSIX::SigRt;
151
983cc415
NC
152use AutoLoader 'AUTOLOAD';
153
3609ea0d 154use Tie::Hash;
3609ea0d 155
b0ac411b 156our @ISA = qw(Tie::StdHash);
3609ea0d 157
b0ac411b
AP
158our ($_SIGRTMIN, $_SIGRTMAX, $_sigrtn);
159
160our $SIGACTION_FLAGS = 0;
3609ea0d 161
3609ea0d
JH
162tie %POSIX::SIGRT, 'POSIX::SigRt';
163
983cc415
NC
164sub DESTROY {};
165
557c0de7 166package POSIX;
d4742b2c
NC
167
1681;
169__END__
170
f2b27c0e 171sub usage {
c07a80fd 172 my ($mess) = @_;
a0d0e21e
LW
173 croak "Usage: POSIX::$mess";
174}
175
a0d0e21e
LW
176sub assert {
177 usage "assert(expr)" if @_ != 1;
178 if (!$_[0]) {
179 croak "Assertion failed";
180 }
181}
182
183sub tolower {
184 usage "tolower(string)" if @_ != 1;
185 lc($_[0]);
186}
187
188sub toupper {
189 usage "toupper(string)" if @_ != 1;
190 uc($_[0]);
191}
192
193sub closedir {
194 usage "closedir(dirhandle)" if @_ != 1;
b56ec344 195 CORE::closedir($_[0]);
a0d0e21e
LW
196}
197
198sub opendir {
199 usage "opendir(directory)" if @_ != 1;
66fbe9e2 200 my $dirhandle;
b56ec344 201 CORE::opendir($dirhandle, $_[0])
a0d0e21e 202 ? $dirhandle
4633a7c4 203 : undef;
a0d0e21e
LW
204}
205
206sub readdir {
207 usage "readdir(dirhandle)" if @_ != 1;
b56ec344 208 CORE::readdir($_[0]);
a0d0e21e
LW
209}
210
211sub rewinddir {
212 usage "rewinddir(dirhandle)" if @_ != 1;
b56ec344 213 CORE::rewinddir($_[0]);
a0d0e21e
LW
214}
215
216sub errno {
217 usage "errno()" if @_ != 0;
218 $! + 0;
219}
220
221sub creat {
222 usage "creat(filename, mode)" if @_ != 2;
94b6baf5 223 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
a0d0e21e
LW
224}
225
226sub fcntl {
227 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
b56ec344 228 CORE::fcntl($_[0], $_[1], $_[2]);
a0d0e21e
LW
229}
230
231sub getgrgid {
232 usage "getgrgid(gid)" if @_ != 1;
b56ec344 233 CORE::getgrgid($_[0]);
a0d0e21e
LW
234}
235
236sub getgrnam {
237 usage "getgrnam(name)" if @_ != 1;
b56ec344 238 CORE::getgrnam($_[0]);
a0d0e21e
LW
239}
240
241sub atan2 {
c43a6b96 242 usage "atan2(x, y)" if @_ != 2;
b56ec344 243 CORE::atan2($_[0], $_[1]);
a0d0e21e
LW
244}
245
246sub cos {
247 usage "cos(x)" if @_ != 1;
b56ec344 248 CORE::cos($_[0]);
a0d0e21e
LW
249}
250
251sub exp {
252 usage "exp(x)" if @_ != 1;
b56ec344 253 CORE::exp($_[0]);
a0d0e21e
LW
254}
255
256sub fabs {
257 usage "fabs(x)" if @_ != 1;
b56ec344 258 CORE::abs($_[0]);
a0d0e21e
LW
259}
260
261sub log {
262 usage "log(x)" if @_ != 1;
b56ec344 263 CORE::log($_[0]);
a0d0e21e
LW
264}
265
266sub pow {
c43a6b96 267 usage "pow(x, exponent)" if @_ != 2;
a0d0e21e
LW
268 $_[0] ** $_[1];
269}
270
271sub sin {
272 usage "sin(x)" if @_ != 1;
b56ec344 273 CORE::sin($_[0]);
a0d0e21e
LW
274}
275
276sub sqrt {
277 usage "sqrt(x)" if @_ != 1;
b56ec344 278 CORE::sqrt($_[0]);
a0d0e21e
LW
279}
280
a0d0e21e
LW
281sub getpwnam {
282 usage "getpwnam(name)" if @_ != 1;
b56ec344 283 CORE::getpwnam($_[0]);
a0d0e21e
LW
284}
285
286sub getpwuid {
287 usage "getpwuid(uid)" if @_ != 1;
b56ec344 288 CORE::getpwuid($_[0]);
a0d0e21e
LW
289}
290
a0d0e21e
LW
291sub kill {
292 usage "kill(pid, sig)" if @_ != 2;
b56ec344 293 CORE::kill $_[1], $_[0];
a0d0e21e
LW
294}
295
296sub raise {
297 usage "raise(sig)" if @_ != 1;
b56ec344 298 CORE::kill $_[0], $$; # Is this good enough?
a0d0e21e
LW
299}
300
a0d0e21e
LW
301sub getc {
302 usage "getc(handle)" if @_ != 1;
b56ec344 303 CORE::getc($_[0]);
a0d0e21e
LW
304}
305
306sub getchar {
307 usage "getchar()" if @_ != 0;
b56ec344 308 CORE::getc(STDIN);
a0d0e21e
LW
309}
310
311sub gets {
312 usage "gets()" if @_ != 0;
313 scalar <STDIN>;
314}
315
316sub perror {
317 print STDERR "@_: " if @_;
318 print STDERR $!,"\n";
319}
320
321sub printf {
322 usage "printf(pattern, args...)" if @_ < 1;
b56ec344 323 CORE::printf STDOUT @_;
a0d0e21e
LW
324}
325
a0d0e21e
LW
326sub remove {
327 usage "remove(filename)" if @_ != 1;
b775e6ba 328 (-d $_[0]) ? CORE::rmdir($_[0]) : CORE::unlink($_[0]);
a0d0e21e
LW
329}
330
331sub rename {
332 usage "rename(oldfilename, newfilename)" if @_ != 2;
b56ec344 333 CORE::rename($_[0], $_[1]);
a0d0e21e
LW
334}
335
336sub rewind {
337 usage "rewind(filehandle)" if @_ != 1;
b56ec344 338 CORE::seek($_[0],0,0);
a0d0e21e
LW
339}
340
a0d0e21e 341sub sprintf {
c43a6b96 342 usage "sprintf(pattern, args...)" if @_ == 0;
b56ec344 343 CORE::sprintf(shift,@_);
a0d0e21e
LW
344}
345
a0d0e21e
LW
346sub abs {
347 usage "abs(x)" if @_ != 1;
b56ec344 348 CORE::abs($_[0]);
a0d0e21e
LW
349}
350
a0d0e21e
LW
351sub exit {
352 usage "exit(status)" if @_ != 1;
b56ec344 353 CORE::exit($_[0]);
a0d0e21e
LW
354}
355
a0d0e21e
LW
356sub getenv {
357 usage "getenv(name)" if @_ != 1;
358 $ENV{$_[0]};
359}
360
a0d0e21e
LW
361sub system {
362 usage "system(command)" if @_ != 1;
b56ec344 363 CORE::system($_[0]);
a0d0e21e
LW
364}
365
a0d0e21e
LW
366sub strerror {
367 usage "strerror(errno)" if @_ != 1;
368 local $! = $_[0];
369 $! . "";
370}
371
a0d0e21e
LW
372sub strstr {
373 usage "strstr(big, little)" if @_ != 2;
b56ec344 374 CORE::index($_[0], $_[1]);
a0d0e21e
LW
375}
376
a0d0e21e 377sub chmod {
3b35bae3 378 usage "chmod(mode, filename)" if @_ != 2;
b56ec344 379 CORE::chmod($_[0], $_[1]);
a0d0e21e
LW
380}
381
382sub fstat {
383 usage "fstat(fd)" if @_ != 1;
c07a80fd 384 local *TMP;
29778b0a 385 CORE::open(TMP, "<&$_[0]"); # Gross.
b56ec344 386 my @l = CORE::stat(TMP);
29778b0a 387 CORE::close(TMP);
a0d0e21e
LW
388 @l;
389}
390
391sub mkdir {
392 usage "mkdir(directoryname, mode)" if @_ != 2;
b56ec344 393 CORE::mkdir($_[0], $_[1]);
a0d0e21e
LW
394}
395
396sub stat {
397 usage "stat(filename)" if @_ != 1;
b56ec344 398 CORE::stat($_[0]);
a0d0e21e
LW
399}
400
401sub umask {
402 usage "umask(mask)" if @_ != 1;
b56ec344 403 CORE::umask($_[0]);
a0d0e21e
LW
404}
405
a0d0e21e 406sub wait {
cb1a09d0 407 usage "wait()" if @_ != 0;
b56ec344 408 CORE::wait();
a0d0e21e
LW
409}
410
411sub waitpid {
cb1a09d0 412 usage "waitpid(pid, options)" if @_ != 2;
b56ec344 413 CORE::waitpid($_[0], $_[1]);
a0d0e21e
LW
414}
415
416sub gmtime {
417 usage "gmtime(time)" if @_ != 1;
b56ec344 418 CORE::gmtime($_[0]);
a0d0e21e
LW
419}
420
421sub localtime {
422 usage "localtime(time)" if @_ != 1;
b56ec344 423 CORE::localtime($_[0]);
a0d0e21e
LW
424}
425
426sub time {
37120919 427 usage "time()" if @_ != 0;
b56ec344 428 CORE::time;
a0d0e21e
LW
429}
430
431sub alarm {
432 usage "alarm(seconds)" if @_ != 1;
b56ec344 433 CORE::alarm($_[0]);
a0d0e21e
LW
434}
435
436sub chdir {
437 usage "chdir(directory)" if @_ != 1;
b56ec344 438 CORE::chdir($_[0]);
a0d0e21e
LW
439}
440
441sub chown {
48065a2c 442 usage "chown(uid, gid, filename)" if @_ != 3;
b56ec344 443 CORE::chown($_[0], $_[1], $_[2]);
a0d0e21e
LW
444}
445
a0d0e21e
LW
446sub fork {
447 usage "fork()" if @_ != 0;
b56ec344 448 CORE::fork;
a0d0e21e
LW
449}
450
a0d0e21e
LW
451sub getegid {
452 usage "getegid()" if @_ != 0;
453 $) + 0;
454}
455
456sub geteuid {
457 usage "geteuid()" if @_ != 0;
458 $> + 0;
459}
460
461sub getgid {
462 usage "getgid()" if @_ != 0;
463 $( + 0;
464}
465
466sub getgroups {
467 usage "getgroups()" if @_ != 0;
c07a80fd 468 my %seen;
a0d0e21e
LW
469 grep(!$seen{$_}++, split(' ', $) ));
470}
471
472sub getlogin {
473 usage "getlogin()" if @_ != 0;
b56ec344 474 CORE::getlogin();
a0d0e21e
LW
475}
476
477sub getpgrp {
478 usage "getpgrp()" if @_ != 0;
5507c093 479 CORE::getpgrp;
a0d0e21e
LW
480}
481
482sub getpid {
483 usage "getpid()" if @_ != 0;
484 $$;
485}
486
487sub getppid {
488 usage "getppid()" if @_ != 0;
b56ec344 489 CORE::getppid;
a0d0e21e
LW
490}
491
492sub getuid {
493 usage "getuid()" if @_ != 0;
494 $<;
495}
496
497sub isatty {
498 usage "isatty(filehandle)" if @_ != 1;
499 -t $_[0];
500}
501
502sub link {
503 usage "link(oldfilename, newfilename)" if @_ != 2;
b56ec344 504 CORE::link($_[0], $_[1]);
a0d0e21e
LW
505}
506
507sub rmdir {
508 usage "rmdir(directoryname)" if @_ != 1;
b56ec344 509 CORE::rmdir($_[0]);
a0d0e21e
LW
510}
511
a0d0e21e
LW
512sub sleep {
513 usage "sleep(seconds)" if @_ != 1;
2ab27a20 514 $_[0] - CORE::sleep($_[0]);
a0d0e21e
LW
515}
516
517sub unlink {
518 usage "unlink(filename)" if @_ != 1;
b56ec344 519 CORE::unlink($_[0]);
a0d0e21e
LW
520}
521
522sub utime {
523 usage "utime(filename, atime, mtime)" if @_ != 3;
b56ec344 524 CORE::utime($_[1], $_[2], $_[0]);
a0d0e21e
LW
525}
526
66fbe9e2 527sub load_imports {
b0ac411b 528our %EXPORT_TAGS = (
66fbe9e2
GS
529
530 assert_h => [qw(assert NDEBUG)],
531
532 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
533 isprint ispunct isspace isupper isxdigit tolower toupper)],
534
d4742b2c 535 dirent_h => [],
66fbe9e2
GS
536
537 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
538 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
539 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
540 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
541 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
542 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
543 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
544 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
545 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
546 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
547 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
548 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
549 EUSERS EWOULDBLOCK EXDEV errno)],
550
551 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
552 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
553 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
554 O_RDONLY O_RDWR O_TRUNC O_WRONLY
555 creat
556 SEEK_CUR SEEK_END SEEK_SET
557 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
558 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
559 S_IWGRP S_IWOTH S_IWUSR)],
560
561 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
562 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
563 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
564 FLT_DIG FLT_EPSILON FLT_MANT_DIG
565 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
566 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
567 FLT_RADIX FLT_ROUNDS
568 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
569 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
570 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
571
d4742b2c 572 grp_h => [],
66fbe9e2
GS
573
574 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
575 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
576 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
577 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
578 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
579 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
580 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
581 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
582 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
583 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
584
83f427f7
JH
585 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
586 LC_MONETARY LC_NUMERIC LC_TIME NULL
587 localeconv setlocale)],
66fbe9e2
GS
588
589 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
590 frexp ldexp log10 modf pow sinh tan tanh)],
591
d4742b2c 592 pwd_h => [],
66fbe9e2
GS
593
594 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
595
596 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
597 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
598 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
3609ea0d 599 SIGPIPE %SIGRT SIGRTMIN SIGRTMAX SIGQUIT SIGSEGV SIGSTOP
ee25ad77
FR
600 SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 SIGBUS
601 SIGPOLL SIGPROF SIGSYS SIGTRAP SIGURG SIGVTALRM SIGXCPU SIGXFSZ
3609ea0d
JH
602 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
603 raise sigaction signal sigpending sigprocmask sigsuspend)],
66fbe9e2 604
d4742b2c 605 stdarg_h => [],
66fbe9e2
GS
606
607 stddef_h => [qw(NULL offsetof)],
608
609 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
610 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
611 STREAM_MAX TMP_MAX stderr stdin stdout
612 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
613 fgets fopen fprintf fputc fputs fread freopen
614 fscanf fseek fsetpos ftell fwrite getchar gets
615 perror putc putchar puts remove rewind
616 scanf setbuf setvbuf sscanf tmpfile tmpnam
617 ungetc vfprintf vprintf vsprintf)],
618
619 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
620 abort atexit atof atoi atol bsearch calloc div
621 free getenv labs ldiv malloc mblen mbstowcs mbtowc
622 qsort realloc strtod strtol strtoul wcstombs wctomb)],
623
624 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
625 strchr strcmp strcoll strcpy strcspn strerror strlen
626 strncat strncmp strncpy strpbrk strrchr strspn strstr
627 strtok strxfrm)],
628
629 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
630 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
631 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
632 fstat mkfifo)],
633
d4742b2c 634 sys_times_h => [],
66fbe9e2 635
d4742b2c 636 sys_types_h => [],
66fbe9e2
GS
637
638 sys_utsname_h => [qw(uname)],
639
640 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
641 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
642
643 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
644 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
645 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
646 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
647 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
648 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
649 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
650 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
651 VSTOP VSUSP VTIME
652 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
653 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
654
655 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
656 difftime mktime strftime tzset tzname)],
657
658 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
b250498f 659 STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
66fbe9e2
GS
660 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
661 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
662 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
663 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
664 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
665 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
d61b6859 666 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
66fbe9e2
GS
667 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
668 _exit access ctermid cuserid
669 dup2 dup execl execle execlp execv execve execvp
f0709b24 670 fpathconf fsync getcwd getegid geteuid getgid getgroups
66fbe9e2
GS
671 getpid getuid isatty lseek pathconf pause setgid setpgid
672 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
673
d4742b2c 674 utime_h => [],
66fbe9e2
GS
675);
676
677# Exporter::export_tags();
85a5de57
NC
678{
679 # De-duplicate the export list:
a146a244
NC
680 my %export;
681 @export{map {@$_} values %EXPORT_TAGS} = ();
682 # Doing the de-dup with a temporary hash has the advantage that the SVs in
b7b1e41b 683 # @EXPORT are actually shared hash key scalars, which will save some memory.
b0ac411b 684 our @EXPORT = keys %export;
66fbe9e2
GS
685}
686
b0ac411b 687our @EXPORT_OK = qw(
d925a710
JH
688 abs
689 alarm
690 atan2
691 chdir
692 chmod
693 chown
694 close
695 closedir
696 cos
697 exit
698 exp
699 fcntl
700 fileno
701 fork
702 getc
703 getgrgid
704 getgrnam
705 getlogin
706 getpgrp
707 getppid
708 getpwnam
709 getpwuid
710 gmtime
711 isatty
712 kill
0d7021f5 713 lchown
d925a710
JH
714 link
715 localtime
716 log
717 mkdir
718 nice
719 open
720 opendir
721 pipe
722 printf
723 rand
724 read
725 readdir
726 rename
727 rewinddir
728 rmdir
729 sin
730 sleep
731 sprintf
732 sqrt
733 srand
734 stat
735 system
736 time
737 times
738 umask
739 unlink
740 utime
741 wait
742 waitpid
743 write
66fbe9e2
GS
744);
745
746require Exporter;
747}
557c0de7
BD
748
749package POSIX::SigAction;
750
fc8b6fe2 751sub new { bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0, SAFE => 0}, $_[0] }
557c0de7
BD
752sub handler { $_[0]->{HANDLER} = $_[1] if @_ > 1; $_[0]->{HANDLER} };
753sub mask { $_[0]->{MASK} = $_[1] if @_ > 1; $_[0]->{MASK} };
754sub flags { $_[0]->{FLAGS} = $_[1] if @_ > 1; $_[0]->{FLAGS} };
d36b6582 755sub safe { $_[0]->{SAFE} = $_[1] if @_ > 1; $_[0]->{SAFE} };
3609ea0d 756
983cc415
NC
757package POSIX::SigRt;
758
983cc415
NC
759sub _init {
760 $_SIGRTMIN = &POSIX::SIGRTMIN;
761 $_SIGRTMAX = &POSIX::SIGRTMAX;
762 $_sigrtn = $_SIGRTMAX - $_SIGRTMIN;
763}
764
765sub _croak {
766 &_init unless defined $_sigrtn;
767 die "POSIX::SigRt not available" unless defined $_sigrtn && $_sigrtn > 0;
768}
769
770sub _getsig {
771 &_croak;
772 my $rtsig = $_[0];
773 # Allow (SIGRT)?MIN( + n)?, a common idiom when doing these things in C.
774 $rtsig = $_SIGRTMIN + ($1 || 0)
775 if $rtsig =~ /^(?:(?:SIG)?RT)?MIN(\s*\+\s*(\d+))?$/;
776 return $rtsig;
777}
778
779sub _exist {
780 my $rtsig = _getsig($_[1]);
781 my $ok = $rtsig >= $_SIGRTMIN && $rtsig <= $_SIGRTMAX;
782 ($rtsig, $ok);
783}
784
785sub _check {
786 my ($rtsig, $ok) = &_exist;
787 die "No POSIX::SigRt signal $_[1] (valid range SIGRTMIN..SIGRTMAX, or $_SIGRTMIN..$_SIGRTMAX)"
788 unless $ok;
789 return $rtsig;
790}
791
792sub new {
793 my ($rtsig, $handler, $flags) = @_;
794 my $sigset = POSIX::SigSet->new($rtsig);
b0ac411b 795 my $sigact = POSIX::SigAction->new($handler, $sigset, $flags);
983cc415
NC
796 POSIX::sigaction($rtsig, $sigact);
797}
798
799sub EXISTS { &_exist }
800sub FETCH { my $rtsig = &_check;
801 my $oa = POSIX::SigAction->new();
802 POSIX::sigaction($rtsig, undef, $oa);
803 return $oa->{HANDLER} }
804sub STORE { my $rtsig = &_check; new($rtsig, $_[2], $SIGACTION_FLAGS) }
805sub DELETE { delete $SIG{ &_check } }
806sub CLEAR { &_exist; delete @SIG{ &POSIX::SIGRTMIN .. &POSIX::SIGRTMAX } }
807sub SCALAR { &_croak; $_sigrtn + 1 }