10 @ISA = qw(Exporter DynaLoader);
12 $VERSION = $VERSION = "1.00" ;
16 assert_h => [qw(assert NDEBUG)],
18 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
19 isprint ispunct isspace isupper isxdigit tolower toupper)],
23 errno_h => [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
24 EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
25 EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
26 ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
27 EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)],
29 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
30 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
31 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
32 O_RDONLY O_RDWR O_TRUNC O_WRONLY
34 SEEK_CUR SEEK_END SEEK_SET
35 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
36 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
37 S_IWGRP S_IWOTH S_IWUSR)],
39 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
40 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
41 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
42 FLT_DIG FLT_EPSILON FLT_MANT_DIG
43 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
44 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
46 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
47 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
48 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
52 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
53 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
54 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
55 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
56 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
57 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
58 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
59 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
60 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
61 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
63 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
64 LC_TIME NULL localeconv setlocale)],
66 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
67 frexp ldexp log10 modf pow sinh tan tanh)],
71 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
73 signal_h => [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
74 SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
75 SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
76 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
77 raise sigaction signal sigpending sigprocmask
82 stddef_h => [qw(NULL offsetof)],
84 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
85 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
86 STREAM_MAX TMP_MAX stderr stdin stdout
87 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
88 fgets fopen fprintf fputc fputs fread freopen
89 fscanf fseek fsetpos ftell fwrite getchar gets
90 perror putc putchar puts remove rewind
91 scanf setbuf setvbuf sscanf tmpfile tmpnam
92 ungetc vfprintf vprintf vsprintf)],
94 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
95 abort atexit atof atoi atol bsearch calloc div
96 free getenv labs ldiv malloc mblen mbstowcs mbtowc
97 qsort realloc strtod strtol stroul wcstombs wctomb)],
99 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
100 strchr strcmp strcoll strcpy strcspn strerror strlen
101 strncat strncmp strncpy strpbrk strrchr strspn strstr
104 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
105 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
106 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
109 sys_times_h => [qw()],
111 sys_types_h => [qw()],
113 sys_utsname_h => [qw(uname)],
115 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
116 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
118 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
119 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
120 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
121 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
122 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
123 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
124 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
125 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
127 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
128 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
130 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
131 difftime mktime strftime tzset tzname)],
133 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
134 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
135 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
136 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
137 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
138 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
139 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
140 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
141 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
142 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
143 _exit access ctermid cuserid
144 dup2 dup execl execle execlp execv execve execvp
145 fpathconf getcwd getegid geteuid getgid getgroups
146 getpid getuid isatty lseek pathconf pause setgid setpgid
147 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
153 Exporter::export_tags();
156 closedir opendir readdir rewinddir
159 atan2 cos exp log sin sqrt
162 fileno getc printf rename sprintf
163 abs exit rand srand system
164 chmod mkdir stat umask
167 gmtime localtime time
168 alarm chdir chown close fork getlogin getppid getpgrp link
169 pipe read rmdir sleep unlink write
173 # Grandfather old foo_h form to new :foo_h form
176 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
177 local $Exporter::ExportLevel = 1;
178 Exporter::import($this,@list);
184 my $EINVAL = constant("EINVAL", 0);
185 my $EAGAIN = constant("EAGAIN", 0);
188 if ($AUTOLOAD =~ /::(_?[a-z])/) {
189 $AutoLoader::AUTOLOAD = $AUTOLOAD;
190 goto &AutoLoader::AUTOLOAD
193 my $constname = $AUTOLOAD;
194 $constname =~ s/.*:://;
195 my $val = constant($constname, $_[0]);
197 *$AUTOLOAD = sub { $val };
199 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
200 *$AUTOLOAD = sub { constant($constname, $_[0]) };
202 elsif ($! == $EINVAL) {
203 croak "$constname is not a valid POSIX macro";
206 croak "Your vendor has not defined POSIX macro $constname, used";
214 croak "Usage: POSIX::$mess";
219 croak "Use method $mess instead";
225 croak "Unimplemented: POSIX::$mess";
228 ############################
229 package POSIX::SigAction;
232 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
235 ############################
236 package POSIX; # return to package POSIX so AutoSplit is happy
241 usage "assert(expr)" if @_ != 1;
243 croak "Assertion failed";
248 usage "tolower(string)" if @_ != 1;
253 usage "toupper(string)" if @_ != 1;
258 usage "closedir(dirhandle)" if @_ != 1;
263 usage "opendir(directory)" if @_ != 1;
264 my $dirhandle = gensym;
265 opendir($dirhandle, $_[0])
271 usage "readdir(dirhandle)" if @_ != 1;
276 usage "rewinddir(dirhandle)" if @_ != 1;
281 usage "errno()" if @_ != 0;
286 usage "creat(filename, mode)" if @_ != 2;
287 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
291 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
292 fcntl($_[0], $_[1], $_[2]);
296 usage "getgrgid(gid)" if @_ != 1;
301 usage "getgrnam(name)" if @_ != 1;
306 usage "atan2(x,y)" if @_ != 2;
311 usage "cos(x)" if @_ != 1;
316 usage "exp(x)" if @_ != 1;
321 usage "fabs(x)" if @_ != 1;
326 usage "log(x)" if @_ != 1;
331 usage "pow(x,exponent)" if @_ != 2;
336 usage "sin(x)" if @_ != 1;
341 usage "sqrt(x)" if @_ != 1;
346 usage "getpwnam(name)" if @_ != 1;
351 usage "getpwuid(uid)" if @_ != 1;
356 unimpl "longjmp() is C-specific: use die instead";
360 unimpl "setjmp() is C-specific: use eval {} instead";
364 unimpl "siglongjmp() is C-specific: use die instead";
368 unimpl "sigsetjmp() is C-specific: use eval {} instead";
372 usage "kill(pid, sig)" if @_ != 2;
377 usage "raise(sig)" if @_ != 1;
378 kill $$, $_[0]; # Is this good enough?
382 unimpl "offsetof() is C-specific, stopped";
386 redef "FileHandle::clearerr()";
390 redef "FileHandle::close()";
394 redef "FileHandle::new_from_fd()";
398 redef "FileHandle::eof()";
402 redef "FileHandle::getc()";
406 redef "FileHandle::gets()";
410 redef "FileHandle::fileno()";
414 redef "FileHandle::open()";
418 unimpl "fprintf() is C-specific--use printf instead";
422 unimpl "fputc() is C-specific--use print instead";
426 unimpl "fputs() is C-specific--use print instead";
430 unimpl "fread() is C-specific--use read instead";
434 unimpl "freopen() is C-specific--use open instead";
438 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
442 redef "FileHandle::seek()";
446 redef "FileHandle::error()";
450 redef "FileHandle::flush()";
454 redef "FileHandle::getpos()";
458 redef "FileHandle::setpos()";
462 redef "FileHandle::tell()";
466 unimpl "fwrite() is C-specific--use print instead";
470 usage "getc(handle)" if @_ != 1;
475 usage "getchar()" if @_ != 0;
480 usage "gets()" if @_ != 0;
485 print STDERR "@_: " if @_;
486 print STDERR $!,"\n";
490 usage "printf(pattern, args...)" if @_ < 1;
495 unimpl "putc() is C-specific--use print instead";
499 unimpl "putchar() is C-specific--use print instead";
503 unimpl "puts() is C-specific--use print instead";
507 usage "remove(filename)" if @_ != 1;
512 usage "rename(oldfilename, newfilename)" if @_ != 2;
513 rename($_[0], $_[1]);
517 usage "rewind(filehandle)" if @_ != 1;
522 unimpl "scanf() is C-specific--use <> and regular expressions instead";
526 usage "sprintf(pattern,args)" if @_ == 0;
531 unimpl "sscanf() is C-specific--use regular expressions instead";
535 redef "FileHandle::new_tmpfile()";
539 redef "FileHandle::ungetc()";
543 unimpl "vfprintf() is C-specific";
547 unimpl "vprintf() is C-specific";
551 unimpl "vsprintf() is C-specific";
555 usage "abs(x)" if @_ != 1;
560 unimpl "atexit() is C-specific: use END {} instead";
564 unimpl "atof() is C-specific, stopped";
568 unimpl "atoi() is C-specific, stopped";
572 unimpl "atol() is C-specific, stopped";
576 unimpl "bsearch() not supplied";
580 unimpl "calloc() is C-specific, stopped";
584 unimpl "div() is C-specific, stopped";
588 usage "exit(status)" if @_ != 1;
593 unimpl "free() is C-specific, stopped";
597 usage "getenv(name)" if @_ != 1;
602 unimpl "labs() is C-specific, use abs instead";
606 unimpl "ldiv() is C-specific, use / and int instead";
610 unimpl "malloc() is C-specific, stopped";
614 unimpl "qsort() is C-specific, use sort instead";
618 unimpl "rand() is non-portable, use Perl's rand instead";
622 unimpl "realloc() is C-specific, stopped";
630 unimpl "strtod() is C-specific, stopped";
634 unimpl "strtol() is C-specific, stopped";
638 unimpl "stroul() 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;
726 unimpl "strtok() is C-specific, stopped";
730 usage "chmod(mode, filename)" if @_ != 2;
735 usage "fstat(fd)" if @_ != 1;
737 open(TMP, "<&$_[0]"); # Gross.
744 usage "mkdir(directoryname, mode)" if @_ != 2;
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 waitpid($_[0], $_[1]);
769 usage "gmtime(time)" if @_ != 1;
774 usage "localtime(time)" if @_ != 1;
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 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;
835 usage "getegid()" if @_ != 0;
840 usage "geteuid()" if @_ != 0;
845 usage "getgid()" if @_ != 0;
850 usage "getgroups()" if @_ != 0;
852 grep(!$seen{$_}++, split(' ', $) ));
856 usage "getlogin()" if @_ != 0;
861 usage "getpgrp()" if @_ != 0;
866 usage "getpid()" if @_ != 0;
871 usage "getppid()" if @_ != 0;
876 usage "getuid()" if @_ != 0;
881 usage "isatty(filehandle)" if @_ != 1;
886 usage "link(oldfilename, newfilename)" if @_ != 2;
891 usage "rmdir(directoryname)" if @_ != 1;
896 usage "setgid(gid)" if @_ != 1;
901 usage "setuid(uid)" if @_ != 1;
906 usage "sleep(seconds)" if @_ != 1;
911 usage "unlink(filename)" if @_ != 1;
916 usage "utime(filename, atime, mtime)" if @_ != 3;
917 utime($_[1], $_[2], $_[0]);