This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Add missing export of "nice" to ext/POSIX/POSIX.pm (Phil Tait)
[perl5.git] / ext / POSIX / POSIX.pm
CommitLineData
a0d0e21e
LW
1package POSIX;
2
73c78b0a
PM
3use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD);
4
a0d0e21e 5use Carp;
3b35bae3 6use AutoLoader;
a0d0e21e 7require Config;
c07a80fd
PP
8use Symbol;
9
10require Exporter;
11require DynaLoader;
fec02dd3 12@ISA = qw(Exporter DynaLoader);
a0d0e21e 13
eea074c3 14$VERSION = "1.02" ;
c07a80fd 15
748a9306 16%EXPORT_TAGS = (
a0d0e21e 17
748a9306 18 assert_h => [qw(assert NDEBUG)],
a0d0e21e 19
748a9306
LW
20 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
21 isprint ispunct isspace isupper isxdigit tolower toupper)],
a0d0e21e 22
748a9306
LW
23 dirent_h => [qw()],
24
774d564b
PP
25 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
26 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
27 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
28 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
29 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
30 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
31 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
32 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
33 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
34 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
35 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
36 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
37 EUSERS EWOULDBLOCK EXDEV errno)],
a0d0e21e 38
748a9306 39 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
a0d0e21e
LW
40 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
41 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
42 O_RDONLY O_RDWR O_TRUNC O_WRONLY
43 creat
44 SEEK_CUR SEEK_END SEEK_SET
45 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
46 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
748a9306 47 S_IWGRP S_IWOTH S_IWUSR)],
a0d0e21e 48
748a9306 49 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
a0d0e21e
LW
50 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
51 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
52 FLT_DIG FLT_EPSILON FLT_MANT_DIG
53 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
54 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
55 FLT_RADIX FLT_ROUNDS
56 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
57 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
748a9306 58 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
a0d0e21e 59
748a9306 60 grp_h => [qw()],
a0d0e21e 61
748a9306 62 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
a0d0e21e
LW
63 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
64 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
65 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
66 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
67 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
68 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
69 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
70 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
748a9306 71 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
a0d0e21e 72
748a9306
LW
73 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
74 LC_TIME NULL localeconv setlocale)],
a0d0e21e 75
748a9306 76 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
3b35bae3 77 frexp ldexp log10 modf pow sinh tan tanh)],
a0d0e21e 78
748a9306 79 pwd_h => [qw()],
a0d0e21e 80
748a9306 81 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
a0d0e21e 82
774d564b
PP
83 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
84 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
85 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
86 SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN
87 SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR
88 SIG_IGN SIG_SETMASK SIG_UNBLOCK raise sigaction signal
89 sigpending sigprocmask sigsuspend)],
a0d0e21e 90
748a9306 91 stdarg_h => [qw()],
a0d0e21e 92
748a9306 93 stddef_h => [qw(NULL offsetof)],
a0d0e21e 94
748a9306 95 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
c07a80fd
PP
96 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
97 STREAM_MAX TMP_MAX stderr stdin stdout
a0d0e21e
LW
98 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
99 fgets fopen fprintf fputc fputs fread freopen
100 fscanf fseek fsetpos ftell fwrite getchar gets
101 perror putc putchar puts remove rewind
102 scanf setbuf setvbuf sscanf tmpfile tmpnam
748a9306 103 ungetc vfprintf vprintf vsprintf)],
a0d0e21e 104
748a9306 105 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
a0d0e21e
LW
106 abort atexit atof atoi atol bsearch calloc div
107 free getenv labs ldiv malloc mblen mbstowcs mbtowc
a89d8a78 108 qsort realloc strtod strtol strtoul wcstombs wctomb)],
a0d0e21e 109
748a9306 110 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
a0d0e21e
LW
111 strchr strcmp strcoll strcpy strcspn strerror strlen
112 strncat strncmp strncpy strpbrk strrchr strspn strstr
748a9306 113 strtok strxfrm)],
a0d0e21e 114
748a9306 115 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
a0d0e21e
LW
116 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
117 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
748a9306 118 fstat mkfifo)],
a0d0e21e 119
748a9306 120 sys_times_h => [qw()],
a0d0e21e 121
748a9306 122 sys_types_h => [qw()],
a0d0e21e 123
748a9306 124 sys_utsname_h => [qw(uname)],
a0d0e21e 125
748a9306
LW
126 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
127 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
a0d0e21e 128
748a9306 129 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
a0d0e21e
LW
130 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
131 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
132 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
133 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
134 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
135 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
136 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
137 VSTOP VSUSP VTIME
138 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
748a9306 139 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
a0d0e21e 140
748a9306
LW
141 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
142 difftime mktime strftime tzset tzname)],
a0d0e21e 143
748a9306 144 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
a0d0e21e
LW
145 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
146 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
147 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
148 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
149 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
150 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
151 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
152 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
153 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
154 _exit access ctermid cuserid
155 dup2 dup execl execle execlp execv execve execvp
156 fpathconf getcwd getegid geteuid getgid getgroups
157 getpid getuid isatty lseek pathconf pause setgid setpgid
748a9306 158 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
a0d0e21e 159
748a9306 160 utime_h => [qw()],
a0d0e21e 161
748a9306 162);
a0d0e21e 163
748a9306 164Exporter::export_tags();
a0d0e21e
LW
165
166@EXPORT_OK = qw(
167 closedir opendir readdir rewinddir
168 fcntl open
169 getgrgid getgrnam
3b35bae3 170 atan2 cos exp log sin sqrt
a0d0e21e
LW
171 getpwnam getpwuid
172 kill
173 fileno getc printf rename sprintf
174 abs exit rand srand system
175 chmod mkdir stat umask
176 times
177 wait waitpid
178 gmtime localtime time
179 alarm chdir chown close fork getlogin getppid getpgrp link
180 pipe read rmdir sleep unlink write
181 utime
2676273e 182 nice
a0d0e21e
LW
183);
184
748a9306 185# Grandfather old foo_h form to new :foo_h form
a0d0e21e
LW
186sub import {
187 my $this = shift;
748a9306 188 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
a0d0e21e
LW
189 local $Exporter::ExportLevel = 1;
190 Exporter::import($this,@list);
191}
192
4633a7c4 193
73c78b0a 194bootstrap POSIX $VERSION;
4633a7c4
LW
195
196my $EINVAL = constant("EINVAL", 0);
197my $EAGAIN = constant("EAGAIN", 0);
198
a0d0e21e
LW
199sub AUTOLOAD {
200 if ($AUTOLOAD =~ /::(_?[a-z])/) {
201 $AutoLoader::AUTOLOAD = $AUTOLOAD;
202 goto &AutoLoader::AUTOLOAD
203 }
4633a7c4
LW
204 local $! = 0;
205 my $constname = $AUTOLOAD;
a0d0e21e 206 $constname =~ s/.*:://;
3f73d1e9 207 my $val = constant($constname, @_ ? $_[0] : 0);
4633a7c4
LW
208 if ($! == 0) {
209 *$AUTOLOAD = sub { $val };
210 }
211 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
212 *$AUTOLOAD = sub { constant($constname, $_[0]) };
213 }
214 elsif ($! == $EINVAL) {
215 croak "$constname is not a valid POSIX macro";
a0d0e21e 216 }
4633a7c4
LW
217 else {
218 croak "Your vendor has not defined POSIX macro $constname, used";
219 }
220
a0d0e21e
LW
221 goto &$AUTOLOAD;
222}
223
a0d0e21e 224sub usage {
c07a80fd 225 my ($mess) = @_;
a0d0e21e
LW
226 croak "Usage: POSIX::$mess";
227}
228
229sub redef {
c07a80fd 230 my ($mess) = @_;
a0d0e21e
LW
231 croak "Use method $mess instead";
232}
233
234sub unimpl {
c07a80fd 235 my ($mess) = @_;
a0d0e21e
LW
236 $mess =~ s/xxx//;
237 croak "Unimplemented: POSIX::$mess";
238}
239
a0d0e21e
LW
240############################
241package POSIX::SigAction;
242
243sub new {
28757baa 244 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
a0d0e21e
LW
245}
246
247############################
a0d0e21e
LW
248package POSIX; # return to package POSIX so AutoSplit is happy
2491;
250__END__
251
252sub assert {
253 usage "assert(expr)" if @_ != 1;
254 if (!$_[0]) {
255 croak "Assertion failed";
256 }
257}
258
259sub tolower {
260 usage "tolower(string)" if @_ != 1;
261 lc($_[0]);
262}
263
264sub toupper {
265 usage "toupper(string)" if @_ != 1;
266 uc($_[0]);
267}
268
269sub closedir {
270 usage "closedir(dirhandle)" if @_ != 1;
271 closedir($_[0]);
a0d0e21e
LW
272}
273
274sub opendir {
275 usage "opendir(directory)" if @_ != 1;
c07a80fd 276 my $dirhandle = gensym;
a0d0e21e
LW
277 opendir($dirhandle, $_[0])
278 ? $dirhandle
4633a7c4 279 : undef;
a0d0e21e
LW
280}
281
282sub readdir {
283 usage "readdir(dirhandle)" if @_ != 1;
284 readdir($_[0]);
285}
286
287sub rewinddir {
288 usage "rewinddir(dirhandle)" if @_ != 1;
289 rewinddir($_[0]);
290}
291
292sub errno {
293 usage "errno()" if @_ != 0;
294 $! + 0;
295}
296
297sub creat {
298 usage "creat(filename, mode)" if @_ != 2;
94b6baf5 299 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
a0d0e21e
LW
300}
301
302sub fcntl {
303 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
304 fcntl($_[0], $_[1], $_[2]);
305}
306
307sub getgrgid {
308 usage "getgrgid(gid)" if @_ != 1;
309 getgrgid($_[0]);
310}
311
312sub getgrnam {
313 usage "getgrnam(name)" if @_ != 1;
314 getgrnam($_[0]);
315}
316
317sub atan2 {
318 usage "atan2(x,y)" if @_ != 2;
319 atan2($_[0], $_[1]);
320}
321
322sub cos {
323 usage "cos(x)" if @_ != 1;
324 cos($_[0]);
325}
326
327sub exp {
328 usage "exp(x)" if @_ != 1;
329 exp($_[0]);
330}
331
332sub fabs {
333 usage "fabs(x)" if @_ != 1;
334 abs($_[0]);
335}
336
337sub log {
338 usage "log(x)" if @_ != 1;
339 log($_[0]);
340}
341
342sub pow {
343 usage "pow(x,exponent)" if @_ != 2;
344 $_[0] ** $_[1];
345}
346
347sub sin {
348 usage "sin(x)" if @_ != 1;
349 sin($_[0]);
350}
351
352sub sqrt {
353 usage "sqrt(x)" if @_ != 1;
354 sqrt($_[0]);
355}
356
a0d0e21e
LW
357sub getpwnam {
358 usage "getpwnam(name)" if @_ != 1;
359 getpwnam($_[0]);
360}
361
362sub getpwuid {
363 usage "getpwuid(uid)" if @_ != 1;
364 getpwuid($_[0]);
365}
366
367sub longjmp {
368 unimpl "longjmp() is C-specific: use die instead";
369}
370
371sub setjmp {
372 unimpl "setjmp() is C-specific: use eval {} instead";
373}
374
375sub siglongjmp {
376 unimpl "siglongjmp() is C-specific: use die instead";
377}
378
379sub sigsetjmp {
380 unimpl "sigsetjmp() is C-specific: use eval {} instead";
381}
382
383sub kill {
384 usage "kill(pid, sig)" if @_ != 2;
385 kill $_[1], $_[0];
386}
387
388sub raise {
389 usage "raise(sig)" if @_ != 1;
eea074c3 390 kill $_[0], $$; # Is this good enough?
a0d0e21e
LW
391}
392
393sub offsetof {
394 unimpl "offsetof() is C-specific, stopped";
395}
396
397sub clearerr {
28757baa 398 redef "IO::Handle::clearerr()";
a0d0e21e
LW
399}
400
401sub fclose {
28757baa 402 redef "IO::Handle::close()";
a0d0e21e
LW
403}
404
405sub fdopen {
28757baa 406 redef "IO::Handle::new_from_fd()";
a0d0e21e
LW
407}
408
409sub feof {
28757baa 410 redef "IO::Handle::eof()";
a0d0e21e
LW
411}
412
413sub fgetc {
28757baa 414 redef "IO::Handle::getc()";
a0d0e21e
LW
415}
416
417sub fgets {
28757baa 418 redef "IO::Handle::gets()";
a0d0e21e
LW
419}
420
421sub fileno {
28757baa 422 redef "IO::Handle::fileno()";
a0d0e21e
LW
423}
424
425sub fopen {
28757baa 426 redef "IO::File::open()";
a0d0e21e
LW
427}
428
429sub fprintf {
430 unimpl "fprintf() is C-specific--use printf instead";
431}
432
433sub fputc {
434 unimpl "fputc() is C-specific--use print instead";
435}
436
437sub fputs {
438 unimpl "fputs() is C-specific--use print instead";
439}
440
441sub fread {
442 unimpl "fread() is C-specific--use read instead";
443}
444
445sub freopen {
446 unimpl "freopen() is C-specific--use open instead";
447}
448
449sub fscanf {
450 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
451}
452
453sub fseek {
28757baa 454 redef "IO::Seekable::seek()";
a0d0e21e
LW
455}
456
457sub ferror {
28757baa 458 redef "IO::Handle::error()";
a0d0e21e
LW
459}
460
461sub fflush {
28757baa 462 redef "IO::Handle::flush()";
a0d0e21e
LW
463}
464
465sub fgetpos {
28757baa 466 redef "IO::Seekable::getpos()";
a0d0e21e
LW
467}
468
469sub fsetpos {
28757baa 470 redef "IO::Seekable::setpos()";
a0d0e21e
LW
471}
472
473sub ftell {
28757baa 474 redef "IO::Seekable::tell()";
a0d0e21e
LW
475}
476
477sub fwrite {
478 unimpl "fwrite() is C-specific--use print instead";
479}
480
481sub getc {
482 usage "getc(handle)" if @_ != 1;
483 getc($_[0]);
484}
485
486sub getchar {
487 usage "getchar()" if @_ != 0;
488 getc(STDIN);
489}
490
491sub gets {
492 usage "gets()" if @_ != 0;
493 scalar <STDIN>;
494}
495
496sub perror {
497 print STDERR "@_: " if @_;
498 print STDERR $!,"\n";
499}
500
501sub printf {
502 usage "printf(pattern, args...)" if @_ < 1;
503 printf STDOUT @_;
504}
505
506sub putc {
507 unimpl "putc() is C-specific--use print instead";
508}
509
510sub putchar {
511 unimpl "putchar() is C-specific--use print instead";
512}
513
514sub puts {
515 unimpl "puts() is C-specific--use print instead";
516}
517
518sub remove {
519 usage "remove(filename)" if @_ != 1;
520 unlink($_[0]);
521}
522
523sub rename {
524 usage "rename(oldfilename, newfilename)" if @_ != 2;
525 rename($_[0], $_[1]);
526}
527
528sub rewind {
529 usage "rewind(filehandle)" if @_ != 1;
530 seek($_[0],0,0);
531}
532
533sub scanf {
534 unimpl "scanf() is C-specific--use <> and regular expressions instead";
535}
536
537sub sprintf {
538 usage "sprintf(pattern,args)" if @_ == 0;
539 sprintf(shift,@_);
540}
541
542sub sscanf {
543 unimpl "sscanf() is C-specific--use regular expressions instead";
544}
545
546sub tmpfile {
28757baa 547 redef "IO::File::new_tmpfile()";
a0d0e21e
LW
548}
549
550sub ungetc {
28757baa 551 redef "IO::Handle::ungetc()";
a0d0e21e
LW
552}
553
554sub vfprintf {
555 unimpl "vfprintf() is C-specific";
556}
557
558sub vprintf {
559 unimpl "vprintf() is C-specific";
560}
561
562sub vsprintf {
563 unimpl "vsprintf() is C-specific";
564}
565
566sub abs {
567 usage "abs(x)" if @_ != 1;
568 abs($_[0]);
569}
570
571sub atexit {
572 unimpl "atexit() is C-specific: use END {} instead";
573}
574
575sub atof {
576 unimpl "atof() is C-specific, stopped";
577}
578
579sub atoi {
580 unimpl "atoi() is C-specific, stopped";
581}
582
583sub atol {
584 unimpl "atol() is C-specific, stopped";
585}
586
587sub bsearch {
37120919 588 unimpl "bsearch() not supplied";
a0d0e21e
LW
589}
590
591sub calloc {
592 unimpl "calloc() is C-specific, stopped";
593}
594
595sub div {
596 unimpl "div() is C-specific, stopped";
597}
598
599sub exit {
600 usage "exit(status)" if @_ != 1;
601 exit($_[0]);
602}
603
604sub free {
605 unimpl "free() is C-specific, stopped";
a0d0e21e
LW
606}
607
608sub getenv {
609 usage "getenv(name)" if @_ != 1;
610 $ENV{$_[0]};
611}
612
613sub labs {
614 unimpl "labs() is C-specific, use abs instead";
615}
616
617sub ldiv {
618 unimpl "ldiv() is C-specific, use / and int instead";
619}
620
621sub malloc {
622 unimpl "malloc() is C-specific, stopped";
623}
624
625sub qsort {
626 unimpl "qsort() is C-specific, use sort instead";
627}
628
629sub rand {
630 unimpl "rand() is non-portable, use Perl's rand instead";
631}
632
633sub realloc {
634 unimpl "realloc() is C-specific, stopped";
635}
636
637sub srand {
638 unimpl "srand()";
639}
640
a0d0e21e
LW
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
LW
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
LW
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
LW
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
AD
759 usage "wait()" if @_ != 0;
760 wait();
a0d0e21e
LW
761}
762
763sub waitpid {
cb1a09d0
AD
764 usage "waitpid(pid, options)" if @_ != 2;
765 waitpid($_[0], $_[1]);
a0d0e21e
LW
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
LW
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
LW
800}
801
802sub execle {
803 unimpl "execle() is C-specific, stopped";
a0d0e21e
LW
804}
805
806sub execlp {
807 unimpl "execlp() is C-specific, stopped";
a0d0e21e
LW
808}
809
810sub execv {
811 unimpl "execv() is C-specific, stopped";
a0d0e21e
LW
812}
813
814sub execve {
815 unimpl "execve() is C-specific, stopped";
a0d0e21e
LW
816}
817
818sub execvp {
819 unimpl "execvp() is C-specific, stopped";
a0d0e21e
LW
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
LW
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