3 use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD);
12 @ISA = qw(Exporter DynaLoader);
18 assert_h => [qw(assert NDEBUG)],
20 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
21 isprint ispunct isspace isupper isxdigit tolower toupper)],
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)],
39 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
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
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
47 S_IWGRP S_IWOTH S_IWUSR)],
49 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
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
56 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
57 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
58 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
62 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
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
71 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
73 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
74 LC_TIME NULL localeconv setlocale)],
76 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
77 frexp ldexp log10 modf pow sinh tan tanh)],
81 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
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)],
93 stddef_h => [qw(NULL offsetof)],
95 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
96 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
97 STREAM_MAX TMP_MAX stderr stdin stdout
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
103 ungetc vfprintf vprintf vsprintf)],
105 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
106 abort atexit atof atoi atol bsearch calloc div
107 free getenv labs ldiv malloc mblen mbstowcs mbtowc
108 qsort realloc strtod strtol strtoul wcstombs wctomb)],
110 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
111 strchr strcmp strcoll strcpy strcspn strerror strlen
112 strncat strncmp strncpy strpbrk strrchr strspn strstr
115 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
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
120 sys_times_h => [qw()],
122 sys_types_h => [qw()],
124 sys_utsname_h => [qw(uname)],
126 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
127 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
129 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
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
138 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
139 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
141 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
142 difftime mktime strftime tzset tzname)],
144 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
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
158 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
164 Exporter::export_tags();
167 closedir opendir readdir rewinddir
170 atan2 cos exp log sin sqrt
173 fileno getc printf rename sprintf
174 abs exit rand srand system
175 chmod mkdir stat umask
178 gmtime localtime time
179 alarm chdir chown close fork getlogin getppid getpgrp link
180 pipe read rmdir sleep unlink write
185 # Grandfather old foo_h form to new :foo_h form
188 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
189 local $Exporter::ExportLevel = 1;
190 Exporter::import($this,@list);
194 bootstrap POSIX $VERSION;
196 my $EINVAL = constant("EINVAL", 0);
197 my $EAGAIN = constant("EAGAIN", 0);
200 if ($AUTOLOAD =~ /::(_?[a-z])/) {
201 $AutoLoader::AUTOLOAD = $AUTOLOAD;
202 goto &AutoLoader::AUTOLOAD
205 my $constname = $AUTOLOAD;
206 $constname =~ s/.*:://;
207 my $val = constant($constname, @_ ? $_[0] : 0);
209 *$AUTOLOAD = sub { $val };
211 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
212 *$AUTOLOAD = sub { constant($constname, $_[0]) };
214 elsif ($! == $EINVAL) {
215 croak "$constname is not a valid POSIX macro";
218 croak "Your vendor has not defined POSIX macro $constname, used";
226 croak "Usage: POSIX::$mess";
231 croak "Use method $mess instead";
237 croak "Unimplemented: POSIX::$mess";
240 ############################
241 package POSIX::SigAction;
244 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
247 ############################
248 package POSIX; # return to package POSIX so AutoSplit is happy
253 usage "assert(expr)" if @_ != 1;
255 croak "Assertion failed";
260 usage "tolower(string)" if @_ != 1;
265 usage "toupper(string)" if @_ != 1;
270 usage "closedir(dirhandle)" if @_ != 1;
271 CORE::closedir($_[0]);
275 usage "opendir(directory)" if @_ != 1;
276 my $dirhandle = gensym;
277 CORE::opendir($dirhandle, $_[0])
283 usage "readdir(dirhandle)" if @_ != 1;
284 CORE::readdir($_[0]);
288 usage "rewinddir(dirhandle)" if @_ != 1;
289 CORE::rewinddir($_[0]);
293 usage "errno()" if @_ != 0;
298 usage "creat(filename, mode)" if @_ != 2;
299 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
303 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
304 CORE::fcntl($_[0], $_[1], $_[2]);
308 usage "getgrgid(gid)" if @_ != 1;
309 CORE::getgrgid($_[0]);
313 usage "getgrnam(name)" if @_ != 1;
314 CORE::getgrnam($_[0]);
318 usage "atan2(x,y)" if @_ != 2;
319 CORE::atan2($_[0], $_[1]);
323 usage "cos(x)" if @_ != 1;
328 usage "exp(x)" if @_ != 1;
333 usage "fabs(x)" if @_ != 1;
338 usage "log(x)" if @_ != 1;
343 usage "pow(x,exponent)" if @_ != 2;
348 usage "sin(x)" if @_ != 1;
353 usage "sqrt(x)" if @_ != 1;
358 usage "getpwnam(name)" if @_ != 1;
359 CORE::getpwnam($_[0]);
363 usage "getpwuid(uid)" if @_ != 1;
364 CORE::getpwuid($_[0]);
368 unimpl "longjmp() is C-specific: use die instead";
372 unimpl "setjmp() is C-specific: use eval {} instead";
376 unimpl "siglongjmp() is C-specific: use die instead";
380 unimpl "sigsetjmp() is C-specific: use eval {} instead";
384 usage "kill(pid, sig)" if @_ != 2;
385 CORE::kill $_[1], $_[0];
389 usage "raise(sig)" if @_ != 1;
390 CORE::kill $_[0], $$; # Is this good enough?
394 unimpl "offsetof() is C-specific, stopped";
398 redef "IO::Handle::clearerr()";
402 redef "IO::Handle::close()";
406 redef "IO::Handle::new_from_fd()";
410 redef "IO::Handle::eof()";
414 redef "IO::Handle::getc()";
418 redef "IO::Handle::gets()";
422 redef "IO::Handle::fileno()";
426 redef "IO::File::open()";
430 unimpl "fprintf() is C-specific--use printf instead";
434 unimpl "fputc() is C-specific--use print instead";
438 unimpl "fputs() is C-specific--use print instead";
442 unimpl "fread() is C-specific--use read instead";
446 unimpl "freopen() is C-specific--use open instead";
450 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
454 redef "IO::Seekable::seek()";
458 redef "IO::Handle::error()";
462 redef "IO::Handle::flush()";
466 redef "IO::Seekable::getpos()";
470 redef "IO::Seekable::setpos()";
474 redef "IO::Seekable::tell()";
478 unimpl "fwrite() is C-specific--use print instead";
482 usage "getc(handle)" if @_ != 1;
487 usage "getchar()" if @_ != 0;
492 usage "gets()" if @_ != 0;
497 print STDERR "@_: " if @_;
498 print STDERR $!,"\n";
502 usage "printf(pattern, args...)" if @_ < 1;
503 CORE::printf STDOUT @_;
507 unimpl "putc() is C-specific--use print instead";
511 unimpl "putchar() is C-specific--use print instead";
515 unimpl "puts() is C-specific--use print instead";
519 usage "remove(filename)" if @_ != 1;
524 usage "rename(oldfilename, newfilename)" if @_ != 2;
525 CORE::rename($_[0], $_[1]);
529 usage "rewind(filehandle)" if @_ != 1;
530 CORE::seek($_[0],0,0);
534 unimpl "scanf() is C-specific--use <> and regular expressions instead";
538 usage "sprintf(pattern,args)" if @_ == 0;
539 CORE::sprintf(shift,@_);
543 unimpl "sscanf() is C-specific--use regular expressions instead";
547 redef "IO::File::new_tmpfile()";
551 redef "IO::Handle::ungetc()";
555 unimpl "vfprintf() is C-specific";
559 unimpl "vprintf() is C-specific";
563 unimpl "vsprintf() is C-specific";
567 usage "abs(x)" if @_ != 1;
572 unimpl "atexit() is C-specific: use END {} instead";
576 unimpl "atof() is C-specific, stopped";
580 unimpl "atoi() is C-specific, stopped";
584 unimpl "atol() is C-specific, stopped";
588 unimpl "bsearch() not supplied";
592 unimpl "calloc() is C-specific, stopped";
596 unimpl "div() is C-specific, stopped";
600 usage "exit(status)" if @_ != 1;
605 unimpl "free() is C-specific, stopped";
609 usage "getenv(name)" if @_ != 1;
614 unimpl "labs() is C-specific, use abs instead";
618 unimpl "ldiv() is C-specific, use / and int instead";
622 unimpl "malloc() is C-specific, stopped";
626 unimpl "qsort() is C-specific, use sort instead";
630 unimpl "rand() is non-portable, use Perl's rand instead";
634 unimpl "realloc() is C-specific, stopped";
642 usage "system(command)" if @_ != 1;
647 unimpl "memchr() is C-specific, use index() instead";
651 unimpl "memcmp() is C-specific, use eq instead";
655 unimpl "memcpy() is C-specific, use = instead";
659 unimpl "memmove() is C-specific, use = instead";
663 unimpl "memset() is C-specific, use x instead";
667 unimpl "strcat() is C-specific, use .= instead";
671 unimpl "strchr() is C-specific, use index() instead";
675 unimpl "strcmp() is C-specific, use eq instead";
679 unimpl "strcpy() is C-specific, use = instead";
683 unimpl "strcspn() is C-specific, use regular expressions instead";
687 usage "strerror(errno)" if @_ != 1;
693 unimpl "strlen() is C-specific, use length instead";
697 unimpl "strncat() is C-specific, use .= instead";
701 unimpl "strncmp() is C-specific, use eq instead";
705 unimpl "strncpy() is C-specific, use = instead";
709 unimpl "strpbrk() is C-specific, stopped";
713 unimpl "strrchr() is C-specific, use rindex() instead";
717 unimpl "strspn() is C-specific, stopped";
721 usage "strstr(big, little)" if @_ != 2;
722 CORE::index($_[0], $_[1]);
726 unimpl "strtok() is C-specific, stopped";
730 usage "chmod(mode, filename)" if @_ != 2;
731 CORE::chmod($_[0], $_[1]);
735 usage "fstat(fd)" if @_ != 1;
737 open(TMP, "<&$_[0]"); # Gross.
738 my @l = CORE::stat(TMP);
744 usage "mkdir(directoryname, mode)" if @_ != 2;
745 CORE::mkdir($_[0], $_[1]);
749 usage "stat(filename)" if @_ != 1;
754 usage "umask(mask)" if @_ != 1;
759 usage "wait()" if @_ != 0;
764 usage "waitpid(pid, options)" if @_ != 2;
765 CORE::waitpid($_[0], $_[1]);
769 usage "gmtime(time)" if @_ != 1;
774 usage "localtime(time)" if @_ != 1;
775 CORE::localtime($_[0]);
779 usage "time()" if @_ != 0;
784 usage "alarm(seconds)" if @_ != 1;
789 usage "chdir(directory)" if @_ != 1;
794 usage "chown(filename, uid, gid)" if @_ != 3;
795 CORE::chown($_[0], $_[1], $_[2]);
799 unimpl "execl() is C-specific, stopped";
803 unimpl "execle() is C-specific, stopped";
807 unimpl "execlp() is C-specific, stopped";
811 unimpl "execv() is C-specific, stopped";
815 unimpl "execve() is C-specific, stopped";
819 unimpl "execvp() is C-specific, stopped";
823 usage "fork()" if @_ != 0;
829 usage "getcwd()" if @_ != 0;
830 if ($^O eq 'MSWin32') {
831 # this perhaps applies to everyone else also?
842 usage "getegid()" if @_ != 0;
847 usage "geteuid()" if @_ != 0;
852 usage "getgid()" if @_ != 0;
857 usage "getgroups()" if @_ != 0;
859 grep(!$seen{$_}++, split(' ', $) ));
863 usage "getlogin()" if @_ != 0;
868 usage "getpgrp()" if @_ != 0;
869 CORE::getpgrp($_[0]);
873 usage "getpid()" if @_ != 0;
878 usage "getppid()" if @_ != 0;
883 usage "getuid()" if @_ != 0;
888 usage "isatty(filehandle)" if @_ != 1;
893 usage "link(oldfilename, newfilename)" if @_ != 2;
894 CORE::link($_[0], $_[1]);
898 usage "rmdir(directoryname)" if @_ != 1;
903 usage "setgid(gid)" if @_ != 1;
908 usage "setuid(uid)" if @_ != 1;
913 usage "sleep(seconds)" if @_ != 1;
918 usage "unlink(filename)" if @_ != 1;
923 usage "utime(filename, atime, mtime)" if @_ != 3;
924 CORE::utime($_[1], $_[2], $_[0]);