Various tweaks to Encode
[p5sagit/p5-mst-13.2.git] / pp_sys.c
index 5955b14..6ed8e0a 100644 (file)
--- a/pp_sys.c
+++ b/pp_sys.c
@@ -80,7 +80,11 @@ extern int h_errno;
 #  endif
 # endif
 # ifdef HAS_GETPWENT
+#ifndef getpwent
   struct passwd *getpwent (void);
+#elif defined (VMS) && defined (my_getpwent)
+  struct passwd *Perl_my_getpwent (void);
+#endif
 # endif
 #endif
 
@@ -92,7 +96,9 @@ extern int h_errno;
     struct group *getgrgid (Gid_t);
 # endif
 # ifdef HAS_GETGRENT
+#ifndef getgrent
     struct group *getgrent (void);
+#endif
 # endif
 #endif
 
@@ -1578,7 +1584,7 @@ PP(pp_sysread)
 #ifdef HAS_SOCKET
     if (PL_op->op_type == OP_RECV) {
        char namebuf[MAXPATHLEN];
-#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE)
+#if (defined(VMS_DO_SOCKETS) && defined(DECCRTL_SOCKETS)) || defined(MPE) || defined(__QNXNTO__)
        bufsize = sizeof (struct sockaddr_in);
 #else
        bufsize = sizeof namebuf;
@@ -4627,12 +4633,14 @@ PP(pp_ghostent)
     STRLEN n_a;
 
     EXTEND(SP, 10);
-    if (which == OP_GHBYNAME)
+    if (which == OP_GHBYNAME) {
 #ifdef HAS_GETHOSTBYNAME
-       hent = PerlSock_gethostbyname(POPpbytex);
+        char* name = POPpbytex;
+       hent = PerlSock_gethostbyname(name);
 #else
        DIE(aTHX_ PL_no_sock_func, "gethostbyname");
 #endif
+    }
     else if (which == OP_GHBYADDR) {
 #ifdef HAS_GETHOSTBYADDR
        int addrtype = POPi;
@@ -4653,8 +4661,14 @@ PP(pp_ghostent)
 #endif
 
 #ifdef HOST_NOT_FOUND
-    if (!hent)
-       STATUS_NATIVE_SET(h_errno);
+       if (!hent) {
+#ifdef USE_REENTRANT_API
+#   ifdef USE_GETHOSTENT_ERRNO
+           h_errno = PL_reentrant_buffer->_gethostent_errno;
+#   endif
+#endif
+           STATUS_NATIVE_SET(h_errno);
+       }
 #endif
 
     if (GIMME != G_ARRAY) {
@@ -4734,12 +4748,14 @@ PP(pp_gnetent)
     struct netent *nent;
     STRLEN n_a;
 
-    if (which == OP_GNBYNAME)
+    if (which == OP_GNBYNAME){
 #ifdef HAS_GETNETBYNAME
-       nent = PerlSock_getnetbyname(POPpbytex);
+        char *name = POPpbytex;
+       nent = PerlSock_getnetbyname(name);
 #else
         DIE(aTHX_ PL_no_sock_func, "getnetbyname");
 #endif
+    }
     else if (which == OP_GNBYADDR) {
 #ifdef HAS_GETNETBYADDR
        int addrtype = POPi;
@@ -4756,6 +4772,17 @@ PP(pp_gnetent)
         DIE(aTHX_ PL_no_sock_func, "getnetent");
 #endif
 
+#ifdef HOST_NOT_FOUND
+       if (!nent) {
+#ifdef USE_REENTRANT_API
+#   ifdef USE_GETNETENT_ERRNO
+            h_errno = PL_reentrant_buffer->_getnetent_errno;
+#   endif
+#endif
+           STATUS_NATIVE_SET(h_errno);
+       }
+#endif
+
     EXTEND(SP, 4);
     if (GIMME != G_ARRAY) {
        PUSHs(sv = sv_newmortal());
@@ -4822,18 +4849,22 @@ PP(pp_gprotoent)
     struct protoent *pent;
     STRLEN n_a;
 
-    if (which == OP_GPBYNAME)
+    if (which == OP_GPBYNAME) {
 #ifdef HAS_GETPROTOBYNAME
-       pent = PerlSock_getprotobyname(POPpbytex);
+        char* name = POPpbytex;
+       pent = PerlSock_getprotobyname(name);
 #else
        DIE(aTHX_ PL_no_sock_func, "getprotobyname");
 #endif
-    else if (which == OP_GPBYNUMBER)
+    }
+    else if (which == OP_GPBYNUMBER) {
 #ifdef HAS_GETPROTOBYNUMBER
-       pent = PerlSock_getprotobynumber(POPi);
+        int number = POPi;
+       pent = PerlSock_getprotobynumber(number);
 #else
-    DIE(aTHX_ PL_no_sock_func, "getprotobynumber");
+       DIE(aTHX_ PL_no_sock_func, "getprotobynumber");
 #endif
+    }
     else
 #ifdef HAS_GETPROTOENT
        pent = PerlSock_getprotoent();
@@ -5154,10 +5185,16 @@ PP(pp_gpwent)
 
     switch (which) {
     case OP_GPWNAM:
-       pwent  = getpwnam(POPpbytex);
-       break;
+      {
+       char* name = POPpbytex;
+       pwent  = getpwnam(name);
+      }
+      break;
     case OP_GPWUID:
-       pwent = getpwuid((Uid_t)POPi);
+      {
+       Uid_t uid = POPi;
+       pwent = getpwuid(uid);
+      }
        break;
     case OP_GPWENT:
 #   ifdef HAS_GETPWENT
@@ -5354,10 +5391,14 @@ PP(pp_ggrent)
     struct group *grent;
     STRLEN n_a;
 
-    if (which == OP_GGRNAM)
-       grent = (struct group *)getgrnam(POPpbytex);
-    else if (which == OP_GGRGID)
-       grent = (struct group *)getgrgid(POPi);
+    if (which == OP_GGRNAM) {
+        char* name = POPpbytex;
+       grent = (struct group *)getgrnam(name);
+    }
+    else if (which == OP_GGRGID) {
+        Gid_t gid = POPi;
+       grent = (struct group *)getgrgid(gid);
+    }
     else
 #ifdef HAS_GETGRENT
        grent = (struct group *)getgrent();
@@ -5389,12 +5430,22 @@ PP(pp_ggrent)
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
        sv_setiv(sv, (IV)grent->gr_gid);
 
+#if !(defined(_CRAYMPP) && defined(USE_REENTRANT_API))
        PUSHs(sv = sv_mortalcopy(&PL_sv_no));
+       /* In UNICOS/mk (_CRAYMPP) the multithreading
+        * versions (getgrnam_r, getgrgid_r)
+        * seem to return an illegal pointer
+        * as the group members list, gr_mem.
+        * getgrent() doesn't even have a _r version
+        * but the gr_mem is poisonous anyway.
+        * So yes, you cannot get the list of group
+        * members if building multithreaded in UNICOS/mk. */
        for (elem = grent->gr_mem; elem && *elem; elem++) {
            sv_catpv(sv, *elem);
            if (elem[1])
                sv_catpvn(sv, " ", 1);
        }
+#endif
     }
 
     RETURN;