bswap.c revision 302408
1153838Sdfr/*
2153838Sdfr * Copyright (c) 2001 Kungliga Tekniska H��gskolan
3153838Sdfr * (Royal Institute of Technology, Stockholm, Sweden).
4153838Sdfr * All rights reserved.
5153838Sdfr *
6153838Sdfr * Redistribution and use in source and binary forms, with or without
7153838Sdfr * modification, are permitted provided that the following conditions
8153838Sdfr * are met:
9153838Sdfr *
10153838Sdfr * 1. Redistributions of source code must retain the above copyright
11153838Sdfr *    notice, this list of conditions and the following disclaimer.
12153838Sdfr *
13153838Sdfr * 2. Redistributions in binary form must reproduce the above copyright
14153838Sdfr *    notice, this list of conditions and the following disclaimer in the
15153838Sdfr *    documentation and/or other materials provided with the distribution.
16153838Sdfr *
17153838Sdfr * 3. Neither the name of the Institute nor the names of its contributors
18153838Sdfr *    may be used to endorse or promote products derived from this software
19153838Sdfr *    without specific prior written permission.
20153838Sdfr *
21153838Sdfr * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22153838Sdfr * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23153838Sdfr * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24153838Sdfr * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25153838Sdfr * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26153838Sdfr * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27153838Sdfr * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28153838Sdfr * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29153838Sdfr * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30153838Sdfr * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31153838Sdfr * SUCH DAMAGE.
32153838Sdfr */
33153838Sdfr
34153838Sdfr#include <config.h>
35153838Sdfr#include "roken.h"
36153838Sdfr
37153838Sdfr#ifndef HAVE_BSWAP32
38153838Sdfr
39153838SdfrROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
40178828Sdfrbswap32 (unsigned int val)
41153838Sdfr{
42153838Sdfr    return (val & 0xff) << 24 |
43153838Sdfr	(val & 0xff00) << 8 |
44153838Sdfr	(val & 0xff0000) >> 8 |
45153838Sdfr	(val & 0xff000000) >> 24;
46153838Sdfr}
47153838Sdfr#endif
48153838Sdfr
49171112Sdfr#ifndef HAVE_BSWAP16
50171112Sdfr
51171112SdfrROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL
52171112Sdfrbswap16 (unsigned short val)
53178828Sdfr{
54178828Sdfr    return (val & 0xff) << 8 |
55178828Sdfr	(val & 0xff00) >> 8;
56178828Sdfr}
57178828Sdfr#endif
58178828Sdfr