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