summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2014-08-31 19:59:18 +0000
committermiod <miod@openbsd.org>2014-08-31 19:59:18 +0000
commitbd303c37ffb7efd1841a5b4bad23519c3c75629b (patch)
tree3bde5a50012ad4f4e3e840c50729ecd31411ab50 /lib
parentFix incorrect behaviour by syncing with FreeBSD; reported by Jonas 'Sortie' (diff)
downloadwireguard-openbsd-bd303c37ffb7efd1841a5b4bad23519c3c75629b.tar.xz
wireguard-openbsd-bd303c37ffb7efd1841a5b4bad23519c3c75629b.zip
Sync with FreeBSD. No functional change but more readable code.
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/uuid/uuid_compare.c38
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