getservby*() calls fail on Windows NT
[p5sagit/p5-mst-13.2.git] / pp.c
diff --git a/pp.c b/pp.c
index 34c4ed3..1cea53f 100644 (file)
--- a/pp.c
+++ b/pp.c
@@ -36,9 +36,9 @@ typedef unsigned UBW;
  * in a double without loss; that is, it has no 32-bit type.
  */
 #if BYTEORDER > 0xFFFF && defined(_CRAY) && !defined(_CRAYMPP)
-#  define BWBITS  32
-#  define BWMASK  ((1 << BWBITS) - 1)
-#  define BWSIGN  (1 << (BWBITS - 1))
+#  define BW_BITS  32
+#  define BW_MASK  ((1 << BW_BITS) - 1)
+#  define BW_SIGN  (1 << (BW_BITS - 1))
 #  define BWi(i)  (((i) & BW_SIGN) ? ((i) | ~BW_MASK) : ((i) & BW_MASK))
 #  define BWu(u)  ((u) & BW_MASK)
 #else
@@ -150,11 +150,9 @@ PP(pp_padhv)
     }
     else if (gimme == G_SCALAR) {
        SV* sv = sv_newmortal();
-       if (HvFILL((HV*)TARG)) {
-           sprintf(buf, "%ld/%ld",
-                   (long)HvFILL((HV*)TARG), (long)HvMAX((HV*)TARG)+1);
-           sv_setpv(sv, buf);
-       }
+       if (HvFILL((HV*)TARG))
+           sv_setpvf(sv, "%ld/%ld",
+                     (long)HvFILL((HV*)TARG), (long)HvMAX((HV*)TARG) + 1);
        else
            sv_setiv(sv, 0);
        SETs(sv);
@@ -180,7 +178,7 @@ PP(pp_rv2gv)
            GV *gv = (GV*) sv_newmortal();
            gv_init(gv, 0, "", 0, 0);
            GvIOp(gv) = (IO *)sv;
-           SvREFCNT_inc(sv);
+           (void)SvREFCNT_inc(sv);
            sv = (SV*) gv;
        } else if (SvTYPE(sv) != SVt_PVGV)
            DIE("Not a GLOB reference");
@@ -778,6 +776,8 @@ PP(pp_modulo)
       if ((left_neg != right_neg) && ans)
        ans = right - ans;
       if (right_neg) {
+       /* XXX may warn: unary minus operator applied to unsigned type */
+       /* could change -foo to be (~foo)+1 instead     */
        if (ans <= -(UV)IV_MAX)
          sv_setiv(TARG, (IV) -ans);
        else
@@ -863,7 +863,7 @@ PP(pp_left_shift)
       IBW shift = POPi;
       if (op->op_private & HINT_INTEGER) {
        IBW i = TOPi;
-       i <<= shift;
+       i = BWi(i) << shift;
        SETi(BWi(i));
       }
       else {
@@ -882,7 +882,7 @@ PP(pp_right_shift)
       IBW shift = POPi;
       if (op->op_private & HINT_INTEGER) {
        IBW i = TOPi;
-       i >>= shift;
+       i = BWi(i) >> shift;
        SETi(BWi(i));
       }
       else {
@@ -2682,7 +2682,9 @@ PP(pp_unpack)
     }
     while (pat < patend) {
       reparse:
-       datumtype = *pat++;
+       datumtype = *pat++ & 0xFF;
+       if (isSPACE(datumtype))
+           continue;
        if (pat >= patend)
            len = 1;
        else if (*pat == '*') {
@@ -2698,7 +2700,7 @@ PP(pp_unpack)
            len = (datumtype != '@');
        switch(datumtype) {
        default:
-           croak("Invalid type in unpack: '%c'", datumtype);
+           croak("Invalid type in unpack: '%c'", (int)datumtype);
        case '%':
            if (len == 1 && pat[-1] != '1')
                len = 16;
@@ -3112,12 +3114,9 @@ PP(pp_unpack)
                        auv = 0;
                    }
                    else if (++bytes >= sizeof(UV)) {   /* promote to string */
-                       char decn[sizeof(UV) * 3 + 1];
                        char *t;
 
-                       (void) sprintf(decn, "%0*ld",
-                                      (int)sizeof(decn) - 1, auv);
-                       sv = newSVpv(decn, 0);
+                       sv = newSVpvf("%.*Vu", (int)TYPE_DIGITS(UV), auv);
                        while (s < strend) {
                            sv = mul128(sv, *s & 0x7f);
                            if (!(*s++ & 0x80)) {
@@ -3460,7 +3459,9 @@ PP(pp_pack)
     sv_setpvn(cat, "", 0);
     while (pat < patend) {
 #define NEXTFROM (items-- > 0 ? *MARK++ : &sv_no)
-       datumtype = *pat++;
+       datumtype = *pat++ & 0xFF;
+       if (isSPACE(datumtype))
+           continue;
        if (*pat == '*') {
            len = strchr("@Xxu", datumtype) ? 0 : items;
            pat++;
@@ -3474,7 +3475,7 @@ PP(pp_pack)
            len = 1;
        switch(datumtype) {
        default:
-           croak("Invalid type in pack: '%c'", datumtype);
+           croak("Invalid type in pack: '%c'", (int)datumtype);
        case '%':
            DIE("%% may only be used in unpack");
        case '@':
@@ -3712,7 +3713,14 @@ PP(pp_pack)
                if (adouble < 0)
                    croak("Cannot compress negative numbers");
 
-               if (adouble <= UV_MAX) {
+               if (
+#ifdef BW_BITS
+                   adouble <= BW_MASK
+#else
+                   adouble <= UV_MAX
+#endif
+                   )
+               {
                    char   buf[1 + sizeof(UV)];
                    char  *in = buf + sizeof(buf);
                    UV     auv = U_V(adouble);;