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