1106184Smarcel/*-
2139601Smarcel * Copyright (c) 2002,2005 Marcel Moolenaar
3106184Smarcel * Copyright (c) 2002 Hiten Mahesh Pandya
4106184Smarcel * All rights reserved.
5106184Smarcel *
6106184Smarcel * Redistribution and use in source and binary forms, with or without
7106184Smarcel * modification, are permitted provided that the following conditions
8106184Smarcel * are met:
9106184Smarcel * 1. Redistributions of source code must retain the above copyright
10106184Smarcel *    notice, this list of conditions and the following disclaimer.
11106184Smarcel * 2. Redistributions in binary form must reproduce the above copyright
12106184Smarcel *    notice, this list of conditions and the following disclaimer in the
13106184Smarcel *    documentation and/or other materials provided with the distribution.
14106184Smarcel *
15106184Smarcel * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16106184Smarcel * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17106184Smarcel * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18106184Smarcel * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19106184Smarcel * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20106184Smarcel * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21106184Smarcel * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22106184Smarcel * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23106184Smarcel * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24106184Smarcel * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25106184Smarcel * SUCH DAMAGE.
26106184Smarcel *
27106184Smarcel * $FreeBSD: releng/10.3/lib/libc/uuid/uuid_is_nil.c 146098 2005-05-11 13:18:10Z delphij $
28106184Smarcel */
29106184Smarcel
30106184Smarcel#include <uuid.h>
31106184Smarcel
32106184Smarcel/*
33106184Smarcel * uuid_is_nil() - return whether the UUID is a nil UUID.
34106184Smarcel * See also:
35106184Smarcel *	http://www.opengroup.org/onlinepubs/009629399/uuid_is_nil.htm
36106184Smarcel */
37106184Smarcelint32_t
38139601Smarceluuid_is_nil(const uuid_t *u, uint32_t *status)
39106184Smarcel{
40146098Sdelphij	const uint32_t *p;
41106184Smarcel
42106184Smarcel	if (status)
43106184Smarcel		*status = uuid_s_ok;
44106184Smarcel
45106184Smarcel	if (!u)
46106184Smarcel		return (1);
47106184Smarcel
48106184Smarcel	/*
49106184Smarcel	 * Pick the largest type that has equivalent alignment constraints
50106184Smarcel	 * as an UUID and use it to test if the UUID consists of all zeroes.
51106184Smarcel	 */
52146098Sdelphij	p = (const uint32_t*)u;
53106184Smarcel	return ((p[0] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0) ? 1 : 0);
54106184Smarcel}
55