diff options
author | Wayne Davison <wayned@samba.org> | 2014-01-19 12:02:38 -0800 |
---|---|---|
committer | Wayne Davison <wayned@samba.org> | 2014-01-19 12:02:38 -0800 |
commit | 5dcef7c6dd2c50cc5a96dc86efcab737fd2b7433 (patch) | |
tree | 3321d80820ada72013c9dc9c57196a9af9ca13ed | |
parent | 72e0c450782ec3a31792eea1e47c78d1efe989cd (diff) | |
download | rsync-5dcef7c6dd2c50cc5a96dc86efcab737fd2b7433.tar.gz rsync-5dcef7c6dd2c50cc5a96dc86efcab737fd2b7433.tar.bz2 rsync-5dcef7c6dd2c50cc5a96dc86efcab737fd2b7433.zip |
Adding IVAL64() and SIVAL64().
-rw-r--r-- | byteorder.h | 26 | ||||
-rw-r--r-- | io.c | 6 |
2 files changed, 28 insertions, 4 deletions
diff --git a/byteorder.h b/byteorder.h index 831644fe..22e807ab 100644 --- a/byteorder.h +++ b/byteorder.h @@ -38,9 +38,11 @@ #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 */ @@ -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 { |