Commit | Line | Data |
a0d0e21e |
1 | package POSIX; |
2 | |
73c78b0a |
3 | use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD); |
4 | |
a0d0e21e |
5 | use Carp; |
3b35bae3 |
6 | use AutoLoader; |
a0d0e21e |
7 | require Config; |
c07a80fd |
8 | use Symbol; |
9 | |
10 | require Exporter; |
11 | require DynaLoader; |
fec02dd3 |
12 | @ISA = qw(Exporter DynaLoader); |
a0d0e21e |
13 | |
73c78b0a |
14 | $VERSION = "1.00" ; |
c07a80fd |
15 | |
748a9306 |
16 | %EXPORT_TAGS = ( |
a0d0e21e |
17 | |
748a9306 |
18 | assert_h => [qw(assert NDEBUG)], |
a0d0e21e |
19 | |
748a9306 |
20 | ctype_h => [qw(isalnum isalpha iscntrl isdigit isgraph islower |
21 | isprint ispunct isspace isupper isxdigit tolower toupper)], |
a0d0e21e |
22 | |
748a9306 |
23 | dirent_h => [qw()], |
24 | |
25 | errno_h => [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM |
a0d0e21e |
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 |
748a9306 |
29 | EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)], |
a0d0e21e |
30 | |
748a9306 |
31 | fcntl_h => [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK |
a0d0e21e |
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 |
35 | creat |
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 |
748a9306 |
39 | S_IWGRP S_IWOTH S_IWUSR)], |
a0d0e21e |
40 | |
748a9306 |
41 | float_h => [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG |
a0d0e21e |
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 |
47 | FLT_RADIX FLT_ROUNDS |
48 | LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG |
49 | LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP |
748a9306 |
50 | LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)], |
a0d0e21e |
51 | |
748a9306 |
52 | grp_h => [qw()], |
a0d0e21e |
53 | |
748a9306 |
54 | limits_h => [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX |
a0d0e21e |
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 |
748a9306 |
63 | _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)], |
a0d0e21e |
64 | |
748a9306 |
65 | locale_h => [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC |
66 | LC_TIME NULL localeconv setlocale)], |
a0d0e21e |
67 | |
748a9306 |
68 | math_h => [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod |
3b35bae3 |
69 | frexp ldexp log10 modf pow sinh tan tanh)], |
a0d0e21e |
70 | |
748a9306 |
71 | pwd_h => [qw()], |
a0d0e21e |
72 | |
748a9306 |
73 | setjmp_h => [qw(longjmp setjmp siglongjmp sigsetjmp)], |
a0d0e21e |
74 | |
748a9306 |
75 | signal_h => [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE |
a0d0e21e |
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 |
748a9306 |
80 | sigsuspend)], |
a0d0e21e |
81 | |
748a9306 |
82 | stdarg_h => [qw()], |
a0d0e21e |
83 | |
748a9306 |
84 | stddef_h => [qw(NULL offsetof)], |
a0d0e21e |
85 | |
748a9306 |
86 | stdio_h => [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid |
c07a80fd |
87 | L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET |
88 | STREAM_MAX TMP_MAX stderr stdin stdout |
a0d0e21e |
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 |
748a9306 |
94 | ungetc vfprintf vprintf vsprintf)], |
a0d0e21e |
95 | |
748a9306 |
96 | stdlib_h => [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX |
a0d0e21e |
97 | abort atexit atof atoi atol bsearch calloc div |
98 | free getenv labs ldiv malloc mblen mbstowcs mbtowc |
a89d8a78 |
99 | qsort realloc strtod strtol strtoul wcstombs wctomb)], |
a0d0e21e |
100 | |
748a9306 |
101 | string_h => [qw(NULL memchr memcmp memcpy memmove memset strcat |
a0d0e21e |
102 | strchr strcmp strcoll strcpy strcspn strerror strlen |
103 | strncat strncmp strncpy strpbrk strrchr strspn strstr |
748a9306 |
104 | strtok strxfrm)], |
a0d0e21e |
105 | |
748a9306 |
106 | sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU |
a0d0e21e |
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 |
748a9306 |
109 | fstat mkfifo)], |
a0d0e21e |
110 | |
748a9306 |
111 | sys_times_h => [qw()], |
a0d0e21e |
112 | |
748a9306 |
113 | sys_types_h => [qw()], |
a0d0e21e |
114 | |
748a9306 |
115 | sys_utsname_h => [qw(uname)], |
a0d0e21e |
116 | |
748a9306 |
117 | sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED |
118 | WNOHANG WSTOPSIG WTERMSIG WUNTRACED)], |
a0d0e21e |
119 | |
748a9306 |
120 | termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400 |
a0d0e21e |
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 |
128 | VSTOP VSUSP VTIME |
129 | cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain |
748a9306 |
130 | tcflow tcflush tcgetattr tcsendbreak tcsetattr )], |
a0d0e21e |
131 | |
748a9306 |
132 | time_h => [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime |
133 | difftime mktime strftime tzset tzname)], |
a0d0e21e |
134 | |
748a9306 |
135 | unistd_h => [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET |
a0d0e21e |
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 |
748a9306 |
149 | setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)], |
a0d0e21e |
150 | |
748a9306 |
151 | utime_h => [qw()], |
a0d0e21e |
152 | |
748a9306 |
153 | ); |
a0d0e21e |
154 | |
748a9306 |
155 | Exporter::export_tags(); |
a0d0e21e |
156 | |
157 | @EXPORT_OK = qw( |
158 | closedir opendir readdir rewinddir |
159 | fcntl open |
160 | getgrgid getgrnam |
3b35bae3 |
161 | atan2 cos exp log sin sqrt |
a0d0e21e |
162 | getpwnam getpwuid |
163 | kill |
164 | fileno getc printf rename sprintf |
165 | abs exit rand srand system |
166 | chmod mkdir stat umask |
167 | times |
168 | wait waitpid |
169 | gmtime localtime time |
170 | alarm chdir chown close fork getlogin getppid getpgrp link |
171 | pipe read rmdir sleep unlink write |
172 | utime |
173 | ); |
174 | |
748a9306 |
175 | # Grandfather old foo_h form to new :foo_h form |
a0d0e21e |
176 | sub import { |
177 | my $this = shift; |
748a9306 |
178 | my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_; |
a0d0e21e |
179 | local $Exporter::ExportLevel = 1; |
180 | Exporter::import($this,@list); |
181 | } |
182 | |
4633a7c4 |
183 | |
73c78b0a |
184 | bootstrap POSIX $VERSION; |
4633a7c4 |
185 | |
186 | my $EINVAL = constant("EINVAL", 0); |
187 | my $EAGAIN = constant("EAGAIN", 0); |
188 | |
a0d0e21e |
189 | sub AUTOLOAD { |
190 | if ($AUTOLOAD =~ /::(_?[a-z])/) { |
191 | $AutoLoader::AUTOLOAD = $AUTOLOAD; |
192 | goto &AutoLoader::AUTOLOAD |
193 | } |
4633a7c4 |
194 | local $! = 0; |
195 | my $constname = $AUTOLOAD; |
a0d0e21e |
196 | $constname =~ s/.*:://; |
3f73d1e9 |
197 | my $val = constant($constname, @_ ? $_[0] : 0); |
4633a7c4 |
198 | if ($! == 0) { |
199 | *$AUTOLOAD = sub { $val }; |
200 | } |
201 | elsif ($! == $EAGAIN) { # Not really a constant, so always call. |
202 | *$AUTOLOAD = sub { constant($constname, $_[0]) }; |
203 | } |
204 | elsif ($! == $EINVAL) { |
205 | croak "$constname is not a valid POSIX macro"; |
a0d0e21e |
206 | } |
4633a7c4 |
207 | else { |
208 | croak "Your vendor has not defined POSIX macro $constname, used"; |
209 | } |
210 | |
a0d0e21e |
211 | goto &$AUTOLOAD; |
212 | } |
213 | |
a0d0e21e |
214 | sub usage { |
c07a80fd |
215 | my ($mess) = @_; |
a0d0e21e |
216 | croak "Usage: POSIX::$mess"; |
217 | } |
218 | |
219 | sub redef { |
c07a80fd |
220 | my ($mess) = @_; |
a0d0e21e |
221 | croak "Use method $mess instead"; |
222 | } |
223 | |
224 | sub unimpl { |
c07a80fd |
225 | my ($mess) = @_; |
a0d0e21e |
226 | $mess =~ s/xxx//; |
227 | croak "Unimplemented: POSIX::$mess"; |
228 | } |
229 | |
a0d0e21e |
230 | ############################ |
231 | package POSIX::SigAction; |
232 | |
233 | sub new { |
28757baa |
234 | bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3] || 0}, $_[0]; |
a0d0e21e |
235 | } |
236 | |
237 | ############################ |
a0d0e21e |
238 | package POSIX; # return to package POSIX so AutoSplit is happy |
239 | 1; |
240 | __END__ |
241 | |
242 | sub assert { |
243 | usage "assert(expr)" if @_ != 1; |
244 | if (!$_[0]) { |
245 | croak "Assertion failed"; |
246 | } |
247 | } |
248 | |
249 | sub tolower { |
250 | usage "tolower(string)" if @_ != 1; |
251 | lc($_[0]); |
252 | } |
253 | |
254 | sub toupper { |
255 | usage "toupper(string)" if @_ != 1; |
256 | uc($_[0]); |
257 | } |
258 | |
259 | sub closedir { |
260 | usage "closedir(dirhandle)" if @_ != 1; |
261 | closedir($_[0]); |
a0d0e21e |
262 | } |
263 | |
264 | sub opendir { |
265 | usage "opendir(directory)" if @_ != 1; |
c07a80fd |
266 | my $dirhandle = gensym; |
a0d0e21e |
267 | opendir($dirhandle, $_[0]) |
268 | ? $dirhandle |
4633a7c4 |
269 | : undef; |
a0d0e21e |
270 | } |
271 | |
272 | sub readdir { |
273 | usage "readdir(dirhandle)" if @_ != 1; |
274 | readdir($_[0]); |
275 | } |
276 | |
277 | sub rewinddir { |
278 | usage "rewinddir(dirhandle)" if @_ != 1; |
279 | rewinddir($_[0]); |
280 | } |
281 | |
282 | sub errno { |
283 | usage "errno()" if @_ != 0; |
284 | $! + 0; |
285 | } |
286 | |
287 | sub creat { |
288 | usage "creat(filename, mode)" if @_ != 2; |
94b6baf5 |
289 | &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]); |
a0d0e21e |
290 | } |
291 | |
292 | sub fcntl { |
293 | usage "fcntl(filehandle, cmd, arg)" if @_ != 3; |
294 | fcntl($_[0], $_[1], $_[2]); |
295 | } |
296 | |
297 | sub getgrgid { |
298 | usage "getgrgid(gid)" if @_ != 1; |
299 | getgrgid($_[0]); |
300 | } |
301 | |
302 | sub getgrnam { |
303 | usage "getgrnam(name)" if @_ != 1; |
304 | getgrnam($_[0]); |
305 | } |
306 | |
307 | sub atan2 { |
308 | usage "atan2(x,y)" if @_ != 2; |
309 | atan2($_[0], $_[1]); |
310 | } |
311 | |
312 | sub cos { |
313 | usage "cos(x)" if @_ != 1; |
314 | cos($_[0]); |
315 | } |
316 | |
317 | sub exp { |
318 | usage "exp(x)" if @_ != 1; |
319 | exp($_[0]); |
320 | } |
321 | |
322 | sub fabs { |
323 | usage "fabs(x)" if @_ != 1; |
324 | abs($_[0]); |
325 | } |
326 | |
327 | sub log { |
328 | usage "log(x)" if @_ != 1; |
329 | log($_[0]); |
330 | } |
331 | |
332 | sub pow { |
333 | usage "pow(x,exponent)" if @_ != 2; |
334 | $_[0] ** $_[1]; |
335 | } |
336 | |
337 | sub sin { |
338 | usage "sin(x)" if @_ != 1; |
339 | sin($_[0]); |
340 | } |
341 | |
342 | sub sqrt { |
343 | usage "sqrt(x)" if @_ != 1; |
344 | sqrt($_[0]); |
345 | } |
346 | |
a0d0e21e |
347 | sub getpwnam { |
348 | usage "getpwnam(name)" if @_ != 1; |
349 | getpwnam($_[0]); |
350 | } |
351 | |
352 | sub getpwuid { |
353 | usage "getpwuid(uid)" if @_ != 1; |
354 | getpwuid($_[0]); |
355 | } |
356 | |
357 | sub longjmp { |
358 | unimpl "longjmp() is C-specific: use die instead"; |
359 | } |
360 | |
361 | sub setjmp { |
362 | unimpl "setjmp() is C-specific: use eval {} instead"; |
363 | } |
364 | |
365 | sub siglongjmp { |
366 | unimpl "siglongjmp() is C-specific: use die instead"; |
367 | } |
368 | |
369 | sub sigsetjmp { |
370 | unimpl "sigsetjmp() is C-specific: use eval {} instead"; |
371 | } |
372 | |
373 | sub kill { |
374 | usage "kill(pid, sig)" if @_ != 2; |
375 | kill $_[1], $_[0]; |
376 | } |
377 | |
378 | sub raise { |
379 | usage "raise(sig)" if @_ != 1; |
380 | kill $$, $_[0]; # Is this good enough? |
381 | } |
382 | |
383 | sub offsetof { |
384 | unimpl "offsetof() is C-specific, stopped"; |
385 | } |
386 | |
387 | sub clearerr { |
28757baa |
388 | redef "IO::Handle::clearerr()"; |
a0d0e21e |
389 | } |
390 | |
391 | sub fclose { |
28757baa |
392 | redef "IO::Handle::close()"; |
a0d0e21e |
393 | } |
394 | |
395 | sub fdopen { |
28757baa |
396 | redef "IO::Handle::new_from_fd()"; |
a0d0e21e |
397 | } |
398 | |
399 | sub feof { |
28757baa |
400 | redef "IO::Handle::eof()"; |
a0d0e21e |
401 | } |
402 | |
403 | sub fgetc { |
28757baa |
404 | redef "IO::Handle::getc()"; |
a0d0e21e |
405 | } |
406 | |
407 | sub fgets { |
28757baa |
408 | redef "IO::Handle::gets()"; |
a0d0e21e |
409 | } |
410 | |
411 | sub fileno { |
28757baa |
412 | redef "IO::Handle::fileno()"; |
a0d0e21e |
413 | } |
414 | |
415 | sub fopen { |
28757baa |
416 | redef "IO::File::open()"; |
a0d0e21e |
417 | } |
418 | |
419 | sub fprintf { |
420 | unimpl "fprintf() is C-specific--use printf instead"; |
421 | } |
422 | |
423 | sub fputc { |
424 | unimpl "fputc() is C-specific--use print instead"; |
425 | } |
426 | |
427 | sub fputs { |
428 | unimpl "fputs() is C-specific--use print instead"; |
429 | } |
430 | |
431 | sub fread { |
432 | unimpl "fread() is C-specific--use read instead"; |
433 | } |
434 | |
435 | sub freopen { |
436 | unimpl "freopen() is C-specific--use open instead"; |
437 | } |
438 | |
439 | sub fscanf { |
440 | unimpl "fscanf() is C-specific--use <> and regular expressions instead"; |
441 | } |
442 | |
443 | sub fseek { |
28757baa |
444 | redef "IO::Seekable::seek()"; |
a0d0e21e |
445 | } |
446 | |
447 | sub ferror { |
28757baa |
448 | redef "IO::Handle::error()"; |
a0d0e21e |
449 | } |
450 | |
451 | sub fflush { |
28757baa |
452 | redef "IO::Handle::flush()"; |
a0d0e21e |
453 | } |
454 | |
455 | sub fgetpos { |
28757baa |
456 | redef "IO::Seekable::getpos()"; |
a0d0e21e |
457 | } |
458 | |
459 | sub fsetpos { |
28757baa |
460 | redef "IO::Seekable::setpos()"; |
a0d0e21e |
461 | } |
462 | |
463 | sub ftell { |
28757baa |
464 | redef "IO::Seekable::tell()"; |
a0d0e21e |
465 | } |
466 | |
467 | sub fwrite { |
468 | unimpl "fwrite() is C-specific--use print instead"; |
469 | } |
470 | |
471 | sub getc { |
472 | usage "getc(handle)" if @_ != 1; |
473 | getc($_[0]); |
474 | } |
475 | |
476 | sub getchar { |
477 | usage "getchar()" if @_ != 0; |
478 | getc(STDIN); |
479 | } |
480 | |
481 | sub gets { |
482 | usage "gets()" if @_ != 0; |
483 | scalar <STDIN>; |
484 | } |
485 | |
486 | sub perror { |
487 | print STDERR "@_: " if @_; |
488 | print STDERR $!,"\n"; |
489 | } |
490 | |
491 | sub printf { |
492 | usage "printf(pattern, args...)" if @_ < 1; |
493 | printf STDOUT @_; |
494 | } |
495 | |
496 | sub putc { |
497 | unimpl "putc() is C-specific--use print instead"; |
498 | } |
499 | |
500 | sub putchar { |
501 | unimpl "putchar() is C-specific--use print instead"; |
502 | } |
503 | |
504 | sub puts { |
505 | unimpl "puts() is C-specific--use print instead"; |
506 | } |
507 | |
508 | sub remove { |
509 | usage "remove(filename)" if @_ != 1; |
510 | unlink($_[0]); |
511 | } |
512 | |
513 | sub rename { |
514 | usage "rename(oldfilename, newfilename)" if @_ != 2; |
515 | rename($_[0], $_[1]); |
516 | } |
517 | |
518 | sub rewind { |
519 | usage "rewind(filehandle)" if @_ != 1; |
520 | seek($_[0],0,0); |
521 | } |
522 | |
523 | sub scanf { |
524 | unimpl "scanf() is C-specific--use <> and regular expressions instead"; |
525 | } |
526 | |
527 | sub sprintf { |
528 | usage "sprintf(pattern,args)" if @_ == 0; |
529 | sprintf(shift,@_); |
530 | } |
531 | |
532 | sub sscanf { |
533 | unimpl "sscanf() is C-specific--use regular expressions instead"; |
534 | } |
535 | |
536 | sub tmpfile { |
28757baa |
537 | redef "IO::File::new_tmpfile()"; |
a0d0e21e |
538 | } |
539 | |
540 | sub ungetc { |
28757baa |
541 | redef "IO::Handle::ungetc()"; |
a0d0e21e |
542 | } |
543 | |
544 | sub vfprintf { |
545 | unimpl "vfprintf() is C-specific"; |
546 | } |
547 | |
548 | sub vprintf { |
549 | unimpl "vprintf() is C-specific"; |
550 | } |
551 | |
552 | sub vsprintf { |
553 | unimpl "vsprintf() is C-specific"; |
554 | } |
555 | |
556 | sub abs { |
557 | usage "abs(x)" if @_ != 1; |
558 | abs($_[0]); |
559 | } |
560 | |
561 | sub atexit { |
562 | unimpl "atexit() is C-specific: use END {} instead"; |
563 | } |
564 | |
565 | sub atof { |
566 | unimpl "atof() is C-specific, stopped"; |
567 | } |
568 | |
569 | sub atoi { |
570 | unimpl "atoi() is C-specific, stopped"; |
571 | } |
572 | |
573 | sub atol { |
574 | unimpl "atol() is C-specific, stopped"; |
575 | } |
576 | |
577 | sub bsearch { |
37120919 |
578 | unimpl "bsearch() not supplied"; |
a0d0e21e |
579 | } |
580 | |
581 | sub calloc { |
582 | unimpl "calloc() is C-specific, stopped"; |
583 | } |
584 | |
585 | sub div { |
586 | unimpl "div() is C-specific, stopped"; |
587 | } |
588 | |
589 | sub exit { |
590 | usage "exit(status)" if @_ != 1; |
591 | exit($_[0]); |
592 | } |
593 | |
594 | sub free { |
595 | unimpl "free() is C-specific, stopped"; |
a0d0e21e |
596 | } |
597 | |
598 | sub getenv { |
599 | usage "getenv(name)" if @_ != 1; |
600 | $ENV{$_[0]}; |
601 | } |
602 | |
603 | sub labs { |
604 | unimpl "labs() is C-specific, use abs instead"; |
605 | } |
606 | |
607 | sub ldiv { |
608 | unimpl "ldiv() is C-specific, use / and int instead"; |
609 | } |
610 | |
611 | sub malloc { |
612 | unimpl "malloc() is C-specific, stopped"; |
613 | } |
614 | |
615 | sub qsort { |
616 | unimpl "qsort() is C-specific, use sort instead"; |
617 | } |
618 | |
619 | sub rand { |
620 | unimpl "rand() is non-portable, use Perl's rand instead"; |
621 | } |
622 | |
623 | sub realloc { |
624 | unimpl "realloc() is C-specific, stopped"; |
625 | } |
626 | |
627 | sub srand { |
628 | unimpl "srand()"; |
629 | } |
630 | |
a0d0e21e |
631 | sub system { |
632 | usage "system(command)" if @_ != 1; |
633 | system($_[0]); |
634 | } |
635 | |
636 | sub memchr { |
637 | unimpl "memchr() is C-specific, use index() instead"; |
638 | } |
639 | |
640 | sub memcmp { |
641 | unimpl "memcmp() is C-specific, use eq instead"; |
642 | } |
643 | |
644 | sub memcpy { |
645 | unimpl "memcpy() is C-specific, use = instead"; |
37120919 |
646 | } |
a0d0e21e |
647 | |
648 | sub memmove { |
649 | unimpl "memmove() is C-specific, use = instead"; |
650 | } |
651 | |
652 | sub memset { |
653 | unimpl "memset() is C-specific, use x instead"; |
654 | } |
655 | |
656 | sub strcat { |
657 | unimpl "strcat() is C-specific, use .= instead"; |
658 | } |
659 | |
660 | sub strchr { |
661 | unimpl "strchr() is C-specific, use index() instead"; |
662 | } |
663 | |
664 | sub strcmp { |
665 | unimpl "strcmp() is C-specific, use eq instead"; |
666 | } |
667 | |
668 | sub strcpy { |
669 | unimpl "strcpy() is C-specific, use = instead"; |
670 | } |
671 | |
672 | sub strcspn { |
673 | unimpl "strcspn() is C-specific, use regular expressions instead"; |
674 | } |
675 | |
676 | sub strerror { |
677 | usage "strerror(errno)" if @_ != 1; |
678 | local $! = $_[0]; |
679 | $! . ""; |
680 | } |
681 | |
682 | sub strlen { |
683 | unimpl "strlen() is C-specific, use length instead"; |
684 | } |
685 | |
686 | sub strncat { |
687 | unimpl "strncat() is C-specific, use .= instead"; |
688 | } |
689 | |
690 | sub strncmp { |
691 | unimpl "strncmp() is C-specific, use eq instead"; |
692 | } |
693 | |
694 | sub strncpy { |
695 | unimpl "strncpy() is C-specific, use = instead"; |
696 | } |
697 | |
698 | sub strpbrk { |
699 | unimpl "strpbrk() is C-specific, stopped"; |
700 | } |
701 | |
702 | sub strrchr { |
703 | unimpl "strrchr() is C-specific, use rindex() instead"; |
704 | } |
705 | |
706 | sub strspn { |
707 | unimpl "strspn() is C-specific, stopped"; |
708 | } |
709 | |
710 | sub strstr { |
711 | usage "strstr(big, little)" if @_ != 2; |
712 | index($_[0], $_[1]); |
713 | } |
714 | |
715 | sub strtok { |
716 | unimpl "strtok() is C-specific, stopped"; |
717 | } |
718 | |
719 | sub chmod { |
3b35bae3 |
720 | usage "chmod(mode, filename)" if @_ != 2; |
a0d0e21e |
721 | chmod($_[0], $_[1]); |
722 | } |
723 | |
724 | sub fstat { |
725 | usage "fstat(fd)" if @_ != 1; |
c07a80fd |
726 | local *TMP; |
a0d0e21e |
727 | open(TMP, "<&$_[0]"); # Gross. |
c07a80fd |
728 | my @l = stat(TMP); |
a0d0e21e |
729 | close(TMP); |
730 | @l; |
731 | } |
732 | |
733 | sub mkdir { |
734 | usage "mkdir(directoryname, mode)" if @_ != 2; |
735 | mkdir($_[0], $_[1]); |
736 | } |
737 | |
738 | sub stat { |
739 | usage "stat(filename)" if @_ != 1; |
740 | stat($_[0]); |
741 | } |
742 | |
743 | sub umask { |
744 | usage "umask(mask)" if @_ != 1; |
745 | umask($_[0]); |
746 | } |
747 | |
a0d0e21e |
748 | sub wait { |
cb1a09d0 |
749 | usage "wait()" if @_ != 0; |
750 | wait(); |
a0d0e21e |
751 | } |
752 | |
753 | sub waitpid { |
cb1a09d0 |
754 | usage "waitpid(pid, options)" if @_ != 2; |
755 | waitpid($_[0], $_[1]); |
a0d0e21e |
756 | } |
757 | |
758 | sub gmtime { |
759 | usage "gmtime(time)" if @_ != 1; |
760 | gmtime($_[0]); |
761 | } |
762 | |
763 | sub localtime { |
764 | usage "localtime(time)" if @_ != 1; |
765 | localtime($_[0]); |
766 | } |
767 | |
768 | sub time { |
37120919 |
769 | usage "time()" if @_ != 0; |
a0d0e21e |
770 | time; |
771 | } |
772 | |
773 | sub alarm { |
774 | usage "alarm(seconds)" if @_ != 1; |
775 | alarm($_[0]); |
776 | } |
777 | |
778 | sub chdir { |
779 | usage "chdir(directory)" if @_ != 1; |
780 | chdir($_[0]); |
781 | } |
782 | |
783 | sub chown { |
784 | usage "chown(filename, uid, gid)" if @_ != 3; |
785 | chown($_[0], $_[1], $_[2]); |
786 | } |
787 | |
788 | sub execl { |
789 | unimpl "execl() is C-specific, stopped"; |
a0d0e21e |
790 | } |
791 | |
792 | sub execle { |
793 | unimpl "execle() is C-specific, stopped"; |
a0d0e21e |
794 | } |
795 | |
796 | sub execlp { |
797 | unimpl "execlp() is C-specific, stopped"; |
a0d0e21e |
798 | } |
799 | |
800 | sub execv { |
801 | unimpl "execv() is C-specific, stopped"; |
a0d0e21e |
802 | } |
803 | |
804 | sub execve { |
805 | unimpl "execve() is C-specific, stopped"; |
a0d0e21e |
806 | } |
807 | |
808 | sub execvp { |
809 | unimpl "execvp() is C-specific, stopped"; |
a0d0e21e |
810 | } |
811 | |
812 | sub fork { |
813 | usage "fork()" if @_ != 0; |
814 | fork; |
815 | } |
816 | |
817 | sub getcwd |
818 | { |
819 | usage "getcwd()" if @_ != 0; |
820 | chop($cwd = `pwd`); |
821 | $cwd; |
822 | } |
823 | |
824 | sub getegid { |
825 | usage "getegid()" if @_ != 0; |
826 | $) + 0; |
827 | } |
828 | |
829 | sub geteuid { |
830 | usage "geteuid()" if @_ != 0; |
831 | $> + 0; |
832 | } |
833 | |
834 | sub getgid { |
835 | usage "getgid()" if @_ != 0; |
836 | $( + 0; |
837 | } |
838 | |
839 | sub getgroups { |
840 | usage "getgroups()" if @_ != 0; |
c07a80fd |
841 | my %seen; |
a0d0e21e |
842 | grep(!$seen{$_}++, split(' ', $) )); |
843 | } |
844 | |
845 | sub getlogin { |
846 | usage "getlogin()" if @_ != 0; |
847 | getlogin(); |
848 | } |
849 | |
850 | sub getpgrp { |
851 | usage "getpgrp()" if @_ != 0; |
852 | getpgrp($_[0]); |
853 | } |
854 | |
855 | sub getpid { |
856 | usage "getpid()" if @_ != 0; |
857 | $$; |
858 | } |
859 | |
860 | sub getppid { |
861 | usage "getppid()" if @_ != 0; |
862 | getppid; |
863 | } |
864 | |
865 | sub getuid { |
866 | usage "getuid()" if @_ != 0; |
867 | $<; |
868 | } |
869 | |
870 | sub isatty { |
871 | usage "isatty(filehandle)" if @_ != 1; |
872 | -t $_[0]; |
873 | } |
874 | |
875 | sub link { |
876 | usage "link(oldfilename, newfilename)" if @_ != 2; |
877 | link($_[0], $_[1]); |
878 | } |
879 | |
880 | sub rmdir { |
881 | usage "rmdir(directoryname)" if @_ != 1; |
882 | rmdir($_[0]); |
883 | } |
884 | |
885 | sub setgid { |
886 | usage "setgid(gid)" if @_ != 1; |
887 | $( = $_[0]; |
888 | } |
889 | |
890 | sub setuid { |
891 | usage "setuid(uid)" if @_ != 1; |
892 | $< = $_[0]; |
893 | } |
894 | |
895 | sub sleep { |
896 | usage "sleep(seconds)" if @_ != 1; |
897 | sleep($_[0]); |
898 | } |
899 | |
900 | sub unlink { |
901 | usage "unlink(filename)" if @_ != 1; |
902 | unlink($_[0]); |
903 | } |
904 | |
905 | sub utime { |
906 | usage "utime(filename, atime, mtime)" if @_ != 3; |
907 | utime($_[1], $_[2], $_[0]); |
908 | } |
909 | |