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