]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
fix some int/long problems for 64bit systems
authorwessels <>
Sun, 30 Nov 1997 09:10:30 +0000 (09:10 +0000)
committerwessels <>
Sun, 30 Nov 1997 09:10:30 +0000 (09:10 +0000)
include/asn1.h
snmplib/asn1.c

index d9702ec808ca864ca7ce64118c69013685d1ca1f..adb774a4b7545b9d871107d114da5adb31b2291a 100644 (file)
@@ -29,8 +29,10 @@ SOFTWARE.
 #ifndef ASN1_H
 #define ASN1_H
 
-
+/* assume someone else includes "config.h" for us */
+#if HAVE_SYS_TYPES_H
 #include <sys/types.h>
+#endif
 
 #ifndef EIGHTBIT_SUBIDS
 typedef u_long oid;
@@ -66,28 +68,27 @@ typedef u_char oid;
 #define IS_CONSTRUCTOR(byte)   ((byte) & ASN_CONSTRUCTOR)
 #define IS_EXTENSION_ID(byte)  (((byte) & ASN_EXTENSION_ID) == ASN_EXTENSION_ID)
 
-/*
- * support for 64 bit linux platform.
- * instead of a rewrite, which is obviously neccessary,
- * we replace `long' by `int32'
- */
-#if defined(__alpha)
-typedef unsigned int u_int32;
-typedef int int32;
+/* 32 bit integer compatability hack */
+#if SIZEOF_INT == 4
+typedef int num32;
+typedef unsigned int u_num32; 
+#elif SIZEOF_LONG == 4
+typedef long num32;
+typedef unsigned long u_num32;
 #else
-typedef unsigned long u_int32;
-typedef long int32;
+typedef long num32;             /* assume that long's are 32bit */
+typedef unsigned long u_num32;
 #endif
+#define NUM32LEN sizeof(num32)  /* this should always be 4 */
 
 /* 
  * internal 64 bit representation:
  */
 struct counter64 {
-    u_int32 high;
-    u_int32 low;
+    u_num32 high;
+    u_num32 low;
 };
 
