paul@181 | 1 | /* |
paul@181 | 2 | * compare.c --- compare whether or not two UUID's are the same |
paul@181 | 3 | * |
paul@181 | 4 | * Returns 0 if the two UUID's are different, and 1 if they are the same. |
paul@181 | 5 | * |
paul@181 | 6 | * Copyright (C) 1996, 1997 Theodore Ts'o. |
paul@181 | 7 | * |
paul@181 | 8 | * %Begin-Header% |
paul@181 | 9 | * Redistribution and use in source and binary forms, with or without |
paul@181 | 10 | * modification, are permitted provided that the following conditions |
paul@181 | 11 | * are met: |
paul@181 | 12 | * 1. Redistributions of source code must retain the above copyright |
paul@181 | 13 | * notice, and the entire permission notice in its entirety, |
paul@181 | 14 | * including the disclaimer of warranties. |
paul@181 | 15 | * 2. Redistributions in binary form must reproduce the above copyright |
paul@181 | 16 | * notice, this list of conditions and the following disclaimer in the |
paul@181 | 17 | * documentation and/or other materials provided with the distribution. |
paul@181 | 18 | * 3. The name of the author may not be used to endorse or promote |
paul@181 | 19 | * products derived from this software without specific prior |
paul@181 | 20 | * written permission. |
paul@181 | 21 | * |
paul@181 | 22 | * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED |
paul@181 | 23 | * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
paul@181 | 24 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF |
paul@181 | 25 | * WHICH ARE HEREBY DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE |
paul@181 | 26 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
paul@181 | 27 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT |
paul@181 | 28 | * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR |
paul@181 | 29 | * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
paul@181 | 30 | * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
paul@181 | 31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE |
paul@181 | 32 | * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH |
paul@181 | 33 | * DAMAGE. |
paul@181 | 34 | * %End-Header% |
paul@181 | 35 | */ |
paul@181 | 36 | |
paul@181 | 37 | #include "config.h" |
paul@181 | 38 | #include "uuidP.h" |
paul@181 | 39 | #include <string.h> |
paul@181 | 40 | |
paul@181 | 41 | #define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1); |
paul@181 | 42 | |
paul@181 | 43 | int uuid_compare(const uuid_t uu1, const uuid_t uu2) |
paul@181 | 44 | { |
paul@181 | 45 | struct uuid uuid1, uuid2; |
paul@181 | 46 | |
paul@181 | 47 | uuid_unpack(uu1, &uuid1); |
paul@181 | 48 | uuid_unpack(uu2, &uuid2); |
paul@181 | 49 | |
paul@181 | 50 | UUCMP(uuid1.time_low, uuid2.time_low); |
paul@181 | 51 | UUCMP(uuid1.time_mid, uuid2.time_mid); |
paul@181 | 52 | UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version); |
paul@181 | 53 | UUCMP(uuid1.clock_seq, uuid2.clock_seq); |
paul@181 | 54 | return memcmp(uuid1.node, uuid2.node, 6); |
paul@181 | 55 | } |
paul@181 | 56 | |