3 our(@ISA, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD, %SIGRT) = ();
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 }
23 # declare usage to assist AutoLoad
26 XSLoader::load 'POSIX', $VERSION;
28 my %NON_CONSTS = (map {($_,1)}
29 qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS
30 WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
33 if ($AUTOLOAD =~ /::(_?[a-z])/) {
35 $AutoLoader::AUTOLOAD = $AUTOLOAD;
36 goto &AutoLoader::AUTOLOAD
39 my $constname = $AUTOLOAD;
40 $constname =~ s/.*:://;
41 if ($NON_CONSTS{$constname}) {
42 my ($val, $error) = &int_macro_int($constname, $_[0]);
43 croak $error if $error;
44 *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) };
46 my ($error, $val) = constant($constname);
47 croak $error if $error;
48 *$AUTOLOAD = sub { $val };
54 package POSIX::SigAction;
56 use AutoLoader 'AUTOLOAD';
57 sub new { bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0, SAFE => 0}, $_[0] }
64 use base qw(Tie::StdHash);
66 use vars qw($SIGACTION_FLAGS);
70 my ($SIGRTMIN, $SIGRTMAX, $sigrtn);
73 $SIGRTMIN = &POSIX::SIGRTMIN;
74 $SIGRTMAX = &POSIX::SIGRTMAX;
75 $sigrtn = $SIGRTMAX - $SIGRTMIN;
79 &_init unless defined $sigrtn;
80 die "POSIX::SigRt not available" unless defined $sigrtn && $sigrtn > 0;
86 # Allow (SIGRT)?MIN( + n)?, a common idiom when doing these things in C.
87 $rtsig = $SIGRTMIN + ($1 || 0)
88 if $rtsig =~ /^(?:(?:SIG)?RT)?MIN(\s*\+\s*(\d+))?$/;
93 my $rtsig = _getsig($_[1]);
94 my $ok = $rtsig >= $SIGRTMIN && $rtsig <= $SIGRTMAX;
99 my ($rtsig, $ok) = &_exist;
100 die "No POSIX::SigRt signal $_[1] (valid range SIGRTMIN..SIGRTMAX, or $SIGRTMIN..$SIGRTMAX)"
106 my ($rtsig, $handler, $flags) = @_;
107 my $sigset = POSIX::SigSet->new($rtsig);
108 my $sigact = POSIX::SigAction->new($handler,
111 POSIX::sigaction($rtsig, $sigact);
114 sub EXISTS { &_exist }
115 sub FETCH { my $rtsig = &_check;
116 my $oa = POSIX::SigAction->new();
117 POSIX::sigaction($rtsig, undef, $oa);
118 return $oa->{HANDLER} }
119 sub STORE { my $rtsig = &_check; new($rtsig, $_[2], $SIGACTION_FLAGS) }
120 sub DELETE { delete $SIG{ &_check } }
121 sub CLEAR { &_exist; delete @SIG{ &POSIX::SIGRTMIN .. &POSIX::SIGRTMAX } }
122 sub SCALAR { &_croak; $sigrtn + 1 }
124 tie %POSIX::SIGRT, 'POSIX::SigRt';
133 croak "Usage: POSIX::$mess";
138 croak "Use method $mess instead";
144 croak "Unimplemented: POSIX::$mess";
148 usage "assert(expr)" if @_ != 1;
150 croak "Assertion failed";
155 usage "tolower(string)" if @_ != 1;
160 usage "toupper(string)" if @_ != 1;
165 usage "closedir(dirhandle)" if @_ != 1;
166 CORE::closedir($_[0]);
170 usage "opendir(directory)" if @_ != 1;
172 CORE::opendir($dirhandle, $_[0])
178 usage "readdir(dirhandle)" if @_ != 1;
179 CORE::readdir($_[0]);
183 usage "rewinddir(dirhandle)" if @_ != 1;
184 CORE::rewinddir($_[0]);
188 usage "errno()" if @_ != 0;
193 usage "creat(filename, mode)" if @_ != 2;
194 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
198 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
199 CORE::fcntl($_[0], $_[1], $_[2]);
203 usage "getgrgid(gid)" if @_ != 1;
204 CORE::getgrgid($_[0]);
208 usage "getgrnam(name)" if @_ != 1;
209 CORE::getgrnam($_[0]);
213 usage "atan2(x,y)" if @_ != 2;
214 CORE::atan2($_[0], $_[1]);
218 usage "cos(x)" if @_ != 1;
223 usage "exp(x)" if @_ != 1;
228 usage "fabs(x)" if @_ != 1;
233 usage "log(x)" if @_ != 1;
238 usage "pow(x,exponent)" if @_ != 2;
243 usage "sin(x)" if @_ != 1;
248 usage "sqrt(x)" if @_ != 1;
253 usage "getpwnam(name)" if @_ != 1;
254 CORE::getpwnam($_[0]);
258 usage "getpwuid(uid)" if @_ != 1;
259 CORE::getpwuid($_[0]);
263 unimpl "longjmp() is C-specific: use die instead";
267 unimpl "setjmp() is C-specific: use eval {} instead";
271 unimpl "siglongjmp() is C-specific: use die instead";
275 unimpl "sigsetjmp() is C-specific: use eval {} instead";
279 usage "kill(pid, sig)" if @_ != 2;
280 CORE::kill $_[1], $_[0];
284 usage "raise(sig)" if @_ != 1;
285 CORE::kill $_[0], $$; # Is this good enough?
289 unimpl "offsetof() is C-specific, stopped";
293 redef "IO::Handle::clearerr()";
297 redef "IO::Handle::close()";
301 redef "IO::Handle::new_from_fd()";
305 redef "IO::Handle::eof()";
309 redef "IO::Handle::getc()";
313 redef "IO::Handle::gets()";
317 redef "IO::Handle::fileno()";
321 redef "IO::File::open()";
325 unimpl "fprintf() is C-specific--use printf instead";
329 unimpl "fputc() is C-specific--use print instead";
333 unimpl "fputs() is C-specific--use print instead";
337 unimpl "fread() is C-specific--use read instead";
341 unimpl "freopen() is C-specific--use open instead";
345 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
349 redef "IO::Seekable::seek()";
353 redef "IO::Handle::sync()";
357 redef "IO::Handle::error()";
361 redef "IO::Handle::flush()";
365 redef "IO::Seekable::getpos()";
369 redef "IO::Seekable::setpos()";
373 redef "IO::Seekable::tell()";
377 unimpl "fwrite() is C-specific--use print instead";
381 usage "getc(handle)" if @_ != 1;
386 usage "getchar()" if @_ != 0;
391 usage "gets()" if @_ != 0;
396 print STDERR "@_: " if @_;
397 print STDERR $!,"\n";
401 usage "printf(pattern, args...)" if @_ < 1;
402 CORE::printf STDOUT @_;
406 unimpl "putc() is C-specific--use print instead";
410 unimpl "putchar() is C-specific--use print instead";
414 unimpl "puts() is C-specific--use print instead";
418 usage "remove(filename)" if @_ != 1;
423 usage "rename(oldfilename, newfilename)" if @_ != 2;
424 CORE::rename($_[0], $_[1]);
428 usage "rewind(filehandle)" if @_ != 1;
429 CORE::seek($_[0],0,0);
433 unimpl "scanf() is C-specific--use <> and regular expressions instead";
437 usage "sprintf(pattern,args)" if @_ == 0;
438 CORE::sprintf(shift,@_);
442 unimpl "sscanf() is C-specific--use regular expressions instead";
446 redef "IO::File::new_tmpfile()";
450 redef "IO::Handle::ungetc()";
454 unimpl "vfprintf() is C-specific";
458 unimpl "vprintf() is C-specific";
462 unimpl "vsprintf() is C-specific";
466 usage "abs(x)" if @_ != 1;
471 unimpl "atexit() is C-specific: use END {} instead";
475 unimpl "atof() is C-specific, stopped";
479 unimpl "atoi() is C-specific, stopped";
483 unimpl "atol() is C-specific, stopped";
487 unimpl "bsearch() not supplied";
491 unimpl "calloc() is C-specific, stopped";
495 unimpl "div() is C-specific, use /, % and int instead";
499 usage "exit(status)" if @_ != 1;
504 unimpl "free() is C-specific, stopped";
508 usage "getenv(name)" if @_ != 1;
513 unimpl "labs() is C-specific, use abs instead";
517 unimpl "ldiv() is C-specific, use /, % and int instead";
521 unimpl "malloc() is C-specific, stopped";
525 unimpl "qsort() is C-specific, use sort instead";
529 unimpl "rand() is non-portable, use Perl's rand instead";
533 unimpl "realloc() is C-specific, stopped";
541 usage "system(command)" if @_ != 1;
546 unimpl "memchr() is C-specific, use index() instead";
550 unimpl "memcmp() is C-specific, use eq instead";
554 unimpl "memcpy() is C-specific, use = instead";
558 unimpl "memmove() is C-specific, use = instead";
562 unimpl "memset() is C-specific, use x instead";
566 unimpl "strcat() is C-specific, use .= instead";
570 unimpl "strchr() is C-specific, use index() instead";
574 unimpl "strcmp() is C-specific, use eq instead";
578 unimpl "strcpy() is C-specific, use = instead";
582 unimpl "strcspn() is C-specific, use regular expressions instead";
586 usage "strerror(errno)" if @_ != 1;
592 unimpl "strlen() is C-specific, use length instead";
596 unimpl "strncat() is C-specific, use .= instead";
600 unimpl "strncmp() is C-specific, use eq instead";
604 unimpl "strncpy() is C-specific, use = instead";
608 unimpl "strpbrk() is C-specific, stopped";
612 unimpl "strrchr() is C-specific, use rindex() instead";
616 unimpl "strspn() is C-specific, stopped";
620 usage "strstr(big, little)" if @_ != 2;
621 CORE::index($_[0], $_[1]);
625 unimpl "strtok() is C-specific, stopped";
629 usage "chmod(mode, filename)" if @_ != 2;
630 CORE::chmod($_[0], $_[1]);
634 usage "fstat(fd)" if @_ != 1;
636 CORE::open(TMP, "<&$_[0]"); # Gross.
637 my @l = CORE::stat(TMP);
643 usage "mkdir(directoryname, mode)" if @_ != 2;
644 CORE::mkdir($_[0], $_[1]);
648 usage "stat(filename)" if @_ != 1;
653 usage "umask(mask)" if @_ != 1;
658 usage "wait()" if @_ != 0;
663 usage "waitpid(pid, options)" if @_ != 2;
664 CORE::waitpid($_[0], $_[1]);
668 usage "gmtime(time)" if @_ != 1;
673 usage "localtime(time)" if @_ != 1;
674 CORE::localtime($_[0]);
678 usage "time()" if @_ != 0;
683 usage "alarm(seconds)" if @_ != 1;
688 usage "chdir(directory)" if @_ != 1;
693 usage "chown(uid, gid, filename)" if @_ != 3;
694 CORE::chown($_[0], $_[1], $_[2]);
698 unimpl "execl() is C-specific, stopped";
702 unimpl "execle() is C-specific, stopped";
706 unimpl "execlp() is C-specific, stopped";
710 unimpl "execv() is C-specific, stopped";
714 unimpl "execve() is C-specific, stopped";
718 unimpl "execvp() is C-specific, stopped";
722 usage "fork()" if @_ != 0;
727 usage "getegid()" if @_ != 0;
732 usage "geteuid()" if @_ != 0;
737 usage "getgid()" if @_ != 0;
742 usage "getgroups()" if @_ != 0;
744 grep(!$seen{$_}++, split(' ', $) ));
748 usage "getlogin()" if @_ != 0;
753 usage "getpgrp()" if @_ != 0;
758 usage "getpid()" if @_ != 0;
763 usage "getppid()" if @_ != 0;
768 usage "getuid()" if @_ != 0;
773 usage "isatty(filehandle)" if @_ != 1;
778 usage "link(oldfilename, newfilename)" if @_ != 2;
779 CORE::link($_[0], $_[1]);
783 usage "rmdir(directoryname)" if @_ != 1;
788 redef "IO::Handle::setbuf()";
792 redef "IO::Handle::setvbuf()";
796 usage "sleep(seconds)" if @_ != 1;
797 $_[0] - CORE::sleep($_[0]);
801 usage "unlink(filename)" if @_ != 1;
806 usage "utime(filename, atime, mtime)" if @_ != 3;
807 CORE::utime($_[1], $_[2], $_[0]);
813 assert_h => [qw(assert NDEBUG)],
815 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
816 isprint ispunct isspace isupper isxdigit tolower toupper)],
820 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
821 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
822 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
823 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
824 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
825 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
826 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
827 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
828 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
829 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
830 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
831 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
832 EUSERS EWOULDBLOCK EXDEV errno)],
834 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
835 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
836 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
837 O_RDONLY O_RDWR O_TRUNC O_WRONLY
839 SEEK_CUR SEEK_END SEEK_SET
840 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
841 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
842 S_IWGRP S_IWOTH S_IWUSR)],
844 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
845 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
846 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
847 FLT_DIG FLT_EPSILON FLT_MANT_DIG
848 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
849 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
851 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
852 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
853 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
857 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
858 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
859 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
860 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
861 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
862 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
863 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
864 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
865 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
866 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
868 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
869 LC_MONETARY LC_NUMERIC LC_TIME NULL
870 localeconv setlocale)],
872 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
873 frexp ldexp log10 modf pow sinh tan tanh)],
877 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
879 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
880 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
881 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
882 SIGPIPE %SIGRT SIGRTMIN SIGRTMAX SIGQUIT SIGSEGV SIGSTOP
883 SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
884 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
885 raise sigaction signal sigpending sigprocmask sigsuspend)],
889 stddef_h => [qw(NULL offsetof)],
891 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
892 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
893 STREAM_MAX TMP_MAX stderr stdin stdout
894 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
895 fgets fopen fprintf fputc fputs fread freopen
896 fscanf fseek fsetpos ftell fwrite getchar gets
897 perror putc putchar puts remove rewind
898 scanf setbuf setvbuf sscanf tmpfile tmpnam
899 ungetc vfprintf vprintf vsprintf)],
901 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
902 abort atexit atof atoi atol bsearch calloc div
903 free getenv labs ldiv malloc mblen mbstowcs mbtowc
904 qsort realloc strtod strtol strtoul wcstombs wctomb)],
906 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
907 strchr strcmp strcoll strcpy strcspn strerror strlen
908 strncat strncmp strncpy strpbrk strrchr strspn strstr
911 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
912 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
913 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
920 sys_utsname_h => [qw(uname)],
922 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
923 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
925 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
926 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
927 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
928 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
929 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
930 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
931 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
932 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
934 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
935 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
937 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
938 difftime mktime strftime tzset tzname)],
940 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
941 STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
942 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
943 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
944 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
945 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
946 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
947 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
948 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
949 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
950 _exit access ctermid cuserid
951 dup2 dup execl execle execlp execv execve execvp
952 fpathconf fsync getcwd getegid geteuid getgid getgroups
953 getpid getuid isatty lseek pathconf pause setgid setpgid
954 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
960 # Exporter::export_tags();
962 # De-duplicate the export list:
964 @export{map {@$_} values %EXPORT_TAGS} = ();
965 # Doing the de-dup with a temporary hash has the advantage that the SVs in
966 # @EXPORT are actually shared hash key sacalars, which will save some memory.
967 push @EXPORT, keys %export;
1032 package POSIX::SigAction;
1034 sub handler { $_[0]->{HANDLER} = $_[1] if @_ > 1; $_[0]->{HANDLER} };
1035 sub mask { $_[0]->{MASK} = $_[1] if @_ > 1; $_[0]->{MASK} };
1036 sub flags { $_[0]->{FLAGS} = $_[1] if @_ > 1; $_[0]->{FLAGS} };
1037 sub safe { $_[0]->{SAFE} = $_[1] if @_ > 1; $_[0]->{SAFE} };