diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2014-08-31 19:59:19 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2014-08-31 19:59:19 +0000 |
commit | 572b0ee79de39a7bee625471e391c860b88e96ab (patch) | |
tree | e8d057d90c0d28273e3b365a938ffaf489dc0ef0 /lib/libc/uuid | |
parent | 9bfcd13657c197aec78035869dc42233b05361d3 (diff) |
Sync with FreeBSD. No functional change but more readable code.
Diffstat (limited to 'lib/libc/uuid')
-rw-r--r-- | lib/libc/uuid/uuid_compare.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/lib/libc/uuid/uuid_compare.c b/lib/libc/uuid/uuid_compare.c index ad03c4dc5e8..3f6bc25fec1 100644 --- a/lib/libc/uuid/uuid_compare.c +++ b/lib/libc/uuid/uuid_compare.c @@ -1,8 +1,8 @@ -/* $OpenBSD: uuid_compare.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */ +/* $OpenBSD: uuid_compare.c,v 1.2 2014/08/31 19:59:18 miod Exp $ */ /* $NetBSD: uuid_compare.c,v 1.2 2008/04/23 07:52:32 plunky Exp $ */ -/* - * Copyright (c) 2002 Marcel Moolenaar +/*- + * Copyright (c) 2002,2005 Marcel Moolenaar * Copyright (c) 2002 Hiten Mahesh Pandya * All rights reserved. * @@ -27,7 +27,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $FreeBSD: src/lib/libc/uuid/uuid_compare.c,v 1.3 2003/08/08 19:18:43 marcel Exp $ + * $FreeBSD: src/lib/libc/uuid/uuid_compare.c,v 1.6 2007/04/05 02:07:33 delphij Exp $ */ #include "namespace.h" @@ -35,6 +35,12 @@ #include <string.h> #include <uuid.h> +/* A macro used to improve the readability of uuid_compare(). */ +#define DIFF_RETURN(a, b, field) do { \ + if ((a)->field != (b)->field) \ + return (((a)->field < (b)->field) ? -1 : 1); \ +} while (0) + /* * uuid_compare() - compare two UUIDs. * See also: @@ -60,24 +66,16 @@ uuid_compare(const uuid_t *a, const uuid_t *b, uint32_t *status) return ((uuid_is_nil(a, NULL)) ? 0 : 1); /* We have to compare the hard way. */ - res = (int)((int64_t)a->time_low - (int64_t)b->time_low); - if (res) - return ((res < 0) ? -1 : 1); - res = (int)a->time_mid - (int)b->time_mid; - if (res) - return ((res < 0) ? -1 : 1); - res = (int)a->time_hi_and_version - (int)b->time_hi_and_version; - if (res) - return ((res < 0) ? -1 : 1); - res = (int)a->clock_seq_hi_and_reserved - - (int)b->clock_seq_hi_and_reserved; - if (res) - return ((res < 0) ? -1 : 1); - res = (int)a->clock_seq_low - (int)b->clock_seq_low; - if (res) - return ((res < 0) ? -1 : 1); + DIFF_RETURN(a, b, time_low); + DIFF_RETURN(a, b, time_mid); + DIFF_RETURN(a, b, time_hi_and_version); + DIFF_RETURN(a, b, clock_seq_hi_and_reserved); + DIFF_RETURN(a, b, clock_seq_low); + res = memcmp(a->node, b->node, sizeof(a->node)); if (res) return ((res < 0) ? -1 : 1); return (0); } + +#undef DIFF_RETURN |