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 EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
26 EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
27 EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
28 ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
29 EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)],
31 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
32 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
33 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
34 O_RDONLY O_RDWR O_TRUNC O_WRONLY
36 SEEK_CUR SEEK_END SEEK_SET
37 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
38 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
39 S_IWGRP S_IWOTH S_IWUSR)],
41 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
42 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
43 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
44 FLT_DIG FLT_EPSILON FLT_MANT_DIG
45 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
46 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
48 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
49 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
50 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
54 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
55 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
56 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
57 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
58 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
59 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
60 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
61 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
62 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
63 _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
65 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
66 LC_TIME NULL localeconv setlocale)],
68 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
69 frexp ldexp log10 modf pow sinh tan tanh)],
73 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
75 signal_h => [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
76 SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
77 SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
78 SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
79 raise sigaction signal sigpending sigprocmask
84 stddef_h => [qw(NULL offsetof)],
86 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
87 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
88 STREAM_MAX TMP_MAX stderr stdin stdout
89 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
90 fgets fopen fprintf fputc fputs fread freopen
91 fscanf fseek fsetpos ftell fwrite getchar gets
92 perror putc putchar puts remove rewind
93 scanf setbuf setvbuf sscanf tmpfile tmpnam
94 ungetc vfprintf vprintf vsprintf)],
96 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
97 abort atexit atof atoi atol bsearch calloc div
98 free getenv labs ldiv malloc mblen mbstowcs mbtowc
99 qsort realloc strtod strtol strtoul wcstombs wctomb)],
101 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
102 strchr strcmp strcoll strcpy strcspn strerror strlen
103 strncat strncmp strncpy strpbrk strrchr strspn strstr
106 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
107 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
108 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
111 sys_times_h => [qw()],
113 sys_types_h => [qw()],
115 sys_utsname_h => [qw(uname)],
117 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
118 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
120 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
121 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
122 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
123 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
124 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
125 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
126 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
127 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
129 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
130 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
132 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
133 difftime mktime strftime tzset tzname)],
135 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
136 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
137 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
138 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
139 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
140 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
141 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
142 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
143 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
144 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
145 _exit access ctermid cuserid
146 dup2 dup execl execle execlp execv execve execvp
147 fpathconf getcwd getegid geteuid getgid getgroups
148 getpid getuid isatty lseek pathconf pause setgid setpgid
149 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
155 Exporter::export_tags();
158 closedir opendir readdir rewinddir
161 atan2 cos exp log sin sqrt
164 fileno getc printf rename sprintf
165 abs exit rand srand system
166 chmod mkdir stat umask
169 gmtime localtime time
170 alarm chdir chown close fork getlogin getppid getpgrp link
171 pipe read rmdir sleep unlink write
175 # Grandfather old foo_h form to new :foo_h form
178 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
179 local $Exporter::ExportLevel = 1;
180 Exporter::import($this,@list);
184 bootstrap POSIX $VERSION;
186 my $EINVAL = constant("EINVAL", 0);
187 my $EAGAIN = constant("EAGAIN", 0);
190 if ($AUTOLOAD =~ /::(_?[a-z])/) {
191 $AutoLoader::AUTOLOAD = $AUTOLOAD;
192 goto &AutoLoader::AUTOLOAD
195 my $constname = $AUTOLOAD;
196 $constname =~ s/.*:://;
197 my $val = constant($constname, $_[0]);
199 *$AUTOLOAD = sub { $val };
201 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
202 *$AUTOLOAD = sub { constant($constname, $_[0]) };
204 elsif ($! == $EINVAL) {
205 croak "$constname is not a valid POSIX macro";
208 croak "Your vendor has not defined POSIX macro $constname, used";
216 croak "Usage: POSIX::$mess";
221 croak "Use method $mess instead";
227 croak "Unimplemented: POSIX::$mess";
230 ############################
231 package POSIX::SigAction;
234 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
237 ############################
238 package POSIX; # return to package POSIX so AutoSplit is happy
243 usage "assert(expr)" if @_ != 1;
245 croak "Assertion failed";
250 usage "tolower(string)" if @_ != 1;
255 usage "toupper(string)" if @_ != 1;
260 usage "closedir(dirhandle)" if @_ != 1;
265 usage "opendir(directory)" if @_ != 1;
266 my $dirhandle = gensym;
267 opendir($dirhandle, $_[0])
273 usage "readdir(dirhandle)" if @_ != 1;
278 usage "rewinddir(dirhandle)" if @_ != 1;
283 usage "errno()" if @_ != 0;
288 usage "creat(filename, mode)" if @_ != 2;
289 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
293 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
294 fcntl($_[0], $_[1], $_[2]);
298 usage "getgrgid(gid)" if @_ != 1;
303 usage "getgrnam(name)" if @_ != 1;
308 usage "atan2(x,y)" if @_ != 2;
313 usage "cos(x)" if @_ != 1;
318 usage "exp(x)" if @_ != 1;
323 usage "fabs(x)" if @_ != 1;
328 usage "log(x)" if @_ != 1;
333 usage "pow(x,exponent)" if @_ != 2;
338 usage "sin(x)" if @_ != 1;
343 usage "sqrt(x)" if @_ != 1;
348 usage "getpwnam(name)" if @_ != 1;
353 usage "getpwuid(uid)" if @_ != 1;
358 unimpl "longjmp() is C-specific: use die instead";
362 unimpl "setjmp() is C-specific: use eval {} instead";
366 unimpl "siglongjmp() is C-specific: use die instead";
370 unimpl "sigsetjmp() is C-specific: use eval {} instead";
374 usage "kill(pid, sig)" if @_ != 2;
379 usage "raise(sig)" if @_ != 1;
380 kill $$, $_[0]; # Is this good enough?
384 unimpl "offsetof() is C-specific, stopped";
388 redef "IO::Handle::clearerr()";
392 redef "IO::Handle::close()";
396 redef "IO::Handle::new_from_fd()";
400 redef "IO::Handle::eof()";
404 redef "IO::Handle::getc()";
408 redef "IO::Handle::gets()";
412 redef "IO::Handle::fileno()";
416 redef "IO::File::open()";
420 unimpl "fprintf() is C-specific--use printf instead";
424 unimpl "fputc() is C-specific--use print instead";
428 unimpl "fputs() is C-specific--use print instead";
432 unimpl "fread() is C-specific--use read instead";
436 unimpl "freopen() is C-specific--use open instead";
440 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
444 redef "IO::Seekable::seek()";
448 redef "IO::Handle::error()";
452 redef "IO::Handle::flush()";
456 redef "IO::Seekable::getpos()";
460 redef "IO::Seekable::setpos()";
464 redef "IO::Seekable::tell()";
468 unimpl "fwrite() is C-specific--use print instead";
472 usage "getc(handle)" if @_ != 1;
477 usage "getchar()" if @_ != 0;
482 usage "gets()" if @_ != 0;
487 print STDERR "@_: " if @_;
488 print STDERR $!,"\n";
492 usage "printf(pattern, args...)" if @_ < 1;
497 unimpl "putc() is C-specific--use print instead";
501 unimpl "putchar() is C-specific--use print instead";
505 unimpl "puts() is C-specific--use print instead";
509 usage "remove(filename)" if @_ != 1;
514 usage "rename(oldfilename, newfilename)" if @_ != 2;
515 rename($_[0], $_[1]);
519 usage "rewind(filehandle)" if @_ != 1;
524 unimpl "scanf() is C-specific--use <> and regular expressions instead";
528 usage "sprintf(pattern,args)" if @_ == 0;
533 unimpl "sscanf() is C-specific--use regular expressions instead";
537 redef "IO::File::new_tmpfile()";
541 redef "IO::Handle::ungetc()";
545 unimpl "vfprintf() is C-specific";
549 unimpl "vprintf() is C-specific";
553 unimpl "vsprintf() is C-specific";
557 usage "abs(x)" if @_ != 1;
562 unimpl "atexit() is C-specific: use END {} instead";
566 unimpl "atof() is C-specific, stopped";
570 unimpl "atoi() is C-specific, stopped";
574 unimpl "atol() is C-specific, stopped";
578 unimpl "bsearch() not supplied";
582 unimpl "calloc() is C-specific, stopped";
586 unimpl "div() is C-specific, stopped";
590 usage "exit(status)" if @_ != 1;
595 unimpl "free() is C-specific, stopped";
599 usage "getenv(name)" if @_ != 1;
604 unimpl "labs() is C-specific, use abs instead";
608 unimpl "ldiv() is C-specific, use / and int instead";
612 unimpl "malloc() is C-specific, stopped";
616 unimpl "qsort() is C-specific, use sort instead";
620 unimpl "rand() is non-portable, use Perl's rand instead";
624 unimpl "realloc() is C-specific, stopped";
632 usage "system(command)" if @_ != 1;
637 unimpl "memchr() is C-specific, use index() instead";
641 unimpl "memcmp() is C-specific, use eq instead";
645 unimpl "memcpy() is C-specific, use = instead";
649 unimpl "memmove() is C-specific, use = instead";
653 unimpl "memset() is C-specific, use x instead";
657 unimpl "strcat() is C-specific, use .= instead";
661 unimpl "strchr() is C-specific, use index() instead";
665 unimpl "strcmp() is C-specific, use eq instead";
669 unimpl "strcpy() is C-specific, use = instead";
673 unimpl "strcspn() is C-specific, use regular expressions instead";
677 usage "strerror(errno)" if @_ != 1;
683 unimpl "strlen() is C-specific, use length instead";
687 unimpl "strncat() is C-specific, use .= instead";
691 unimpl "strncmp() is C-specific, use eq instead";
695 unimpl "strncpy() is C-specific, use = instead";
699 unimpl "strpbrk() is C-specific, stopped";
703 unimpl "strrchr() is C-specific, use rindex() instead";
707 unimpl "strspn() is C-specific, stopped";
711 usage "strstr(big, little)" if @_ != 2;
716 unimpl "strtok() is C-specific, stopped";
720 usage "chmod(mode, filename)" if @_ != 2;
725 usage "fstat(fd)" if @_ != 1;
727 open(TMP, "<&$_[0]"); # Gross.
734 usage "mkdir(directoryname, mode)" if @_ != 2;
739 usage "stat(filename)" if @_ != 1;
744 usage "umask(mask)" if @_ != 1;
749 usage "wait()" if @_ != 0;
754 usage "waitpid(pid, options)" if @_ != 2;
755 waitpid($_[0], $_[1]);
759 usage "gmtime(time)" if @_ != 1;
764 usage "localtime(time)" if @_ != 1;
769 usage "time()" if @_ != 0;
774 usage "alarm(seconds)" if @_ != 1;
779 usage "chdir(directory)" if @_ != 1;
784 usage "chown(filename, uid, gid)" if @_ != 3;
785 chown($_[0], $_[1], $_[2]);
789 unimpl "execl() is C-specific, stopped";
793 unimpl "execle() is C-specific, stopped";
797 unimpl "execlp() is C-specific, stopped";
801 unimpl "execv() is C-specific, stopped";
805 unimpl "execve() is C-specific, stopped";
809 unimpl "execvp() is C-specific, stopped";
813 usage "fork()" if @_ != 0;
819 usage "getcwd()" if @_ != 0;
825 usage "getegid()" if @_ != 0;
830 usage "geteuid()" if @_ != 0;
835 usage "getgid()" if @_ != 0;
840 usage "getgroups()" if @_ != 0;
842 grep(!$seen{$_}++, split(' ', $) ));
846 usage "getlogin()" if @_ != 0;
851 usage "getpgrp()" if @_ != 0;
856 usage "getpid()" if @_ != 0;
861 usage "getppid()" if @_ != 0;
866 usage "getuid()" if @_ != 0;
871 usage "isatty(filehandle)" if @_ != 1;
876 usage "link(oldfilename, newfilename)" if @_ != 2;
881 usage "rmdir(directoryname)" if @_ != 1;
886 usage "setgid(gid)" if @_ != 1;
891 usage "setuid(uid)" if @_ != 1;
896 usage "sleep(seconds)" if @_ != 1;
901 usage "unlink(filename)" if @_ != 1;
906 usage "utime(filename, atime, mtime)" if @_ != 3;
907 utime($_[1], $_[2], $_[0]);