This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
integrate cfgperl contents into mainline
[perl5.git] / ext / POSIX / POSIX.pm
CommitLineData
a0d0e21e
LW
1package POSIX;
2
17f410f9 3our(@ISA, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD) = ();
73c78b0a 4
a0d0e21e 5use Carp;
3b35bae3 6use AutoLoader;
a0d0e21e 7require Config;
c07a80fd
PP
8use Symbol;
9
10require Exporter;
9426adcd
IZ
11use XSLoader ();
12@ISA = qw(Exporter);
a0d0e21e 13
17f410f9 14our $VERSION = "1.03" ;
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
4670cb3e 71 _POSIX_STREAM_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
76b4e777 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
e3d0cac0
IZ
164# Exporter::export_tags();
165for (values %EXPORT_TAGS) {
166 push @EXPORT, @$_;
167}
a0d0e21e
LW
168
169@EXPORT_OK = qw(
170 closedir opendir readdir rewinddir
171 fcntl open
172 getgrgid getgrnam
3b35bae3 173 atan2 cos exp log sin sqrt
a0d0e21e
LW
174 getpwnam getpwuid
175 kill
176 fileno getc printf rename sprintf
177 abs exit rand srand system
178 chmod mkdir stat umask
179 times
180 wait waitpid
181 gmtime localtime time
182 alarm chdir chown close fork getlogin getppid getpgrp link
183 pipe read rmdir sleep unlink write
184 utime
2676273e 185 nice
a0d0e21e
LW
186);
187
748a9306 188# Grandfather old foo_h form to new :foo_h form
a0d0e21e
LW
189sub import {
190 my $this = shift;
748a9306 191 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
a0d0e21e
LW
192 local $Exporter::ExportLevel = 1;
193 Exporter::import($this,@list);
194}
195
4633a7c4 196
9426adcd 197XSLoader::load 'POSIX', $VERSION;
4633a7c4
LW
198
199my $EINVAL = constant("EINVAL", 0);
200my $EAGAIN = constant("EAGAIN", 0);
201
a0d0e21e
LW
202sub AUTOLOAD {
203 if ($AUTOLOAD =~ /::(_?[a-z])/) {
204 $AutoLoader::AUTOLOAD = $AUTOLOAD;
205 goto &AutoLoader::AUTOLOAD
206 }
4633a7c4
LW
207 local $! = 0;
208 my $constname = $AUTOLOAD;
a0d0e21e 209 $constname =~ s/.*:://;
3f73d1e9 210 my $val = constant($constname, @_ ? $_[0] : 0);
4633a7c4
LW
211 if ($! == 0) {
212 *$AUTOLOAD = sub { $val };
213 }
214 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
215 *$AUTOLOAD = sub { constant($constname, $_[0]) };
216 }
217 elsif ($! == $EINVAL) {
218 croak "$constname is not a valid POSIX macro";
a0d0e21e 219 }
4633a7c4
LW
220 else {
221 croak "Your vendor has not defined POSIX macro $constname, used";
222 }
223
a0d0e21e
LW
224 goto &$AUTOLOAD;
225}
226
a0d0e21e 227sub usage {
c07a80fd 228 my ($mess) = @_;
a0d0e21e
LW
229 croak "Usage: POSIX::$mess";
230}
231
232sub redef {
c07a80fd 233 my ($mess) = @_;
a0d0e21e
LW
234 croak "Use method $mess instead";
235}
236
237sub unimpl {
c07a80fd 238 my ($mess) = @_;
a0d0e21e
LW
239 $mess =~ s/xxx//;
240 croak "Unimplemented: POSIX::$mess";
241}
242
a0d0e21e
LW
243############################
244package POSIX::SigAction;
245
246sub new {
28757baa 247 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
a0d0e21e
LW
248}
249
250############################
a0d0e21e
LW
251package POSIX; # return to package POSIX so AutoSplit is happy
2521;
253__END__
254
255sub assert {
256 usage "assert(expr)" if @_ != 1;
257 if (!$_[0]) {
258 croak "Assertion failed";
259 }
260}
261
262sub tolower {
263 usage "tolower(string)" if @_ != 1;
264 lc($_[0]);
265}
266
267sub toupper {
268 usage "toupper(string)" if @_ != 1;
269 uc($_[0]);
270}
271
272sub closedir {
273 usage "closedir(dirhandle)" if @_ != 1;
b56ec344 274 CORE::closedir($_[0]);
a0d0e21e
LW
275}
276
277sub opendir {
278 usage "opendir(directory)" if @_ != 1;
c07a80fd 279 my $dirhandle = gensym;
b56ec344 280 CORE::opendir($dirhandle, $_[0])
a0d0e21e 281 ? $dirhandle
4633a7c4 282 : undef;
a0d0e21e
LW
283}
284
285sub readdir {
286 usage "readdir(dirhandle)" if @_ != 1;
b56ec344 287 CORE::readdir($_[0]);
a0d0e21e
LW
288}
289
290sub rewinddir {
291 usage "rewinddir(dirhandle)" if @_ != 1;
b56ec344 292 CORE::rewinddir($_[0]);
a0d0e21e
LW
293}
294
295sub errno {
296 usage "errno()" if @_ != 0;
297 $! + 0;
298}
299
300sub creat {
301 usage "creat(filename, mode)" if @_ != 2;
94b6baf5 302 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
a0d0e21e
LW
303}
304
305sub fcntl {
306 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
b56ec344 307 CORE::fcntl($_[0], $_[1], $_[2]);
a0d0e21e
LW
308}
309
310sub getgrgid {
311 usage "getgrgid(gid)" if @_ != 1;
b56ec344 312 CORE::getgrgid($_[0]);
a0d0e21e
LW
313}
314
315sub getgrnam {
316 usage "getgrnam(name)" if @_ != 1;
b56ec344 317 CORE::getgrnam($_[0]);
a0d0e21e
LW
318}
319
320sub atan2 {
321 usage "atan2(x,y)" if @_ != 2;
b56ec344 322 CORE::atan2($_[0], $_[1]);
a0d0e21e
LW
323}
324
325sub cos {
326 usage "cos(x)" if @_ != 1;
b56ec344 327 CORE::cos($_[0]);
a0d0e21e
LW
328}
329
330sub exp {
331 usage "exp(x)" if @_ != 1;
b56ec344 332 CORE::exp($_[0]);
a0d0e21e
LW
333}
334
335sub fabs {
336 usage "fabs(x)" if @_ != 1;
b56ec344 337 CORE::abs($_[0]);
a0d0e21e
LW
338}
339
340sub log {
341 usage "log(x)" if @_ != 1;
b56ec344 342 CORE::log($_[0]);
a0d0e21e
LW
343}
344
345sub pow {
346 usage "pow(x,exponent)" if @_ != 2;
347 $_[0] ** $_[1];
348}
349
350sub sin {
351 usage "sin(x)" if @_ != 1;
b56ec344 352 CORE::sin($_[0]);
a0d0e21e
LW
353}
354
355sub sqrt {
356 usage "sqrt(x)" if @_ != 1;
b56ec344 357 CORE::sqrt($_[0]);
a0d0e21e
LW
358}
359
a0d0e21e
LW
360sub getpwnam {
361 usage "getpwnam(name)" if @_ != 1;
b56ec344 362 CORE::getpwnam($_[0]);
a0d0e21e
LW
363}
364
365sub getpwuid {
366 usage "getpwuid(uid)" if @_ != 1;
b56ec344 367 CORE::getpwuid($_[0]);
a0d0e21e
LW
368}
369
370sub longjmp {
371 unimpl "longjmp() is C-specific: use die instead";
372}
373
374sub setjmp {
375 unimpl "setjmp() is C-specific: use eval {} instead";
376}
377
378sub siglongjmp {
379 unimpl "siglongjmp() is C-specific: use die instead";
380}
381
382sub sigsetjmp {
383 unimpl "sigsetjmp() is C-specific: use eval {} instead";
384}
385
386sub kill {
387 usage "kill(pid, sig)" if @_ != 2;
b56ec344 388 CORE::kill $_[1], $_[0];
a0d0e21e
LW
389}
390
391sub raise {
392 usage "raise(sig)" if @_ != 1;
b56ec344 393 CORE::kill $_[0], $$; # Is this good enough?
a0d0e21e
LW
394}
395
396sub offsetof {
397 unimpl "offsetof() is C-specific, stopped";
398}
399
400sub clearerr {
28757baa 401 redef "IO::Handle::clearerr()";
a0d0e21e
LW
402}
403
404sub fclose {
28757baa 405 redef "IO::Handle::close()";
a0d0e21e
LW
406}
407
408sub fdopen {
28757baa 409 redef "IO::Handle::new_from_fd()";
a0d0e21e
LW
410}
411
412sub feof {
28757baa 413 redef "IO::Handle::eof()";
a0d0e21e
LW
414}
415
416sub fgetc {
28757baa 417 redef "IO::Handle::getc()";
a0d0e21e
LW
418}
419
420sub fgets {
28757baa 421 redef "IO::Handle::gets()";
a0d0e21e
LW
422}
423
424sub fileno {
28757baa 425 redef "IO::Handle::fileno()";
a0d0e21e
LW
426}
427
428sub fopen {
28757baa 429 redef "IO::File::open()";
a0d0e21e
LW
430}
431
432sub fprintf {
433 unimpl "fprintf() is C-specific--use printf instead";
434}
435
436sub fputc {
437 unimpl "fputc() is C-specific--use print instead";
438}
439
440sub fputs {
441 unimpl "fputs() is C-specific--use print instead";
442}
443
444sub fread {
445 unimpl "fread() is C-specific--use read instead";
446}
447
448sub freopen {
449 unimpl "freopen() is C-specific--use open instead";
450}
451
452sub fscanf {
453 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
454}
455
456sub fseek {
28757baa 457 redef "IO::Seekable::seek()";
a0d0e21e
LW
458}
459
460sub ferror {
28757baa 461 redef "IO::Handle::error()";
a0d0e21e
LW
462}
463
464sub fflush {
28757baa 465 redef "IO::Handle::flush()";
a0d0e21e
LW
466}
467
468sub fgetpos {
28757baa 469 redef "IO::Seekable::getpos()";
a0d0e21e
LW
470}
471
472sub fsetpos {
28757baa 473 redef "IO::Seekable::setpos()";
a0d0e21e
LW
474}
475
476sub ftell {
28757baa 477 redef "IO::Seekable::tell()";
a0d0e21e
LW
478}
479
480sub fwrite {
481 unimpl "fwrite() is C-specific--use print instead";
482}
483
484sub getc {
485 usage "getc(handle)" if @_ != 1;
b56ec344 486 CORE::getc($_[0]);
a0d0e21e
LW
487}
488
489sub getchar {
490 usage "getchar()" if @_ != 0;
b56ec344 491 CORE::getc(STDIN);
a0d0e21e
LW
492}
493
494sub gets {
495 usage "gets()" if @_ != 0;
496 scalar <STDIN>;
497}
498
499sub perror {
500 print STDERR "@_: " if @_;
501 print STDERR $!,"\n";
502}
503
504sub printf {
505 usage "printf(pattern, args...)" if @_ < 1;
b56ec344 506 CORE::printf STDOUT @_;
a0d0e21e
LW
507}
508
509sub putc {
510 unimpl "putc() is C-specific--use print instead";
511}
512
513sub putchar {
514 unimpl "putchar() is C-specific--use print instead";
515}
516
517sub puts {
518 unimpl "puts() is C-specific--use print instead";
519}
520
521sub remove {
522 usage "remove(filename)" if @_ != 1;
b56ec344 523 CORE::unlink($_[0]);
a0d0e21e
LW
524}
525
526sub rename {
527 usage "rename(oldfilename, newfilename)" if @_ != 2;
b56ec344 528 CORE::rename($_[0], $_[1]);
a0d0e21e
LW
529}
530
531sub rewind {
532 usage "rewind(filehandle)" if @_ != 1;
b56ec344 533 CORE::seek($_[0],0,0);
a0d0e21e
LW
534}
535
536sub scanf {
537 unimpl "scanf() is C-specific--use <> and regular expressions instead";
538}
539
540sub sprintf {
541 usage "sprintf(pattern,args)" if @_ == 0;
b56ec344 542 CORE::sprintf(shift,@_);
a0d0e21e
LW
543}
544
545sub sscanf {
546 unimpl "sscanf() is C-specific--use regular expressions instead";
547}
548
549sub tmpfile {
28757baa 550 redef "IO::File::new_tmpfile()";
a0d0e21e
LW
551}
552
553sub ungetc {
28757baa 554 redef "IO::Handle::ungetc()";
a0d0e21e
LW
555}
556
557sub vfprintf {
558 unimpl "vfprintf() is C-specific";
559}
560
561sub vprintf {
562 unimpl "vprintf() is C-specific";
563}
564
565sub vsprintf {
566 unimpl "vsprintf() is C-specific";
567}
568
569sub abs {
570 usage "abs(x)" if @_ != 1;
b56ec344 571 CORE::abs($_[0]);
a0d0e21e
LW
572}
573
574sub atexit {
575 unimpl "atexit() is C-specific: use END {} instead";
576}
577
578sub atof {
579 unimpl "atof() is C-specific, stopped";
580}
581
582sub atoi {
583 unimpl "atoi() is C-specific, stopped";
584}
585
586sub atol {
587 unimpl "atol() is C-specific, stopped";
588}
589
590sub bsearch {
37120919 591 unimpl "bsearch() not supplied";
a0d0e21e
LW
592}
593
594sub calloc {
595 unimpl "calloc() is C-specific, stopped";
596}
597
598sub div {
599 unimpl "div() is C-specific, stopped";
600}
601
602sub exit {
603 usage "exit(status)" if @_ != 1;
b56ec344 604 CORE::exit($_[0]);
a0d0e21e
LW
605}
606
607sub free {
608 unimpl "free() is C-specific, stopped";
a0d0e21e
LW
609}
610
611sub getenv {
612 usage "getenv(name)" if @_ != 1;
613 $ENV{$_[0]};
614}
615
616sub labs {
617 unimpl "labs() is C-specific, use abs instead";
618}
619
620sub ldiv {
621 unimpl "ldiv() is C-specific, use / and int instead";
622}
623
624sub malloc {
625 unimpl "malloc() is C-specific, stopped";
626}
627
628sub qsort {
629 unimpl "qsort() is C-specific, use sort instead";
630}
631
632sub rand {
633 unimpl "rand() is non-portable, use Perl's rand instead";
634}
635
636sub realloc {
637 unimpl "realloc() is C-specific, stopped";
638}
639
640sub srand {
641 unimpl "srand()";
642}
643
a0d0e21e
LW
644sub system {
645 usage "system(command)" if @_ != 1;
b56ec344 646 CORE::system($_[0]);
a0d0e21e
LW
647}
648
649sub memchr {
650 unimpl "memchr() is C-specific, use index() instead";
651}
652
653sub memcmp {
654 unimpl "memcmp() is C-specific, use eq instead";
655}
656
657sub memcpy {
658 unimpl "memcpy() is C-specific, use = instead";
37120919 659}
a0d0e21e
LW
660
661sub memmove {
662 unimpl "memmove() is C-specific, use = instead";
663}
664
665sub memset {
666 unimpl "memset() is C-specific, use x instead";
667}
668
669sub strcat {
670 unimpl "strcat() is C-specific, use .= instead";
671}
672
673sub strchr {
674 unimpl "strchr() is C-specific, use index() instead";
675}
676
677sub strcmp {
678 unimpl "strcmp() is C-specific, use eq instead";
679}
680
681sub strcpy {
682 unimpl "strcpy() is C-specific, use = instead";
683}
684
685sub strcspn {
686 unimpl "strcspn() is C-specific, use regular expressions instead";
687}
688
689sub strerror {
690 usage "strerror(errno)" if @_ != 1;
691 local $! = $_[0];
692 $! . "";
693}
694
695sub strlen {
696 unimpl "strlen() is C-specific, use length instead";
697}
698
699sub strncat {
700 unimpl "strncat() is C-specific, use .= instead";
701}
702
703sub strncmp {
704 unimpl "strncmp() is C-specific, use eq instead";
705}
706
707sub strncpy {
708 unimpl "strncpy() is C-specific, use = instead";
709}
710
711sub strpbrk {
712 unimpl "strpbrk() is C-specific, stopped";
713}
714
715sub strrchr {
716 unimpl "strrchr() is C-specific, use rindex() instead";
717}
718
719sub strspn {
720 unimpl "strspn() is C-specific, stopped";
721}
722
723sub strstr {
724 usage "strstr(big, little)" if @_ != 2;
b56ec344 725 CORE::index($_[0], $_[1]);
a0d0e21e
LW
726}
727
728sub strtok {
729 unimpl "strtok() is C-specific, stopped";
730}
731
732sub chmod {
3b35bae3 733 usage "chmod(mode, filename)" if @_ != 2;
b56ec344 734 CORE::chmod($_[0], $_[1]);
a0d0e21e
LW
735}
736
737sub fstat {
738 usage "fstat(fd)" if @_ != 1;
c07a80fd 739 local *TMP;
a0d0e21e 740 open(TMP, "<&$_[0]"); # Gross.
b56ec344 741 my @l = CORE::stat(TMP);
a0d0e21e
LW
742 close(TMP);
743 @l;
744}
745
746sub mkdir {
747 usage "mkdir(directoryname, mode)" if @_ != 2;
b56ec344 748 CORE::mkdir($_[0], $_[1]);
a0d0e21e
LW
749}
750
751sub stat {
752 usage "stat(filename)" if @_ != 1;
b56ec344 753 CORE::stat($_[0]);
a0d0e21e
LW
754}
755
756sub umask {
757 usage "umask(mask)" if @_ != 1;
b56ec344 758 CORE::umask($_[0]);
a0d0e21e
LW
759}
760
a0d0e21e 761sub wait {
cb1a09d0 762 usage "wait()" if @_ != 0;
b56ec344 763 CORE::wait();
a0d0e21e
LW
764}
765
766sub waitpid {
cb1a09d0 767 usage "waitpid(pid, options)" if @_ != 2;
b56ec344 768 CORE::waitpid($_[0], $_[1]);
a0d0e21e
LW
769}
770
771sub gmtime {
772 usage "gmtime(time)" if @_ != 1;
b56ec344 773 CORE::gmtime($_[0]);
a0d0e21e
LW
774}
775
776sub localtime {
777 usage "localtime(time)" if @_ != 1;
b56ec344 778 CORE::localtime($_[0]);
a0d0e21e
LW
779}
780
781sub time {
37120919 782 usage "time()" if @_ != 0;
b56ec344 783 CORE::time;
a0d0e21e
LW
784}
785
786sub alarm {
787 usage "alarm(seconds)" if @_ != 1;
b56ec344 788 CORE::alarm($_[0]);
a0d0e21e
LW
789}
790
791sub chdir {
792 usage "chdir(directory)" if @_ != 1;
b56ec344 793 CORE::chdir($_[0]);
a0d0e21e
LW
794}
795
796sub chown {
797 usage "chown(filename, uid, gid)" if @_ != 3;
b56ec344 798 CORE::chown($_[0], $_[1], $_[2]);
a0d0e21e
LW
799}
800
801sub execl {
802 unimpl "execl() is C-specific, stopped";
a0d0e21e
LW
803}
804
805sub execle {
806 unimpl "execle() is C-specific, stopped";
a0d0e21e
LW
807}
808
809sub execlp {
810 unimpl "execlp() is C-specific, stopped";
a0d0e21e
LW
811}
812
813sub execv {
814 unimpl "execv() is C-specific, stopped";
a0d0e21e
LW
815}
816
817sub execve {
818 unimpl "execve() is C-specific, stopped";
a0d0e21e
LW
819}
820
821sub execvp {
822 unimpl "execvp() is C-specific, stopped";
a0d0e21e
LW
823}
824
825sub fork {
826 usage "fork()" if @_ != 0;
b56ec344 827 CORE::fork;
a0d0e21e
LW
828}
829
830sub getcwd
831{
832 usage "getcwd()" if @_ != 0;
6dead956
GS
833 if ($^O eq 'MSWin32') {
834 # this perhaps applies to everyone else also?
835 require Cwd;
836 $cwd = &Cwd::cwd;
837 }
838 else {
839 chop($cwd = `pwd`);
840 }
a0d0e21e
LW
841 $cwd;
842}
843
844sub getegid {
845 usage "getegid()" if @_ != 0;
846 $) + 0;
847}
848
849sub geteuid {
850 usage "geteuid()" if @_ != 0;
851 $> + 0;
852}
853
854sub getgid {
855 usage "getgid()" if @_ != 0;
856 $( + 0;
857}
858
859sub getgroups {
860 usage "getgroups()" if @_ != 0;
c07a80fd 861 my %seen;
a0d0e21e
LW
862 grep(!$seen{$_}++, split(' ', $) ));
863}
864
865sub getlogin {
866 usage "getlogin()" if @_ != 0;
b56ec344 867 CORE::getlogin();
a0d0e21e
LW
868}
869
870sub getpgrp {
871 usage "getpgrp()" if @_ != 0;
5507c093 872 CORE::getpgrp;
a0d0e21e
LW
873}
874
875sub getpid {
876 usage "getpid()" if @_ != 0;
877 $$;
878}
879
880sub getppid {
881 usage "getppid()" if @_ != 0;
b56ec344 882 CORE::getppid;
a0d0e21e
LW
883}
884
885sub getuid {
886 usage "getuid()" if @_ != 0;
887 $<;
888}
889
890sub isatty {
891 usage "isatty(filehandle)" if @_ != 1;
892 -t $_[0];
893}
894
895sub link {
896 usage "link(oldfilename, newfilename)" if @_ != 2;
b56ec344 897 CORE::link($_[0], $_[1]);
a0d0e21e
LW
898}
899
900sub rmdir {
901 usage "rmdir(directoryname)" if @_ != 1;
b56ec344 902 CORE::rmdir($_[0]);
a0d0e21e
LW
903}
904
a41ecaa8
JH
905sub setbuf {
906 redef "IO::Handle::setbuf()";
907}
908
a0d0e21e
LW
909sub setgid {
910 usage "setgid(gid)" if @_ != 1;
911 $( = $_[0];
912}
913
914sub setuid {
915 usage "setuid(uid)" if @_ != 1;
916 $< = $_[0];
917}
918
a41ecaa8
JH
919sub setvbuf {
920 redef "IO::Handle::setvbuf()";
921}
922
a0d0e21e
LW
923sub sleep {
924 usage "sleep(seconds)" if @_ != 1;
b56ec344 925 CORE::sleep($_[0]);
a0d0e21e
LW
926}
927
928sub unlink {
929 usage "unlink(filename)" if @_ != 1;
b56ec344 930 CORE::unlink($_[0]);
a0d0e21e
LW
931}
932
933sub utime {
934 usage "utime(filename, atime, mtime)" if @_ != 3;
b56ec344 935 CORE::utime($_[1], $_[2], $_[0]);
a0d0e21e
LW
936}
937