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