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