Add new step to run_byacc which:
[p5sagit/p5-mst-13.2.git] / ext / POSIX / POSIX.pm
index 9416f70..bdbf1d4 100644 (file)
@@ -6,7 +6,7 @@ use AutoLoader;
 
 use XSLoader ();
 
-our $VERSION = "1.03" ;
+our $VERSION = "1.04" ;
 
 # Grandfather old foo_h form to new :foo_h form
 my $loaded;
@@ -23,8 +23,9 @@ sub croak { require Carp;  goto &Carp::croak }
 
 XSLoader::load 'POSIX', $VERSION;
 
-my $EINVAL = constant("EINVAL", 0);
-my $EAGAIN = constant("EAGAIN", 0);
+my %NON_CONSTS = (map {($_,1)}
+                  qw(S_ISBLK S_ISCHR S_ISDIR S_ISFIFO S_ISREG WEXITSTATUS
+                     WIFEXITED WIFSIGNALED WIFSTOPPED WSTOPSIG WTERMSIG));
 
 sub AUTOLOAD {
     if ($AUTOLOAD =~ /::(_?[a-z])/) {
@@ -35,19 +36,15 @@ sub AUTOLOAD {
     local $! = 0;
     my $constname = $AUTOLOAD;
     $constname =~ s/.*:://;
-    my $val = constant($constname, @_ ? $_[0] : 0);
-    if ($! == 0) {
+    if ($NON_CONSTS{$constname}) {
+        my ($val, $error) = &int_macro_int($constname, $_[0]);
+        croak $error if $error;
+        *$AUTOLOAD = sub { &int_macro_int($constname, $_[0]) };
+    } else {
+        my ($error, $val) = constant($constname);
+        croak $error if $error;
        *$AUTOLOAD = sub { $val };
     }
-    elsif ($! == $EAGAIN) {    # Not really a constant, so always call.
-       *$AUTOLOAD = sub { constant($constname, $_[0]) };
-    }
-    elsif ($! == $EINVAL) {
-       croak "$constname is not a valid POSIX macro";
-    }
-    else {
-       croak "Your vendor has not defined POSIX macro $constname, used";
-    }
 
     goto &$AUTOLOAD;
 }
@@ -565,9 +562,9 @@ sub chmod {
 sub fstat {
     usage "fstat(fd)" if @_ != 1;
     local *TMP;
-    open(TMP, "<&$_[0]");              # Gross.
+    CORE::open(TMP, "<&$_[0]");                # Gross.
     my @l = CORE::stat(TMP);
-    close(TMP);
+    CORE::close(TMP);
     @l;
 }
 
@@ -655,20 +652,6 @@ sub fork {
     CORE::fork;
 }
 
-sub getcwd
-{
-    usage "getcwd()" if @_ != 0;
-    if ($^O eq 'MSWin32') {
-       # this perhaps applies to everyone else also?
-       require Cwd;
-       $cwd = &Cwd::cwd;
-    }
-    else {
-       chop($cwd = `pwd`);
-    }
-    $cwd;
-}
-
 sub getegid {
     usage "getegid()" if @_ != 0;
     $) + 0;
@@ -734,16 +717,6 @@ sub setbuf {
     redef "IO::Handle::setbuf()";
 }
 
-sub setgid {
-    usage "setgid(gid)" if @_ != 1;
-    $( = $_[0];
-}
-
-sub setuid {
-    usage "setuid(uid)" if @_ != 1;
-    $< = $_[0];
-}
-
 sub setvbuf {
     redef "IO::Handle::setvbuf()";
 }
@@ -893,7 +866,7 @@ sub load_imports {
                difftime mktime strftime tzset tzname)],
 
     unistd_h =>        [qw(F_OK NULL R_OK SEEK_CUR SEEK_END SEEK_SET
-               STRERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
+               STDERR_FILENO STDIN_FILENO STDOUT_FILENO W_OK X_OK
                _PC_CHOWN_RESTRICTED _PC_LINK_MAX _PC_MAX_CANON
                _PC_MAX_INPUT _PC_NAME_MAX _PC_NO_TRUNC _PC_PATH_MAX
                _PC_PIPE_BUF _PC_VDISABLE _POSIX_CHOWN_RESTRICTED