ossp-pkg/uuid/uuid.c 1.1 -> 1.2
--- uuid.c 2004/01/06 20:14:28 1.1
+++ uuid.c 2004/01/06 20:43:34 1.2
@@ -135,11 +135,59 @@
return UUID_RC_OK;
}
-uuid_rc_t uuid_compare(uuid_t *uuid, uuid_t *uuid2, int *result)
+uuid_rc_t uuid_compare(uuid_t *a, uuid_t *b, int *result)
{
- if (uuid == NULL || uuid2 == NULL || result == NULL)
+ int r;
+
+ if (result == NULL)
return UUID_RC_ARG;
- /* FIXME */
+
+ /* deal with NULL or equal pointers. */
+ if (a == b) {
+ *result = 0;
+ return UUID_RC_OK;
+ }
+ if (a == NULL && b == NULL) {
+ *result = 0;
+ return UUID_RC_OK;
+ }
+ if (a == NULL) {
+ *result = ((uuid_isnull(b, &r), r) ? 0 : -1);
+ return UUID_RC_OK;
+ }
+ if (b == NULL) {
+ *result = ((uuid_isnull(a, &r), r) ? 0 : 1);
+ return UUID_RC_OK;
+ }
+
+ /* we have to compare the hard way. */
+ if (a->time_low != b->time_low) {
+ *result = ((a->time_low < b->time_low) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+ if ((r = (int)a->time_mid - (int)b->time_mid) != 0) {
+ *result = ((r < 0) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+ if ((r = (int)a->time_hi_and_version - (int)b->time_hi_and_version) != 0) {
+ *result = ((r < 0) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+ if ((r = (int)a->clock_seq_hi_and_reserved - (int)b->clock_seq_hi_and_reserved) != 0) {
+ *result = ((r < 0) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+ if ((r = (int)a->clock_seq_low - (int)b->clock_seq_low) != 0) {
+ *result = ((r < 0) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+ if ((r = memcmp(a->node, b->node, sizeof(a->node))) != 0) {
+ *result = ((r < 0) ? -1 : 1);
+ return UUID_RC_OK;
+ }
+
+ /* else the keys are equal */
+ *result = 0;
return UUID_RC_OK;
}
|
|