3 # use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD);
4 (@ISA, %EXPORT_TAGS,@EXPORT_OK,$AUTOLOAD) = ();
13 @ISA = qw(Exporter DynaLoader);
15 $VERSION = $VERSION = "1.03" ;
19 assert_h => [qw(assert NDEBUG)],
21 ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower
22 isprint ispunct isspace isupper isxdigit tolower toupper)],
26 errno_h => [qw(E2BIG EACCES EADDRINUSE EADDRNOTAVAIL EAFNOSUPPORT
27 EAGAIN EALREADY EBADF EBUSY ECHILD ECONNABORTED
28 ECONNREFUSED ECONNRESET EDEADLK EDESTADDRREQ EDOM EDQUOT
29 EEXIST EFAULT EFBIG EHOSTDOWN EHOSTUNREACH EINPROGRESS
30 EINTR EINVAL EIO EISCONN EISDIR ELOOP EMFILE EMLINK
31 EMSGSIZE ENAMETOOLONG ENETDOWN ENETRESET ENETUNREACH
32 ENFILE ENOBUFS ENODEV ENOENT ENOEXEC ENOLCK ENOMEM
33 ENOPROTOOPT ENOSPC ENOSYS ENOTBLK ENOTCONN ENOTDIR
34 ENOTEMPTY ENOTSOCK ENOTTY ENXIO EOPNOTSUPP EPERM
35 EPFNOSUPPORT EPIPE EPROCLIM EPROTONOSUPPORT EPROTOTYPE
36 ERANGE EREMOTE ERESTART EROFS ESHUTDOWN ESOCKTNOSUPPORT
37 ESPIPE ESRCH ESTALE ETIMEDOUT ETOOMANYREFS ETXTBSY
38 EUSERS EWOULDBLOCK EXDEV errno)],
40 fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
41 F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
42 O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
43 O_RDONLY O_RDWR O_TRUNC O_WRONLY
45 SEEK_CUR SEEK_END SEEK_SET
46 S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
47 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
48 S_IWGRP S_IWOTH S_IWUSR)],
50 float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
51 DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
52 DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
53 FLT_DIG FLT_EPSILON FLT_MANT_DIG
54 FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
55 FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
57 LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
58 LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
59 LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
63 limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
64 INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
65 MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
66 PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
67 SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
68 ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
69 _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
70 _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
71 _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
72 _POSIX_STREAM_MAX _POSIX_TZNAME_MAX)],
74 locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
75 LC_TIME NULL localeconv setlocale)],
77 math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
78 frexp ldexp log10 modf pow sinh tan tanh)],
82 setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)],
84 signal_h => [qw(SA_NOCLDSTOP SA_NOCLDWAIT SA_NODEFER SA_ONSTACK
85 SA_RESETHAND SA_RESTART SA_SIGINFO SIGABRT SIGALRM
86 SIGCHLD SIGCONT SIGFPE SIGHUP SIGILL SIGINT SIGKILL
87 SIGPIPE SIGQUIT SIGSEGV SIGSTOP SIGTERM SIGTSTP SIGTTIN
88 SIGTTOU SIGUSR1 SIGUSR2 SIG_BLOCK SIG_DFL SIG_ERR
89 SIG_IGN SIG_SETMASK SIG_UNBLOCK raise sigaction signal
90 sigpending sigprocmask sigsuspend)],
94 stddef_h => [qw(NULL offsetof)],
96 stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
97 L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET
98 STREAM_MAX TMP_MAX stderr stdin stdout
99 clearerr fclose fdopen feof ferror fflush fgetc fgetpos
100 fgets fopen fprintf fputc fputs fread freopen
101 fscanf fseek fsetpos ftell fwrite getchar gets
102 perror putc putchar puts remove rewind
103 scanf setbuf setvbuf sscanf tmpfile tmpnam
104 ungetc vfprintf vprintf vsprintf)],
106 stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
107 abort atexit atof atoi atol bsearch calloc div
108 free getenv labs ldiv malloc mblen mbstowcs mbtowc
109 qsort realloc strtod strtol strtoul wcstombs wctomb)],
111 string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat
112 strchr strcmp strcoll strcpy strcspn strerror strlen
113 strncat strncmp strncpy strpbrk strrchr strspn strstr
116 sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
117 S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
118 S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
121 sys_times_h => [qw()],
123 sys_types_h => [qw()],
125 sys_utsname_h => [qw(uname)],
127 sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
128 WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
130 termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
131 B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
132 CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
133 ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
134 INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
135 PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
136 TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
137 TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
139 cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
140 tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
142 time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
143 difftime mktime strftime tzset tzname)],
145 unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
146 STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
147 _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
148 _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
149 _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
150 _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
151 _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
152 _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
153 _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
154 _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
155 _exit access ctermid cuserid
156 dup2 dup execl execle execlp execv execve execvp
157 fpathconf getcwd getegid geteuid getgid getgroups
158 getpid getuid isatty lseek pathconf pause setgid setpgid
159 setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
165 # Exporter::export_tags();
166 for (values %EXPORT_TAGS) {
171 closedir opendir readdir rewinddir
174 atan2 cos exp log sin sqrt
177 fileno getc printf rename sprintf
178 abs exit rand srand system
179 chmod mkdir stat umask
182 gmtime localtime time
183 alarm chdir chown close fork getlogin getppid getpgrp link
184 pipe read rmdir sleep unlink write
189 # Grandfather old foo_h form to new :foo_h form
192 my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
193 local $Exporter::ExportLevel = 1;
194 Exporter::import($this,@list);
198 bootstrap POSIX $VERSION;
200 my $EINVAL = constant("EINVAL", 0);
201 my $EAGAIN = constant("EAGAIN", 0);
204 if ($AUTOLOAD =~ /::(_?[a-z])/) {
205 $AutoLoader::AUTOLOAD = $AUTOLOAD;
206 goto &AutoLoader::AUTOLOAD
209 my $constname = $AUTOLOAD;
210 $constname =~ s/.*:://;
211 my $val = constant($constname, @_ ? $_[0] : 0);
213 *$AUTOLOAD = sub { $val };
215 elsif ($! == $EAGAIN) { # Not really a constant, so always call.
216 *$AUTOLOAD = sub { constant($constname, $_[0]) };
218 elsif ($! == $EINVAL) {
219 croak "$constname is not a valid POSIX macro";
222 croak "Your vendor has not defined POSIX macro $constname, used";
230 croak "Usage: POSIX::$mess";
235 croak "Use method $mess instead";
241 croak "Unimplemented: POSIX::$mess";
244 ############################
245 package POSIX::SigAction;
248 bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0];
251 ############################
252 package POSIX; # return to package POSIX so AutoSplit is happy
257 usage "assert(expr)" if @_ != 1;
259 croak "Assertion failed";
264 usage "tolower(string)" if @_ != 1;
269 usage "toupper(string)" if @_ != 1;
274 usage "closedir(dirhandle)" if @_ != 1;
275 CORE::closedir($_[0]);
279 usage "opendir(directory)" if @_ != 1;
280 my $dirhandle = gensym;
281 CORE::opendir($dirhandle, $_[0])
287 usage "readdir(dirhandle)" if @_ != 1;
288 CORE::readdir($_[0]);
292 usage "rewinddir(dirhandle)" if @_ != 1;
293 CORE::rewinddir($_[0]);
297 usage "errno()" if @_ != 0;
302 usage "creat(filename, mode)" if @_ != 2;
303 &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
307 usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
308 CORE::fcntl($_[0], $_[1], $_[2]);
312 usage "getgrgid(gid)" if @_ != 1;
313 CORE::getgrgid($_[0]);
317 usage "getgrnam(name)" if @_ != 1;
318 CORE::getgrnam($_[0]);
322 usage "atan2(x,y)" if @_ != 2;
323 CORE::atan2($_[0], $_[1]);
327 usage "cos(x)" if @_ != 1;
332 usage "exp(x)" if @_ != 1;
337 usage "fabs(x)" if @_ != 1;
342 usage "log(x)" if @_ != 1;
347 usage "pow(x,exponent)" if @_ != 2;
352 usage "sin(x)" if @_ != 1;
357 usage "sqrt(x)" if @_ != 1;
362 usage "getpwnam(name)" if @_ != 1;
363 CORE::getpwnam($_[0]);
367 usage "getpwuid(uid)" if @_ != 1;
368 CORE::getpwuid($_[0]);
372 unimpl "longjmp() is C-specific: use die instead";
376 unimpl "setjmp() is C-specific: use eval {} instead";
380 unimpl "siglongjmp() is C-specific: use die instead";
384 unimpl "sigsetjmp() is C-specific: use eval {} instead";
388 usage "kill(pid, sig)" if @_ != 2;
389 CORE::kill $_[1], $_[0];
393 usage "raise(sig)" if @_ != 1;
394 CORE::kill $_[0], $$; # Is this good enough?
398 unimpl "offsetof() is C-specific, stopped";
402 redef "IO::Handle::clearerr()";
406 redef "IO::Handle::close()";
410 redef "IO::Handle::new_from_fd()";
414 redef "IO::Handle::eof()";
418 redef "IO::Handle::getc()";
422 redef "IO::Handle::gets()";
426 redef "IO::Handle::fileno()";
430 redef "IO::File::open()";
434 unimpl "fprintf() is C-specific--use printf instead";
438 unimpl "fputc() is C-specific--use print instead";
442 unimpl "fputs() is C-specific--use print instead";
446 unimpl "fread() is C-specific--use read instead";
450 unimpl "freopen() is C-specific--use open instead";
454 unimpl "fscanf() is C-specific--use <> and regular expressions instead";
458 redef "IO::Seekable::seek()";
462 redef "IO::Handle::error()";
466 redef "IO::Handle::flush()";
470 redef "IO::Seekable::getpos()";
474 redef "IO::Seekable::setpos()";
478 redef "IO::Seekable::tell()";
482 unimpl "fwrite() is C-specific--use print instead";
486 usage "getc(handle)" if @_ != 1;
491 usage "getchar()" if @_ != 0;
496 usage "gets()" if @_ != 0;
501 print STDERR "@_: " if @_;
502 print STDERR $!,"\n";
506 usage "printf(pattern, args...)" if @_ < 1;
507 CORE::printf STDOUT @_;
511 unimpl "putc() is C-specific--use print instead";
515 unimpl "putchar() is C-specific--use print instead";
519 unimpl "puts() is C-specific--use print instead";
523 usage "remove(filename)" if @_ != 1;
528 usage "rename(oldfilename, newfilename)" if @_ != 2;
529 CORE::rename($_[0], $_[1]);
533 usage "rewind(filehandle)" if @_ != 1;
534 CORE::seek($_[0],0,0);
538 unimpl "scanf() is C-specific--use <> and regular expressions instead";
542 usage "sprintf(pattern,args)" if @_ == 0;
543 CORE::sprintf(shift,@_);
547 unimpl "sscanf() is C-specific--use regular expressions instead";
551 redef "IO::File::new_tmpfile()";
555 redef "IO::Handle::ungetc()";
559 unimpl "vfprintf() is C-specific";
563 unimpl "vprintf() is C-specific";
567 unimpl "vsprintf() is C-specific";
571 usage "abs(x)" if @_ != 1;
576 unimpl "atexit() is C-specific: use END {} instead";
580 unimpl "atof() is C-specific, stopped";
584 unimpl "atoi() is C-specific, stopped";
588 unimpl "atol() is C-specific, stopped";
592 unimpl "bsearch() not supplied";
596 unimpl "calloc() is C-specific, stopped";
600 unimpl "div() is C-specific, stopped";
604 usage "exit(status)" if @_ != 1;
609 unimpl "free() is C-specific, stopped";
613 usage "getenv(name)" if @_ != 1;
618 unimpl "labs() is C-specific, use abs instead";
622 unimpl "ldiv() is C-specific, use / and int instead";
626 unimpl "malloc() is C-specific, stopped";
630 unimpl "qsort() is C-specific, use sort instead";
634 unimpl "rand() is non-portable, use Perl's rand instead";
638 unimpl "realloc() is C-specific, stopped";
646 usage "system(command)" if @_ != 1;
651 unimpl "memchr() is C-specific, use index() instead";
655 unimpl "memcmp() is C-specific, use eq instead";
659 unimpl "memcpy() is C-specific, use = instead";
663 unimpl "memmove() is C-specific, use = instead";
667 unimpl "memset() is C-specific, use x instead";
671 unimpl "strcat() is C-specific, use .= instead";
675 unimpl "strchr() is C-specific, use index() instead";
679 unimpl "strcmp() is C-specific, use eq instead";
683 unimpl "strcpy() is C-specific, use = instead";
687 unimpl "strcspn() is C-specific, use regular expressions instead";
691 usage "strerror(errno)" if @_ != 1;
697 unimpl "strlen() is C-specific, use length instead";
701 unimpl "strncat() is C-specific, use .= instead";
705 unimpl "strncmp() is C-specific, use eq instead";
709 unimpl "strncpy() is C-specific, use = instead";
713 unimpl "strpbrk() is C-specific, stopped";
717 unimpl "strrchr() is C-specific, use rindex() instead";
721 unimpl "strspn() is C-specific, stopped";
725 usage "strstr(big, little)" if @_ != 2;
726 CORE::index($_[0], $_[1]);
730 unimpl "strtok() is C-specific, stopped";
734 usage "chmod(mode, filename)" if @_ != 2;
735 CORE::chmod($_[0], $_[1]);
739 usage "fstat(fd)" if @_ != 1;
741 open(TMP, "<&$_[0]"); # Gross.
742 my @l = CORE::stat(TMP);
748 usage "mkdir(directoryname, mode)" if @_ != 2;
749 CORE::mkdir($_[0], $_[1]);
753 usage "stat(filename)" if @_ != 1;
758 usage "umask(mask)" if @_ != 1;
763 usage "wait()" if @_ != 0;
768 usage "waitpid(pid, options)" if @_ != 2;
769 CORE::waitpid($_[0], $_[1]);
773 usage "gmtime(time)" if @_ != 1;
778 usage "localtime(time)" if @_ != 1;
779 CORE::localtime($_[0]);
783 usage "time()" if @_ != 0;
788 usage "alarm(seconds)" if @_ != 1;
793 usage "chdir(directory)" if @_ != 1;
798 usage "chown(filename, uid, gid)" if @_ != 3;
799 CORE::chown($_[0], $_[1], $_[2]);
803 unimpl "execl() is C-specific, stopped";
807 unimpl "execle() is C-specific, stopped";
811 unimpl "execlp() is C-specific, stopped";
815 unimpl "execv() is C-specific, stopped";
819 unimpl "execve() is C-specific, stopped";
823 unimpl "execvp() is C-specific, stopped";
827 usage "fork()" if @_ != 0;
833 usage "getcwd()" if @_ != 0;
834 if ($^O eq 'MSWin32') {
835 # this perhaps applies to everyone else also?
846 usage "getegid()" if @_ != 0;
851 usage "geteuid()" if @_ != 0;
856 usage "getgid()" if @_ != 0;
861 usage "getgroups()" if @_ != 0;
863 grep(!$seen{$_}++, split(' ', $) ));
867 usage "getlogin()" if @_ != 0;
872 usage "getpgrp()" if @_ != 0;
877 usage "getpid()" if @_ != 0;
882 usage "getppid()" if @_ != 0;
887 usage "getuid()" if @_ != 0;
892 usage "isatty(filehandle)" if @_ != 1;
897 usage "link(oldfilename, newfilename)" if @_ != 2;
898 CORE::link($_[0], $_[1]);
902 usage "rmdir(directoryname)" if @_ != 1;
907 redef "IO::Handle::setbuf()";
911 usage "setgid(gid)" if @_ != 1;
916 usage "setuid(uid)" if @_ != 1;
921 redef "IO::Handle::setvbuf()";
925 usage "sleep(seconds)" if @_ != 1;
930 usage "unlink(filename)" if @_ != 1;
935 usage "utime(filename, atime, mtime)" if @_ != 3;
936 CORE::utime($_[1], $_[2], $_[0]);