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 tan 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
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);
180 my $EINVAL = constant("EINVAL", 0);
181 my $EAGAIN = constant("EAGAIN", 0);
184 if ($AUTOLOAD =~ /::(_?[a-z])/) {
185 $AutoLoader::AUTOLOAD = $AUTOLOAD;
186 goto &AutoLoader::AUTOLOAD
189 my $constname = $AUTOLOAD;
190 $constname =~ s/.*:://;
191 my $val = constant($constname, $_[0]);
193 *$AUTOLOAD = sub { $val };
195 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
196 *$AUTOLOAD = sub { constant($constname, $_[0]) };
198 elsif ($! == $EINVAL) {
199 croak "$constname is not a valid POSIX macro";
202 croak "Your vendor has not defined POSIX macro $constname, used";
210 croak "Usage: POSIX::$mess";
215 croak "Use method $mess instead";
221 croak "Unimplemented: POSIX::$mess";
225 my $pkg = @_ ? ref($_[0]) || $_[0] : "";
226 local *{$pkg . "::GLOB" . ++$seq};
227 \delete ${$pkg . "::"}{'GLOB' . $seq};
233 ############################
234 package POSIX::SigAction;
237 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
240 ############################
244 POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
245 local($class,$filename,$mode) = @_;
246 local($sym) = $class->POSIX::gensym;
247 $mode =~ s/a.*/>>/ ||
250 open($sym, "$mode $filename") and
251 bless $sym => $class;
255 POSIX::usage "FileHandle->new_from_fd(fd,mode)" if @_ != 3;
256 local($class,$fd,$mode) = @_;
257 local($sym) = $class->POSIX::gensym;
258 $mode =~ s/a.*/>>/ ||
261 open($sym, "$mode&=$fd") and
262 bless $sym => $class;
266 POSIX::usage "clearerr(filehandle)" if @_ != 1;
271 POSIX::usage "close(filehandle)" if @_ != 1;
280 POSIX::usage "eof(filehandle)" if @_ != 1;
285 POSIX::usage "getc(filehandle)" if @_ != 1;
290 POSIX::usage "gets(filehandle)" if @_ != 1;
296 POSIX::usage "fileno(filehandle)" if @_ != 1;
301 POSIX::usage "seek(filehandle,pos,whence)" if @_ != 3;
302 seek($_[0], $_[1], $_[2]);
306 POSIX::usage "tell(filehandle)" if @_ != 1;
309 ############################
310 package POSIX; # return to package POSIX so AutoSplit is happy
315 usage "assert(expr)" if @_ != 1;
317 croak "Assertion failed";
322 usage "tolower(string)" if @_ != 1;
327 usage "toupper(string)" if @_ != 1;
332 usage "closedir(dirhandle)" if @_ != 1;
337 usage "opendir(directory)" if @_ != 1;
338 local($dirhandle) = POSIX->gensym;
339 opendir($dirhandle, $_[0])
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 "getpwnam(name)" if @_ != 1;
425 usage "getpwuid(uid)" if @_ != 1;
430 unimpl "longjmp() is C-specific: use die instead";
434 unimpl "setjmp() is C-specific: use eval {} instead";
438 unimpl "siglongjmp() is C-specific: use die instead";
442 unimpl "sigsetjmp() is C-specific: use eval {} instead";
446 usage "kill(pid, sig)" if @_ != 2;
451 usage "raise(sig)" if @_ != 1;
452 kill $$, $_[0]; # Is this good enough?
456 unimpl "offsetof() is C-specific, stopped";
460 redef "FileHandle::clearerr()";
464 redef "FileHandle::close()";
468 redef "FileHandle::new_from_fd()";
472 redef "FileHandle::eof()";
476 redef "FileHandle::getc()";
480 redef "FileHandle::gets()";
484 redef "FileHandle::fileno()";
488 redef "FileHandle::open()";
492 unimpl "fprintf() is C-specific--use printf instead";
496 unimpl "fputc() is C-specific--use print instead";
500 unimpl "fputs() is C-specific--use print instead";
504 unimpl "fread() is C-specific--use read instead";
508 unimpl "freopen() is C-specific--use open instead";
512 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
516 redef "FileHandle::seek()";
520 redef "FileHandle::error()";
524 redef "FileHandle::flush()";
528 redef "FileHandle::getpos()";
532 redef "FileHandle::setpos()";
536 redef "FileHandle::tell()";
540 unimpl "fwrite() is C-specific--use print instead";
544 usage "getc(handle)" if @_ != 1;
549 usage "getchar()" if @_ != 0;
554 usage "gets()" if @_ != 0;
559 print STDERR "@_: " if @_;
560 print STDERR $!,"\n";
564 usage "printf(pattern, args...)" if @_ < 1;
569 unimpl "putc() is C-specific--use print instead";
573 unimpl "putchar() is C-specific--use print instead";
577 unimpl "puts() is C-specific--use print instead";
581 usage "remove(filename)" if @_ != 1;
586 usage "rename(oldfilename, newfilename)" if @_ != 2;
587 rename($_[0], $_[1]);
591 usage "rewind(filehandle)" if @_ != 1;
596 unimpl "scanf() is C-specific--use <> and regular expressions instead";
600 usage "sprintf(pattern,args)" if @_ == 0;
605 unimpl "sscanf() is C-specific--use regular expressions instead";
609 redef "FileHandle::new_tmpfile()";
613 redef "FileHandle::ungetc()";
617 unimpl "vfprintf() is C-specific";
621 unimpl "vprintf() is C-specific";
625 unimpl "vsprintf() is C-specific";
629 usage "abs(x)" if @_ != 1;
634 unimpl "atexit() is C-specific: use END {} instead";
638 unimpl "atof() is C-specific, stopped";
642 unimpl "atoi() is C-specific, stopped";
646 unimpl "atol() is C-specific, stopped";
650 unimpl "bsearch() not supplied";
654 unimpl "calloc() is C-specific, stopped";
658 unimpl "div() is C-specific, stopped";
662 usage "exit(status)" if @_ != 1;
667 unimpl "free() is C-specific, stopped";
671 usage "getenv(name)" if @_ != 1;
676 unimpl "labs() is C-specific, use abs instead";
680 unimpl "ldiv() is C-specific, use / and int instead";
684 unimpl "malloc() is C-specific, stopped";
688 unimpl "qsort() is C-specific, use sort instead";
692 unimpl "rand() is non-portable, use Perl's rand instead";
696 unimpl "realloc() is C-specific, stopped";
704 unimpl "strtod() is C-specific, stopped";
708 unimpl "strtol() is C-specific, stopped";
712 unimpl "stroul() is C-specific, stopped";
716 usage "system(command)" if @_ != 1;
721 unimpl "memchr() is C-specific, use index() instead";
725 unimpl "memcmp() is C-specific, use eq instead";
729 unimpl "memcpy() is C-specific, use = instead";
733 unimpl "memmove() is C-specific, use = instead";
737 unimpl "memset() is C-specific, use x instead";
741 unimpl "strcat() is C-specific, use .= instead";
745 unimpl "strchr() is C-specific, use index() instead";
749 unimpl "strcmp() is C-specific, use eq instead";
753 unimpl "strcpy() is C-specific, use = instead";
757 unimpl "strcspn() is C-specific, use regular expressions instead";
761 usage "strerror(errno)" if @_ != 1;
767 unimpl "strlen() is C-specific, use length instead";
771 unimpl "strncat() is C-specific, use .= instead";
775 unimpl "strncmp() is C-specific, use eq instead";
779 unimpl "strncpy() is C-specific, use = instead";
783 unimpl "strpbrk() is C-specific, stopped";
787 unimpl "strrchr() is C-specific, use rindex() instead";
791 unimpl "strspn() is C-specific, stopped";
795 usage "strstr(big, little)" if @_ != 2;
800 unimpl "strtok() is C-specific, stopped";
804 usage "chmod(mode, filename)" if @_ != 2;
809 usage "fstat(fd)" if @_ != 1;
811 open(TMP, "<&$_[0]"); # Gross.
812 local(@l) = stat(TMP);
818 usage "mkdir(directoryname, mode)" if @_ != 2;
823 usage "stat(filename)" if @_ != 1;
828 usage "umask(mask)" if @_ != 1;
833 usage "wait(statusvariable)" if @_ != 1;
834 local $result = wait();
840 usage "waitpid(pid, statusvariable, options)" if @_ != 3;
841 local $result = waitpid($_[0], $_[2]);
847 usage "gmtime(time)" if @_ != 1;
852 usage "localtime(time)" if @_ != 1;
857 usage "time()" if @_ != 0;
862 usage "alarm(seconds)" if @_ != 1;
867 usage "chdir(directory)" if @_ != 1;
872 usage "chown(filename, uid, gid)" if @_ != 3;
873 chown($_[0], $_[1], $_[2]);
877 unimpl "execl() is C-specific, stopped";
881 unimpl "execle() is C-specific, stopped";
885 unimpl "execlp() is C-specific, stopped";
889 unimpl "execv() is C-specific, stopped";
893 unimpl "execve() is C-specific, stopped";
897 unimpl "execvp() is C-specific, stopped";
901 usage "fork()" if @_ != 0;
907 usage "getcwd()" if @_ != 0;
913 usage "getegid()" if @_ != 0;
918 usage "geteuid()" if @_ != 0;
923 usage "getgid()" if @_ != 0;
928 usage "getgroups()" if @_ != 0;
930 grep(!$seen{$_}++, split(' ', $) ));
934 usage "getlogin()" if @_ != 0;
939 usage "getpgrp()" if @_ != 0;
944 usage "getpid()" if @_ != 0;
949 usage "getppid()" if @_ != 0;
954 usage "getuid()" if @_ != 0;
959 usage "isatty(filehandle)" if @_ != 1;
964 usage "link(oldfilename, newfilename)" if @_ != 2;
969 usage "rmdir(directoryname)" if @_ != 1;
974 usage "setgid(gid)" if @_ != 1;
979 usage "setuid(uid)" if @_ != 1;
984 usage "sleep(seconds)" if @_ != 1;
989 usage "unlink(filename)" if @_ != 1;
994 usage "utime(filename, atime, mtime)" if @_ != 3;
995 utime($_[1], $_[2], $_[0]);