home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / perl501m.zip / lib / POSIX.pm < prev    next >
Text File  |  1995-03-16  |  20KB  |  1,016 lines

  1. package POSIX;
  2.  
  3. use Carp;
  4. require Exporter;
  5. require AutoLoader;
  6. require DynaLoader;
  7. require Config;
  8. @ISA = qw(Exporter DynaLoader);
  9.  
  10. %EXPORT_TAGS = (
  11.  
  12.     assert_h =>    [qw(assert NDEBUG)],
  13.  
  14.     ctype_h =>    [qw(isalnum isalpha iscntrl isdigit isgraph islower
  15.         isprint ispunct isspace isupper isxdigit tolower toupper)],
  16.  
  17.     dirent_h =>    [qw()],
  18.  
  19.     errno_h =>    [qw(E2BIG EACCES EAGAIN EBADF EBUSY ECHILD EDEADLK EDOM
  20.         EEXIST EFAULT EFBIG EINTR EINVAL EIO EISDIR EMFILE
  21.         EMLINK ENAMETOOLONG ENFILE ENODEV ENOENT ENOEXEC ENOLCK
  22.         ENOMEM ENOSPC ENOSYS ENOTDIR ENOTEMPTY ENOTTY ENXIO
  23.         EPERM EPIPE ERANGE EROFS ESPIPE ESRCH EXDEV errno)],
  24.  
  25.     fcntl_h =>    [qw(FD_CLOEXEC F_DUPFD F_GETFD F_GETFL F_GETLK F_RDLCK
  26.         F_SETFD F_SETFL F_SETLK F_SETLKW F_UNLCK F_WRLCK
  27.         O_ACCMODE O_APPEND O_CREAT O_EXCL O_NOCTTY O_NONBLOCK
  28.         O_RDONLY O_RDWR O_TRUNC O_WRONLY
  29.         creat
  30.         SEEK_CUR SEEK_END SEEK_SET
  31.         S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  32.         S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG S_ISUID
  33.         S_IWGRP S_IWOTH S_IWUSR)],
  34.  
  35.     float_h =>    [qw(DBL_DIG DBL_EPSILON DBL_MANT_DIG
  36.         DBL_MAX DBL_MAX_10_EXP DBL_MAX_EXP
  37.         DBL_MIN DBL_MIN_10_EXP DBL_MIN_EXP
  38.         FLT_DIG FLT_EPSILON FLT_MANT_DIG
  39.         FLT_MAX FLT_MAX_10_EXP FLT_MAX_EXP
  40.         FLT_MIN FLT_MIN_10_EXP FLT_MIN_EXP
  41.         FLT_RADIX FLT_ROUNDS
  42.         LDBL_DIG LDBL_EPSILON LDBL_MANT_DIG
  43.         LDBL_MAX LDBL_MAX_10_EXP LDBL_MAX_EXP
  44.         LDBL_MIN LDBL_MIN_10_EXP LDBL_MIN_EXP)],
  45.  
  46.     grp_h =>    [qw()],
  47.  
  48.     limits_h =>    [qw( ARG_MAX CHAR_BIT CHAR_MAX CHAR_MIN CHILD_MAX
  49.         INT_MAX INT_MIN LINK_MAX LONG_MAX LONG_MIN MAX_CANON
  50.         MAX_INPUT MB_LEN_MAX NAME_MAX NGROUPS_MAX OPEN_MAX
  51.         PATH_MAX PIPE_BUF SCHAR_MAX SCHAR_MIN SHRT_MAX SHRT_MIN
  52.         SSIZE_MAX STREAM_MAX TZNAME_MAX UCHAR_MAX UINT_MAX
  53.         ULONG_MAX USHRT_MAX _POSIX_ARG_MAX _POSIX_CHILD_MAX
  54.         _POSIX_LINK_MAX _POSIX_MAX_CANON _POSIX_MAX_INPUT
  55.         _POSIX_NAME_MAX _POSIX_NGROUPS_MAX _POSIX_OPEN_MAX
  56.         _POSIX_PATH_MAX _POSIX_PIPE_BUF _POSIX_SSIZE_MAX
  57.         _POSIX_STREADM_MAX _POSIX_TZNAME_MAX)],
  58.  
  59.     locale_h =>    [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
  60.         LC_TIME NULL localeconv setlocale)],
  61.  
  62.     math_h =>    [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
  63.         frexp ldexp log10 modf pow sinh tanh)],
  64.  
  65.     pwd_h =>    [qw()],
  66.  
  67.     setjmp_h =>    [qw(longjmp setjmp siglongjmp sigsetjmp)],
  68.  
  69.     signal_h =>    [qw(SA_NOCLDSTOP SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE
  70.         SIGHUP SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  71.         SIGSTOP SIGTERM SIGTSTP SIGTTIN SIGTTOU SIGUSR1 SIGUSR2
  72.         SIG_BLOCK SIG_DFL SIG_ERR SIG_IGN SIG_SETMASK SIG_UNBLOCK
  73.         raise sigaction signal sigpending sigprocmask
  74.         sigsuspend)],
  75.  
  76.     stdarg_h =>    [qw()],
  77.  
  78.     stddef_h =>    [qw(NULL offsetof)],
  79.  
  80.     stdio_h =>    [qw(BUFSIZ EOF FILENAME_MAX L_ctermid L_cuserid
  81.         L_tmpname NULL SEEK_CUR SEEK_END SEEK_SET STREAM_MAX
  82.         TMP_MAX stderr stdin stdout _IOFBF _IOLBF _IONBF
  83.         clearerr fclose fdopen feof ferror fflush fgetc fgetpos
  84.         fgets fopen fprintf fputc fputs fread freopen
  85.         fscanf fseek fsetpos ftell fwrite getchar gets
  86.         perror putc putchar puts remove rewind
  87.         scanf setbuf setvbuf sscanf tmpfile tmpnam
  88.         ungetc vfprintf vprintf vsprintf)],
  89.  
  90.     stdlib_h =>    [qw(EXIT_FAILURE EXIT_SUCCESS MB_CUR_MAX NULL RAND_MAX
  91.         abort atexit atof atoi atol bsearch calloc div
  92.         free getenv labs ldiv malloc mblen mbstowcs mbtowc
  93.         qsort realloc strtod strtol stroul wcstombs wctomb)],
  94.  
  95.     string_h =>    [qw(NULL memchr memcmp memcpy memmove memset strcat
  96.         strchr strcmp strcoll strcpy strcspn strerror strlen
  97.         strncat strncmp strncpy strpbrk strrchr strspn strstr
  98.         strtok strxfrm)],
  99.  
  100.     sys_stat_h => [qw(S_IRGRP S_IROTH S_IRUSR S_IRWXG S_IRWXO S_IRWXU
  101.         S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISGID S_ISREG
  102.         S_ISUID S_IWGRP S_IWOTH S_IWUSR S_IXGRP S_IXOTH S_IXUSR
  103.         fstat mkfifo)],
  104.  
  105.     sys_times_h => [qw()],
  106.  
  107.     sys_types_h => [qw()],
  108.  
  109.     sys_utsname_h => [qw(uname)],
  110.  
  111.     sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
  112.         WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
  113.  
  114.     termios_h => [qw( B0 B110 B1200 B134 B150 B1800 B19200 B200 B2400
  115.         B300 B38400 B4800 B50 B600 B75 B9600 BRKINT CLOCAL
  116.         CREAD CS5 CS6 CS7 CS8 CSIZE CSTOPB ECHO ECHOE ECHOK
  117.         ECHONL HUPCL ICANON ICRNL IEXTEN IGNBRK IGNCR IGNPAR
  118.         INLCR INPCK ISIG ISTRIP IXOFF IXON NCCS NOFLSH OPOST
  119.         PARENB PARMRK PARODD TCIFLUSH TCIOFF TCIOFLUSH TCION
  120.         TCOFLUSH TCOOFF TCOON TCSADRAIN TCSAFLUSH TCSANOW
  121.         TOSTOP VEOF VEOL VERASE VINTR VKILL VMIN VQUIT VSTART
  122.         VSTOP VSUSP VTIME
  123.         cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
  124.         tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
  125.  
  126.     time_h =>    [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
  127.         difftime mktime strftime tzset tzname)],
  128.  
  129.     unistd_h =>    [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
  130.         STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
  131.         _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
  132.         _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
  133.         _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED
  134.         _POSIX_JOB_CONTROL _POSIX_NO_TRUNC _POSIX_SAVED_IDS
  135.         _POSIX_VDISABLE _POSIX_VERSION _SC_ARG_MAX
  136.         _SC_CHILD_MAX _SC_CLK_TCK _SC_JOB_CONTROL
  137.         _SC_NGROUPS_MAX _SC_OPEN_MAX _SC_SAVED_IDS
  138.         _SC_STREAM_MAX _SC_TZNAME_MAX _SC_VERSION
  139.         _exit access ctermid cuserid
  140.         dup2 dup execl execle execlp execv execve execvp
  141.         fpathconf getcwd getegid geteuid getgid getgroups
  142.         getpid getuid isatty lseek pathconf pause setgid setpgid
  143.         setsid setuid sysconf tcgetpgrp tcsetpgrp ttyname)],
  144.  
  145.     utime_h =>    [qw()],
  146.  
  147. );
  148.  
  149. Exporter::export_tags();
  150.  
  151. @EXPORT_OK = qw(
  152.     closedir opendir readdir rewinddir
  153.     fcntl open
  154.     getgrgid getgrnam
  155.     atan2 cos exp log sin sqrt tan
  156.     getpwnam getpwuid
  157.     kill
  158.     fileno getc printf rename sprintf
  159.     abs exit rand srand system
  160.     chmod mkdir stat umask
  161.     times
  162.     wait waitpid
  163.     gmtime localtime time 
  164.     alarm chdir chown close fork getlogin getppid getpgrp link
  165.     pipe read rmdir sleep unlink write
  166.     utime
  167. );
  168.  
  169. # Grandfather old foo_h form to new :foo_h form
  170. sub import {
  171.     my $this = shift;
  172.     my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
  173.     local $Exporter::ExportLevel = 1;
  174.     Exporter::import($this,@list);
  175. }
  176.  
  177. sub AUTOLOAD {
  178.     if ($AUTOLOAD =~ /::(_?[a-z])/) {
  179.     $AutoLoader::AUTOLOAD = $AUTOLOAD;
  180.     goto &AutoLoader::AUTOLOAD
  181.     }
  182.     local $constname = $AUTOLOAD;
  183.     $constname =~ s/.*:://;
  184.     $val = constant($constname, $_[0]);
  185.     if ($! != 0) {
  186.     if ($! =~ /Invalid/) {
  187.         croak "$constname is not a valid POSIX macro";
  188.     }
  189.     else {
  190.         croak "Your vendor has not defined POSIX macro $constname, used";
  191.     }
  192.     }
  193.     eval "sub $AUTOLOAD { $val }";
  194.     goto &$AUTOLOAD;
  195. }
  196.  
  197.  
  198. @liblist = ();
  199. @liblist = split ' ', $Config::Config{"POSIX_loadlibs"} 
  200.     if defined $Config::Config{"POSIX_loadlibs"};
  201. bootstrap POSIX @liblist;
  202.  
  203. sub usage { 
  204.     local ($mess) = @_;
  205.     croak "Usage: POSIX::$mess";
  206. }
  207.  
  208. sub redef { 
  209.     local ($mess) = @_;
  210.     croak "Use method $mess instead";
  211. }
  212.  
  213. sub unimpl { 
  214.     local ($mess) = @_;
  215.     $mess =~ s/xxx//;
  216.     croak "Unimplemented: POSIX::$mess";
  217. }
  218.  
  219. $gensym = "SYM000";
  220.  
  221. sub gensym {
  222.     *{"POSIX::" . $gensym++};
  223. }
  224.  
  225. sub ungensym {
  226.     local($x) = shift;
  227.     $x =~ s/.*:://;
  228.     delete $POSIX::{$x};
  229. }
  230.  
  231. ############################
  232. package POSIX::SigAction;
  233.  
  234. sub new {
  235.     bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
  236. }
  237.  
  238. ############################
  239. package FileHandle;
  240.  
  241. sub new {
  242.     POSIX::usage "FileHandle->new(filename, posixmode)" if @_ != 3;
  243.     local($class,$filename,$mode) = @_;
  244.     local($glob) = &POSIX::gensym;
  245.     $mode =~ s/a.*/>>/ ||
  246.     $mode =~ s/w.*/>/ ||
  247.     ($mode = '<');
  248.     open($glob, "$mode $filename") and
  249.     bless \$glob;
  250. }
  251.  
  252. sub new_from_fd {
  253.     POSIX::usage "FileHandle->new_from_fd(fd,mode)" if @_ != 3;
  254.     local($class,$fd,$mode) = @_;
  255.     local($glob) = &POSIX::gensym;
  256.     $mode =~ s/a.*/>>/ ||
  257.     $mode =~ s/w.*/>/ ||
  258.     ($mode = '<');
  259.     open($glob, "$mode&=$fd") and
  260.     bless \$glob;
  261. }
  262.  
  263. sub clearerr {
  264.     POSIX::usage "clearerr(filehandle)" if @_ != 1;
  265.     seek($_[0], 0, 1);
  266. }
  267.  
  268. sub close {
  269.     POSIX::usage "close(filehandle)" if @_ != 1;
  270.     close($_[0]);
  271. }
  272.  
  273. sub DESTROY {
  274.     close($_[0]);
  275.     ungensym($_[0]);
  276. }
  277.  
  278. sub eof {
  279.     POSIX::usage "eof(filehandle)" if @_ != 1;
  280.     eof($_[0]);
  281. }
  282.  
  283. sub getc {
  284.     POSIX::usage "getc(filehandle)" if @_ != 1;
  285.     getc($_[0]);
  286. }
  287.  
  288. sub gets {
  289.     POSIX::usage "gets(filehandle)" if @_ != 1;
  290.     local($handle) = @_;
  291.     scalar <$handle>;
  292. }
  293.  
  294. sub fileno {
  295.     POSIX::usage "fileno(filehandle)" if @_ != 1;
  296.     fileno($_[0]);
  297. }
  298.  
  299. sub seek {
  300.     POSIX::usage "seek(filehandle,pos,whence)" if @_ != 3;
  301.     seek($_[0], $_[1], $_[2]);
  302. }
  303.  
  304. sub tell {
  305.     POSIX::usage "tell(filehandle)" if @_ != 1;
  306.     tell($_[0]);
  307. }
  308. ############################
  309. package POSIX; # return to package POSIX so AutoSplit is happy
  310. 1;
  311. __END__
  312.  
  313. sub assert {
  314.     usage "assert(expr)" if @_ != 1;
  315.     if (!$_[0]) {
  316.     croak "Assertion failed";
  317.     }
  318. }
  319.  
  320. sub tolower {
  321.     usage "tolower(string)" if @_ != 1;
  322.     lc($_[0]);
  323. }
  324.  
  325. sub toupper {
  326.     usage "toupper(string)" if @_ != 1;
  327.     uc($_[0]);
  328. }
  329.  
  330. sub closedir {
  331.     usage "closedir(dirhandle)" if @_ != 1;
  332.     closedir($_[0]);
  333.     ungensym($_[0]);
  334. }
  335.  
  336. sub opendir {
  337.     usage "opendir(directory)" if @_ != 1;
  338.     local($dirhandle) = &gensym;
  339.     opendir($dirhandle, $_[0])
  340.     ? $dirhandle
  341.     : (ungensym($dirhandle), undef);
  342. }
  343.  
  344. sub readdir {
  345.     usage "readdir(dirhandle)" if @_ != 1;
  346.     readdir($_[0]);
  347. }
  348.  
  349. sub rewinddir {
  350.     usage "rewinddir(dirhandle)" if @_ != 1;
  351.     rewinddir($_[0]);
  352. }
  353.  
  354. sub errno {
  355.     usage "errno()" if @_ != 0;
  356.     $! + 0;
  357. }
  358.  
  359. sub creat {
  360.     usage "creat(filename, mode)" if @_ != 2;
  361.     &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
  362. }
  363.  
  364. sub fcntl {
  365.     usage "fcntl(filehandle, cmd, arg)" if @_ != 3;
  366.     fcntl($_[0], $_[1], $_[2]);
  367. }
  368.  
  369. sub getgrgid {
  370.     usage "getgrgid(gid)" if @_ != 1;
  371.     getgrgid($_[0]);
  372. }
  373.  
  374. sub getgrnam {
  375.     usage "getgrnam(name)" if @_ != 1;
  376.     getgrnam($_[0]);
  377. }
  378.  
  379. sub atan2 {
  380.     usage "atan2(x,y)" if @_ != 2;
  381.     atan2($_[0], $_[1]);
  382. }
  383.  
  384. sub cos {
  385.     usage "cos(x)" if @_ != 1;
  386.     cos($_[0]);
  387. }
  388.  
  389. sub exp {
  390.     usage "exp(x)" if @_ != 1;
  391.     exp($_[0]);
  392. }
  393.  
  394. sub fabs {
  395.     usage "fabs(x)" if @_ != 1;
  396.     abs($_[0]);
  397. }
  398.  
  399. sub log {
  400.     usage "log(x)" if @_ != 1;
  401.     log($_[0]);
  402. }
  403.  
  404. sub pow {
  405.     usage "pow(x,exponent)" if @_ != 2;
  406.     $_[0] ** $_[1];
  407. }
  408.  
  409. sub sin {
  410.     usage "sin(x)" if @_ != 1;
  411.     sin($_[0]);
  412. }
  413.  
  414. sub sqrt {
  415.     usage "sqrt(x)" if @_ != 1;
  416.     sqrt($_[0]);
  417. }
  418.  
  419. sub tan {
  420.     usage "tan(x)" if @_ != 1;
  421.     tan($_[0]);
  422. }
  423.  
  424. sub getpwnam {
  425.     usage "getpwnam(name)" if @_ != 1;
  426.     getpwnam($_[0]);
  427. }
  428.  
  429. sub getpwuid {
  430.     usage "getpwuid(uid)" if @_ != 1;
  431.     getpwuid($_[0]);
  432. }
  433.  
  434. sub longjmp {
  435.     unimpl "longjmp() is C-specific: use die instead";
  436. }
  437.  
  438. sub setjmp {
  439.     unimpl "setjmp() is C-specific: use eval {} instead";
  440. }
  441.  
  442. sub siglongjmp {
  443.     unimpl "siglongjmp() is C-specific: use die instead";
  444. }
  445.  
  446. sub sigsetjmp {
  447.     unimpl "sigsetjmp() is C-specific: use eval {} instead";
  448. }
  449.  
  450. sub kill {
  451.     usage "kill(pid, sig)" if @_ != 2;
  452.     kill $_[1], $_[0];
  453. }
  454.  
  455. sub raise {
  456.     usage "raise(sig)" if @_ != 1;
  457.     kill $$, $_[0];    # Is this good enough?
  458. }
  459.  
  460. sub offsetof {
  461.     unimpl "offsetof() is C-specific, stopped";
  462. }
  463.  
  464. sub clearerr {
  465.     redef "$filehandle->clearerr(filehandle)";
  466. }
  467.  
  468. sub fclose {
  469.     redef "$filehandle->fclose(filehandle)";
  470. }
  471.  
  472. sub fdopen {
  473.     redef "FileHandle->new_from_fd(fd,mode)";
  474. }
  475.  
  476. sub feof {
  477.     redef "$filehandle->eof()";
  478. }
  479.  
  480. sub fgetc {
  481.     redef "$filehandle->getc()";
  482. }
  483.  
  484. sub fgets {
  485.     redef "$filehandle->gets()";
  486. }
  487.  
  488. sub fileno {
  489.     redef "$filehandle->fileno()";
  490. }
  491.  
  492. sub fopen {
  493.     redef "FileHandle->open()";
  494. }
  495.  
  496. sub fprintf {
  497.     unimpl "fprintf() is C-specific--use printf instead";
  498. }
  499.  
  500. sub fputc {
  501.     unimpl "fputc() is C-specific--use print instead";
  502. }
  503.  
  504. sub fputs {
  505.     unimpl "fputs() is C-specific--use print instead";
  506. }
  507.  
  508. sub fread {
  509.     unimpl "fread() is C-specific--use read instead";
  510. }
  511.  
  512. sub freopen {
  513.     unimpl "freopen() is C-specific--use open instead";
  514. }
  515.  
  516. sub fscanf {
  517.     unimpl "fscanf() is C-specific--use <> and regular expressions instead";
  518. }
  519.  
  520. sub fseek {
  521.     redef "$filehandle->seek(pos,whence)";
  522. }
  523.  
  524. sub ferror {
  525.     redef "$filehandle->error()";
  526. }
  527.  
  528. sub fflush {
  529.     redef "$filehandle->flush()";
  530. }
  531.  
  532. sub fgetpos {
  533.     redef "$filehandle->getpos()";
  534. }
  535.  
  536. sub fsetpos {
  537.     redef "$filehandle->setpos(pos)";
  538. }
  539.  
  540. sub ftell {
  541.     redef "$filehandle->tell()";
  542. }
  543.  
  544. sub fwrite {
  545.     unimpl "fwrite() is C-specific--use print instead";
  546. }
  547.  
  548. sub getc {
  549.     usage "getc(handle)" if @_ != 1;
  550.     getc($_[0]);
  551. }
  552.  
  553. sub getchar {
  554.     usage "getchar()" if @_ != 0;
  555.     getc(STDIN);
  556. }
  557.  
  558. sub gets {
  559.     usage "gets()" if @_ != 0;
  560.     scalar <STDIN>;
  561. }
  562.  
  563. sub perror {
  564.     print STDERR "@_: " if @_;
  565.     print STDERR $!,"\n";
  566. }
  567.  
  568. sub printf {
  569.     usage "printf(pattern, args...)" if @_ < 1;
  570.     printf STDOUT @_;
  571. }
  572.  
  573. sub putc {
  574.     unimpl "putc() is C-specific--use print instead";
  575. }
  576.  
  577. sub putchar {
  578.     unimpl "putchar() is C-specific--use print instead";
  579. }
  580.  
  581. sub puts {
  582.     unimpl "puts() is C-specific--use print instead";
  583. }
  584.  
  585. sub remove {
  586.     usage "remove(filename)" if @_ != 1;
  587.     unlink($_[0]);
  588. }
  589.  
  590. sub rename {
  591.     usage "rename(oldfilename, newfilename)" if @_ != 2;
  592.     rename($_[0], $_[1]);
  593. }
  594.  
  595. sub rewind {
  596.     usage "rewind(filehandle)" if @_ != 1;
  597.     seek($_[0],0,0);
  598. }
  599.  
  600. sub scanf {
  601.     unimpl "scanf() is C-specific--use <> and regular expressions instead";
  602. }
  603.  
  604. sub sprintf {
  605.     usage "sprintf(pattern,args)" if @_ == 0;
  606.     sprintf(shift,@_);
  607. }
  608.  
  609. sub sscanf {
  610.     unimpl "sscanf() is C-specific--use regular expressions instead";
  611. }
  612.  
  613. sub tmpfile {
  614.     redef "FileHandle->new_tmpfile()";
  615. }
  616.  
  617. sub ungetc {
  618.     redef "$filehandle->ungetc(char)";
  619. }
  620.  
  621. sub vfprintf {
  622.     unimpl "vfprintf() is C-specific";
  623. }
  624.  
  625. sub vprintf {
  626.     unimpl "vprintf() is C-specific";
  627. }
  628.  
  629. sub vsprintf {
  630.     unimpl "vsprintf() is C-specific";
  631. }
  632.  
  633. sub abs {
  634.     usage "abs(x)" if @_ != 1;
  635.     abs($_[0]);
  636. }
  637.  
  638. sub atexit {
  639.     unimpl "atexit() is C-specific: use END {} instead";
  640. }
  641.  
  642. sub atof {
  643.     unimpl "atof() is C-specific, stopped";
  644. }
  645.  
  646. sub atoi {
  647.     unimpl "atoi() is C-specific, stopped";
  648. }
  649.  
  650. sub atol {
  651.     unimpl "atol() is C-specific, stopped";
  652. }
  653.  
  654. sub bsearch {
  655.     unimpl "bsearch(xxx)" if @_ != 123;
  656.     bsearch($_[0]);
  657. }
  658.  
  659. sub calloc {
  660.     unimpl "calloc() is C-specific, stopped";
  661. }
  662.  
  663. sub div {
  664.     unimpl "div() is C-specific, stopped";
  665. }
  666.  
  667. sub exit {
  668.     usage "exit(status)" if @_ != 1;
  669.     exit($_[0]);
  670. }
  671.  
  672. sub free {
  673.     unimpl "free() is C-specific, stopped";
  674.     free($_[0]);
  675. }
  676.  
  677. sub getenv {
  678.     usage "getenv(name)" if @_ != 1;
  679.     $ENV{$_[0]};
  680. }
  681.  
  682. sub labs {
  683.     unimpl "labs() is C-specific, use abs instead";
  684. }
  685.  
  686. sub ldiv {
  687.     unimpl "ldiv() is C-specific, use / and int instead";
  688. }
  689.  
  690. sub malloc {
  691.     unimpl "malloc() is C-specific, stopped";
  692. }
  693.  
  694. sub qsort {
  695.     unimpl "qsort() is C-specific, use sort instead";
  696. }
  697.  
  698. sub rand {
  699.     unimpl "rand() is non-portable, use Perl's rand instead";
  700. }
  701.  
  702. sub realloc {
  703.     unimpl "realloc() is C-specific, stopped";
  704. }
  705.  
  706. sub srand {
  707.     unimpl "srand()";
  708. }
  709.  
  710. sub strtod {
  711.     unimpl "strtod() is C-specific, stopped";
  712. }
  713.  
  714. sub strtol {
  715.     unimpl "strtol() is C-specific, stopped";
  716. }
  717.  
  718. sub stroul {
  719.     unimpl "stroul() is C-specific, stopped";
  720. }
  721.  
  722. sub system {
  723.     usage "system(command)" if @_ != 1;
  724.     system($_[0]);
  725. }
  726.  
  727. sub memchr {
  728.     unimpl "memchr() is C-specific, use index() instead";
  729. }
  730.  
  731. sub memcmp {
  732.     unimpl "memcmp() is C-specific, use eq instead";
  733. }
  734.  
  735. sub memcpy {
  736.     unimpl "memcpy() is C-specific, use = instead";
  737.     memcpy($_[0]);
  738.  
  739. sub memmove {
  740.     unimpl "memmove() is C-specific, use = instead";
  741. }
  742.  
  743. sub memset {
  744.     unimpl "memset() is C-specific, use x instead";
  745. }
  746.  
  747. sub strcat {
  748.     unimpl "strcat() is C-specific, use .= instead";
  749. }
  750.  
  751. sub strchr {
  752.     unimpl "strchr() is C-specific, use index() instead";
  753. }
  754.  
  755. sub strcmp {
  756.     unimpl "strcmp() is C-specific, use eq instead";
  757. }
  758.  
  759. sub strcpy {
  760.     unimpl "strcpy() is C-specific, use = instead";
  761. }
  762.  
  763. sub strcspn {
  764.     unimpl "strcspn() is C-specific, use regular expressions instead";
  765. }
  766.  
  767. sub strerror {
  768.     usage "strerror(errno)" if @_ != 1;
  769.     local $! = $_[0];
  770.     $! . "";
  771. }
  772.  
  773. sub strlen {
  774.     unimpl "strlen() is C-specific, use length instead";
  775. }
  776.  
  777. sub strncat {
  778.     unimpl "strncat() is C-specific, use .= instead";
  779. }
  780.  
  781. sub strncmp {
  782.     unimpl "strncmp() is C-specific, use eq instead";
  783. }
  784.  
  785. sub strncpy {
  786.     unimpl "strncpy() is C-specific, use = instead";
  787. }
  788.  
  789. sub strpbrk {
  790.     unimpl "strpbrk() is C-specific, stopped";
  791. }
  792.  
  793. sub strrchr {
  794.     unimpl "strrchr() is C-specific, use rindex() instead";
  795. }
  796.  
  797. sub strspn {
  798.     unimpl "strspn() is C-specific, stopped";
  799. }
  800.  
  801. sub strstr {
  802.     usage "strstr(big, little)" if @_ != 2;
  803.     index($_[0], $_[1]);
  804. }
  805.  
  806. sub strtok {
  807.     unimpl "strtok() is C-specific, stopped";
  808. }
  809.  
  810. sub chmod {
  811.     usage "chmod(filename, mode)" if @_ != 2;
  812.     chmod($_[0], $_[1]);
  813. }
  814.  
  815. sub fstat {
  816.     usage "fstat(fd)" if @_ != 1;
  817.     local(*TMP);
  818.     open(TMP, "<&$_[0]");        # Gross.
  819.     local(@l) = stat(TMP);
  820.     close(TMP);
  821.     @l;
  822. }
  823.  
  824. sub mkdir {
  825.     usage "mkdir(directoryname, mode)" if @_ != 2;
  826.     mkdir($_[0], $_[1]);
  827. }
  828.  
  829. sub stat {
  830.     usage "stat(filename)" if @_ != 1;
  831.     stat($_[0]);
  832. }
  833.  
  834. sub umask {
  835.     usage "umask(mask)" if @_ != 1;
  836.     umask($_[0]);
  837. }
  838.  
  839. sub times {
  840.     usage "times()" if @_ != 0;
  841.     times();
  842. }
  843.  
  844. sub wait {
  845.     usage "wait(statusvariable)" if @_ != 1;
  846.     local $result = wait();
  847.     $_[0] = $?;
  848.     $result;
  849. }
  850.  
  851. sub waitpid {
  852.     usage "waitpid(pid, statusvariable, options)" if @_ != 3;
  853.     local $result = waitpid($_[0], $_[2]);
  854.     $_[1] = $?;
  855.     $result;
  856. }
  857.  
  858. sub gmtime {
  859.     usage "gmtime(time)" if @_ != 1;
  860.     gmtime($_[0]);
  861. }
  862.  
  863. sub localtime {
  864.     usage "localtime(time)" if @_ != 1;
  865.     localtime($_[0]);
  866. }
  867.  
  868. sub time {
  869.     unimpl "time()" if @_ != 0;
  870.     time;
  871. }
  872.  
  873. sub alarm {
  874.     usage "alarm(seconds)" if @_ != 1;
  875.     alarm($_[0]);
  876. }
  877.  
  878. sub chdir {
  879.     usage "chdir(directory)" if @_ != 1;
  880.     chdir($_[0]);
  881. }
  882.  
  883. sub chown {
  884.     usage "chown(filename, uid, gid)" if @_ != 3;
  885.     chown($_[0], $_[1], $_[2]);
  886. }
  887.  
  888. sub execl {
  889.     unimpl "execl() is C-specific, stopped";
  890.     execl($_[0]);
  891. }
  892.  
  893. sub execle {
  894.     unimpl "execle() is C-specific, stopped";
  895.     execle($_[0]);
  896. }
  897.  
  898. sub execlp {
  899.     unimpl "execlp() is C-specific, stopped";
  900.     execlp($_[0]);
  901. }
  902.  
  903. sub execv {
  904.     unimpl "execv() is C-specific, stopped";
  905.     execv($_[0]);
  906. }
  907.  
  908. sub execve {
  909.     unimpl "execve() is C-specific, stopped";
  910.     execve($_[0]);
  911. }
  912.  
  913. sub execvp {
  914.     unimpl "execvp() is C-specific, stopped";
  915.     execvp($_[0]);
  916. }
  917.  
  918. sub fork {
  919.     usage "fork()" if @_ != 0;
  920.     fork;
  921. }
  922.  
  923. sub getcwd
  924. {
  925.     usage "getcwd()" if @_ != 0;
  926.     chop($cwd = `pwd`);
  927.     $cwd;
  928. }
  929.  
  930. sub getegid {
  931.     usage "getegid()" if @_ != 0;
  932.     $) + 0;
  933. }
  934.  
  935. sub geteuid {
  936.     usage "geteuid()" if @_ != 0;
  937.     $> + 0;
  938. }
  939.  
  940. sub getgid {
  941.     usage "getgid()" if @_ != 0;
  942.     $( + 0;
  943. }
  944.  
  945. sub getgroups {
  946.     usage "getgroups()" if @_ != 0;
  947.     local(%seen) = ();
  948.     grep(!$seen{$_}++, split(' ', $) ));
  949. }
  950.  
  951. sub getlogin {
  952.     usage "getlogin()" if @_ != 0;
  953.     getlogin();
  954. }
  955.  
  956. sub getpgrp {
  957.     usage "getpgrp()" if @_ != 0;
  958.     getpgrp($_[0]);
  959. }
  960.  
  961. sub getpid {
  962.     usage "getpid()" if @_ != 0;
  963.     $$;
  964. }
  965.  
  966. sub getppid {
  967.     usage "getppid()" if @_ != 0;
  968.     getppid;
  969. }
  970.  
  971. sub getuid {
  972.     usage "getuid()" if @_ != 0;
  973.     $<;
  974. }
  975.  
  976. sub isatty {
  977.     usage "isatty(filehandle)" if @_ != 1;
  978.     -t $_[0];
  979. }
  980.  
  981. sub link {
  982.     usage "link(oldfilename, newfilename)" if @_ != 2;
  983.     link($_[0], $_[1]);
  984. }
  985.  
  986. sub rmdir {
  987.     usage "rmdir(directoryname)" if @_ != 1;
  988.     rmdir($_[0]);
  989. }
  990.  
  991. sub setgid {
  992.     usage "setgid(gid)" if @_ != 1;
  993.     $( = $_[0];
  994. }
  995.  
  996. sub setuid {
  997.     usage "setuid(uid)" if @_ != 1;
  998.     $< = $_[0];
  999. }
  1000.  
  1001. sub sleep {
  1002.     usage "sleep(seconds)" if @_ != 1;
  1003.     sleep($_[0]);
  1004. }
  1005.  
  1006. sub unlink {
  1007.     usage "unlink(filename)" if @_ != 1;
  1008.     unlink($_[0]);
  1009. }
  1010.  
  1011. sub utime {
  1012.     usage "utime(filename, atime, mtime)" if @_ != 3;
  1013.     utime($_[1], $_[2], $_[0]);
  1014. }
  1015.  
  1016.