File: swap.h

package info (click to toggle)
cntlm 0.35.1-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 408 kB
  • ctags: 325
  • sloc: ansic: 4,519; sh: 267; makefile: 125
file content (67 lines) | stat: -rw-r--r-- 2,209 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
/*
 * These are little/big endian routines for the main module of CNTLM
 *
 * CNTLM is free software; you can redistribute it and/or modify it under the
 * terms of the GNU General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * CNTLM is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 51 Franklin
 * St, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Copyright (c) 2007 David Kubicek
 *
 */

#ifndef _SWAP_H
#define _SWAP_H

#include <stdint.h>
#include "config/config.h"

#define swap16(x) \
	((uint16_t)( \
		(((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
		(((uint16_t)(x) & (uint16_t)0xff00U) >> 8) ))

#define swap32(x) \
	((uint32_t)( \
		(((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
		(((uint32_t)(x) & (uint32_t)0x0000ff00UL) <<  8) | \
		(((uint32_t)(x) & (uint32_t)0x00ff0000UL) >>  8) | \
		(((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) ))

#define swap64(x) \
	((uint64_t)( \
		(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) | \
		(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
		(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
		(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
		(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
		(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
		(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
		(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) ))

#if config_endian == 0
# define U16LE(x)		swap16(x)
# define U32LE(x)		swap32(x)
# define U64LE(x)		swap64(x)
# define U16BE(x)		(x)
# define U32BE(x)		(x)
# define U64BE(x)		(x)
#else
# define U16LE(x)		(x)
# define U32LE(x)		(x)
# define U64LE(x)		(x)
# define U16BE(x)		swap16(x)
# define U32BE(x)		swap32(x)
# define U64BE(x)		swap64(x)
#endif

#endif /* _SWAP_H */