11e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o/*
21e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * compare.c --- compare whether or not two UUID's are the same
31e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o *
41e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o * Returns 0 if the two UUID's are different, and 1 if they are the same.
5efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o *
619c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * Copyright (C) 1996, 1997 Theodore Ts'o.
719c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o *
819c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %Begin-Header%
91bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * Redistribution and use in source and binary forms, with or without
101bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * modification, are permitted provided that the following conditions
111bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * are met:
121bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 1. Redistributions of source code must retain the above copyright
131bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    notice, and the entire permission notice in its entirety,
141bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    including the disclaimer of warranties.
151bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 2. Redistributions in binary form must reproduce the above copyright
161bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    notice, this list of conditions and the following disclaimer in the
171bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    documentation and/or other materials provided with the distribution.
181bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * 3. The name of the author may not be used to endorse or promote
191bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    products derived from this software without specific prior
201bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o *    written permission.
21efc6f628e15de95bcd13e4f0ee223cb42115d520Theodore Ts'o *
221bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
231bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
241bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ALL OF
251bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * WHICH ARE HEREBY DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE
261bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
271bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
281bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
291bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
301bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
311bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
321bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * USE OF THIS SOFTWARE, EVEN IF NOT ADVISED OF THE POSSIBILITY OF SUCH
331bbfec624c4bbe767060a13762aa9a656536a4fdTheodore Ts'o * DAMAGE.
3419c78dc07fce2d6f39b5e541562afc3ca1ea38ffTheodore Ts'o * %End-Header%
351e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o */
361e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
371e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o#include "uuidP.h"
38b1416db3227b4b7192ee0d2d3ff6e00e92e9d3e2Theodore Ts'o#include <string.h>
391e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
40ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o#define UUCMP(u1,u2) if (u1 != u2) return((u1 < u2) ? -1 : 1);
41ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o
42ce2722f86de298ad1a8965f55a453b5723d2b2b9Theodore Ts'oint uuid_compare(const uuid_t uu1, const uuid_t uu2)
431e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o{
44ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	struct uuid	uuid1, uuid2;
45ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o
46ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	uuid_unpack(uu1, &uuid1);
47ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	uuid_unpack(uu2, &uuid2);
481e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
49ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	UUCMP(uuid1.time_low, uuid2.time_low);
50ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	UUCMP(uuid1.time_mid, uuid2.time_mid);
51ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	UUCMP(uuid1.time_hi_and_version, uuid2.time_hi_and_version);
52ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	UUCMP(uuid1.clock_seq, uuid2.clock_seq);
53ffd3af5874950a38f4e383331a5a332e40cabf80Theodore Ts'o	return memcmp(uuid1.node, uuid2.node, 6);
541e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o}
551e3472c5f37ca3686dd69b079d4d02a302f5798dTheodore Ts'o
56