/src/util-linux/include/iso9660.h
Line | Count | Source |
1 | | /* |
2 | | * No copyright is claimed. This code is in the public domain; do with |
3 | | * it what you wish. |
4 | | */ |
5 | | #ifndef UTIL_LINUX_ISO_H |
6 | | #define UTIL_LINUX_ISO_H |
7 | | |
8 | | #include <inttypes.h> |
9 | | #include <stdbool.h> |
10 | | #include <stdint.h> |
11 | | |
12 | | #include "c.h" |
13 | | |
14 | | static inline uint16_t isonum_721(const unsigned char *p) |
15 | 282 | { |
16 | 282 | return ((p[0] & 0xff) |
17 | 282 | | ((p[1] & 0xff) << 8)); |
18 | 282 | } |
19 | | |
20 | | static inline uint16_t isonum_722(const unsigned char *p) |
21 | 282 | { |
22 | 282 | return ((p[1] & 0xff) |
23 | 282 | | ((p[0] & 0xff) << 8)); |
24 | 282 | } |
25 | | |
26 | | static inline uint16_t isonum_723(const unsigned char *p, bool check_match) |
27 | 282 | { |
28 | 282 | uint16_t le = isonum_721(p); |
29 | 282 | uint16_t be = isonum_722(p + 2); |
30 | | |
31 | 282 | if (check_match && le != be) |
32 | | /* translation is useless */ |
33 | 0 | warnx("723error: le=%d be=%d", le, be); |
34 | 282 | return (le); |
35 | 282 | } |
36 | | |
37 | | static inline uint32_t isonum_731(const unsigned char *p) |
38 | 744 | { |
39 | 744 | return ((p[0] & 0xff) |
40 | 744 | | ((p[1] & 0xff) << 8) |
41 | 744 | | ((p[2] & 0xff) << 16) |
42 | 744 | | (((uint32_t) p[3] & 0xff) << 24)); |
43 | 744 | } |
44 | | |
45 | | static inline uint32_t isonum_732(const unsigned char *p) |
46 | 282 | { |
47 | 282 | return ((p[3] & 0xff) |
48 | 282 | | ((p[2] & 0xff) << 8) |
49 | 282 | | ((p[1] & 0xff) << 16) |
50 | 282 | | (((uint32_t) p[0] & 0xff) << 24)); |
51 | 282 | } |
52 | | |
53 | | static inline uint32_t isonum_733(const unsigned char *p, bool check_match) |
54 | 282 | { |
55 | 282 | uint32_t le = isonum_731(p); |
56 | 282 | uint32_t be = isonum_732(p + 4); |
57 | | |
58 | 282 | if (check_match && le != be) |
59 | | /* translation is useless */ |
60 | 0 | warnx("733error: le=%"PRIu32" be=%"PRIu32, le, be); |
61 | 282 | return(le); |
62 | 282 | } |
63 | | |
64 | | #endif |