Imported Upstream version 2.2.51
[platform/upstream/acl.git] / libacl / byteorder.h
1 /*
2   Copyright (C) 2000, 2002  Andreas Gruenbacher <agruen@suse.de>
3
4   This program is free software: you can redistribute it and/or modify it
5   under the terms of the GNU Lesser General Public License as published by
6   the Free Software Foundation, either version 2.1 of the License, or
7   (at your option) any later version.
8
9   This program is distributed in the hope that it will be useful,
10   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12   GNU Lesser General Public License for more details.
13
14   You should have received a copy of the GNU Lesser General Public License
15   along with this program.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18 #include <endian.h>
19
20 #if __BYTE_ORDER == __BIG_ENDIAN
21 # define cpu_to_le16(w16) le16_to_cpu(w16)
22 # define le16_to_cpu(w16) ((u_int16_t)((u_int16_t)(w16) >> 8) | \
23                            (u_int16_t)((u_int16_t)(w16) << 8))
24 # define cpu_to_le32(w32) le32_to_cpu(w32)
25 # define le32_to_cpu(w32) ((u_int32_t)( (u_int32_t)(w32) >>24) | \
26                            (u_int32_t)(((u_int32_t)(w32) >> 8) & 0xFF00) | \
27                            (u_int32_t)(((u_int32_t)(w32) << 8) & 0xFF0000) | \
28                            (u_int32_t)( (u_int32_t)(w32) <<24))
29 #elif __BYTE_ORDER == __LITTLE_ENDIAN
30 # define cpu_to_le16(w16) ((u_int16_t)(w16))
31 # define le16_to_cpu(w16) ((u_int16_t)(w16))
32 # define cpu_to_le32(w32) ((u_int32_t)(w32))
33 # define le32_to_cpu(w32) ((u_int32_t)(w32))
34 #else
35 # error unknown endianess?
36 #endif
37