-
 extern u_char *asn_parse_int (u_char * data,
        int *datalength,
        u_char * type,
index e97f8f9c4f3879ec010a4011a6d8f624abb0dd49..15a8be7480f3f8bd5f3e8e2e6e209d2b2c9cf7f1 100644 (file)
@@ -202,7 +202,7 @@ asn_build_int(data, datalength, type, intp, intsize)
      * consecutive 1's or 0's at the most significant end of the
      * integer.
      */
-    mask = 0x1FF << ((8 * (sizeof(int32) - 1)) - 1);
+    mask = 0x1FF << ((8 * (NUM32LEN - 1)) - 1);
     /* mask is 0xFF800000 on a big-endian machine */
     while ((((integer & mask) == 0) || ((integer & mask) == mask))
        && intsize > 1) {
@@ -215,10 +215,10 @@ asn_build_int(data, datalength, type, intp, intsize)
     if (*datalength < intsize)
        return NULL;
     *datalength -= intsize;
-    mask = 0xFF << (8 * (sizeof(int32) - 1));
+    mask = 0xFF << (8 * (NUM32LEN - 1));
     /* mask is 0xFF000000 on a big-endian machine */
     while (intsize--) {
-       *data++ = (u_char) ((integer & mask) >> (8 * (sizeof(int32) - 1)));
+       *data++ = (u_char) ((integer & mask) >> (8 * (NUM32LEN - 1)));
        integer <<= 8;
     }
     return data;
@@ -256,9 +256,9 @@ asn_build_unsigned_int(data, datalength, type, intp, intsize)
        return NULL;
     }
     integer = *intp;
-    mask = 0xFF << (8 * (sizeof(int32) - 1));
+    mask = 0xFF << (8 * (NUM32LEN - 1));
     /* mask is 0xFF000000 on a big-endian machine */
-    if ((u_char) ((integer & mask) >> (8 * (sizeof(int32) - 1))) & 0x80) {
+    if ((u_char) ((integer & mask) >> (8 * (NUM32LEN - 1))) & 0x80) {
        /* if MSB is set */
        add_null_byte = 1;
        intsize++;
@@ -268,7 +268,7 @@ asn_build_unsigned_int(data, datalength, type, intp, intsize)
      * There should be no sequence of 9 consecutive 1's or 0's at the most significant end of the
      * integer.
      */
-    mask = 0x1FF << ((8 * (sizeof(int32) - 1)) - 1);
+    mask = 0x1FF << ((8 * (NUM32LEN - 1)) - 1);
     /* mask is 0xFF800000 on a big-endian machine */
     while ((((integer & mask) == 0) || ((integer & mask) == mask)) && intsize > 1) {
        intsize--;
@@ -284,10 +284,10 @@ asn_build_unsigned_int(data, datalength, type, intp, intsize)
        *data++ = '\0';
        intsize--;
     }
-    mask = 0xFF << (8 * (sizeof(int32) - 1));
+    mask = 0xFF << (8 * (NUM32LEN - 1));
     /* mask is 0xFF000000 on a big-endian machine */
     while (intsize--) {
-       *data++ = (u_char) ((integer & mask) >> (8 * (sizeof(int32) - 1)));
+       *data++ = (u_char) ((integer & mask) >> (8 * (NUM32LEN - 1)));
        integer <<= 8;
     }
     return data;
@@ -937,8 +937,8 @@ asn_build_unsigned_int64(data, datalength, type, cp, countersize)
  * ASN.1 integer ::= 0x02 asnlength byte {byte}*
  */
 
-    u_int32 low, high;
-    u_int32 mask, mask2;
+    u_num32 low, high;
+    u_num32 mask, mask2;
     int add_null_byte = 0;
     int intsize;
 
@@ -949,9 +949,9 @@ asn_build_unsigned_int64(data, datalength, type, cp, countersize)
     intsize = 8;
     low = cp->low;
     high = cp->high;
-    mask = 0xFF << (8 * (sizeof(int32) - 1));
+    mask = 0xFF << (8 * (NUM32LEN - 1));
     /* mask is 0xFF000000 on a big-endian machine */
-    if ((u_char) ((high & mask) >> (8 * (sizeof(int32) - 1))) & 0x80) {
+    if ((u_char) ((high & mask) >> (8 * (NUM32LEN - 1))) & 0x80) {
        /* if MSB is set */
        add_null_byte = 1;
        intsize++;
@@ -962,13 +962,13 @@ asn_build_unsigned_int64(data, datalength, type, cp, countersize)
      * There should be no sequence of 9 consecutive 1's or 0's at the most
      * significant end of the integer.
      */
-    mask2 = 0x1FF << ((8 * (sizeof(int32) - 1)) - 1);
+    mask2 = 0x1FF << ((8 * (NUM32LEN - 1)) - 1);
     /* mask2 is 0xFF800000 on a big-endian machine */
     while ((((high & mask2) == 0) || ((high & mask2) == mask2))
        && intsize > 1) {
        intsize--;
        high = (high << 8)
-           | ((low & mask) >> (8 * (sizeof(int32) - 1)));
+           | ((low & mask) >> (8 * (NUM32LEN - 1)));
        low <<= 8;
     }
     data = asn_build_header(data, datalength, type, intsize);
@@ -982,9 +982,9 @@ asn_build_unsigned_int64(data, datalength, type, cp, countersize)
        intsize--;
     }
     while (intsize--) {
-       *data++ = (u_char) ((high & mask) >> (8 * (sizeof(int32) - 1)));
+       *data++ = (u_char) ((high & mask) >> (8 * (NUM32LEN - 1)));
        high = (high << 8)
-           | ((low & mask) >> (8 * (sizeof(int32) - 1)));
+           | ((low & mask) >> (8 * (NUM32LEN - 1)));
        low <<= 8;
 
     }