+1999-05-03 <tytso@rsts-11.mit.edu>
+
+ * compare.c (uuid_compare): Change sense of uuid_compare so that
+ its return values match that of memcpy and the
+ uuid_compare() found in Paul Leach's internet-draft.
+
1999-03-11 Andreas Dilger <adilger@enel.ucalgary.ca>
* Created man pages for libuuid functions.
#include "uuidP.h"
+#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
+
int uuid_compare(uuid_t uu1, uuid_t uu2)
{
- unsigned char *cp1, *cp2;
- int i;
+ struct uuid uuid1, uuid2;
+
+ uuid_unpack(uu1, &uuid1);
+ uuid_unpack(uu2, &uuid2);
- for (i=0, cp1 = uu1, cp2 = uu2; i < 16; i++)
- if (*cp1++ != *cp2++)
- return 0;
- return 1;
+ UUCMP(uuid1.time_low, uuid2.time_low);
+ UUCMP(uuid1.time_mid, uuid2.time_mid);
+ UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
+ UUCMP(uuid1.clock_seq, uuid2.clock_seq);
+ return memcmp(uuid1.node, uuid2.node, 6);
}
.IR uu1 " and " uu2
to each other.
.SH RETURN VALUE
-Returns 1 if the two UUIDs are the same and 0 otherwise.
+Returns an integer less than, equal to, or greater than zero if
+.I uu1
+is found, respectively, to be lexigraphically less than, equal, or
+greater than
+.IR uu2 .
.SH AUTHOR
.B uuid_compare
was written by Theodore Y. Ts'o for the ext2 filesystem utilties.