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