8 @ISA = (Exporter, DynaLoader);
10 $H{assert_h} = [qw(assert NDEBUG)];
12 $H{ctype_h} = [qw(isalnum isalpha iscntrl isdigit isgraph islower
13 isprint ispunct isspace isupper isxdigit tolower toupper)];
15 $H{dirent_h} = [qw()];
17 $H{errno_h} = [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
18 EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
19 EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
20 ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
21 EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)];
23 $H{fcntl_h} = [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
24 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
25 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
26 O_RDONLY O_RDWR O_TRUNC O_WRONLY
28 SEEK_CUR SEEK_END SEEK_SET
29 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
30 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
31 S_IWGRP S_IWOTH S_IWUSR)];
33 $H{float_h} = [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
34 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
35 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
36 FLT_DIG FLT_EPSILON FLT_MANT_DIG
37 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
38 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
40 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
41 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
42 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)];
46 $H{limits_h} = [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
47 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
48 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
49 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
50 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
51 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
52 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
53 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
54 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
55 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)];
57 $H{locale_h} = [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
58 LC_TIME NULL localeconv setlocale)];
60 $H{math_h} = [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
61 frexp ldexp log10 modf pow sinh tanh)];
65 $H{setjmp_h} = [qw(longjmp setjmp siglongjmp sigsetjmp)];
67 $H{signal_h} = [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
68 SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
69 SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
70 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
71 raise sigaction signal sigpending sigprocmask
74 $H{stdarg_h} = [qw()];
76 $H{stddef_h} = [qw(NULL offsetof)];
78 $H{stdio_h} = [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
79 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET STREAM_MAX
80 TMP_MAX stderr stdin stdout _IOFBF _IOLBF _IONBF
81 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
82 fgets fopen fprintf fputc fputs fread freopen
83 fscanf fseek fsetpos ftell fwrite getchar gets
84 perror putc putchar puts remove rewind
85 scanf setbuf setvbuf sscanf tmpfile tmpnam
86 ungetc vfprintf vprintf vsprintf)];
88 $H{stdlib_h} = [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
89 abort atexit atof atoi atol bsearch calloc div
90 free getenv labs ldiv malloc mblen mbstowcs mbtowc
91 qsort realloc strtod strtol stroul wcstombs wctomb)];
93 $H{string_h} = [qw(NULL memchr memcmp memcpy memmove memset strcat
94 strchr strcmp strcoll strcpy strcspn strerror strlen
95 strncat strncmp strncpy strpbrk strrchr strspn strstr
98 $H{sys_stat_h} = [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
99 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
100 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
103 $H{sys_times_h} = [qw()];
105 $H{sys_types_h} = [qw()];
107 $H{sys_utsname_h} = [qw(uname)];
109 $H{sys_wait_h} = [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
110 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)];
112 $H{termios_h} = [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
113 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
114 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
115 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
116 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
117 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
118 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
119 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
121 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
122 tcflow tcflush tcgetattr tcsendbreak tcsetattr )];
124 $H{time_h} = [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
125 difftime mktime strftime tzset tzname)];
127 $H{unistd_h} = [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
128 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
129 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
130 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
131 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
132 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
133 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
134 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
135 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
136 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
137 _exit access ctermid cuserid
138 dup2 dup execl execle execlp execv execve execvp
139 fpathconf getcwd getegid geteuid getgid getgroups
140 getpid getuid isatty lseek pathconf pause setgid setpgid
141 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)];
143 $H{utime_h} = [qw()];
147 foreach $entry (@_) {
149 push(@mylist, @{$H{$entry}});
152 push(@mylist, $entry);
158 @EXPORT = expand qw(assert_h ctype_h dirent_h errno_h fcntl_h float_h
159 grp_h limits_h locale_h math_h pwd_h setjmp_h signal_h
160 stdarg_h stddef_h stdio_h stdlib_h string_h sys_stat_h
161 sys_times_h sys_types_h sys_utsname_h sys_wait_h
162 termios_h time_h unistd_h utime_h);
165 closedir opendir readdir rewinddir
168 atan2 cos exp log sin sqrt tan
171 fileno getc printf rename sprintf
172 abs exit rand srand system
173 chmod mkdir stat umask
176 gmtime localtime time
177 alarm chdir chown close fork getlogin getppid getpgrp link
178 pipe read rmdir sleep unlink write
184 my @list = expand @_;
185 local $Exporter::ExportLevel = 1;
186 Exporter::import($this,@list);
190 if ($AUTOLOAD =~ /::(_?[a-z])/) {
191 $AutoLoader::AUTOLOAD = $AUTOLOAD;
192 goto &AutoLoader::AUTOLOAD
194 local $constname = $AUTOLOAD;
195 $constname =~ s/.*:://;
196 $val = constant($constname, $_[0]);
198 if ($! =~ /Invalid/) {
199 croak "$constname is not a valid POSIX macro";
202 croak "Your vendor has not defined POSIX macro $constname, used";
205 eval "sub $AUTOLOAD { $val }";
211 @liblist = split ' ', $Config::Config{"POSIX_loadlibs"}
212 if defined $Config::Config{"POSIX_loadlibs"};
213 bootstrap POSIX @liblist;
217 croak "Usage: POSIX::$mess";
222 croak "Use method $mess instead";
228 croak "Unimplemented: POSIX::$mess";
234 *{"POSIX::" . $gensym++};
240 delete $::_POSIX{$x};
243 ############################
244 package POSIX::SigAction;
247 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
250 ############################
254 POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
255 local($class,$filename,$mode) = @_;
256 local($glob) = &POSIX::gensym;
257 $mode =~ s/a.*/>>/ ||
260 open($glob, "$mode $filename");
265 POSIX::usage "FileHandle->new_from_fd(fd,mode)" if @_ != 3;
266 local($class,$fd,$mode) = @_;
267 local($glob) = &POSIX::gensym;
268 $mode =~ s/a.*/>>/ ||
271 open($glob, "$mode&=$fd");
276 POSIX::usage "clearerr(filehandle)" if @_ != 1;
281 POSIX::usage "close(filehandle)" if @_ != 1;
287 POSIX::usage "eof(filehandle)" if @_ != 1;
292 POSIX::usage "getc(filehandle)" if @_ != 1;
297 POSIX::usage "gets(filehandle)" if @_ != 1;
303 POSIX::usage "fileno(filehandle)" if @_ != 1;
308 POSIX::usage "seek(filehandle,pos,whence)" if @_ != 3;
309 seek($_[0], $_[1], $_[2]);
313 POSIX::usage "tell(filehandle)" if @_ != 1;
316 ############################
317 package POSIX; # return to package POSIX so AutoSplit is happy
322 usage "assert(expr)" if @_ != 1;
324 croak "Assertion failed";
329 usage "tolower(string)" if @_ != 1;
334 usage "toupper(string)" if @_ != 1;
339 usage "closedir(dirhandle)" if @_ != 1;
345 usage "opendir(directory)" if @_ != 1;
346 local($dirhandle) = &gensym;
347 opendir($dirhandle, $_[0])
349 : (ungensym($dirhandle), undef);
353 usage "readdir(dirhandle)" if @_ != 1;
358 usage "rewinddir(dirhandle)" if @_ != 1;
363 usage "errno()" if @_ != 0;
368 usage "creat(filename, mode)" if @_ != 2;
369 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
373 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
374 fcntl($_[0], $_[1], $_[2]);
378 usage "getgrgid(gid)" if @_ != 1;
383 usage "getgrnam(name)" if @_ != 1;
388 usage "atan2(x,y)" if @_ != 2;
393 usage "cos(x)" if @_ != 1;
398 usage "exp(x)" if @_ != 1;
403 usage "fabs(x)" if @_ != 1;
408 usage "log(x)" if @_ != 1;
413 usage "pow(x,exponent)" if @_ != 2;
418 usage "sin(x)" if @_ != 1;
423 usage "sqrt(x)" if @_ != 1;
428 usage "tan(x)" if @_ != 1;
433 usage "getpwnam(name)" if @_ != 1;
438 usage "getpwuid(uid)" if @_ != 1;
443 unimpl "longjmp() is C-specific: use die instead";
447 unimpl "setjmp() is C-specific: use eval {} instead";
451 unimpl "siglongjmp() is C-specific: use die instead";
455 unimpl "sigsetjmp() is C-specific: use eval {} instead";
459 usage "kill(pid, sig)" if @_ != 2;
464 usage "raise(sig)" if @_ != 1;
465 kill $$, $_[0]; # Is this good enough?
469 unimpl "offsetof() is C-specific, stopped";
473 redef "$filehandle->clearerr(filehandle)";
477 redef "$filehandle->fclose(filehandle)";
481 redef "FileHandle->new_from_fd(fd,mode)";
485 redef "$filehandle->eof()";
489 redef "$filehandle->getc()";
493 redef "$filehandle->gets()";
497 redef "$filehandle->fileno()";
501 redef "FileHandle->open()";
505 unimpl "fprintf() is C-specific--use printf instead";
509 unimpl "fputc() is C-specific--use print instead";
513 unimpl "fputs() is C-specific--use print instead";
517 unimpl "fread() is C-specific--use read instead";
521 unimpl "freopen() is C-specific--use open instead";
525 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
529 redef "$filehandle->seek(pos,whence)";
533 redef "$filehandle->error()";
537 redef "$filehandle->flush()";
541 redef "$filehandle->getpos()";
545 redef "$filehandle->setpos(pos)";
549 redef "$filehandle->tell()";
553 unimpl "fwrite() is C-specific--use print instead";
557 usage "getc(handle)" if @_ != 1;
562 usage "getchar()" if @_ != 0;
567 usage "gets()" if @_ != 0;
572 print STDERR "@_: " if @_;
573 print STDERR $!,"\n";
577 usage "printf(pattern, args...)" if @_ < 1;
582 unimpl "putc() is C-specific--use print instead";
586 unimpl "putchar() is C-specific--use print instead";
590 unimpl "puts() is C-specific--use print instead";
594 usage "remove(filename)" if @_ != 1;
599 usage "rename(oldfilename, newfilename)" if @_ != 2;
600 rename($_[0], $_[1]);
604 usage "rewind(filehandle)" if @_ != 1;
609 unimpl "scanf() is C-specific--use <> and regular expressions instead";
613 usage "sprintf(pattern,args)" if @_ == 0;
618 unimpl "sscanf() is C-specific--use regular expressions instead";
622 redef "FileHandle->new_tmpfile()";
626 redef "$filehandle->ungetc(char)";
630 unimpl "vfprintf() is C-specific";
634 unimpl "vprintf() is C-specific";
638 unimpl "vsprintf() is C-specific";
642 usage "abs(x)" if @_ != 1;
647 unimpl "atexit() is C-specific: use END {} instead";
651 unimpl "atof() is C-specific, stopped";
655 unimpl "atoi() is C-specific, stopped";
659 unimpl "atol() is C-specific, stopped";
663 unimpl "bsearch(xxx)" if @_ != 123;
668 unimpl "calloc() is C-specific, stopped";
672 unimpl "div() is C-specific, stopped";
676 usage "exit(status)" if @_ != 1;
681 unimpl "free() is C-specific, stopped";
686 usage "getenv(name)" if @_ != 1;
691 unimpl "labs() is C-specific, use abs instead";
695 unimpl "ldiv() is C-specific, use / and int instead";
699 unimpl "malloc() is C-specific, stopped";
703 unimpl "qsort() is C-specific, use sort instead";
707 unimpl "rand() is non-portable, use Perl's rand instead";
711 unimpl "realloc() is C-specific, stopped";
719 unimpl "strtod() is C-specific, stopped";
723 unimpl "strtol() is C-specific, stopped";
727 unimpl "stroul() is C-specific, stopped";
731 usage "system(command)" if @_ != 1;
736 unimpl "memchr() is C-specific, use index() instead";
740 unimpl "memcmp() is C-specific, use eq instead";
744 unimpl "memcpy() is C-specific, use = instead";
748 unimpl "memmove() is C-specific, use = instead";
752 unimpl "memset() is C-specific, use x instead";
756 unimpl "strcat() is C-specific, use .= instead";
760 unimpl "strchr() is C-specific, use index() instead";
764 unimpl "strcmp() is C-specific, use eq instead";
768 unimpl "strcpy() is C-specific, use = instead";
772 unimpl "strcspn() is C-specific, use regular expressions instead";
776 usage "strerror(errno)" if @_ != 1;
782 unimpl "strlen() is C-specific, use length instead";
786 unimpl "strncat() is C-specific, use .= instead";
790 unimpl "strncmp() is C-specific, use eq instead";
794 unimpl "strncpy() is C-specific, use = instead";
798 unimpl "strpbrk() is C-specific, stopped";
802 unimpl "strrchr() is C-specific, use rindex() instead";
806 unimpl "strspn() is C-specific, stopped";
810 usage "strstr(big, little)" if @_ != 2;
815 unimpl "strtok() is C-specific, stopped";
819 usage "chmod(filename, mode)" if @_ != 2;
824 usage "fstat(fd)" if @_ != 1;
826 open(TMP, "<&$_[0]"); # Gross.
827 local(@l) = stat(TMP);
833 usage "mkdir(directoryname, mode)" if @_ != 2;
838 usage "stat(filename)" if @_ != 1;
843 usage "umask(mask)" if @_ != 1;
848 usage "times()" if @_ != 0;
853 usage "wait(statusvariable)" if @_ != 1;
854 local $result = wait();
860 usage "waitpid(pid, statusvariable, options)" if @_ != 3;
861 local $result = waitpid($_[0], $_[2]);
867 usage "gmtime(time)" if @_ != 1;
872 usage "localtime(time)" if @_ != 1;
877 unimpl "time()" if @_ != 0;
882 usage "alarm(seconds)" if @_ != 1;
887 usage "chdir(directory)" if @_ != 1;
892 usage "chown(filename, uid, gid)" if @_ != 3;
893 chown($_[0], $_[1], $_[2]);
897 unimpl "execl() is C-specific, stopped";
902 unimpl "execle() is C-specific, stopped";
907 unimpl "execlp() is C-specific, stopped";
912 unimpl "execv() is C-specific, stopped";
917 unimpl "execve() is C-specific, stopped";
922 unimpl "execvp() is C-specific, stopped";
927 usage "fork()" if @_ != 0;
933 usage "getcwd()" if @_ != 0;
939 usage "getegid()" if @_ != 0;
944 usage "geteuid()" if @_ != 0;
949 usage "getgid()" if @_ != 0;
954 usage "getgroups()" if @_ != 0;
956 grep(!$seen{$_}++, split(' ', $) ));
960 usage "getlogin()" if @_ != 0;
965 usage "getpgrp()" if @_ != 0;
970 usage "getpid()" if @_ != 0;
975 usage "getppid()" if @_ != 0;
980 usage "getuid()" if @_ != 0;
985 usage "isatty(filehandle)" if @_ != 1;
990 usage "link(oldfilename, newfilename)" if @_ != 2;
995 usage "rmdir(directoryname)" if @_ != 1;
1000 usage "setgid(gid)" if @_ != 1;
1005 usage "setuid(uid)" if @_ != 1;
1010 usage "sleep(seconds)" if @_ != 1;
1015 usage "unlink(filename)" if @_ != 1;
1020 usage "utime(filename, atime, mtime)" if @_ != 3;
1021 utime($_[1], $_[2], $_[0]);