1 /* $NetBSD: serial.c,v 1.1 2024/02/18 20:57:50 christos Exp $ */
2
3 /*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16 /*! \file */
17
18 #include <inttypes.h>
19 #include <stdbool.h>
20
21 #include <isc/serial.h>
22
23 bool
isc_serial_lt(uint32_t a,uint32_t b)24 isc_serial_lt(uint32_t a, uint32_t b) {
25 /*
26 * Undefined => false
27 */
28 if (a == (b ^ 0x80000000U)) {
29 return (false);
30 }
31 return (((int32_t)(a - b) < 0) ? true : false);
32 }
33
34 bool
isc_serial_gt(uint32_t a,uint32_t b)35 isc_serial_gt(uint32_t a, uint32_t b) {
36 return (((int32_t)(a - b) > 0) ? true : false);
37 }
38
39 bool
isc_serial_le(uint32_t a,uint32_t b)40 isc_serial_le(uint32_t a, uint32_t b) {
41 return ((a == b) ? true : isc_serial_lt(a, b));
42 }
43
44 bool
isc_serial_ge(uint32_t a,uint32_t b)45 isc_serial_ge(uint32_t a, uint32_t b) {
46 return ((a == b) ? true : isc_serial_gt(a, b));
47 }
48
49 bool
isc_serial_eq(uint32_t a,uint32_t b)50 isc_serial_eq(uint32_t a, uint32_t b) {
51 return ((a == b) ? true : false);
52 }
53
54 bool
isc_serial_ne(uint32_t a,uint32_t b)55 isc_serial_ne(uint32_t a, uint32_t b) {
56 return ((a != b) ? true : false);
57 }
58