This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
foreach defelem magic should only be applied to PL_sv_undef
[perl5.git] / pp_sys.c
index 31f6fa5..e2c4111 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -1561,6 +1561,10 @@ PP(pp_sysread)
                          (struct sockaddr *)namebuf, &bufsize);
        if (count < 0)
            RETPUSHUNDEF;
+#ifdef EPOC
+        /* Bogus return without padding */
+       bufsize = sizeof (struct sockaddr_in);
+#endif
        SvCUR_set(bufsv, count);
        *SvEND(bufsv) = '\0';
        (void)SvPOK_only(bufsv);
@@ -1634,8 +1638,7 @@ PP(pp_sysread)
            count = -1;
     }
     if (count < 0) {
-       if ((IoTYPE(io) == IoTYPE_WRONLY || IoIFP(io) == PerlIO_stdout()
-           || IoIFP(io) == PerlIO_stderr()) && ckWARN(WARN_IO))
+       if ((IoTYPE(io) == IoTYPE_WRONLY) && ckWARN(WARN_IO))
        {
            /* integrate with report_evil_fh()? */
            char *name = NULL;
@@ -2193,6 +2196,9 @@ PP(pp_socket)
        RETPUSHUNDEF;
     }
 
+    if (IoIFP(io))
+       do_close(gv, FALSE);
+
     TAINT_PROPER("socket");
     fd = PerlSock_socket(domain, type, protocol);
     if (fd < 0)
@@ -2251,6 +2257,11 @@ PP(pp_sockpair)
        RETPUSHUNDEF;
     }
 
+    if (IoIFP(io1))
+       do_close(gv1, FALSE);
+    if (IoIFP(io2))
+       do_close(gv2, FALSE);
+
     TAINT_PROPER("socketpair");
     if (PerlSock_socketpair(domain, type, protocol, fd) < 0)
        RETPUSHUNDEF;
@@ -2440,7 +2451,8 @@ PP(pp_accept)
 #endif
 
 #ifdef EPOC
-    len = sizeof saddr;  /* EPOC somehow truncates info */
+    len = sizeof saddr;          /* EPOC somehow truncates info */
+    setbuf( IoIFP(nstio), NULL); /* EPOC gets confused about sockets */
 #endif
 
     PUSHp((char *)&saddr, len);
@@ -4514,7 +4526,7 @@ PP(pp_ghostent)
     EXTEND(SP, 10);
     if (which == OP_GHBYNAME)
 #ifdef HAS_GETHOSTBYNAME
-       hent = PerlSock_gethostbyname(POPpx);
+       hent = PerlSock_gethostbyname(POPpbytex);
 #else
        DIE(aTHX_ PL_no_sock_func, "gethostbyname");
 #endif
@@ -4523,7 +4535,7 @@ PP(pp_ghostent)
        int addrtype = POPi;
        SV *addrsv = POPs;
        STRLEN addrlen;
-       Netdb_host_t addr = (Netdb_host_t) SvPV(addrsv, addrlen);
+       Netdb_host_t addr = (Netdb_host_t) SvPVbyte(addrsv, addrlen);
 
        hent = PerlSock_gethostbyaddr(addr, (Netdb_hlen_t) addrlen, addrtype);
 #else
@@ -4621,7 +4633,7 @@ PP(pp_gnetent)
 
     if (which == OP_GNBYNAME)
 #ifdef HAS_GETNETBYNAME
-       nent = PerlSock_getnetbyname(POPpx);
+       nent = PerlSock_getnetbyname(POPpbytex);
 #else
         DIE(aTHX_ PL_no_sock_func, "getnetbyname");
 #endif
@@ -4709,7 +4721,7 @@ PP(pp_gprotoent)
 
     if (which == OP_GPBYNAME)
 #ifdef HAS_GETPROTOBYNAME
-       pent = PerlSock_getprotobyname(POPpx);
+       pent = PerlSock_getprotobyname(POPpbytex);
 #else
        DIE(aTHX_ PL_no_sock_func, "getprotobyname");
 #endif
@@ -4792,8 +4804,8 @@ PP(pp_gservent)
 
     if (which == OP_GSBYNAME) {
 #ifdef HAS_GETSERVBYNAME
-       char *proto = POPpx;
-       char *name = POPpx;
+       char *proto = POPpbytex;
+       char *name = POPpbytex;
 
        if (proto && !*proto)
            proto = Nullch;
@@ -4805,7 +4817,7 @@ PP(pp_gservent)
     }
     else if (which == OP_GSBYPORT) {
 #ifdef HAS_GETSERVBYPORT
-       char *proto = POPpx;
+       char *proto = POPpbytex;
        unsigned short port = POPu;
 
 #ifdef HAS_HTONS
@@ -5039,7 +5051,7 @@ PP(pp_gpwent)
 
     switch (which) {
     case OP_GPWNAM:
-       pwent  = getpwnam(POPpx);
+       pwent  = getpwnam(POPpbytex);
        break;
     case OP_GPWUID:
        pwent = getpwuid((Uid_t)POPi);
@@ -5240,7 +5252,7 @@ PP(pp_ggrent)
     STRLEN n_a;
 
     if (which == OP_GGRNAM)
-       grent = (struct group *)getgrnam(POPpx);
+       grent = (struct group *)getgrnam(POPpbytex);
     else if (which == OP_GGRGID)
        grent = (struct group *)getgrgid(POPi);
     else