1adb0ddaeSAssar Westerlund /*
2*ae771770SStanislav Sedov * Copyright (c) 2001 Kungliga Tekniska Högskolan
3adb0ddaeSAssar Westerlund * (Royal Institute of Technology, Stockholm, Sweden).
4adb0ddaeSAssar Westerlund * All rights reserved.
5adb0ddaeSAssar Westerlund *
6adb0ddaeSAssar Westerlund * Redistribution and use in source and binary forms, with or without
7adb0ddaeSAssar Westerlund * modification, are permitted provided that the following conditions
8adb0ddaeSAssar Westerlund * are met:
9adb0ddaeSAssar Westerlund *
10adb0ddaeSAssar Westerlund * 1. Redistributions of source code must retain the above copyright
11adb0ddaeSAssar Westerlund * notice, this list of conditions and the following disclaimer.
12adb0ddaeSAssar Westerlund *
13adb0ddaeSAssar Westerlund * 2. Redistributions in binary form must reproduce the above copyright
14adb0ddaeSAssar Westerlund * notice, this list of conditions and the following disclaimer in the
15adb0ddaeSAssar Westerlund * documentation and/or other materials provided with the distribution.
16adb0ddaeSAssar Westerlund *
17adb0ddaeSAssar Westerlund * 3. Neither the name of the Institute nor the names of its contributors
18adb0ddaeSAssar Westerlund * may be used to endorse or promote products derived from this software
19adb0ddaeSAssar Westerlund * without specific prior written permission.
20adb0ddaeSAssar Westerlund *
21adb0ddaeSAssar Westerlund * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22adb0ddaeSAssar Westerlund * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23adb0ddaeSAssar Westerlund * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24adb0ddaeSAssar Westerlund * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25adb0ddaeSAssar Westerlund * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26adb0ddaeSAssar Westerlund * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27adb0ddaeSAssar Westerlund * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28adb0ddaeSAssar Westerlund * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29adb0ddaeSAssar Westerlund * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30adb0ddaeSAssar Westerlund * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31adb0ddaeSAssar Westerlund * SUCH DAMAGE.
32adb0ddaeSAssar Westerlund */
33adb0ddaeSAssar Westerlund
34adb0ddaeSAssar Westerlund #include <config.h>
35adb0ddaeSAssar Westerlund #include "roken.h"
36adb0ddaeSAssar Westerlund
37adb0ddaeSAssar Westerlund #ifndef HAVE_BSWAP32
38adb0ddaeSAssar Westerlund
39*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION unsigned int ROKEN_LIB_CALL
bswap32(unsigned int val)40adb0ddaeSAssar Westerlund bswap32 (unsigned int val)
41adb0ddaeSAssar Westerlund {
42adb0ddaeSAssar Westerlund return (val & 0xff) << 24 |
43adb0ddaeSAssar Westerlund (val & 0xff00) << 8 |
44adb0ddaeSAssar Westerlund (val & 0xff0000) >> 8 |
45adb0ddaeSAssar Westerlund (val & 0xff000000) >> 24;
46adb0ddaeSAssar Westerlund }
47adb0ddaeSAssar Westerlund #endif
48adb0ddaeSAssar Westerlund
49adb0ddaeSAssar Westerlund #ifndef HAVE_BSWAP16
50adb0ddaeSAssar Westerlund
51*ae771770SStanislav Sedov ROKEN_LIB_FUNCTION unsigned short ROKEN_LIB_CALL
bswap16(unsigned short val)52adb0ddaeSAssar Westerlund bswap16 (unsigned short val)
53adb0ddaeSAssar Westerlund {
54adb0ddaeSAssar Westerlund return (val & 0xff) << 8 |
55adb0ddaeSAssar Westerlund (val & 0xff00) >> 8;
56adb0ddaeSAssar Westerlund }
57adb0ddaeSAssar Westerlund #endif
58