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