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