Use CSTD and remove local CSTD settings which are no longer needed.
[dragonfly.git] / lib / libstand / bswap.c
CommitLineData
984263bc
MD
1/*
2 * Written by Manuel Bouyer <bouyer@netbsd.org>.
3 * Public domain.
1de703da
MD
4 *
5 * $NetBSD: bswap32.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $
6 * $NetBSD: bswap64.c,v 1.1 1997/10/09 15:42:33 bouyer Exp $
ff2aef30 7 * $DragonFly: src/lib/libstand/bswap.c,v 1.3 2005/12/11 02:27:26 swildner Exp $
984263bc
MD
8 */
9
984263bc
MD
10#include <sys/types.h>
11
12#undef bswap32
13#undef bswap64
14
15u_int32_t
ff2aef30 16bswap32(u_int32_t x)
984263bc
MD
17{
18 return ((x << 24) & 0xff000000 ) |
19 ((x << 8) & 0x00ff0000 ) |
20 ((x >> 8) & 0x0000ff00 ) |
21 ((x >> 24) & 0x000000ff );
22}
23
24u_int64_t
ff2aef30 25bswap64(u_int64_t x)
984263bc
MD
26{
27 u_int32_t *p = (u_int32_t*)&x;
28 u_int32_t t;
29 t = bswap32(p[0]);
30 p[0] = bswap32(p[1]);
31 p[1] = t;
32 return x;
33}