3 our(@ISA, %EXPORT_TAGS, @EXPORT_OK, $AUTOLOAD, %SIGRT) = ();
11 use Fcntl qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK F_SETFD
12 F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK O_ACCMODE O_APPEND
13 O_CREAT O_EXCL O_NOCTTY O_NONBLOCK O_RDONLY O_RDWR O_TRUNC
16 # Grandfather old foo_h form to new :foo_h form
20 load_imports() unless $loaded++;
22 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
23 local $Exporter::ExportLevel = 1;
24 Exporter::import($this,@list);
27 sub croak { require Carp; goto &Carp::croak }
28 # declare usage to assist AutoLoad
31 XSLoader::load 'POSIX', $VERSION;
33 my %NON_CONSTS = (map {($_,1)}
34 qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS
35 WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
38 if ($AUTOLOAD =~ /::(_?[a-z])/) {
40 $AutoLoader::AUTOLOAD = $AUTOLOAD;
41 goto &AutoLoader::AUTOLOAD
44 my $constname = $AUTOLOAD;
45 $constname =~ s/.*:://;
46 if ($NON_CONSTS{$constname}) {
47 my ($val, $error) = &int_macro_int($constname, $_[0]);
48 croak $error if $error;
49 *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) };
51 my ($error, $val) = constant($constname);
52 croak $error if $error;
53 *$AUTOLOAD = sub { $val };
59 package POSIX::SigAction;
61 use AutoLoader 'AUTOLOAD';
62 sub new { bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0, SAFE => 0}, $_[0] }
69 use base qw(Tie::StdHash);
71 use vars qw($SIGACTION_FLAGS);
75 my ($SIGRTMIN, $SIGRTMAX, $sigrtn);
78 $SIGRTMIN = &POSIX::SIGRTMIN;
79 $SIGRTMAX = &POSIX::SIGRTMAX;
80 $sigrtn = $SIGRTMAX - $SIGRTMIN;
84 &_init unless defined $sigrtn;
85 die "POSIX::SigRt not available" unless defined $sigrtn && $sigrtn > 0;
91 # Allow (SIGRT)?MIN( + n)?, a common idiom when doing these things in C.
92 $rtsig = $SIGRTMIN + ($1 || 0)
93 if $rtsig =~ /^(?:(?:SIG)?RT)?MIN(\s*\+\s*(\d+))?$/;
98 my $rtsig = _getsig($_[1]);
99 my $ok = $rtsig >= $SIGRTMIN && $rtsig <= $SIGRTMAX;
104 my ($rtsig, $ok) = &_exist;
105 die "No POSIX::SigRt signal $_[1] (valid range SIGRTMIN..SIGRTMAX, or $SIGRTMIN..$SIGRTMAX)"
111 my ($rtsig, $handler, $flags) = @_;
112 my $sigset = POSIX::SigSet->new($rtsig);
113 my $sigact = POSIX::SigAction->new($handler,
116 POSIX::sigaction($rtsig, $sigact);
119 sub EXISTS { &_exist }
120 sub FETCH { my $rtsig = &_check;
121 my $oa = POSIX::SigAction->new();
122 POSIX::sigaction($rtsig, undef, $oa);
123 return $oa->{HANDLER} }
124 sub STORE { my $rtsig = &_check; new($rtsig, $_[2], $SIGACTION_FLAGS) }
125 sub DELETE { delete $SIG{ &_check } }
126 sub CLEAR { &_exist; delete @SIG{ &POSIX::SIGRTMIN .. &POSIX::SIGRTMAX } }
127 sub SCALAR { &_croak; $sigrtn + 1 }
129 tie %POSIX::SIGRT, 'POSIX::SigRt';
138 croak "Usage: POSIX::$mess";
143 croak "Use method $mess instead";
149 croak "Unimplemented: POSIX::$mess";
153 usage "assert(expr)" if @_ != 1;
155 croak "Assertion failed";
160 usage "tolower(string)" if @_ != 1;
165 usage "toupper(string)" if @_ != 1;
170 usage "closedir(dirhandle)" if @_ != 1;
171 CORE::closedir($_[0]);
175 usage "opendir(directory)" if @_ != 1;
177 CORE::opendir($dirhandle, $_[0])
183 usage "readdir(dirhandle)" if @_ != 1;
184 CORE::readdir($_[0]);
188 usage "rewinddir(dirhandle)" if @_ != 1;
189 CORE::rewinddir($_[0]);
193 usage "errno()" if @_ != 0;
198 usage "creat(filename, mode)" if @_ != 2;
199 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
203 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
204 CORE::fcntl($_[0], $_[1], $_[2]);
208 usage "getgrgid(gid)" if @_ != 1;
209 CORE::getgrgid($_[0]);
213 usage "getgrnam(name)" if @_ != 1;
214 CORE::getgrnam($_[0]);
218 usage "atan2(x,y)" if @_ != 2;
219 CORE::atan2($_[0], $_[1]);
223 usage "cos(x)" if @_ != 1;
228 usage "exp(x)" if @_ != 1;
233 usage "fabs(x)" if @_ != 1;
238 usage "log(x)" if @_ != 1;
243 usage "pow(x,exponent)" if @_ != 2;
248 usage "sin(x)" if @_ != 1;
253 usage "sqrt(x)" if @_ != 1;
258 usage "getpwnam(name)" if @_ != 1;
259 CORE::getpwnam($_[0]);
263 usage "getpwuid(uid)" if @_ != 1;
264 CORE::getpwuid($_[0]);
268 unimpl "longjmp() is C-specific: use die instead";
272 unimpl "setjmp() is C-specific: use eval {} instead";
276 unimpl "siglongjmp() is C-specific: use die instead";
280 unimpl "sigsetjmp() is C-specific: use eval {} instead";
284 usage "kill(pid, sig)" if @_ != 2;
285 CORE::kill $_[1], $_[0];
289 usage "raise(sig)" if @_ != 1;
290 CORE::kill $_[0], $$; # Is this good enough?
294 unimpl "offsetof() is C-specific, stopped";
298 redef "IO::Handle::clearerr()";
302 redef "IO::Handle::close()";
306 redef "IO::Handle::new_from_fd()";
310 redef "IO::Handle::eof()";
314 redef "IO::Handle::getc()";
318 redef "IO::Handle::gets()";
322 redef "IO::Handle::fileno()";
326 redef "IO::File::open()";
330 unimpl "fprintf() is C-specific--use printf instead";
334 unimpl "fputc() is C-specific--use print instead";
338 unimpl "fputs() is C-specific--use print instead";
342 unimpl "fread() is C-specific--use read instead";
346 unimpl "freopen() is C-specific--use open instead";
350 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
354 redef "IO::Seekable::seek()";
358 redef "IO::Handle::sync()";
362 redef "IO::Handle::error()";
366 redef "IO::Handle::flush()";
370 redef "IO::Seekable::getpos()";
374 redef "IO::Seekable::setpos()";
378 redef "IO::Seekable::tell()";
382 unimpl "fwrite() is C-specific--use print instead";
386 usage "getc(handle)" if @_ != 1;
391 usage "getchar()" if @_ != 0;
396 usage "gets()" if @_ != 0;
401 print STDERR "@_: " if @_;
402 print STDERR $!,"\n";
406 usage "printf(pattern, args...)" if @_ < 1;
407 CORE::printf STDOUT @_;
411 unimpl "putc() is C-specific--use print instead";
415 unimpl "putchar() is C-specific--use print instead";
419 unimpl "puts() is C-specific--use print instead";
423 usage "remove(filename)" if @_ != 1;
428 usage "rename(oldfilename, newfilename)" if @_ != 2;
429 CORE::rename($_[0], $_[1]);
433 usage "rewind(filehandle)" if @_ != 1;
434 CORE::seek($_[0],0,0);
438 unimpl "scanf() is C-specific--use <> and regular expressions instead";
442 usage "sprintf(pattern,args)" if @_ == 0;
443 CORE::sprintf(shift,@_);
447 unimpl "sscanf() is C-specific--use regular expressions instead";
451 redef "IO::File::new_tmpfile()";
455 redef "IO::Handle::ungetc()";
459 unimpl "vfprintf() is C-specific";
463 unimpl "vprintf() is C-specific";
467 unimpl "vsprintf() is C-specific";
471 usage "abs(x)" if @_ != 1;
476 unimpl "atexit() is C-specific: use END {} instead";
480 unimpl "atof() is C-specific, stopped";
484 unimpl "atoi() is C-specific, stopped";
488 unimpl "atol() is C-specific, stopped";
492 unimpl "bsearch() not supplied";
496 unimpl "calloc() is C-specific, stopped";
500 unimpl "div() is C-specific, use /, % and int instead";
504 usage "exit(status)" if @_ != 1;
509 unimpl "free() is C-specific, stopped";
513 usage "getenv(name)" if @_ != 1;
518 unimpl "labs() is C-specific, use abs instead";
522 unimpl "ldiv() is C-specific, use /, % and int instead";
526 unimpl "malloc() is C-specific, stopped";
530 unimpl "qsort() is C-specific, use sort instead";
534 unimpl "rand() is non-portable, use Perl's rand instead";
538 unimpl "realloc() is C-specific, stopped";
546 usage "system(command)" if @_ != 1;
551 unimpl "memchr() is C-specific, use index() instead";
555 unimpl "memcmp() is C-specific, use eq instead";
559 unimpl "memcpy() is C-specific, use = instead";
563 unimpl "memmove() is C-specific, use = instead";
567 unimpl "memset() is C-specific, use x instead";
571 unimpl "strcat() is C-specific, use .= instead";
575 unimpl "strchr() is C-specific, use index() instead";
579 unimpl "strcmp() is C-specific, use eq instead";
583 unimpl "strcpy() is C-specific, use = instead";
587 unimpl "strcspn() is C-specific, use regular expressions instead";
591 usage "strerror(errno)" if @_ != 1;
597 unimpl "strlen() is C-specific, use length instead";
601 unimpl "strncat() is C-specific, use .= instead";
605 unimpl "strncmp() is C-specific, use eq instead";
609 unimpl "strncpy() is C-specific, use = instead";
613 unimpl "strpbrk() is C-specific, stopped";
617 unimpl "strrchr() is C-specific, use rindex() instead";
621 unimpl "strspn() is C-specific, stopped";
625 usage "strstr(big, little)" if @_ != 2;
626 CORE::index($_[0], $_[1]);
630 unimpl "strtok() is C-specific, stopped";
634 usage "chmod(mode, filename)" if @_ != 2;
635 CORE::chmod($_[0], $_[1]);
639 usage "fstat(fd)" if @_ != 1;
641 CORE::open(TMP, "<&$_[0]"); # Gross.
642 my @l = CORE::stat(TMP);
648 usage "mkdir(directoryname, mode)" if @_ != 2;
649 CORE::mkdir($_[0], $_[1]);
653 usage "stat(filename)" if @_ != 1;
658 usage "umask(mask)" if @_ != 1;
663 usage "wait()" if @_ != 0;
668 usage "waitpid(pid, options)" if @_ != 2;
669 CORE::waitpid($_[0], $_[1]);
673 usage "gmtime(time)" if @_ != 1;
678 usage "localtime(time)" if @_ != 1;
679 CORE::localtime($_[0]);
683 usage "time()" if @_ != 0;
688 usage "alarm(seconds)" if @_ != 1;
693 usage "chdir(directory)" if @_ != 1;
698 usage "chown(uid, gid, filename)" if @_ != 3;
699 CORE::chown($_[0], $_[1], $_[2]);
703 unimpl "execl() is C-specific, stopped";
707 unimpl "execle() is C-specific, stopped";
711 unimpl "execlp() is C-specific, stopped";
715 unimpl "execv() is C-specific, stopped";
719 unimpl "execve() is C-specific, stopped";
723 unimpl "execvp() is C-specific, stopped";
727 usage "fork()" if @_ != 0;
732 usage "getegid()" if @_ != 0;
737 usage "geteuid()" if @_ != 0;
742 usage "getgid()" if @_ != 0;
747 usage "getgroups()" if @_ != 0;
749 grep(!$seen{$_}++, split(' ', $) ));
753 usage "getlogin()" if @_ != 0;
758 usage "getpgrp()" if @_ != 0;
763 usage "getpid()" if @_ != 0;
768 usage "getppid()" if @_ != 0;
773 usage "getuid()" if @_ != 0;
778 usage "isatty(filehandle)" if @_ != 1;
783 usage "link(oldfilename, newfilename)" if @_ != 2;
784 CORE::link($_[0], $_[1]);
788 usage "rmdir(directoryname)" if @_ != 1;
793 redef "IO::Handle::setbuf()";
797 redef "IO::Handle::setvbuf()";
801 usage "sleep(seconds)" if @_ != 1;
802 $_[0] - CORE::sleep($_[0]);
806 usage "unlink(filename)" if @_ != 1;
811 usage "utime(filename, atime, mtime)" if @_ != 3;
812 CORE::utime($_[1], $_[2], $_[0]);
818 assert_h => [qw(assert NDEBUG)],
820 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
821 isprint ispunct isspace isupper isxdigit tolower toupper)],
825 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
826 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
827 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
828 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
829 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
830 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
831 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
832 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
833 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
834 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
835 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
836 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
837 EUSERS EWOULDBLOCK EXDEV errno)],
839 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
840 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
841 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
842 O_RDONLY O_RDWR O_TRUNC O_WRONLY
844 SEEK_CUR SEEK_END SEEK_SET
845 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
846 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
847 S_IWGRP S_IWOTH S_IWUSR)],
849 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
850 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
851 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
852 FLT_DIG FLT_EPSILON FLT_MANT_DIG
853 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
854 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
856 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
857 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
858 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
862 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
863 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
864 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
865 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
866 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
867 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
868 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
869 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
870 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
871 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
873 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MESSAGES
874 LC_MONETARY LC_NUMERIC LC_TIME NULL
875 localeconv setlocale)],
877 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
878 frexp ldexp log10 modf pow sinh tan tanh)],
882 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
884 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
885 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
886 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
887 SIGPIPE %SIGRT SIGRTMIN SIGRTMAX SIGQUIT SIGSEGV SIGSTOP
888 SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
889 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
890 raise sigaction signal sigpending sigprocmask sigsuspend)],
894 stddef_h => [qw(NULL offsetof)],
896 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
897 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
898 STREAM_MAX TMP_MAX stderr stdin stdout
899 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
900 fgets fopen fprintf fputc fputs fread freopen
901 fscanf fseek fsetpos ftell fwrite getchar gets
902 perror putc putchar puts remove rewind
903 scanf setbuf setvbuf sscanf tmpfile tmpnam
904 ungetc vfprintf vprintf vsprintf)],
906 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
907 abort atexit atof atoi atol bsearch calloc div
908 free getenv labs ldiv malloc mblen mbstowcs mbtowc
909 qsort realloc strtod strtol strtoul wcstombs wctomb)],
911 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
912 strchr strcmp strcoll strcpy strcspn strerror strlen
913 strncat strncmp strncpy strpbrk strrchr strspn strstr
916 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
917 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
918 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
925 sys_utsname_h => [qw(uname)],
927 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
928 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
930 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
931 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
932 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
933 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
934 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
935 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
936 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
937 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
939 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
940 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
942 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
943 difftime mktime strftime tzset tzname)],
945 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
946 STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
947 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
948 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
949 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
950 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
951 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
952 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
953 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_PAGESIZE _SC_SAVED_IDS
954 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
955 _exit access ctermid cuserid
956 dup2 dup execl execle execlp execv execve execvp
957 fpathconf fsync getcwd getegid geteuid getgid getgroups
958 getpid getuid isatty lseek pathconf pause setgid setpgid
959 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
965 # Exporter::export_tags();
967 # De-duplicate the export list:
969 @export{map {@$_} values %EXPORT_TAGS} = ();
970 # Doing the de-dup with a temporary hash has the advantage that the SVs in
971 # @EXPORT are actually shared hash key sacalars, which will save some memory.
972 push @EXPORT, keys %export;
1037 package POSIX::SigAction;
1039 sub handler { $_[0]->{HANDLER} = $_[1] if @_ > 1; $_[0]->{HANDLER} };
1040 sub mask { $_[0]->{MASK} = $_[1] if @_ > 1; $_[0]->{MASK} };
1041 sub flags { $_[0]->{FLAGS} = $_[1] if @_ > 1; $_[0]->{FLAGS} };
1042 sub safe { $_[0]->{SAFE} = $_[1] if @_ > 1; $_[0]->{SAFE} };