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