endian.h

00001 /*
00002     libparted - a library for manipulating disk partitions
00003     Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
00004 
00005     This program is free software; you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published by
00007     the Free Software Foundation; either version 2 of the License, or
00008     (at your option) any later version.
00009 
00010     This program is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with this program; if not, write to the Free Software
00017     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
00018 */
00019 
00020 /* should only be #included by files in libparted */
00021 
00022 #ifndef PED_ENDIAN_H_INCLUDED
00023 #define PED_ENDIAN_H_INCLUDED
00024 
00025 #include <config.h>
00026 #include <stdint.h>
00027 
00028 /* returns the n'th least significant byte */
00029 #define _GET_BYTE(x, n)         ( ((x) >> (8 * (n))) & 0xff )
00030 
00031 #define _PED_SWAP16(x)          ( (_GET_BYTE(x, 0) << 8)        \
00032                                 + (_GET_BYTE(x, 1) << 0) )
00033 
00034 #define _PED_SWAP32(x)          ( (_GET_BYTE(x, 0) << 24)       \
00035                                 + (_GET_BYTE(x, 1) << 16)       \
00036                                 + (_GET_BYTE(x, 2) << 8)        \
00037                                 + (_GET_BYTE(x, 3) << 0) )
00038 
00039 #define _PED_SWAP64(x)          ( (_GET_BYTE(x, 0) << 56)       \
00040                                 + (_GET_BYTE(x, 1) << 48)       \
00041                                 + (_GET_BYTE(x, 2) << 40)       \
00042                                 + (_GET_BYTE(x, 3) << 32)       \
00043                                 + (_GET_BYTE(x, 4) << 24)       \
00044                                 + (_GET_BYTE(x, 5) << 16)       \
00045                                 + (_GET_BYTE(x, 6) << 8)        \
00046                                 + (_GET_BYTE(x, 7) << 0) )
00047 
00048 #define PED_SWAP16(x)           ((uint16_t) _PED_SWAP16( (uint16_t) (x) ))
00049 #define PED_SWAP32(x)           ((uint32_t) _PED_SWAP32( (uint32_t) (x) ))
00050 #define PED_SWAP64(x)           ((uint64_t) _PED_SWAP64( (uint64_t) (x) ))
00051 
00052 #ifdef WORDS_BIGENDIAN
00053 
00054 #define PED_CPU_TO_LE16(x)      PED_SWAP16(x)
00055 #define PED_CPU_TO_BE16(x)      (x)
00056 #define PED_CPU_TO_LE32(x)      PED_SWAP32(x)
00057 #define PED_CPU_TO_BE32(x)      (x)
00058 #define PED_CPU_TO_LE64(x)      PED_SWAP64(x)
00059 #define PED_CPU_TO_BE64(x)      (x)
00060 
00061 #define PED_LE16_TO_CPU(x)      PED_SWAP16(x)
00062 #define PED_BE16_TO_CPU(x)      (x)
00063 #define PED_LE32_TO_CPU(x)      PED_SWAP32(x)
00064 #define PED_BE32_TO_CPU(x)      (x)
00065 #define PED_LE64_TO_CPU(x)      PED_SWAP64(x)
00066 #define PED_BE64_TO_CPU(x)      (x)
00067 
00068 #else /* !WORDS_BIGENDIAN */
00069 
00070 #define PED_CPU_TO_LE16(x)      (x)
00071 #define PED_CPU_TO_BE16(x)      PED_SWAP16(x)
00072 #define PED_CPU_TO_LE32(x)      (x)
00073 #define PED_CPU_TO_BE32(x)      PED_SWAP32(x)
00074 #define PED_CPU_TO_LE64(x)      (x)
00075 #define PED_CPU_TO_BE64(x)      PED_SWAP64(x)
00076 
00077 #define PED_LE16_TO_CPU(x)      (x)
00078 #define PED_BE16_TO_CPU(x)      PED_SWAP16(x)
00079 #define PED_LE32_TO_CPU(x)      (x)
00080 #define PED_BE32_TO_CPU(x)      PED_SWAP32(x)
00081 #define PED_LE64_TO_CPU(x)      (x)
00082 #define PED_BE64_TO_CPU(x)      PED_SWAP64(x)
00083 
00084 #endif /* !WORDS_BIGENDIAN */
00085 
00086 #endif /* PED_ENDIAN_H_INCLUDED */
00087 

Generated on Fri May 4 05:15:31 2007 for libparted by  doxygen 1.5.2