home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / D12 / PERL1.TGZ / perl1.tar / usr / lib / perl5 / POSIX.pm < prev    next >
Text File  |  1996-06-28  |  18KB  |  922 lines

  1. package POSIX;
  2.  
  3. use vars qw($VERSION @ISA %EXPORT_TAGS @EXPORT_OK $AUTOLOAD); 
  4.  
  5. use Carp;
  6. use AutoLoader;
  7. require Config;
  8. use Symbol;
  9.  
  10. require Exporter;
  11. require DynaLoader;
  12. @ISA = qw(Exporter DynaLoader);
  13.  
  14. $VERSION = "1.00" ;
  15.  
  16. %EXPORT_TAGS = (
  17.  
  18.     assert_h =>    [qw(assert NDEBUG)],
  19.  
  20.     ctype_h =>    [qw(isalnum isalpha iscntrl isdigit isgraph islower
  21.         isprint ispunct isspace isupper isxdigit tolower toupper)],
  22.  
  23.     dirent_h =>    [qw()],
  24.  
  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)],
  30.  
  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
  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
  39.         S_IWGRP S_IWOTH S_IWUSR)],
  40.  
  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
  47.         FLT_RADIX FLT_ROUNDS
  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)],
  51.  
  52.     grp_h =>    [qw()],
  53.  
  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)],
  64.  
  65.     locale_h =>    [qw(LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY LC_NUMERIC
  66.         LC_TIME NULL localeconv setlocale)],
  67.  
  68.     math_h =>    [qw(HUGE_VAL acos asin atan ceil cosh fabs floor fmod
  69.         frexp ldexp log10 modf pow sinh tan tanh)],
  70.  
  71.     pwd_h =>    [qw()],
  72.  
  73.     setjmp_h =>    [qw(longjmp setjmp siglongjmp sigsetjmp)],
  74.  
  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
  80.         sigsuspend)],
  81.  
  82.     stdarg_h =>    [qw()],
  83.  
  84.     stddef_h =>    [qw(NULL offsetof)],
  85.  
  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)],
  95.  
  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 stroul wcstombs wctomb)],
  100.  
  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
  104.         strtok strxfrm)],
  105.  
  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
  109.         fstat mkfifo)],
  110.  
  111.     sys_times_h => [qw()],
  112.  
  113.     sys_types_h => [qw()],
  114.  
  115.     sys_utsname_h => [qw(uname)],
  116.  
  117.     sys_wait_h => [qw(WEXITSTATUS WIFEXITED WIFSIGNALED WIFSTOPPED
  118.         WNOHANG WSTOPSIG WTERMSIG WUNTRACED)],
  119.  
  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
  128.         VSTOP VSUSP VTIME
  129.         cfgetispeed cfgetospeed cfsetispeed cfsetospeed tcdrain
  130.         tcflow tcflush tcgetattr tcsendbreak tcsetattr )],
  131.  
  132.     time_h =>    [qw(CLK_TCK CLOCKS_PER_SEC NULL asctime clock ctime
  133.         difftime mktime strftime tzset tzname)],
  134.  
  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)],
  150.  
  151.     utime_h =>    [qw()],
  152.  
  153. );
  154.  
  155. Exporter::export_tags();
  156.  
  157. @EXPORT_OK = qw(
  158.     closedir opendir readdir rewinddir
  159.     fcntl open
  160.     getgrgid getgrnam
  161.     atan2 cos exp log sin sqrt
  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.  
  175. # Grandfather old foo_h form to new :foo_h form
  176. sub import {
  177.     my $this = shift;
  178.     my @list = map { m/^\w+_h$/ ? ":$_" : $_ } @_;
  179.     local $Exporter::ExportLevel = 1;
  180.     Exporter::import($this,@list);
  181. }
  182.  
  183.  
  184. bootstrap POSIX $VERSION;
  185.  
  186. my $EINVAL = constant("EINVAL", 0);
  187. my $EAGAIN = constant("EAGAIN", 0);
  188.  
  189. sub AUTOLOAD {
  190.     if ($AUTOLOAD =~ /::(_?[a-z])/) {
  191.     $AutoLoader::AUTOLOAD = $AUTOLOAD;
  192.     goto &AutoLoader::AUTOLOAD
  193.     }
  194.     local $! = 0;
  195.     my $constname = $AUTOLOAD;
  196.     $constname =~ s/.*:://;
  197.     my $val = constant($constname, $_[0]);
  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";
  206.     }
  207.     else {
  208.     croak "Your vendor has not defined POSIX macro $constname, used";
  209.     }
  210.  
  211.     goto &$AUTOLOAD;
  212. }
  213.  
  214. sub usage { 
  215.     my ($mess) = @_;
  216.     croak "Usage: POSIX::$mess";
  217. }
  218.  
  219. sub redef { 
  220.     my ($mess) = @_;
  221.     croak "Use method $mess instead";
  222. }
  223.  
  224. sub unimpl { 
  225.     my ($mess) = @_;
  226.     $mess =~ s/xxx//;
  227.     croak "Unimplemented: POSIX::$mess";
  228. }
  229.  
  230. ############################
  231. package POSIX::SigAction;
  232.  
  233. sub new {
  234.     bless {HANDLER => $_[1], MASK => $_[2], FLAGS => $_[3]};
  235. }
  236.  
  237. ############################
  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]);
  262. }
  263.  
  264. sub opendir {
  265.     usage "opendir(directory)" if @_ != 1;
  266.     my $dirhandle = gensym;
  267.     opendir($dirhandle, $_[0])
  268.     ? $dirhandle
  269.     : undef;
  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;
  289.     &open($_[0], &O_WRONLY | &O_CREAT | &O_TRUNC, $_[1]);
  290. }
  291.  
  292. sub fcntl {
  293.     usage "fcntl(filehandle, cmd, arg)" if @_ !