]> git.ipfire.org Git - thirdparty/rsync.git/commitdiff
Adding IVAL64() and SIVAL64().
authorWayne Davison <wayned@samba.org>
Sun, 19 Jan 2014 20:02:38 +0000 (12:02 -0800)
committerWayne Davison <wayned@samba.org>
Sun, 19 Jan 2014 20:02:38 +0000 (12:02 -0800)
byteorder.h
io.c

index 831644fe67d8f343bdeb777c99c433d0c96077a2..22e807ab341694d4f624abbc4db31641f09be1fa 100644 (file)
 
 #define PVAL(buf,pos) (UVAL(buf,pos)|UVAL(buf,(pos)+1)<<8)
 #define IVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+2)<<16)
+#define IVAL64(buf,pos) (IVAL(buf,pos)|(int64)IVAL(buf,(pos)+4)<<32)
 #define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8)
 #define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16))
-#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val)))
+#define SIVAL(buf,pos,val) SIVALX(buf,pos,(uint32)(val))
+#define SIVAL64(buf,pos,val) (SIVAL(buf,pos,val),SIVAL(buf,(pos)+4,(val)>>32))
 
 #define IVALu(buf,pos) IVAL(buf,pos)
 #define SIVALu(buf,pos,val) SIVAL(buf,pos,val)
@@ -95,6 +97,28 @@ SIVAL(char *buf, int pos, uint32 val)
        SIVALu((uchar*)buf, pos, val);
 }
 
+static inline int64
+IVAL64(const char *buf, int pos)
+{
+       union {
+               const char *b;
+               const int64 *num;
+       } u;
+       u.b = buf + pos;
+       return *u.num;
+}
+
+static inline void
+SIVAL64(char *buf, int pos, int64 val)
+{
+       union {
+               char *b;
+               int64 *num;
+       } u;
+       u.b = buf + pos;
+       *u.num = val;
+}
+
 # endif /* !AVOID_BYTEORDER_INLINE */
 
 #endif /* !CAREFUL_ALIGNMENT */
diff --git a/io.c b/io.c
index 264824e70ee6be8fc92f5a302c77f23893cde6f4..354fc133a9e24f7ef92561c74c14e428f4ae9efa 100644 (file)
--- a/io.c
+++ b/io.c
@@ -1785,7 +1785,7 @@ int64 read_varlong(int f, uchar min_bytes)
 #if SIZEOF_INT64 < 8
        u.x = IVAL(u.b,0);
 #elif CAREFUL_ALIGNMENT
-       u.x = IVAL(u.b,0) | (((int64)IVAL(u.b,4))<<32);
+       u.x = IVAL64(u.b,0);
 #endif
        return u.x;
 }
@@ -2037,10 +2037,10 @@ void write_varlong(int f, int64 x, uchar min_bytes)
        uchar bit;
        int cnt = 8;
 
-       SIVAL(b, 1, x);
 #if SIZEOF_INT64 >= 8
-       SIVAL(b, 5, x >> 32);
+       SIVAL64(b, 1, x);
 #else
+       SIVAL(b, 1, x);
        if (x <= 0x7FFFFFFF && x >= 0)
                memset(b + 5, 0, 4);
        else {