From c4ef94b1a270ab01d0ca50ecbc1df7fcdf6fc44f Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Mon, 30 Aug 1999 14:45:01 +0000 Subject: [PATCH] Add 32 bit serial arithmetic support. --- lib/isc/include/isc/Makefile.in | 4 +-- lib/isc/include/isc/serial.h | 55 +++++++++++++++++++++++++++++++++ lib/isc/serial.c | 39 +++++++++++++++++++++++ 3 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 lib/isc/include/isc/serial.h create mode 100644 lib/isc/serial.c diff --git a/lib/isc/include/isc/Makefile.in b/lib/isc/include/isc/Makefile.in index 47d79bd05c..13e1c0389d 100644 --- a/lib/isc/include/isc/Makefile.in +++ b/lib/isc/include/isc/Makefile.in @@ -22,8 +22,8 @@ top_srcdir = @top_srcdir@ HEADERS = assertions.h base64.h boolean.h buffer.h error.h event.h \ eventclass.h heap.h int.h interfaceiter.h lang.h lex.h lib.h \ list.h mem.h msgcat.h netaddr.h rbtgen.h region.h result.h \ - resultclass.h rwlock.h sockaddr.h socket.h str.h symtab.h \ - task.h timer.h types.h + resultclass.h rwlock.h serial.h sockaddr.h socket.h str.h \ + symtab.h task.h timer.h types.h SUBDIRS = TARGETS = diff --git a/lib/isc/include/isc/serial.h b/lib/isc/include/isc/serial.h new file mode 100644 index 0000000000..abd4ddd3bc --- /dev/null +++ b/lib/isc/include/isc/serial.h @@ -0,0 +1,55 @@ + + /* $Id: serial.h,v 1.1 1999/08/30 14:44:11 marka Exp $ */ + +#ifndef isc_serial_h +#define isc_serial_h + +#include +#include +#include + +ISC_LANG_BEGINDECLS + +/* + * Implement 32 bit serial space arithmetic comparision functions. + * + * Note: Undefined results are returned as ISC_FALSE. + */ + +/*** + *** Functions + ***/ + +isc_boolean_t isc_serial_lt(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' < 'b' otherwise false. + */ + +isc_boolean_t isc_serial_gt(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' > 'b' otherwise false. + */ + +isc_boolean_t isc_serial_le(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' <= 'b' otherwise false. + */ + +isc_boolean_t isc_serial_ge(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' >= 'b' otherwise false. + */ + +isc_boolean_t isc_serial_eq(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' == 'b' otherwise false. + */ + +isc_boolean_t isc_serial_ne(isc_uint32_t a, isc_uint32_t b); +/* + * Return true if 'a' != 'b' otherwise false. + */ + +ISC_LANG_ENDDECLS + +#endif /* isc_serial_h */ diff --git a/lib/isc/serial.c b/lib/isc/serial.c new file mode 100644 index 0000000000..0f10008df5 --- /dev/null +++ b/lib/isc/serial.c @@ -0,0 +1,39 @@ + + /* $Id: serial.c,v 1.1 1999/08/30 14:45:01 marka Exp $ */ + +#include + +isc_boolean_t +isc_serial_lt(isc_uint32_t a, isc_uint32_t b) { + /* + * Undefined => ISC_FALSE + */ + if (a == (b ^ 0x80000000U)) + return (ISC_FALSE); + return (((isc_int32_t)(a - b) < 0) ? ISC_TRUE : ISC_FALSE); +} + +isc_boolean_t +isc_serial_gt(isc_uint32_t a, isc_uint32_t b) { + return (((isc_int32_t)(a - b) > 0) ? ISC_TRUE : ISC_FALSE); +} + +isc_boolean_t +isc_serial_le(isc_uint32_t a, isc_uint32_t b) { + return ((a == b) ? ISC_TRUE : isc_serial_lt(a, b)); +} + +isc_boolean_t +isc_serial_ge(isc_uint32_t a, isc_uint32_t b) { + return ((a == b) ? ISC_TRUE : isc_serial_gt(a, b)); +} + +isc_boolean_t +isc_serial_eq(isc_uint32_t a, isc_uint32_t b) { + return ((a == b) ? ISC_TRUE : ISC_FALSE); +} + +isc_boolean_t +isc_serial_ne(isc_uint32_t a, isc_uint32_t b) { + return ((a != b) ? ISC_TRUE : ISC_FALSE); +}