mirror of
https://git.hardenedbsd.org/hardenedbsd/HardenedBSD.git
synced 2024-12-29 15:10:57 +01:00
Implement DCE 1.1 compliant UUID functions. Immediate use of these
functions is expected for uuidgen(1), mca(8) and gpt(8). Given the generic use of UUIDs beyond the scope of the DCE 1.1 specification, visibility of the data structure at all levels of the machine, including firmware and the wish to not create a permanent build- time FreeBSD-ism for DCE compliant applications by creating a new library, it was decided that libc would be the least inappropriate place. Also, because the UUID functions live in libc under IRIX as well, we have maximized our portability and left as many options open as possible. This implementation introduces an extension not found in the specification: the status parameter is allowed to be a NULL- pointer. The reason for introducing the extension is because the status is almost never of any use. The manpage that's part of this commit is a minimal place-holder and is further fleshed-out in the near future. Approved by: re@ Contributed by: Hiten Mahesh Pandya <hiten@unixdaemons.com> Sponsored by: marcel :-) Tested on: alpha, i386, ia64
This commit is contained in:
parent
961a3727e7
commit
65393a863e
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=106184
57
include/uuid.h
Normal file
57
include/uuid.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _UUID_H_
|
||||
#define _UUID_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uuid.h>
|
||||
|
||||
/*
|
||||
* This implementation mostly conforms to the DCE 1.1 specification.
|
||||
* See Also:
|
||||
* uuidgen(1), uuidgen(2), uuid(3)
|
||||
*/
|
||||
|
||||
/* Status codes returned by the functions. */
|
||||
#define uuid_s_ok 0
|
||||
#define uuid_s_bad_version 1
|
||||
#define uuid_s_invalid_string_uuid 2
|
||||
#define uuid_s_no_memory 3
|
||||
|
||||
int32_t uuid_compare(uuid_t *, uuid_t *, uint32_t *);
|
||||
void uuid_create(uuid_t *, uint32_t *);
|
||||
void uuid_create_nil(uuid_t *, uint32_t *);
|
||||
int32_t uuid_equal(uuid_t *, uuid_t *, uint32_t *);
|
||||
void uuid_from_string(const char *, uuid_t *, uint32_t *);
|
||||
uint16_t uuid_hash(uuid_t *, uint32_t *);
|
||||
int32_t uuid_is_nil(uuid_t *, uint32_t *);
|
||||
void uuid_to_string(uuid_t *, char **, uint32_t *);
|
||||
|
||||
#endif /* _UUID_H_ */
|
@ -37,6 +37,7 @@ NOASM=
|
||||
.include "${.CURDIR}/../libc/string/Makefile.inc"
|
||||
.include "${.CURDIR}/../libc/sys/Makefile.inc"
|
||||
.include "${.CURDIR}/../libc/rpc/Makefile.inc"
|
||||
.include "${.CURDIR}/../libc/uuid/Makefile.inc"
|
||||
.include "${.CURDIR}/../libc/xdr/Makefile.inc"
|
||||
.if !defined(NO_YP_LIBC)
|
||||
CFLAGS+= -DYP
|
||||
|
22
lib/libc/uuid/Makefile.inc
Normal file
22
lib/libc/uuid/Makefile.inc
Normal file
@ -0,0 +1,22 @@
|
||||
# $FreeBSD$
|
||||
|
||||
# DCE 1.1 UUID implementation sources
|
||||
|
||||
.PATH: ${.CURDIR}/../libc/uuid
|
||||
|
||||
SRCS+= uuid_compare.c uuid_create.c uuid_create_nil.c uuid_equal.c \
|
||||
uuid_from_string.c uuid_hash.c uuid_is_nil.c uuid_to_string.c
|
||||
|
||||
INCS+= uuid.h
|
||||
|
||||
.if ${LIB} == "c"
|
||||
MAN+= uuid.3
|
||||
MLINKS+=uuid.3 uuid_compare.3
|
||||
MLINKS+=uuid.3 uuid_create.3
|
||||
MLINKS+=uuid.3 uuid_create_nil.3
|
||||
MLINKS+=uuid.3 uuid_equal.3
|
||||
MLINKS+=uuid.3 uuid_from_string.3
|
||||
MLINKS+=uuid.3 uuid_hash.3
|
||||
MLINKS+=uuid.3 uuid_is_nil.3
|
||||
MLINKS+=uuid.3 uuid_to_string.3
|
||||
.endif
|
98
lib/libc/uuid/uuid.3
Normal file
98
lib/libc/uuid/uuid.3
Normal file
@ -0,0 +1,98 @@
|
||||
.\" Copyright (c) 2002 Marcel Moolenaar
|
||||
.\" Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" Redistribution and use in source and binary forms, with or without
|
||||
.\" modification, are permitted provided that the following conditions
|
||||
.\" are met:
|
||||
.\" 1. Redistributions of source code must retain the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer.
|
||||
.\" 2. Redistributions in binary form must reproduce the above copyright
|
||||
.\" notice, this list of conditions and the following disclaimer in the
|
||||
.\" documentation and/or other materials provided with the distribution.
|
||||
.\"
|
||||
.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
||||
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
||||
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
.\" BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
.\" AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
.\" OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
.\" SUCH DAMAGE.
|
||||
.\"
|
||||
.\" $FreeBSD$
|
||||
.\"
|
||||
.Dd October 29, 2002
|
||||
.Dt UUID 3
|
||||
.Os
|
||||
.Sh NAME
|
||||
.Nm uuid_compare , uuid_create , uuid_create_nil , uuid_equal ,
|
||||
.Nm uuid_from_string , uuid_hash , uuid_is_nil , uuid_to_string
|
||||
.Nd DCE 1.1 compliant UUID functions
|
||||
.Sh LIBRARY
|
||||
.Lb libc
|
||||
.Sh SYNOPSIS
|
||||
.In uuid.h
|
||||
.Ft int32_t
|
||||
.Fn uuid_compare "uuid_t *uuid1" "uuid_t *uuid2" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_create "uuid_t *uuid" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_create_nil "uuid_t *uuid" "uint32_t *status"
|
||||
.Ft int32_t
|
||||
.Fn uuid_equal "uuid_t *uuid1" "uuid_t *uuid2" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_from_string "const char *str" "uuid_t *uuid" "uint32_t *status"
|
||||
.Ft uint16_t
|
||||
.Fn uuid_hash "uuid_t *uuid" "uint32_t *status"
|
||||
.Ft int32_t
|
||||
.Fn uuid_is_nil "uuid_t *uuid" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_to_string "uuid_t *uuid" "char **str" "uint32_t *status"
|
||||
.Sh DESCRIPTION
|
||||
The family of DCE 1.1 compliant UUID functions allow applications to operate
|
||||
on universally unique identifiers, or UUIDs.
|
||||
The
|
||||
.Fn uuid_create
|
||||
and
|
||||
.Fn uuid_create_nil
|
||||
functions create UUIDs.
|
||||
The
|
||||
.Fn uuid_compare , uuid_equal
|
||||
and
|
||||
.Fn uuid_is_nil
|
||||
functions can be used to test UUIDs.
|
||||
To convert from the binary representation to the string representation or
|
||||
vice versa, use
|
||||
.Fn uuid_to_string
|
||||
or
|
||||
.Fn uuid_from_string
|
||||
respectively.
|
||||
A 16-bit hash value can be obtained by calling
|
||||
.Fn uuid_hash .
|
||||
.Sh RETURN VALUES
|
||||
The successful or unsuccessful completion of the function is returned in
|
||||
the
|
||||
.Fa status
|
||||
parameter. Possible values are:
|
||||
.Pp
|
||||
.Bl -tag -width uuid_s_invalid_string_uuid
|
||||
.It Dv uuid_s_ok
|
||||
The function completed successfully.
|
||||
.It Dv uuid_s_bad_version
|
||||
The UUID does not have a known version.
|
||||
.It Dv uuid_s_invalid_string_uuid
|
||||
The string representation of an UUID is not valid.
|
||||
.It Dv uuid_s_no_memory
|
||||
The meaning of the code escaped the writers mind.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr uuidgen 1 ,
|
||||
.Xr uuidgen 2
|
||||
.Sh BUGS
|
||||
This manpage can be improved.
|
||||
.Sh STANDARDS
|
||||
The UUID functions conform to the DCE 1.1 RPC specification.
|
57
lib/libc/uuid/uuid.h
Normal file
57
lib/libc/uuid/uuid.h
Normal file
@ -0,0 +1,57 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#ifndef _UUID_H_
|
||||
#define _UUID_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uuid.h>
|
||||
|
||||
/*
|
||||
* This implementation mostly conforms to the DCE 1.1 specification.
|
||||
* See Also:
|
||||
* uuidgen(1), uuidgen(2), uuid(3)
|
||||
*/
|
||||
|
||||
/* Status codes returned by the functions. */
|
||||
#define uuid_s_ok 0
|
||||
#define uuid_s_bad_version 1
|
||||
#define uuid_s_invalid_string_uuid 2
|
||||
#define uuid_s_no_memory 3
|
||||
|
||||
int32_t uuid_compare(uuid_t *, uuid_t *, uint32_t *);
|
||||
void uuid_create(uuid_t *, uint32_t *);
|
||||
void uuid_create_nil(uuid_t *, uint32_t *);
|
||||
int32_t uuid_equal(uuid_t *, uuid_t *, uint32_t *);
|
||||
void uuid_from_string(const char *, uuid_t *, uint32_t *);
|
||||
uint16_t uuid_hash(uuid_t *, uint32_t *);
|
||||
int32_t uuid_is_nil(uuid_t *, uint32_t *);
|
||||
void uuid_to_string(uuid_t *, char **, uint32_t *);
|
||||
|
||||
#endif /* _UUID_H_ */
|
76
lib/libc/uuid/uuid_compare.c
Normal file
76
lib/libc/uuid/uuid_compare.c
Normal file
@ -0,0 +1,76 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_compare() - compare two UUIDs.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_compare.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_compare.html
|
||||
*
|
||||
* NOTE: Either UUID can be NULL, meaning a nil UUID. nil UUIDs are smaller
|
||||
* than any non-nil UUID.
|
||||
*/
|
||||
int32_t
|
||||
uuid_compare(uuid_t *a, uuid_t *b, uint32_t *status)
|
||||
{
|
||||
int res;
|
||||
|
||||
if (status != NULL)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
/* Deal with NULL or equal pointers. */
|
||||
if (a == b)
|
||||
return (0);
|
||||
if (a == NULL)
|
||||
return ((uuid_is_nil(b, NULL)) ? 0 : -1);
|
||||
if (b == NULL)
|
||||
return ((uuid_is_nil(a, NULL)) ? 0 : 1);
|
||||
|
||||
/* We have to compare the hard way. */
|
||||
res = (int)((int64_t)a->time_low - (int64_t)b->time_low);
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
res = (int)a->time_mid - (int)b->time_mid;
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
res = (int)a->time_hi_and_version - (int)b->time_hi_and_version;
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
res = (int)a->clock_seq_hi_and_reserved -
|
||||
(int)b->clock_seq_hi_and_reserved;
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
res = (int)a->clock_seq_low - (int)b->clock_seq_low;
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
return (memcmp(a->node, b->node, sizeof(uuid_t)));
|
||||
}
|
46
lib/libc/uuid/uuid_create.c
Normal file
46
lib/libc/uuid/uuid_create.c
Normal file
@ -0,0 +1,46 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_create() - create an UUID.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_create.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_create.html
|
||||
*/
|
||||
void
|
||||
uuid_create(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
uuidgen(u, 1);
|
||||
}
|
47
lib/libc/uuid/uuid_create_nil.c
Normal file
47
lib/libc/uuid/uuid_create_nil.c
Normal file
@ -0,0 +1,47 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <strings.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_create_nil() - create a nil UUID.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_create_nil.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_create_nil.html
|
||||
*/
|
||||
void
|
||||
uuid_create_nil(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
bzero(u, sizeof(*u));
|
||||
}
|
56
lib/libc/uuid/uuid_equal.c
Normal file
56
lib/libc/uuid/uuid_equal.c
Normal file
@ -0,0 +1,56 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_equal() - compare for equality.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_equal.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_equal.html
|
||||
*/
|
||||
int32_t
|
||||
uuid_equal(uuid_t *a, uuid_t *b, uint32_t *status)
|
||||
{
|
||||
|
||||
if (status != NULL)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
/* Deal with equal or NULL pointers. */
|
||||
if (a == b)
|
||||
return (1);
|
||||
if (a == NULL)
|
||||
return (uuid_is_nil(b, NULL));
|
||||
if (b == NULL)
|
||||
return (uuid_is_nil(a, NULL));
|
||||
|
||||
/* Do a byte for byte comparison. */
|
||||
return ((memcmp(a, b, sizeof(uuid_t))) ? 0 : 1);
|
||||
}
|
93
lib/libc/uuid/uuid_from_string.c
Normal file
93
lib/libc/uuid/uuid_from_string.c
Normal file
@ -0,0 +1,93 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_from_string() - convert a string representation of an UUID into
|
||||
* a binary representation.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_from_string.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_from_string.html
|
||||
*
|
||||
* NOTE: The sequence field is in big-endian, while the time fields are in
|
||||
* native byte order.
|
||||
*/
|
||||
void
|
||||
uuid_from_string(const char *s, uuid_t *u, uint32_t *status)
|
||||
{
|
||||
int n;
|
||||
|
||||
/* Short-circuit 2 special cases: NULL pointer and empty string. */
|
||||
if (s == NULL || *s == '\0') {
|
||||
uuid_create_nil(u, status);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Assume the worst. */
|
||||
if (status != NULL)
|
||||
*status = uuid_s_invalid_string_uuid;
|
||||
|
||||
/* The UUID string representation has a fixed length. */
|
||||
if (strlen(s) != 36)
|
||||
return;
|
||||
|
||||
/*
|
||||
* We only work with "new" UUIDs. New UUIDs have the form:
|
||||
* 01234567-89ab-cdef-0123-456789abcdef
|
||||
* The so called "old" UUIDs, which we don't support, have the form:
|
||||
* 0123456789ab.cd.ef.01.23.45.67.89.ab
|
||||
*/
|
||||
if (s[8] != '-')
|
||||
return;
|
||||
|
||||
n = sscanf(s,
|
||||
"%8x-%4hx-%4hx-%2hhx%2hhx-%2hhx%2hhx%2hhx%2hhx%2hhx%2hhx",
|
||||
&u->time_low, &u->time_mid, &u->time_hi_and_version,
|
||||
&u->clock_seq_hi_and_reserved, &u->clock_seq_low, &u->node[0],
|
||||
&u->node[1], &u->node[2], &u->node[3], &u->node[4], &u->node[5]);
|
||||
|
||||
/* Make sure we have all conversions. */
|
||||
if (n != 11)
|
||||
return;
|
||||
|
||||
/* We have a successful scan. Check semantics... */
|
||||
n = u->clock_seq_hi_and_reserved;
|
||||
if ((n & 0x80) != 0x00 && /* variant 0? */
|
||||
(n & 0xc0) != 0x80 && /* variant 1? */
|
||||
(n & 0xe0) != 0xc0) { /* variant 2? */
|
||||
if (status != NULL)
|
||||
*status = uuid_s_bad_version;
|
||||
} else {
|
||||
if (status != NULL)
|
||||
*status = uuid_s_ok;
|
||||
}
|
||||
}
|
50
lib/libc/uuid/uuid_hash.c
Normal file
50
lib/libc/uuid/uuid_hash.c
Normal file
@ -0,0 +1,50 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_hash() - generate a hash value.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_hash.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_hash.html
|
||||
*/
|
||||
uint16_t
|
||||
uuid_hash(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
/*
|
||||
* Use the most frequently changing bits in the UUID as the hash
|
||||
* value. This should yield a good enough distribution...
|
||||
*/
|
||||
return ((u) ? u->time_low & 0xffff : 0);
|
||||
}
|
55
lib/libc/uuid/uuid_is_nil.c
Normal file
55
lib/libc/uuid/uuid_is_nil.c
Normal file
@ -0,0 +1,55 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_is_nil() - return whether the UUID is a nil UUID.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_is_nil.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_is_nil.html
|
||||
*/
|
||||
int32_t
|
||||
uuid_is_nil(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
uint32_t *p;
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
if (!u)
|
||||
return (1);
|
||||
|
||||
/*
|
||||
* Pick the largest type that has equivalent alignment constraints
|
||||
* as an UUID and use it to test if the UUID consists of all zeroes.
|
||||
*/
|
||||
p = (uint32_t*)u;
|
||||
return ((p[0] == 0 && p[1] == 0 && p[2] == 0 && p[3] == 0) ? 1 : 0);
|
||||
}
|
68
lib/libc/uuid/uuid_to_string.c
Normal file
68
lib/libc/uuid/uuid_to_string.c
Normal file
@ -0,0 +1,68 @@
|
||||
/*-
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* Copyright (c) 2002 Hiten Mahesh Pandya
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $FreeBSD$
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_to_string() - Convert a binary UUID into a string representation.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_to_string.htm
|
||||
* http://www.transarc.ibm.com/Library/documentation/dce/1.1/uuid_to_string.html
|
||||
*
|
||||
* NOTE: The references given above do not have a status code for when
|
||||
* the string could not be allocated. The status code has been
|
||||
* taken from the Hewlett-Packard implementation.
|
||||
*/
|
||||
void
|
||||
uuid_to_string(uuid_t *u, char **s, uint32_t *status)
|
||||
{
|
||||
uuid_t nil;
|
||||
|
||||
if (status != NULL)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
/* Why allow a NULL-pointer here? */
|
||||
if (s == 0)
|
||||
return;
|
||||
|
||||
if (u == NULL) {
|
||||
u = &nil;
|
||||
uuid_create_nil(u, NULL);
|
||||
}
|
||||
|
||||
asprintf(s, "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
|
||||
u->time_low, u->time_mid, u->time_hi_and_version,
|
||||
u->clock_seq_hi_and_reserved, u->clock_seq_low, u->node[0],
|
||||
u->node[1], u->node[2], u->node[3], u->node[4], u->node[5]);
|
||||
|
||||
if (*s == NULL && status != NULL)
|
||||
*status = uuid_s_no_memory;
|
||||
}
|
Loading…
Reference in New Issue
Block a user