2 * Copyright (C) 2013 Intel Corporation. All rights reserved.
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public License
6 * as published by the Free Software Foundation; either version 2.1 of
7 * the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
19 * @author Lucas De Marchi <lucas.demarchi@intel.com>
27 #include <lightmediascanner_utils.h>
29 #define NSEC100_PER_SEC 10000000ULL
30 #define MSEC_PER_SEC 1000ULL
32 #define get_unaligned(ptr) \
34 struct __attribute__((packed)) { \
36 } *__p = (typeof(__p)) (ptr); \
40 #if __BYTE_ORDER == __LITTLE_ENDIAN
41 static inline uint64_t get_le64(const void *ptr)
43 return get_unaligned((const uint64_t *) ptr);
46 static inline uint64_t get_be64(const void *ptr)
48 return bswap_64(get_unaligned((const uint64_t *) ptr));
51 static inline uint32_t get_le32(const void *ptr)
53 return get_unaligned((const uint32_t *) ptr);
56 static inline uint32_t get_be32(const void *ptr)
58 return bswap_32(get_unaligned((const uint32_t *) ptr));
61 static inline uint16_t get_le16(const void *ptr)
63 return get_unaligned((const uint16_t *) ptr);
66 static inline uint16_t get_be16(const void *ptr)
68 return bswap_16(get_unaligned((const uint16_t *) ptr));
71 #elif __BYTE_ORDER == __BIG_ENDIAN
72 static inline uint64_t get_le64(const void *ptr)
74 return bswap_64(get_unaligned((const uint64_t *) ptr));
77 static inline uint64_t get_be64(const void *ptr)
79 return get_unaligned((const uint64_t *) ptr);
82 static inline uint32_t get_le32(const void *ptr)
84 return bswap_32(get_unaligned((const uint32_t *) ptr));
87 static inline uint32_t get_be32(const void *ptr)
89 return get_unaligned((const uint32_t *) ptr);
92 static inline uint16_t get_le16(const void *ptr)
94 return bswap_16(get_unaligned((const uint16_t *) ptr));
97 static inline uint16_t get_be16(const void *ptr)
99 return get_unaligned((const uint16_t *) ptr);
103 #error "Unknown byte order"