Commit | Line | Data |
8990e307 |
1 | package POSIX; |
2 | |
3 | require Exporter; |
4 | require AutoLoader; |
5 | @ISA = (Exporter, AutoLoader, DynamicLoader); |
6 | |
7 | $H{assert_h} = [qw(assert NDEBUG)]; |
8 | |
9 | $H{ctype_h} = [qw(isalnum isalpha iscntrl isdigit isgraph islower |
10 | isprint ispunct isspace isupper isxdigit tolower toupper)]; |
11 | |
12 | $H{dirent_h} = [qw(closedir opendir readdir rewinddir)]; |
13 | |
14 | $H{errno_h} = [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM |
15 | EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE |
16 | EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK |
17 | ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO |
18 | EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)]; |
19 | |
20 | $H{fcntl_h} = [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK |
21 | F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK |
22 | O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK |
23 | O_RDONLY O_RDWR O_TRUNC O_WRONLY |
24 | creat fcntl open |
25 | SEEK_CUR SEEK_END SEEK_SET |
26 | S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU |
27 | S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID |
28 | S_IWGRP S_IWOTH S_IWUSR)]; |
29 | |
30 | $H{float_h} = [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG |
31 | DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP |
32 | DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP |
33 | FLT_DIG FLT_EPSILON FLT_MANT_DIG |
34 | FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP |
35 | FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP |
36 | FLT_RADIX FLT_ROUNDS |
37 | LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG |
38 | LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP |
39 | LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)]; |
40 | |
41 | $H{grp_h} = [qw(getgrgid getgrnam)]; |
42 | |
43 | $H{limits_h} = [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX |
44 | INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON |
45 | MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX |
46 | PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN |
47 | SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX |
48 | ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX |
49 | _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT |
50 | _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX |
51 | _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX |
52 | _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)]; |
53 | |
54 | $H{locale_h} = [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC |
55 | LC_TIME NULL localeconf setlocale)]; |
56 | |
57 | $H{math_h} = [qw(HUGE_VAL acos asin atan2 atan ceil cos cosh exp |
58 | fabs floor fmod frexp ldexp log10 log modf pow sin sinh |
59 | sqrt tan tanh)]; |
60 | |
61 | $H{pwd_h} = [qw(getpwnam getpwuid)]; |
62 | |
63 | $H{setjmp_h} = [qw(longjmp setjmp siglongjmp sigsetjmp)]; |
64 | |
65 | $H{signal_h} = [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE |
66 | SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV |
67 | SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2 |
68 | SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK |
69 | kill raise sigaction sigaddset sigdelset sigemptyset |
70 | sigfillset sigismember signal sigpending sigprocmask |
71 | sigsuspend)]; |
72 | |
73 | $H{stdarg_h} = [qw()]; |
74 | |
75 | $H{stddef_h} = [qw(NULL offsetof)]; |
76 | |
77 | $H{stdio_h} = [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid |
78 | L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET STREAM_MAX |
79 | TMP_MAX stderr stdin stdout _IOFBF _IOLBF _IONBF |
80 | clearerr fclose fdopen feof ferror fflush fgetc fgetpos |
81 | fgets fileno fopen fprintf fputc fputs fread freopen |
82 | fscanf fseek fsetpos ftell fwrite getc getchar gets |
83 | perror printf putc putchar puts remove rename rewind |
84 | scanf setbuf setvbuf sprintf sscanf tmpfile tmpnam |
85 | ungetc vfprintf vprintf vsprintf)]; |
86 | |
87 | $H{stdlib_h} = [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX |
88 | abort abs atexit atof atoi atol bsearch calloc div exit |
89 | free getenv labs ldiv malloc mblen mbstowcs mbtowc |
90 | qsort rand realloc srand strtod strtol stroul system |
91 | wcstombs wctomb)]; |
92 | |
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 |
96 | strtok strxfrm)]; |
97 | |
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 |
101 | chmod fstat mkdir mkfifo stat umask)]; |
102 | |
103 | $H{sys_times_h} = [qw(times)]; |
104 | |
105 | $H{sys_types_h} = [qw()]; |
106 | |
107 | $H{sys_utsname_h} = [qw(uname)]; |
108 | |
109 | $H{sys_wait_h} = [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED |
110 | WNOHANG WSTOPSIG WTERMSIG WUNTRACED wait waitpid)]; |
111 | |
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 |
120 | VSTOP VSUSP VTIME |
121 | cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain |
122 | tcflow tcflush tcgetattr tcsendbreak tcsetattr )]; |
123 | |
124 | $H{time_h} = [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime |
125 | difftime gmtime localtime mktime strftime time tzset tzname)]; |
126 | |
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 alarm chdir chown close ctermid cuserid |
138 | dup2 dup execl execle execlp execv execve execvp fork |
139 | fpathconf getcwd getegid geteuid getgid getgroups |
140 | getlogin getpgrp getpid getppid getuid isatty link |
141 | lseek pathconf pause pipe read rmdir setgid setpgid |
142 | setsid setuid sleep sysconf tcgetpgrp tcsetpgrp ttyname |
143 | unlink write)]; |
144 | |
145 | $H{utime_h} = [qw(utime)]; |
146 | |
147 | sub expand { |
148 | local (@mylist); |
149 | foreach $entry (@_) { |
150 | if ($H{$entry}) { |
151 | push(@mylist, @{$H{$entry}}); |
152 | } |
153 | else { |
154 | push(@mylist, $entry); |
155 | } |
156 | } |
157 | @mylist; |
158 | } |
159 | |
160 | @EXPORT = expand qw(assert_h ctype_h dirent_h errno_h fcntl_h float_h |
161 | grp_h limits_h locale_h math_h pwd_h setjmp_h signal_h |
162 | stdarg_h stddef_h stdio_h stdlib_h string_h sys_stat_h |
163 | sys_times_h sys_types_h sys_utsname_h sys_wait_h |
164 | termios_h time_h unistd_h utime_h); |
165 | |
166 | sub import { |
167 | my $this = shift; |
168 | my @list = expand @_; |
169 | local $Exporter::ExportLevel = 1; |
170 | Exporter::import($this,@list); |
171 | } |
172 | |
173 | bootstrap POSIX; |
174 | |
175 | sub usage { local ($mess, $pack, $file, $line) = @_; |
176 | die "Usage: POSIX::$_[0] at $file line $line\n"; |
177 | } |
178 | |
179 | 1; |
180 | |
181 | __END__ |
182 | sub getpid { |
183 | usage "getpid()", caller if @_ != 0; |
184 | $$; |
185 | } |
186 | |
187 | sub getppid { |
188 | usage "getppid()", caller if @_ != 0; |
189 | getppid; |
190 | } |
191 | |
192 | sub fork { |
193 | usage "fork()", caller if @_ != 0; |
194 | fork; |
195 | } |
196 | |
197 | sub kill { |
198 | usage "kill(pid, sig)", caller if @_ != 2; |
199 | kill $_[1], $_[0]; |
200 | } |