1 /*****************************************************************************
3 * version - simple version handling functions for major.minor version
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 ****************************************************************************/
26 #ifndef CCAN_VERSION_H
27 #define CCAN_VERSION_H
32 uint32_t _v; /* major << 16 | minor */
36 * version_major - return the major version of the given struct
37 * @v: the version number to obtain the major number from
39 static inline uint16_t version_major(struct version v) {
40 return (v._v & 0xFFFF0000) >> 16;
44 * version_minor - return the minor version of the given struct
45 * @v: the version number to obtain the minor number from
47 static inline uint16_t version_minor(const struct version v) {
52 * version - create a new version number
53 * @major: major version number
54 * @minor: minor version number
56 static inline struct version version(uint16_t major, uint16_t minor)
58 struct version v = { ._v = major << 16 | minor };
63 * version_cmp - compare two versions
64 * @a: the first version number
65 * @b: the second version number
66 * @return a number greater, equal, or less than 0 if a is greater, equal or
67 * less than b, respectively
70 * struct version a = version(1, 0);
71 * struct version b = version(1, 3);
72 * if (version_cmp(a, b) < 0)
73 * printf("b is smaller than b\n");
75 static inline int version_cmp(struct version a, struct version b)
77 return (a._v == b._v) ? 0 : (a._v > b._v) ? 1 : - 1;
80 #endif /* CCAN_VERSION_H */