VERSION Patch
[p5sagit/p5-mst-13.2.git] / ext / POSIX / POSIX.pm
CommitLineData
a0d0e21e 1package POSIX;
2
3use Carp;
3b35bae3 4use AutoLoader;
a0d0e21e 5require Config;
c07a80fd 6use Symbol;
7
8require Exporter;
9require DynaLoader;
fec02dd3 10@ISA = qw(Exporter DynaLoader);
a0d0e21e 11
c07a80fd 12$VERSION = $VERSION = "1.00" ;
13
748a9306 14%EXPORT_TAGS = (
a0d0e21e 15
748a9306 16 assert_h => [qw(assert NDEBUG)],
a0d0e21e 17
748a9306 18 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
19 isprint ispunct isspace isupper isxdigit tolower toupper)],
a0d0e21e 20
748a9306 21 dirent_h => [qw()],
22
23 errno_h => [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
a0d0e21e 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
748a9306 27 EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)],
a0d0e21e 28
748a9306 29 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
a0d0e21e 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
748a9306 37 S_IWGRP S_IWOTH S_IWUSR)],
a0d0e21e 38
748a9306 39 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
a0d0e21e 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
748a9306 48 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
a0d0e21e 49
748a9306 50 grp_h => [qw()],
a0d0e21e 51
748a9306 52 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
a0d0e21e 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
748a9306 61 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
a0d0e21e 62
748a9306 63 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
64 LC_TIME NULL localeconv setlocale)],
a0d0e21e 65
748a9306 66 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
3b35bae3 67 frexp ldexp log10 modf pow sinh tan tanh)],
a0d0e21e 68
748a9306 69 pwd_h => [qw()],
a0d0e21e 70
748a9306 71 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
a0d0e21e 72
748a9306 73 signal_h => [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
a0d0e21e 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
748a9306 78 sigsuspend)],
a0d0e21e 79
748a9306 80 stdarg_h => [qw()],
a0d0e21e 81
748a9306 82 stddef_h => [qw(NULL offsetof)],
a0d0e21e 83
748a9306 84 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
c07a80fd 85 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
86 STREAM_MAX TMP_MAX stderr stdin stdout
a0d0e21e 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
748a9306 92 ungetc vfprintf vprintf vsprintf)],
a0d0e21e 93
748a9306 94 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
a0d0e21e 95 abort atexit atof atoi atol bsearch calloc div
96 free getenv labs ldiv malloc mblen mbstowcs mbtowc
748a9306 97 qsort realloc strtod strtol stroul wcstombs wctomb)],
a0d0e21e 98
748a9306 99 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
a0d0e21e 100 strchr strcmp strcoll strcpy strcspn strerror strlen
101 strncat strncmp strncpy strpbrk strrchr strspn strstr
748a9306 102 strtok strxfrm)],
a0d0e21e 103
748a9306 104 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
a0d0e21e 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
748a9306 107 fstat mkfifo)],
a0d0e21e 108
748a9306 109 sys_times_h => [qw()],
a0d0e21e 110
748a9306 111 sys_types_h => [qw()],
a0d0e21e 112
748a9306 113 sys_utsname_h => [qw(uname)],
a0d0e21e 114
748a9306 115 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
116 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
a0d0e21e 117
748a9306 118 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
a0d0e21e 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
748a9306 128 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
a0d0e21e 129
748a9306 130 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
131 difftime mktime strftime tzset tzname)],
a0d0e21e 132
748a9306 133 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
a0d0e21e 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
748a9306 147 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
a0d0e21e 148
748a9306 149 utime_h => [qw()],
a0d0e21e 150
748a9306 151);
a0d0e21e 152
748a9306 153Exporter::export_tags();
a0d0e21e 154
155@EXPORT_OK = qw(
156 closedir opendir readdir rewinddir
157 fcntl open
158 getgrgid getgrnam
3b35bae3 159 atan2 cos exp log sin sqrt
a0d0e21e 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
748a9306 173# Grandfather old foo_h form to new :foo_h form
a0d0e21e 174sub import {
175 my $this = shift;
748a9306 176 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
a0d0e21e 177 local $Exporter::ExportLevel = 1;
178 Exporter::import($this,@list);
179}
180
4633a7c4 181
182bootstrap POSIX;
183
184my $EINVAL = constant("EINVAL", 0);
185my $EAGAIN = constant("EAGAIN", 0);
186
a0d0e21e 187sub AUTOLOAD {
188 if ($AUTOLOAD =~ /::(_?[a-z])/) {
189 $AutoLoader::AUTOLOAD = $AUTOLOAD;
190 goto &AutoLoader::AUTOLOAD
191 }
4633a7c4 192 local $! = 0;
193 my $constname = $AUTOLOAD;
a0d0e21e 194 $constname =~ s/.*:://;
4633a7c4 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";
a0d0e21e 204 }
4633a7c4 205 else {
206 croak "Your vendor has not defined POSIX macro $constname, used";
207 }
208
a0d0e21e 209 goto &$AUTOLOAD;
210}
211
a0d0e21e 212sub usage {
c07a80fd 213 my ($mess) = @_;
a0d0e21e 214 croak "Usage: POSIX::$mess";
215}
216
217sub redef {
c07a80fd 218 my ($mess) = @_;
a0d0e21e 219 croak "Use method $mess instead";
220}
221
222sub unimpl {
c07a80fd 223 my ($mess) = @_;
a0d0e21e 224 $mess =~ s/xxx//;
225 croak "Unimplemented: POSIX::$mess";
226}
227
a0d0e21e 228############################
229package POSIX::SigAction;
230
231sub new {
232 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
233}
234
235############################
a0d0e21e 236package POSIX; # return to package POSIX so AutoSplit is happy
2371;
238__END__
239
240sub assert {
241 usage "assert(expr)" if @_ != 1;
242 if (!$_[0]) {
243 croak "Assertion failed";
244 }
245}
246
247sub tolower {
248 usage "tolower(string)" if @_ != 1;
249 lc($_[0]);
250}
251
252sub toupper {
253 usage "toupper(string)" if @_ != 1;
254 uc($_[0]);
255}
256
257sub closedir {
258 usage "closedir(dirhandle)" if @_ != 1;
259 closedir($_[0]);
a0d0e21e 260}
261
262sub opendir {
263 usage "opendir(directory)" if @_ != 1;
c07a80fd 264 my $dirhandle = gensym;
a0d0e21e 265 opendir($dirhandle, $_[0])
266 ? $dirhandle
4633a7c4 267 : undef;
a0d0e21e 268}
269
270sub readdir {
271 usage "readdir(dirhandle)" if @_ != 1;
272 readdir($_[0]);
273}
274
275sub rewinddir {
276 usage "rewinddir(dirhandle)" if @_ != 1;
277 rewinddir($_[0]);
278}
279
280sub errno {
281 usage "errno()" if @_ != 0;
282 $! + 0;
283}
284
285sub creat {
286 usage "creat(filename, mode)" if @_ != 2;
94b6baf5 287 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
a0d0e21e 288}
289
290sub fcntl {
291 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
292 fcntl($_[0], $_[1], $_[2]);
293}
294
295sub getgrgid {
296 usage "getgrgid(gid)" if @_ != 1;
297 getgrgid($_[0]);
298}
299
300sub getgrnam {
301 usage "getgrnam(name)" if @_ != 1;
302 getgrnam($_[0]);
303}
304
305sub atan2 {
306 usage "atan2(x,y)" if @_ != 2;
307 atan2($_[0], $_[1]);
308}
309
310sub cos {
311 usage "cos(x)" if @_ != 1;
312 cos($_[0]);
313}
314
315sub exp {
316 usage "exp(x)" if @_ != 1;
317 exp($_[0]);
318}
319
320sub fabs {
321 usage "fabs(x)" if @_ != 1;
322 abs($_[0]);
323}
324
325sub log {
326 usage "log(x)" if @_ != 1;
327 log($_[0]);
328}
329
330sub pow {
331 usage "pow(x,exponent)" if @_ != 2;
332 $_[0] ** $_[1];
333}
334
335sub sin {
336 usage "sin(x)" if @_ != 1;
337 sin($_[0]);
338}
339
340sub sqrt {
341 usage "sqrt(x)" if @_ != 1;
342 sqrt($_[0]);
343}
344
a0d0e21e 345sub getpwnam {
346 usage "getpwnam(name)" if @_ != 1;
347 getpwnam($_[0]);
348}
349
350sub getpwuid {
351 usage "getpwuid(uid)" if @_ != 1;
352 getpwuid($_[0]);
353}
354
355sub longjmp {
356 unimpl "longjmp() is C-specific: use die instead";
357}
358
359sub setjmp {
360 unimpl "setjmp() is C-specific: use eval {} instead";
361}
362
363sub siglongjmp {
364 unimpl "siglongjmp() is C-specific: use die instead";
365}
366
367sub sigsetjmp {
368 unimpl "sigsetjmp() is C-specific: use eval {} instead";
369}
370
371sub kill {
372 usage "kill(pid, sig)" if @_ != 2;
373 kill $_[1], $_[0];
374}
375
376sub raise {
377 usage "raise(sig)" if @_ != 1;
378 kill $$, $_[0]; # Is this good enough?
379}
380
381sub offsetof {
382 unimpl "offsetof() is C-specific, stopped";
383}
384
385sub clearerr {
37120919 386 redef "FileHandle::clearerr()";
a0d0e21e 387}
388
389sub fclose {
37120919 390 redef "FileHandle::close()";
a0d0e21e 391}
392
393sub fdopen {
37120919 394 redef "FileHandle::new_from_fd()";
a0d0e21e 395}
396
397sub feof {
37120919 398 redef "FileHandle::eof()";
a0d0e21e 399}
400
401sub fgetc {
37120919 402 redef "FileHandle::getc()";
a0d0e21e 403}
404
405sub fgets {
37120919 406 redef "FileHandle::gets()";
a0d0e21e 407}
408
409sub fileno {
37120919 410 redef "FileHandle::fileno()";
a0d0e21e 411}
412
413sub fopen {
37120919 414 redef "FileHandle::open()";
a0d0e21e 415}
416
417sub fprintf {
418 unimpl "fprintf() is C-specific--use printf instead";
419}
420
421sub fputc {
422 unimpl "fputc() is C-specific--use print instead";
423}
424
425sub fputs {
426 unimpl "fputs() is C-specific--use print instead";
427}
428
429sub fread {
430 unimpl "fread() is C-specific--use read instead";
431}
432
433sub freopen {
434 unimpl "freopen() is C-specific--use open instead";
435}
436
437sub fscanf {
438 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
439}
440
441sub fseek {
37120919 442 redef "FileHandle::seek()";
a0d0e21e 443}
444
445sub ferror {
37120919 446 redef "FileHandle::error()";
a0d0e21e 447}
448
449sub fflush {
37120919 450 redef "FileHandle::flush()";
a0d0e21e 451}
452
453sub fgetpos {
37120919 454 redef "FileHandle::getpos()";
a0d0e21e 455}
456
457sub fsetpos {
37120919 458 redef "FileHandle::setpos()";
a0d0e21e 459}
460
461sub ftell {
37120919 462 redef "FileHandle::tell()";
a0d0e21e 463}
464
465sub fwrite {
466 unimpl "fwrite() is C-specific--use print instead";
467}
468
469sub getc {
470 usage "getc(handle)" if @_ != 1;
471 getc($_[0]);
472}
473
474sub getchar {
475 usage "getchar()" if @_ != 0;
476 getc(STDIN);
477}
478
479sub gets {
480 usage "gets()" if @_ != 0;
481 scalar <STDIN>;
482}
483
484sub perror {
485 print STDERR "@_: " if @_;
486 print STDERR $!,"\n";
487}
488
489sub printf {
490 usage "printf(pattern, args...)" if @_ < 1;
491 printf STDOUT @_;
492}
493
494sub putc {
495 unimpl "putc() is C-specific--use print instead";
496}
497
498sub putchar {
499 unimpl "putchar() is C-specific--use print instead";
500}
501
502sub puts {
503 unimpl "puts() is C-specific--use print instead";
504}
505
506sub remove {
507 usage "remove(filename)" if @_ != 1;
508 unlink($_[0]);
509}
510
511sub rename {
512 usage "rename(oldfilename, newfilename)" if @_ != 2;
513 rename($_[0], $_[1]);
514}
515
516sub rewind {
517 usage "rewind(filehandle)" if @_ != 1;
518 seek($_[0],0,0);
519}
520
521sub scanf {
522 unimpl "scanf() is C-specific--use <> and regular expressions instead";
523}
524
525sub sprintf {
526 usage "sprintf(pattern,args)" if @_ == 0;
527 sprintf(shift,@_);
528}
529
530sub sscanf {
531 unimpl "sscanf() is C-specific--use regular expressions instead";
532}
533
534sub tmpfile {
37120919 535 redef "FileHandle::new_tmpfile()";
a0d0e21e 536}
537
538sub ungetc {
37120919 539 redef "FileHandle::ungetc()";
a0d0e21e 540}
541
542sub vfprintf {
543 unimpl "vfprintf() is C-specific";
544}
545
546sub vprintf {
547 unimpl "vprintf() is C-specific";
548}
549
550sub vsprintf {
551 unimpl "vsprintf() is C-specific";
552}
553
554sub abs {
555 usage "abs(x)" if @_ != 1;
556 abs($_[0]);
557}
558
559sub atexit {
560 unimpl "atexit() is C-specific: use END {} instead";
561}
562
563sub atof {
564 unimpl "atof() is C-specific, stopped";
565}
566
567sub atoi {
568 unimpl "atoi() is C-specific, stopped";
569}
570
571sub atol {
572 unimpl "atol() is C-specific, stopped";
573}
574
575sub bsearch {
37120919 576 unimpl "bsearch() not supplied";
a0d0e21e 577}
578
579sub calloc {
580 unimpl "calloc() is C-specific, stopped";
581}
582
583sub div {
584 unimpl "div() is C-specific, stopped";
585}
586
587sub exit {
588 usage "exit(status)" if @_ != 1;
589 exit($_[0]);
590}
591
592sub free {
593 unimpl "free() is C-specific, stopped";
a0d0e21e 594}
595
596sub getenv {
597 usage "getenv(name)" if @_ != 1;
598 $ENV{$_[0]};
599}
600
601sub labs {
602 unimpl "labs() is C-specific, use abs instead";
603}
604
605sub ldiv {
606 unimpl "ldiv() is C-specific, use / and int instead";
607}
608
609sub malloc {
610 unimpl "malloc() is C-specific, stopped";
611}
612
613sub qsort {
614 unimpl "qsort() is C-specific, use sort instead";
615}
616
617sub rand {
618 unimpl "rand() is non-portable, use Perl's rand instead";
619}
620
621sub realloc {
622 unimpl "realloc() is C-specific, stopped";
623}
624
625sub srand {
626 unimpl "srand()";
627}
628
629sub strtod {
630 unimpl "strtod() is C-specific, stopped";
631}
632
633sub strtol {
634 unimpl "strtol() is C-specific, stopped";
635}
636
637sub stroul {
638 unimpl "stroul() is C-specific, stopped";
639}
640
641sub system {
642 usage "system(command)" if @_ != 1;
643 system($_[0]);
644}
645
646sub memchr {
647 unimpl "memchr() is C-specific, use index() instead";
648}
649
650sub memcmp {
651 unimpl "memcmp() is C-specific, use eq instead";
652}
653
654sub memcpy {
655 unimpl "memcpy() is C-specific, use = instead";
37120919 656}
a0d0e21e 657
658sub memmove {
659 unimpl "memmove() is C-specific, use = instead";
660}
661
662sub memset {
663 unimpl "memset() is C-specific, use x instead";
664}
665
666sub strcat {
667 unimpl "strcat() is C-specific, use .= instead";
668}
669
670sub strchr {
671 unimpl "strchr() is C-specific, use index() instead";
672}
673
674sub strcmp {
675 unimpl "strcmp() is C-specific, use eq instead";
676}
677
678sub strcpy {
679 unimpl "strcpy() is C-specific, use = instead";
680}
681
682sub strcspn {
683 unimpl "strcspn() is C-specific, use regular expressions instead";
684}
685
686sub strerror {
687 usage "strerror(errno)" if @_ != 1;
688 local $! = $_[0];
689 $! . "";
690}
691
692sub strlen {
693 unimpl "strlen() is C-specific, use length instead";
694}
695
696sub strncat {
697 unimpl "strncat() is C-specific, use .= instead";
698}
699
700sub strncmp {
701 unimpl "strncmp() is C-specific, use eq instead";
702}
703
704sub strncpy {
705 unimpl "strncpy() is C-specific, use = instead";
706}
707
708sub strpbrk {
709 unimpl "strpbrk() is C-specific, stopped";
710}
711
712sub strrchr {
713 unimpl "strrchr() is C-specific, use rindex() instead";
714}
715
716sub strspn {
717 unimpl "strspn() is C-specific, stopped";
718}
719
720sub strstr {
721 usage "strstr(big, little)" if @_ != 2;
722 index($_[0], $_[1]);
723}
724
725sub strtok {
726 unimpl "strtok() is C-specific, stopped";
727}
728
729sub chmod {
3b35bae3 730 usage "chmod(mode, filename)" if @_ != 2;
a0d0e21e 731 chmod($_[0], $_[1]);
732}
733
734sub fstat {
735 usage "fstat(fd)" if @_ != 1;
c07a80fd 736 local *TMP;
a0d0e21e 737 open(TMP, "<&$_[0]"); # Gross.
c07a80fd 738 my @l = stat(TMP);
a0d0e21e 739 close(TMP);
740 @l;
741}
742
743sub mkdir {
744 usage "mkdir(directoryname, mode)" if @_ != 2;
745 mkdir($_[0], $_[1]);
746}
747
748sub stat {
749 usage "stat(filename)" if @_ != 1;
750 stat($_[0]);
751}
752
753sub umask {
754 usage "umask(mask)" if @_ != 1;
755 umask($_[0]);
756}
757
a0d0e21e 758sub wait {
cb1a09d0 759 usage "wait()" if @_ != 0;
760 wait();
a0d0e21e 761}
762
763sub waitpid {
cb1a09d0 764 usage "waitpid(pid, options)" if @_ != 2;
765 waitpid($_[0], $_[1]);
a0d0e21e 766}
767
768sub gmtime {
769 usage "gmtime(time)" if @_ != 1;
770 gmtime($_[0]);
771}
772
773sub localtime {
774 usage "localtime(time)" if @_ != 1;
775 localtime($_[0]);
776}
777
778sub time {
37120919 779 usage "time()" if @_ != 0;
a0d0e21e 780 time;
781}
782
783sub alarm {
784 usage "alarm(seconds)" if @_ != 1;
785 alarm($_[0]);
786}
787
788sub chdir {
789 usage "chdir(directory)" if @_ != 1;
790 chdir($_[0]);
791}
792
793sub chown {
794 usage "chown(filename, uid, gid)" if @_ != 3;
795 chown($_[0], $_[1], $_[2]);
796}
797
798sub execl {
799 unimpl "execl() is C-specific, stopped";
a0d0e21e 800}
801
802sub execle {
803 unimpl "execle() is C-specific, stopped";
a0d0e21e 804}
805
806sub execlp {
807 unimpl "execlp() is C-specific, stopped";
a0d0e21e 808}
809
810sub execv {
811 unimpl "execv() is C-specific, stopped";
a0d0e21e 812}
813
814sub execve {
815 unimpl "execve() is C-specific, stopped";
a0d0e21e 816}
817
818sub execvp {
819 unimpl "execvp() is C-specific, stopped";
a0d0e21e 820}
821
822sub fork {
823 usage "fork()" if @_ != 0;
824 fork;
825}
826
827sub getcwd
828{
829 usage "getcwd()" if @_ != 0;
830 chop($cwd = `pwd`);
831 $cwd;
832}
833
834sub getegid {
835 usage "getegid()" if @_ != 0;
836 $) + 0;
837}
838
839sub geteuid {
840 usage "geteuid()" if @_ != 0;
841 $> + 0;
842}
843
844sub getgid {
845 usage "getgid()" if @_ != 0;
846 $( + 0;
847}
848
849sub getgroups {
850 usage "getgroups()" if @_ != 0;
c07a80fd 851 my %seen;
a0d0e21e 852 grep(!$seen{$_}++, split(' ', $) ));
853}
854
855sub getlogin {
856 usage "getlogin()" if @_ != 0;
857 getlogin();
858}
859
860sub getpgrp {
861 usage "getpgrp()" if @_ != 0;
862 getpgrp($_[0]);
863}
864
865sub getpid {
866 usage "getpid()" if @_ != 0;
867 $$;
868}
869
870sub getppid {
871 usage "getppid()" if @_ != 0;
872 getppid;
873}
874
875sub getuid {
876 usage "getuid()" if @_ != 0;
877 $<;
878}
879
880sub isatty {
881 usage "isatty(filehandle)" if @_ != 1;
882 -t $_[0];
883}
884
885sub link {
886 usage "link(oldfilename, newfilename)" if @_ != 2;
887 link($_[0], $_[1]);
888}
889
890sub rmdir {
891 usage "rmdir(directoryname)" if @_ != 1;
892 rmdir($_[0]);
893}
894
895sub setgid {
896 usage "setgid(gid)" if @_ != 1;
897 $( = $_[0];
898}
899
900sub setuid {
901 usage "setuid(uid)" if @_ != 1;
902 $< = $_[0];
903}
904
905sub sleep {
906 usage "sleep(seconds)" if @_ != 1;
907 sleep($_[0]);
908}
909
910sub unlink {
911 usage "unlink(filename)" if @_ != 1;
912 unlink($_[0]);
913}
914
915sub utime {
916 usage "utime(filename, atime, mtime)" if @_ != 3;
917 utime($_[1], $_[2], $_[0]);
918}
919