[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-devel
Subject: Re: Byte order conversions
From: Szombathelyi "György" <gyurco () freemail ! hu>
Date: 2004-10-27 16:42:51
Message-ID: 200410271842.51788.gyurco () freemail ! hu
[Download RAW message or body]
Ok, here comes my version. I'd like to commit it to kdelibs/kdecore, but only
after I get the green light. Any comments?
Bye,
György
____________________________________________________________________
Miert fizetsz az internetert? Korlatlan, ingyenes internet hozzaferes a FreeStarttol.
Probald ki most! http://www.freestart.hu
["kswap.h" (text/x-chdr)]
#ifndef _KSWAP_H_
#define _KSWAP_H_
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <qglobal.h>
#ifdef HAVE_BYTESWAP_H
#include <byteswap.h>
static inline Q_UINT16 KSWAP_16( Q_UINT16 b ) { return bswap_16( b ); }
static inline Q_INT16 KSWAP_16( Q_INT16 b ) { return bswap_16( (Q_UINT16)b ); }
static inline Q_UINT32 KSWAP_32( Q_UINT32 b ) { return bswap_32( b ); }
static inline Q_INT32 KSWAP_32( Q_INT32 b ) { return bswap_32( (Q_UINT32)b ); }
static inline Q_UINT64 KSWAP_64( Q_UINT64 b ) { return bswap_64( b ); }
static inline Q_INT64 KSWAP_64( Q_INT64 b ) { return bswap_64( (Q_UINT64)b ); }
#else /* HAVE_BYTESWAP_H */
#ifdef WORDS_BIGENDIAN
static inline Q_UINT16 KSWAP_16( Q_UINT16 b ) {
return (((b) & 0x00ff) << 8 | ((b) & 0xff00) >> 8); }
static inline Q_INT16 KSWAP_16( Q_INT16 b ) {
return ((((Q_UINT16)b) & 0x00ff) << 8 | (((Q_UINT16)b) & 0xff00) >> 8); }
static inline Q_UINT32 KSWAP_32( Q_UINT32 b ) {
return
((((b) & 0xff000000) >> 24) | (((b) & 0x00ff0000) >> 8) | \
(((b) & 0x0000ff00) << 8) | (((b) & 0x000000ff) << 24)); }
static inline Q_INT32 KSWAP_32( Q_INT32 b ) {
return
(((((Q_UINT32)b) & 0xff000000) >> 24) | ((((Q_UINT32)b) & 0x00ff0000) >> 8) | \
((((Q_UINT32)b) & 0x0000ff00) << 8) | ((((Q_UINT32)b) & 0x000000ff) << 24)); }
#else /* WORDS_BIGENDIAN */
#include <sys/types.h>
#include <netinet/in.h>
static inline Q_UINT16 KSWAP_16( Q_UINT16 b ) {
return htons(b); }
static inline Q_INT16 KSWAP_16( Q_INT16 b ) {
return htons((Q_UINT16)b); }
static inline Q_UINT32 KSWAP_32( Q_UINT32 b ) {
return htonl(b); }
static inline Q_INT32 KSWAP_32( Q_INT32 b ) {
return htonl((Q_UINT32)b); }
#endif
static inline Q_UINT64 KSWAP_64( Q_UINT64 b ) {
union {
Q_UINT64 ll;
Q_UINT32 l[2];
} w, r;
w.ll = b;
r.l[0] = KSWAP_32( w.l[1] );
r.l[1] = KSWAP_32( w.l[0] );
return r.ll;
}
static inline Q_INT64 KSWAP_64( Q_INT64 b ) {
union {
Q_UINT64 ll;
Q_UINT32 l[2];
} w, r;
w.ll = (Q_UINT64) b;
r.l[0] = KSWAP_32( w.l[1] );
r.l[1] = KSWAP_32( w.l[0] );
return r.ll;
}
#endif /* !HAVE_BYTESWAP_H */
// KBE2ME ... BigEndian to MachineEndian
// KLE2ME ... LittleEndian to MachineEndian
#ifdef WORDS_BIGENDIAN
#define KBE2ME_16(x) (x)
#define KBE2ME_32(x) (x)
#define KBE2ME_64(x) (x)
#define KLE2ME_16(x) KSWAP_16(x)
#define KLE2ME_32(x) KSWAP_32(x)
#define KLE2ME_64(x) KSWAP_64(x)
#else
#define KBE2ME_16(x) KSWAP_16(x)
#define KBE2ME_32(x) KSWAP_32(x)
#define KBE2ME_64(x) KSWAP_64(x)
#define KLE2ME_16(x) (x)
#define KLE2ME_32(x) (x)
#define KLE2ME_64(x) (x)
#endif
// KME2BE ... MachineEndian to BigEndian
// KME2LE ... MachineEndian to LittleEndian
#define KME2BE_16(x) KBE2ME_16(x)
#define KME2BE_32(x) KBE2ME_32(x)
#define KME2BE_64(x) KBE2ME_64(x)
#define KME2LE_16(x) KLE2ME_16(x)
#define KME2LE_32(x) KLE2ME_32(x)
#define KME2LE_64(x) KLE2ME_64(x)
#endif /* _KSWAP_H_ */
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic