8 @ISA = qw(Exporter DynaLoader);
12 assert_h => [qw(assert NDEBUG)],
14 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
15 isprint ispunct isspace isupper isxdigit tolower toupper)],
19 errno_h => [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
20 EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
21 EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
22 ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
23 EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)],
25 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
26 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
27 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
28 O_RDONLY O_RDWR O_TRUNC O_WRONLY
30 SEEK_CUR SEEK_END SEEK_SET
31 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
32 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
33 S_IWGRP S_IWOTH S_IWUSR)],
35 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
36 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
37 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
38 FLT_DIG FLT_EPSILON FLT_MANT_DIG
39 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
40 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
42 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
43 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
44 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
48 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
49 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
50 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
51 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
52 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
53 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
54 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
55 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
56 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
57 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
59 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
60 LC_TIME NULL localeconv setlocale)],
62 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
63 frexp ldexp log10 modf pow sinh tanh)],
67 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
69 signal_h => [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
70 SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
71 SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
72 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
73 raise sigaction signal sigpending sigprocmask
78 stddef_h => [qw(NULL offsetof)],
80 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
81 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET STREAM_MAX
82 TMP_MAX stderr stdin stdout _IOFBF _IOLBF _IONBF
83 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
84 fgets fopen fprintf fputc fputs fread freopen
85 fscanf fseek fsetpos ftell fwrite getchar gets
86 perror putc putchar puts remove rewind
87 scanf setbuf setvbuf sscanf tmpfile tmpnam
88 ungetc vfprintf vprintf vsprintf)],
90 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
91 abort atexit atof atoi atol bsearch calloc div
92 free getenv labs ldiv malloc mblen mbstowcs mbtowc
93 qsort realloc strtod strtol stroul wcstombs wctomb)],
95 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
96 strchr strcmp strcoll strcpy strcspn strerror strlen
97 strncat strncmp strncpy strpbrk strrchr strspn strstr
100 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
101 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
102 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
105 sys_times_h => [qw()],
107 sys_types_h => [qw()],
109 sys_utsname_h => [qw(uname)],
111 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
112 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
114 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
115 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
116 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
117 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
118 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
119 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
120 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
121 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
123 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
124 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
126 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
127 difftime mktime strftime tzset tzname)],
129 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
130 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
131 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
132 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
133 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
134 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
135 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
136 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
137 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
138 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
139 _exit access ctermid cuserid
140 dup2 dup execl execle execlp execv execve execvp
141 fpathconf getcwd getegid geteuid getgid getgroups
142 getpid getuid isatty lseek pathconf pause setgid setpgid
143 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
149 Exporter::export_tags();
152 closedir opendir readdir rewinddir
155 atan2 cos exp log sin sqrt tan
158 fileno getc printf rename sprintf
159 abs exit rand srand system
160 chmod mkdir stat umask
163 gmtime localtime time
164 alarm chdir chown close fork getlogin getppid getpgrp link
165 pipe read rmdir sleep unlink write
169 # Grandfather old foo_h form to new :foo_h form
172 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
173 local $Exporter::ExportLevel = 1;
174 Exporter::import($this,@list);
178 if ($AUTOLOAD =~ /::(_?[a-z])/) {
179 $AutoLoader::AUTOLOAD = $AUTOLOAD;
180 goto &AutoLoader::AUTOLOAD
182 local $constname = $AUTOLOAD;
183 $constname =~ s/.*:://;
184 $val = constant($constname, $_[0]);
186 if ($! =~ /Invalid/) {
187 croak "$constname is not a valid POSIX macro";
190 croak "Your vendor has not defined POSIX macro $constname, used";
193 eval "sub $AUTOLOAD { $val }";
199 @liblist = split ' ', $Config::Config{"POSIX_loadlibs"}
200 if defined $Config::Config{"POSIX_loadlibs"};
201 bootstrap POSIX @liblist;
205 croak "Usage: POSIX::$mess";
210 croak "Use method $mess instead";
216 croak "Unimplemented: POSIX::$mess";
222 *{"POSIX::" . $gensym++};
231 ############################
232 package POSIX::SigAction;
235 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
238 ############################
242 POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
243 local($class,$filename,$mode) = @_;
244 local($glob) = &POSIX::gensym;
245 $mode =~ s/a.*/>>/ ||
248 open($glob, "$mode $filename") and
253 POSIX::usage "FileHandle->new_from_fd(fd,mode)" if @_ != 3;
254 local($class,$fd,$mode) = @_;
255 local($glob) = &POSIX::gensym;
256 $mode =~ s/a.*/>>/ ||
259 open($glob, "$mode&=$fd") and
264 POSIX::usage "clearerr(filehandle)" if @_ != 1;
269 POSIX::usage "close(filehandle)" if @_ != 1;
279 POSIX::usage "eof(filehandle)" if @_ != 1;
284 POSIX::usage "getc(filehandle)" if @_ != 1;
289 POSIX::usage "gets(filehandle)" if @_ != 1;
295 POSIX::usage "fileno(filehandle)" if @_ != 1;
300 POSIX::usage "seek(filehandle,pos,whence)" if @_ != 3;
301 seek($_[0], $_[1], $_[2]);
305 POSIX::usage "tell(filehandle)" if @_ != 1;
308 ############################
309 package POSIX; # return to package POSIX so AutoSplit is happy
314 usage "assert(expr)" if @_ != 1;
316 croak "Assertion failed";
321 usage "tolower(string)" if @_ != 1;
326 usage "toupper(string)" if @_ != 1;
331 usage "closedir(dirhandle)" if @_ != 1;
337 usage "opendir(directory)" if @_ != 1;
338 local($dirhandle) = &gensym;
339 opendir($dirhandle, $_[0])
341 : (ungensym($dirhandle), undef);
345 usage "readdir(dirhandle)" if @_ != 1;
350 usage "rewinddir(dirhandle)" if @_ != 1;
355 usage "errno()" if @_ != 0;
360 usage "creat(filename, mode)" if @_ != 2;
361 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
365 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
366 fcntl($_[0], $_[1], $_[2]);
370 usage "getgrgid(gid)" if @_ != 1;
375 usage "getgrnam(name)" if @_ != 1;
380 usage "atan2(x,y)" if @_ != 2;
385 usage "cos(x)" if @_ != 1;
390 usage "exp(x)" if @_ != 1;
395 usage "fabs(x)" if @_ != 1;
400 usage "log(x)" if @_ != 1;
405 usage "pow(x,exponent)" if @_ != 2;
410 usage "sin(x)" if @_ != 1;
415 usage "sqrt(x)" if @_ != 1;
420 usage "tan(x)" if @_ != 1;
425 usage "getpwnam(name)" if @_ != 1;
430 usage "getpwuid(uid)" if @_ != 1;
435 unimpl "longjmp() is C-specific: use die instead";
439 unimpl "setjmp() is C-specific: use eval {} instead";
443 unimpl "siglongjmp() is C-specific: use die instead";
447 unimpl "sigsetjmp() is C-specific: use eval {} instead";
451 usage "kill(pid, sig)" if @_ != 2;
456 usage "raise(sig)" if @_ != 1;
457 kill $$, $_[0]; # Is this good enough?
461 unimpl "offsetof() is C-specific, stopped";
465 redef "$filehandle->clearerr(filehandle)";
469 redef "$filehandle->fclose(filehandle)";
473 redef "FileHandle->new_from_fd(fd,mode)";
477 redef "$filehandle->eof()";
481 redef "$filehandle->getc()";
485 redef "$filehandle->gets()";
489 redef "$filehandle->fileno()";
493 redef "FileHandle->open()";
497 unimpl "fprintf() is C-specific--use printf instead";
501 unimpl "fputc() is C-specific--use print instead";
505 unimpl "fputs() is C-specific--use print instead";
509 unimpl "fread() is C-specific--use read instead";
513 unimpl "freopen() is C-specific--use open instead";
517 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
521 redef "$filehandle->seek(pos,whence)";
525 redef "$filehandle->error()";
529 redef "$filehandle->flush()";
533 redef "$filehandle->getpos()";
537 redef "$filehandle->setpos(pos)";
541 redef "$filehandle->tell()";
545 unimpl "fwrite() is C-specific--use print instead";
549 usage "getc(handle)" if @_ != 1;
554 usage "getchar()" if @_ != 0;
559 usage "gets()" if @_ != 0;
564 print STDERR "@_: " if @_;
565 print STDERR $!,"\n";
569 usage "printf(pattern, args...)" if @_ < 1;
574 unimpl "putc() is C-specific--use print instead";
578 unimpl "putchar() is C-specific--use print instead";
582 unimpl "puts() is C-specific--use print instead";
586 usage "remove(filename)" if @_ != 1;
591 usage "rename(oldfilename, newfilename)" if @_ != 2;
592 rename($_[0], $_[1]);
596 usage "rewind(filehandle)" if @_ != 1;
601 unimpl "scanf() is C-specific--use <> and regular expressions instead";
605 usage "sprintf(pattern,args)" if @_ == 0;
610 unimpl "sscanf() is C-specific--use regular expressions instead";
614 redef "FileHandle->new_tmpfile()";
618 redef "$filehandle->ungetc(char)";
622 unimpl "vfprintf() is C-specific";
626 unimpl "vprintf() is C-specific";
630 unimpl "vsprintf() is C-specific";
634 usage "abs(x)" if @_ != 1;
639 unimpl "atexit() is C-specific: use END {} instead";
643 unimpl "atof() is C-specific, stopped";
647 unimpl "atoi() is C-specific, stopped";
651 unimpl "atol() is C-specific, stopped";
655 unimpl "bsearch(xxx)" if @_ != 123;
660 unimpl "calloc() is C-specific, stopped";
664 unimpl "div() is C-specific, stopped";
668 usage "exit(status)" if @_ != 1;
673 unimpl "free() is C-specific, stopped";
678 usage "getenv(name)" if @_ != 1;
683 unimpl "labs() is C-specific, use abs instead";
687 unimpl "ldiv() is C-specific, use / and int instead";
691 unimpl "malloc() is C-specific, stopped";
695 unimpl "qsort() is C-specific, use sort instead";
699 unimpl "rand() is non-portable, use Perl's rand instead";
703 unimpl "realloc() is C-specific, stopped";
711 unimpl "strtod() is C-specific, stopped";
715 unimpl "strtol() is C-specific, stopped";
719 unimpl "stroul() is C-specific, stopped";
723 usage "system(command)" if @_ != 1;
728 unimpl "memchr() is C-specific, use index() instead";
732 unimpl "memcmp() is C-specific, use eq instead";
736 unimpl "memcpy() is C-specific, use = instead";
740 unimpl "memmove() is C-specific, use = instead";
744 unimpl "memset() is C-specific, use x instead";
748 unimpl "strcat() is C-specific, use .= instead";
752 unimpl "strchr() is C-specific, use index() instead";
756 unimpl "strcmp() is C-specific, use eq instead";
760 unimpl "strcpy() is C-specific, use = instead";
764 unimpl "strcspn() is C-specific, use regular expressions instead";
768 usage "strerror(errno)" if @_ != 1;
774 unimpl "strlen() is C-specific, use length instead";
778 unimpl "strncat() is C-specific, use .= instead";
782 unimpl "strncmp() is C-specific, use eq instead";
786 unimpl "strncpy() is C-specific, use = instead";
790 unimpl "strpbrk() is C-specific, stopped";
794 unimpl "strrchr() is C-specific, use rindex() instead";
798 unimpl "strspn() is C-specific, stopped";
802 usage "strstr(big, little)" if @_ != 2;
807 unimpl "strtok() is C-specific, stopped";
811 usage "chmod(filename, mode)" if @_ != 2;
816 usage "fstat(fd)" if @_ != 1;
818 open(TMP, "<&$_[0]"); # Gross.
819 local(@l) = stat(TMP);
825 usage "mkdir(directoryname, mode)" if @_ != 2;
830 usage "stat(filename)" if @_ != 1;
835 usage "umask(mask)" if @_ != 1;
840 usage "times()" if @_ != 0;
845 usage "wait(statusvariable)" if @_ != 1;
846 local $result = wait();
852 usage "waitpid(pid, statusvariable, options)" if @_ != 3;
853 local $result = waitpid($_[0], $_[2]);
859 usage "gmtime(time)" if @_ != 1;
864 usage "localtime(time)" if @_ != 1;
869 unimpl "time()" if @_ != 0;
874 usage "alarm(seconds)" if @_ != 1;
879 usage "chdir(directory)" if @_ != 1;
884 usage "chown(filename, uid, gid)" if @_ != 3;
885 chown($_[0], $_[1], $_[2]);
889 unimpl "execl() is C-specific, stopped";
894 unimpl "execle() is C-specific, stopped";
899 unimpl "execlp() is C-specific, stopped";
904 unimpl "execv() is C-specific, stopped";
909 unimpl "execve() is C-specific, stopped";
914 unimpl "execvp() is C-specific, stopped";
919 usage "fork()" if @_ != 0;
925 usage "getcwd()" if @_ != 0;
931 usage "getegid()" if @_ != 0;
936 usage "geteuid()" if @_ != 0;
941 usage "getgid()" if @_ != 0;
946 usage "getgroups()" if @_ != 0;
948 grep(!$seen{$_}++, split(' ', $) ));
952 usage "getlogin()" if @_ != 0;
957 usage "getpgrp()" if @_ != 0;
962 usage "getpid()" if @_ != 0;
967 usage "getppid()" if @_ != 0;
972 usage "getuid()" if @_ != 0;
977 usage "isatty(filehandle)" if @_ != 1;
982 usage "link(oldfilename, newfilename)" if @_ != 2;
987 usage "rmdir(directoryname)" if @_ != 1;
992 usage "setgid(gid)" if @_ != 1;
997 usage "setuid(uid)" if @_ != 1;
1002 usage "sleep(seconds)" if @_ != 1;
1007 usage "unlink(filename)" if @_ != 1;
1012 usage "utime(filename, atime, mtime)" if @_ != 3;
1013 utime($_[1], $_[2], $_[0]);