]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libstand/bswap.c
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libstand / bswap.c
1 /*
2  * Written by Manuel Bouyer <bouyer@netbsd.org>.
3  * Public domain.
4  */
5
6 #include <sys/cdefs.h>
7 __FBSDID("$FreeBSD$");
8
9 #if defined(LIBC_SCCS) && !defined(lint)
10 static char *rcsid = "$NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $";
11 static 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
19 u_int32_t
20 bswap32(x)
21     u_int32_t x;
22 {
23         return  ((x << 24) & 0xff000000 ) |
24                         ((x <<  8) & 0x00ff0000 ) |
25                         ((x >>  8) & 0x0000ff00 ) |
26                         ((x >> 24) & 0x000000ff );
27 }
28
29 u_int64_t
30 bswap64(x)
31     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