Change 12534 by jhi@alpha on 2001/10/20 15:14:25

        Integrate perlio change #12532:
        introduce and use PerlIO_intmod2str().

Affected files ...

... //depot/perl/doio.c#172 integrate
... //depot/perl/lib/Net/Domain.pm#4 integrate
... //depot/perl/perlio.c#127 integrate
... //depot/perl/perlio.h#33 integrate

Differences ...

==== //depot/perl/doio.c#172 (text) ====
Index: perl/doio.c
--- perl/doio.c.~1~     Sat Oct 20 09:30:05 2001
+++ perl/doio.c Sat Oct 20 09:30:05 2001
@@ -158,45 +158,7 @@
        rawmode |= O_LARGEFILE; /* Transparently largefiley. */
 #endif
 
-#ifndef O_ACCMODE
-#define O_ACCMODE 3            /* Assume traditional implementation */
-#endif
-
-       switch (result = rawmode & O_ACCMODE) {
-       case O_RDONLY:
-            IoTYPE(io) = IoTYPE_RDONLY;
-            break;
-       case O_WRONLY:
-            IoTYPE(io) = IoTYPE_WRONLY;
-            break;
-       case O_RDWR:
-       default:
-            IoTYPE(io) = IoTYPE_RDWR;
-            break;
-       }
-       writing = (result != O_RDONLY);
-
-       if (result == O_RDONLY) {
-           mode[ix++] = 'r';
-       }
-#ifdef O_APPEND
-       else if (rawmode & O_APPEND) {
-           mode[ix++] = 'a';
-           if (result != O_WRONLY)
-               mode[ix++] = '+';
-       }
-#endif
-       else {
-           if (result == O_WRONLY)
-               mode[ix++] = 'w';
-           else {
-               mode[ix++] = 'r';
-               mode[ix++] = '+';
-           }
-       }
-       if (rawmode & O_BINARY)
-           mode[ix++] = 'b';
-       mode[ix] = '\0';
+        IoTYPE(io) = PerlIO_intmode2str(rawmode, &mode[ix], &writing);
 
        namesv = sv_2mortal(newSVpvn(name,strlen(name)));
        num_svs = 1;
@@ -1693,7 +1655,7 @@
 
            if ( accessed == &PL_sv_undef && modified == &PL_sv_undef )
              utbufp = NULL;
-           
+
            Zero(&utbuf, sizeof utbuf, char);
 #ifdef BIG_TIME
            utbuf.actime = (Time_t)SvNVx(accessed);     /* time accessed */

==== //depot/perl/lib/Net/Domain.pm#4 (text) ====
Index: perl/lib/Net/Domain.pm
--- perl/lib/Net/Domain.pm.~1~  Sat Oct 20 09:30:05 2001
+++ perl/lib/Net/Domain.pm      Sat Oct 20 09:30:05 2001
@@ -36,8 +36,8 @@
           my $a = shift(@addr);
           $host = gethostbyaddr($a,Socket::AF_INET());
           last if defined $host;
-         } 
-        if (index($host,'.') > 0) {
+         }
+        if (defined($host) && index($host,'.') > 0) {
            $fqdn = $host;
            ($host,$domain) = $fqdn =~ /^([^\.]+)\.(.*)$/;
          }
@@ -102,7 +102,7 @@
        };
     }
 
-    # remove garbage 
+    # remove garbage
     $host =~ s/[\0\r\n]+//go;
     $host =~ s/(\A\.+|\.+\Z)//go;
     $host =~ s/\.\.+/\./go;
@@ -147,7 +147,7 @@
 
     @hosts = ($host,"localhost");
 
-    unless($host =~ /\./) {
+    unless (defined($host) && $host =~ /\./) {
        my $dom = undef;
         eval {
            my $tmp = "\0" x 256; ## preload scalar
@@ -179,19 +179,19 @@
 
     # Attempt to locate FQDN
 
-    foreach (@hosts) {
+    foreach (grep {defined $_} @hosts) {
        my @info = gethostbyname($_);
 
        next unless @info;
 
        # look at real name & aliases
        my $site;
-       foreach $site ($info[0], split(/ /,$info[1])) { 
+       foreach $site ($info[0], split(/ /,$info[1])) {
            if(rindex($site,".") > 0) {
 
                # Extract domain from FQDN
 
-               ($domain = $site) =~ s/\A[^\.]+\.//; 
+               ($domain = $site) =~ s/\A[^\.]+\.//;
                return $domain;
            }
        }

==== //depot/perl/perlio.c#127 (text) ====
Index: perl/perlio.c
--- perl/perlio.c.~1~   Sat Oct 20 09:30:05 2001
+++ perl/perlio.c       Sat Oct 20 09:30:05 2001
@@ -99,6 +99,55 @@
 #endif
 }
 
+#ifndef O_ACCMODE
+#define O_ACCMODE 3            /* Assume traditional implementation */
+#endif
+
+int
+PerlIO_intmode2str(int rawmode, char *mode, int *writing)
+{
+    int result = rawmode & O_ACCMODE;
+    int ix = 0;
+    int ptype;
+    switch (result) {
+    case O_RDONLY:
+       ptype = IoTYPE_RDONLY;
+       break;
+    case O_WRONLY:
+       ptype = IoTYPE_WRONLY;
+       break;
+    case O_RDWR:
+    default:
+       ptype = IoTYPE_RDWR;
+       break;
+    }
+    if (writing)
+       *writing = (result != O_RDONLY);
+
+    if (result == O_RDONLY) {
+       mode[ix++] = 'r';
+    }
+#ifdef O_APPEND
+    else if (rawmode & O_APPEND) {
+       mode[ix++] = 'a';
+       if (result != O_WRONLY)
+           mode[ix++] = '+';
+    }
+#endif
+    else {
+       if (result == O_WRONLY)
+           mode[ix++] = 'w';
+       else {
+           mode[ix++] = 'r';
+           mode[ix++] = '+';
+       }
+    }
+    if (rawmode & O_BINARY)
+       mode[ix++] = 'b';
+    mode[ix] = '\0';
+    return ptype;
+}
+
 #ifndef PERLIO_LAYERS
 int
 PerlIO_apply_layers(pTHX_ PerlIO *f, const char *mode, const char *names)
@@ -134,8 +183,11 @@
     if (f) {
        int fd = PerlLIO_dup(PerlIO_fileno(f));
        if (fd >= 0) {
+           char mode[8];
+           int omode = fcntl(fd, F_GETFL);
+           PerlIO_intmode2str(omode,mode,NULL);
            /* the r+ is a hack */
-           return PerlIO_fdopen(fd, "r+");
+           return PerlIO_fdopen(fd, mode);
        }
        return NULL;
     }

==== //depot/perl/perlio.h#33 (text) ====
Index: perl/perlio.h
--- perl/perlio.h.~1~   Sat Oct 20 09:30:05 2001
+++ perl/perlio.h       Sat Oct 20 09:30:05 2001
@@ -346,6 +346,8 @@
 
 extern void PerlIO_destruct(pTHX);
 
+extern int PerlIO_intmode2str(int rawmode, char *mode, int *writing);
+
 #ifndef PERLIO_IS_STDIO
 
 extern void PerlIO_cleanup(void);
End of Patch.

Reply via email to