3 our(@ISA, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD) = ();
9 our $VERSION = "1.05" ;
11 # Grandfather old foo_h form to new :foo_h form
15 load_imports() unless $loaded++;
17 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
18 local $Exporter::ExportLevel = 1;
19 Exporter::import($this,@list);
22 sub croak { require Carp; goto &Carp::croak }
24 XSLoader::load 'POSIX', $VERSION;
26 my %NON_CONSTS = (map {($_,1)}
27 qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS
28 WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
31 if ($AUTOLOAD =~ /::(_?[a-z])/) {
33 $AutoLoader::AUTOLOAD = $AUTOLOAD;
34 goto &AutoLoader::AUTOLOAD
37 my $constname = $AUTOLOAD;
38 $constname =~ s/.*:://;
39 if ($NON_CONSTS{$constname}) {
40 my ($val, $error) = &int_macro_int($constname, $_[0]);
41 croak $error if $error;
42 *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) };
44 my ($error, $val) = constant($constname);
45 croak $error if $error;
46 *$AUTOLOAD = sub { $val };
52 sub POSIX::SigAction::new {
53 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
61 croak "Usage: POSIX::$mess";
66 croak "Use method $mess instead";
72 croak "Unimplemented: POSIX::$mess";
76 usage "assert(expr)" if @_ != 1;
78 croak "Assertion failed";
83 usage "tolower(string)" if @_ != 1;
88 usage "toupper(string)" if @_ != 1;
93 usage "closedir(dirhandle)" if @_ != 1;
94 CORE::closedir($_[0]);
98 usage "opendir(directory)" if @_ != 1;
100 CORE::opendir($dirhandle, $_[0])
106 usage "readdir(dirhandle)" if @_ != 1;
107 CORE::readdir($_[0]);
111 usage "rewinddir(dirhandle)" if @_ != 1;
112 CORE::rewinddir($_[0]);
116 usage "errno()" if @_ != 0;
121 usage "creat(filename, mode)" if @_ != 2;
122 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
126 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
127 CORE::fcntl($_[0], $_[1], $_[2]);
131 usage "getgrgid(gid)" if @_ != 1;
132 CORE::getgrgid($_[0]);
136 usage "getgrnam(name)" if @_ != 1;
137 CORE::getgrnam($_[0]);
141 usage "atan2(x,y)" if @_ != 2;
142 CORE::atan2($_[0], $_[1]);
146 usage "cos(x)" if @_ != 1;
151 usage "exp(x)" if @_ != 1;
156 usage "fabs(x)" if @_ != 1;
161 usage "log(x)" if @_ != 1;
166 usage "pow(x,exponent)" if @_ != 2;
171 usage "sin(x)" if @_ != 1;
176 usage "sqrt(x)" if @_ != 1;
181 usage "getpwnam(name)" if @_ != 1;
182 CORE::getpwnam($_[0]);
186 usage "getpwuid(uid)" if @_ != 1;
187 CORE::getpwuid($_[0]);
191 unimpl "longjmp() is C-specific: use die instead";
195 unimpl "setjmp() is C-specific: use eval {} instead";
199 unimpl "siglongjmp() is C-specific: use die instead";
203 unimpl "sigsetjmp() is C-specific: use eval {} instead";
207 usage "kill(pid, sig)" if @_ != 2;
208 CORE::kill $_[1], $_[0];
212 usage "raise(sig)" if @_ != 1;
213 CORE::kill $_[0], $$; # Is this good enough?
217 unimpl "offsetof() is C-specific, stopped";
221 redef "IO::Handle::clearerr()";
225 redef "IO::Handle::close()";
229 redef "IO::Handle::new_from_fd()";
233 redef "IO::Handle::eof()";
237 redef "IO::Handle::getc()";
241 redef "IO::Handle::gets()";
245 redef "IO::Handle::fileno()";
249 redef "IO::File::open()";
253 unimpl "fprintf() is C-specific--use printf instead";
257 unimpl "fputc() is C-specific--use print instead";
261 unimpl "fputs() is C-specific--use print instead";
265 unimpl "fread() is C-specific--use read instead";
269 unimpl "freopen() is C-specific--use open instead";
273 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
277 redef "IO::Seekable::seek()";
281 redef "IO::Handle::error()";
285 redef "IO::Handle::flush()";
289 redef "IO::Seekable::getpos()";
293 redef "IO::Seekable::setpos()";
297 redef "IO::Seekable::tell()";
301 unimpl "fwrite() is C-specific--use print instead";
305 usage "getc(handle)" if @_ != 1;
310 usage "getchar()" if @_ != 0;
315 usage "gets()" if @_ != 0;
320 print STDERR "@_: " if @_;
321 print STDERR $!,"\n";
325 usage "printf(pattern, args...)" if @_ < 1;
326 CORE::printf STDOUT @_;
330 unimpl "putc() is C-specific--use print instead";
334 unimpl "putchar() is C-specific--use print instead";
338 unimpl "puts() is C-specific--use print instead";
342 usage "remove(filename)" if @_ != 1;
347 usage "rename(oldfilename, newfilename)" if @_ != 2;
348 CORE::rename($_[0], $_[1]);
352 usage "rewind(filehandle)" if @_ != 1;
353 CORE::seek($_[0],0,0);
357 unimpl "scanf() is C-specific--use <> and regular expressions instead";
361 usage "sprintf(pattern,args)" if @_ == 0;
362 CORE::sprintf(shift,@_);
366 unimpl "sscanf() is C-specific--use regular expressions instead";
370 redef "IO::File::new_tmpfile()";
374 redef "IO::Handle::ungetc()";
378 unimpl "vfprintf() is C-specific";
382 unimpl "vprintf() is C-specific";
386 unimpl "vsprintf() is C-specific";
390 usage "abs(x)" if @_ != 1;
395 unimpl "atexit() is C-specific: use END {} instead";
399 unimpl "atof() is C-specific, stopped";
403 unimpl "atoi() is C-specific, stopped";
407 unimpl "atol() is C-specific, stopped";
411 unimpl "bsearch() not supplied";
415 unimpl "calloc() is C-specific, stopped";
419 unimpl "div() is C-specific, stopped";
423 usage "exit(status)" if @_ != 1;
428 unimpl "free() is C-specific, stopped";
432 usage "getenv(name)" if @_ != 1;
437 unimpl "labs() is C-specific, use abs instead";
441 unimpl "ldiv() is C-specific, use / and int instead";
445 unimpl "malloc() is C-specific, stopped";
449 unimpl "qsort() is C-specific, use sort instead";
453 unimpl "rand() is non-portable, use Perl's rand instead";
457 unimpl "realloc() is C-specific, stopped";
465 usage "system(command)" if @_ != 1;
470 unimpl "memchr() is C-specific, use index() instead";
474 unimpl "memcmp() is C-specific, use eq instead";
478 unimpl "memcpy() is C-specific, use = instead";
482 unimpl "memmove() is C-specific, use = instead";
486 unimpl "memset() is C-specific, use x instead";
490 unimpl "strcat() is C-specific, use .= instead";
494 unimpl "strchr() is C-specific, use index() instead";
498 unimpl "strcmp() is C-specific, use eq instead";
502 unimpl "strcpy() is C-specific, use = instead";
506 unimpl "strcspn() is C-specific, use regular expressions instead";
510 usage "strerror(errno)" if @_ != 1;
516 unimpl "strlen() is C-specific, use length instead";
520 unimpl "strncat() is C-specific, use .= instead";
524 unimpl "strncmp() is C-specific, use eq instead";
528 unimpl "strncpy() is C-specific, use = instead";
532 unimpl "strpbrk() is C-specific, stopped";
536 unimpl "strrchr() is C-specific, use rindex() instead";
540 unimpl "strspn() is C-specific, stopped";
544 usage "strstr(big, little)" if @_ != 2;
545 CORE::index($_[0], $_[1]);
549 unimpl "strtok() is C-specific, stopped";
553 usage "chmod(mode, filename)" if @_ != 2;
554 CORE::chmod($_[0], $_[1]);
558 usage "fstat(fd)" if @_ != 1;
560 CORE::open(TMP, "<&$_[0]"); # Gross.
561 my @l = CORE::stat(TMP);
567 usage "mkdir(directoryname, mode)" if @_ != 2;
568 CORE::mkdir($_[0], $_[1]);
572 usage "stat(filename)" if @_ != 1;
577 usage "umask(mask)" if @_ != 1;
582 usage "wait()" if @_ != 0;
587 usage "waitpid(pid, options)" if @_ != 2;
588 CORE::waitpid($_[0], $_[1]);
592 usage "gmtime(time)" if @_ != 1;
597 usage "localtime(time)" if @_ != 1;
598 CORE::localtime($_[0]);
602 usage "time()" if @_ != 0;
607 usage "alarm(seconds)" if @_ != 1;
612 usage "chdir(directory)" if @_ != 1;
617 usage "chown(filename, uid, gid)" if @_ != 3;
618 CORE::chown($_[0], $_[1], $_[2]);
622 unimpl "execl() is C-specific, stopped";
626 unimpl "execle() is C-specific, stopped";
630 unimpl "execlp() is C-specific, stopped";
634 unimpl "execv() is C-specific, stopped";
638 unimpl "execve() is C-specific, stopped";
642 unimpl "execvp() is C-specific, stopped";
646 usage "fork()" if @_ != 0;
651 usage "getegid()" if @_ != 0;
656 usage "geteuid()" if @_ != 0;
661 usage "getgid()" if @_ != 0;
666 usage "getgroups()" if @_ != 0;
668 grep(!$seen{$_}++, split(' ', $) ));
672 usage "getlogin()" if @_ != 0;
677 usage "getpgrp()" if @_ != 0;
682 usage "getpid()" if @_ != 0;
687 usage "getppid()" if @_ != 0;
692 usage "getuid()" if @_ != 0;
697 usage "isatty(filehandle)" if @_ != 1;
702 usage "link(oldfilename, newfilename)" if @_ != 2;
703 CORE::link($_[0], $_[1]);
707 usage "rmdir(directoryname)" if @_ != 1;
712 redef "IO::Handle::setbuf()";
716 redef "IO::Handle::setvbuf()";
720 usage "sleep(seconds)" if @_ != 1;
725 usage "unlink(filename)" if @_ != 1;
730 usage "utime(filename, atime, mtime)" if @_ != 3;
731 CORE::utime($_[1], $_[2], $_[0]);
737 assert_h => [qw(assert NDEBUG)],
739 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
740 isprint ispunct isspace isupper isxdigit tolower toupper)],
744 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
745 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
746 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
747 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
748 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
749 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
750 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
751 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
752 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
753 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
754 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
755 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
756 EUSERS EWOULDBLOCK EXDEV errno)],
758 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
759 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
760 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
761 O_RDONLY O_RDWR O_TRUNC O_WRONLY
763 SEEK_CUR SEEK_END SEEK_SET
764 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
765 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
766 S_IWGRP S_IWOTH S_IWUSR)],
768 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
769 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
770 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
771 FLT_DIG FLT_EPSILON FLT_MANT_DIG
772 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
773 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
775 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
776 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
777 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
781 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
782 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
783 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
784 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
785 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
786 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
787 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
788 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
789 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
790 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
792 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
793 LC_MONETARY LC_NUMERIC LC_TIME NULL
794 localeconv setlocale)],
796 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
797 frexp ldexp log10 modf pow sinh tan tanh)],
801 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
803 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
804 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
805 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
806 SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN
807 SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR
808 SIG_IGN SIG_SETMASK SIG_UNBLOCK raise sigaction signal
809 sigpending sigprocmask sigsuspend)],
813 stddef_h => [qw(NULL offsetof)],
815 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
816 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
817 STREAM_MAX TMP_MAX stderr stdin stdout
818 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
819 fgets fopen fprintf fputc fputs fread freopen
820 fscanf fseek fsetpos ftell fwrite getchar gets
821 perror putc putchar puts remove rewind
822 scanf setbuf setvbuf sscanf tmpfile tmpnam
823 ungetc vfprintf vprintf vsprintf)],
825 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
826 abort atexit atof atoi atol bsearch calloc div
827 free getenv labs ldiv malloc mblen mbstowcs mbtowc
828 qsort realloc strtod strtol strtoul wcstombs wctomb)],
830 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
831 strchr strcmp strcoll strcpy strcspn strerror strlen
832 strncat strncmp strncpy strpbrk strrchr strspn strstr
835 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
836 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
837 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
844 sys_utsname_h => [qw(uname)],
846 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
847 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
849 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
850 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
851 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
852 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
853 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
854 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
855 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
856 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
858 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
859 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
861 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
862 difftime mktime strftime tzset tzname)],
864 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
865 STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
866 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
867 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
868 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
869 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
870 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
871 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
872 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
873 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
874 _exit access ctermid cuserid
875 dup2 dup execl execle execlp execv execve execvp
876 fpathconf getcwd getegid geteuid getgid getgroups
877 getpid getuid isatty lseek pathconf pause setgid setpgid
878 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
884 # Exporter::export_tags();
885 for (values %EXPORT_TAGS) {
890 closedir opendir readdir rewinddir
893 atan2 cos exp log sin sqrt
896 fileno getc printf rename sprintf
897 abs exit rand srand system
898 chmod mkdir stat umask
901 gmtime localtime time
902 alarm chdir chown close fork getlogin getppid getpgrp link
903 pipe read rmdir sleep unlink write