Deleted Added
full compact
bswap.c (84221) bswap.c (221358)
1/*
2 * Written by Manuel Bouyer <bouyer@netbsd.org>.
3 * Public domain.
4 */
5
6#include <sys/cdefs.h>
1/*
2 * Written by Manuel Bouyer <bouyer@netbsd.org>.
3 * Public domain.
4 */
5
6#include <sys/cdefs.h>
7__FBSDID("$FreeBSD: head/lib/libstand/bswap.c 84221 2001-09-30 22:28:01Z dillon $");
7__FBSDID("$FreeBSD: head/lib/libstand/bswap.c 221358 2011-05-03 04:44:50Z rodrigc $");
8
9#if defined(LIBC_SCCS) && !defined(lint)
10static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
11static char *rcsid = "$NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
12#endif
13
14#include <sys/types.h>
15
16#undef bswap32
17#undef bswap64
18
8
9#if defined(LIBC_SCCS) && !defined(lint)
10static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
11static char *rcsid = "$NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
12#endif
13
14#include <sys/types.h>
15
16#undef bswap32
17#undef bswap64
18
19u_int32_t bswap32(u_int32_t x);
20u_int64_t bswap64(u_int64_t x);
21
19u_int32_t
22u_int32_t
20bswap32(x)
21 u_int32_t x;
23bswap32(u_int32_t x)
22{
23 return ((x << 24) & 0xff000000 ) |
24 ((x << 8) & 0x00ff0000 ) |
25 ((x >> 8) & 0x0000ff00 ) |
26 ((x >> 24) & 0x000000ff );
27}
28
29u_int64_t
24{
25 return ((x << 24) & 0xff000000 ) |
26 ((x << 8) & 0x00ff0000 ) |
27 ((x >> 8) & 0x0000ff00 ) |
28 ((x >> 24) & 0x000000ff );
29}
30
31u_int64_t
30bswap64(x)
31 u_int64_t x;
32bswap64(u_int64_t x)
32{
33 u_int32_t *p = (u_int32_t*)&x;
34 u_int32_t t;
35 t = bswap32(p[0]);
36 p[0] = bswap32(p[1]);
37 p[1] = t;
38 return x;
39}
40
33{
34 u_int32_t *p = (u_int32_t*)&x;
35 u_int32_t t;
36 t = bswap32(p[0]);
37 p[0] = bswap32(p[1]);
38 p[1] = t;
39 return x;
40}
41