uuid_equal.c revision 139601
1227825Stheraven/*-
2227825Stheraven * Copyright (c) 2002,2005 Marcel Moolenaar
3227825Stheraven * Copyright (c) 2002 Hiten Mahesh Pandya
4227825Stheraven * All rights reserved.
5227825Stheraven *
6227825Stheraven * Redistribution and use in source and binary forms, with or without
7227825Stheraven * modification, are permitted provided that the following conditions
8227825Stheraven * are met:
9227825Stheraven * 1. Redistributions of source code must retain the above copyright
10227825Stheraven *    notice, this list of conditions and the following disclaimer.
11227825Stheraven * 2. Redistributions in binary form must reproduce the above copyright
12227825Stheraven *    notice, this list of conditions and the following disclaimer in the
13227825Stheraven *    documentation and/or other materials provided with the distribution.
14227825Stheraven *
15227825Stheraven * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16227825Stheraven * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17227825Stheraven * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18227825Stheraven * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19227825Stheraven * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20227825Stheraven * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21227825Stheraven * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22227825Stheraven * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23227825Stheraven * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24227825Stheraven * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25227825Stheraven * SUCH DAMAGE.
26227825Stheraven *
27227825Stheraven * $FreeBSD: head/lib/libc/uuid/uuid_equal.c 139601 2005-01-03 02:56:15Z marcel $
28227825Stheraven */
29227825Stheraven
30227825Stheraven#include <string.h>
31227825Stheraven#include <uuid.h>
32227825Stheraven
33227825Stheraven/*
34227825Stheraven * uuid_equal() - compare for equality.
35227825Stheraven * See also:
36227825Stheraven *	http://www.opengroup.org/onlinepubs/009629399/uuid_equal.htm
37227825Stheraven */
38227825Stheravenint32_t
39227825Stheravenuuid_equal(const uuid_t *a, const uuid_t *b, uint32_t *status)
40227825Stheraven{
41262801Sdim
42227825Stheraven	if (status != NULL)
43227825Stheraven		*status = uuid_s_ok;
44227825Stheraven
45227825Stheraven	/* Deal with equal or NULL pointers. */
46227825Stheraven	if (a == b)
47227825Stheraven		return (1);
48227825Stheraven	if (a == NULL)
49227825Stheraven		return (uuid_is_nil(b, NULL));
50227825Stheraven	if (b == NULL)
51227825Stheraven		return (uuid_is_nil(a, NULL));
52227825Stheraven
53227825Stheraven	/* Do a byte for byte comparison. */
54227825Stheraven	return ((memcmp(a, b, sizeof(uuid_t))) ? 0 : 1);
55227825Stheraven}
56227825Stheraven