mirror of
https://github.com/openbsd/src.git
synced 2025-01-02 14:25:36 -08:00
Add uuid support routines to libc. From FreeBSD via NetBSD via Bitrig via
Markus Mueller.
This commit is contained in:
parent
beb593258d
commit
9a210c530b
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile,v 1.193 2014/07/14 01:01:27 deraadt Exp $
|
||||
# $OpenBSD: Makefile,v 1.194 2014/08/31 09:36:36 miod Exp $
|
||||
# $NetBSD: Makefile,v 1.59 1996/05/15 21:36:43 jtc Exp $
|
||||
|
||||
# @(#)Makefile 5.45.1.1 (Berkeley) 5/6/91
|
||||
@ -19,7 +19,7 @@ FILES= a.out.h ar.h asr.h assert.h bitstring.h blf.h bsd_auth.h \
|
||||
resolv.h rmd160.h search.h setjmp.h sha1.h sha2.h signal.h sndio.h \
|
||||
spawn.h stdbool.h stddef.h stdio.h stdlib.h string.h strings.h struct.h \
|
||||
sysexits.h tar.h tgmath.h time.h ttyent.h tzfile.h unistd.h utime.h \
|
||||
utmp.h vis.h wchar.h wctype.h
|
||||
utmp.h uuid.h vis.h wchar.h wctype.h
|
||||
|
||||
FILES+= link.h link_elf.h
|
||||
|
||||
|
69
include/uuid.h
Normal file
69
include/uuid.h
Normal file
@ -0,0 +1,69 @@
|
||||
/* $OpenBSD: uuid.h,v 1.1 2014/08/31 09:36:36 miod Exp $ */
|
||||
/* $NetBSD: uuid.h,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/include/uuid.h,v 1.2 2002/11/05 10:55:16 jmallett Exp $
|
||||
*/
|
||||
|
||||
#ifndef _UUID_H_
|
||||
#define _UUID_H_
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/uuid.h>
|
||||
|
||||
/* 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
|
||||
|
||||
/* Length of a printed UUID. */
|
||||
#define UUID_BUF_LEN _UUID_BUF_LEN
|
||||
|
||||
/* Length of a UUID. */
|
||||
#define UUID_STR_LEN 36
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
|
||||
__BEGIN_DECLS
|
||||
int32_t uuid_compare(const uuid_t *, const uuid_t *, uint32_t *);
|
||||
void uuid_create(uuid_t *, uint32_t *);
|
||||
void uuid_create_nil(uuid_t *, uint32_t *);
|
||||
int32_t uuid_equal(const uuid_t *, const uuid_t *, uint32_t *);
|
||||
void uuid_from_string(const char *, uuid_t *, uint32_t *);
|
||||
uint16_t uuid_hash(const uuid_t *, uint32_t *);
|
||||
int32_t uuid_is_nil(const uuid_t *, uint32_t *);
|
||||
void uuid_to_string(const uuid_t *, char **, uint32_t *);
|
||||
|
||||
void uuid_enc_le(void *, const uuid_t *);
|
||||
void uuid_dec_le(const void *, uuid_t *);
|
||||
void uuid_enc_be(void *, const uuid_t *);
|
||||
void uuid_dec_be(const void *, uuid_t *);
|
||||
__END_DECLS
|
||||
|
||||
#endif /* _UUID_H_ */
|
@ -1,4 +1,4 @@
|
||||
# $OpenBSD: Makefile.inc,v 1.21 2014/07/10 12:55:14 tedu Exp $
|
||||
# $OpenBSD: Makefile.inc,v 1.22 2014/08/31 09:36:39 miod Exp $
|
||||
#
|
||||
# This file contains make rules used to build libc
|
||||
#
|
||||
@ -52,6 +52,7 @@ AINC+= -nostdinc -idirafter ${DESTDIR}/usr/include
|
||||
.include "${LIBCSRCDIR}/termios/Makefile.inc"
|
||||
.include "${LIBCSRCDIR}/thread/Makefile.inc"
|
||||
.include "${LIBCSRCDIR}/time/Makefile.inc"
|
||||
.include "${LIBCSRCDIR}/uuid/Makefile.inc"
|
||||
.include "${LIBCSRCDIR}/sys/Makefile.inc"
|
||||
.if (${YP:L} == "yes")
|
||||
.include "${LIBCSRCDIR}/yp/Makefile.inc"
|
||||
|
26
lib/libc/uuid/Makefile.inc
Normal file
26
lib/libc/uuid/Makefile.inc
Normal file
@ -0,0 +1,26 @@
|
||||
# $OpenBSD: Makefile.inc,v 1.1 2014/08/31 09:36:39 miod Exp $
|
||||
# $NetBSD: Makefile.inc,v 1.1 2004/09/13 21:44:54 thorpej Exp $
|
||||
|
||||
# DCE 1.1 compatible UUID implementation sources
|
||||
|
||||
.PATH: ${LIBCSRCDIR}/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_stream.c \
|
||||
uuid_to_string.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
|
||||
|
||||
MLINKS+=uuid.3 uuid_enc_le.3
|
||||
MLINKS+=uuid.3 uuid_dec_le.3
|
||||
MLINKS+=uuid.3 uuid_enc_be.3
|
||||
MLINKS+=uuid.3 uuid_dec_be.3
|
206
lib/libc/uuid/uuid.3
Normal file
206
lib/libc/uuid/uuid.3
Normal file
@ -0,0 +1,206 @@
|
||||
.\" $OpenBSD: uuid.3,v 1.1 2014/08/31 09:36:39 miod Exp $
|
||||
.\" $NetBSD: uuid.3,v 1.7 2008/05/02 18:11:05 martin Exp $
|
||||
.\"
|
||||
.\" Copyright (c) 2004 The NetBSD Foundation, Inc.
|
||||
.\" All rights reserved.
|
||||
.\"
|
||||
.\" This code is derived from software contributed to The NetBSD Foundation
|
||||
.\" by Jason R. Thorpe.
|
||||
.\"
|
||||
.\" 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 NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
||||
.\"
|
||||
.\" 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: src/lib/libc/uuid/uuid.3,v 1.4 2003/08/08 19:12:28 marcel Exp $
|
||||
.\"
|
||||
.Dd $Mdocdate: August 31 2014 $
|
||||
.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 ,
|
||||
.Nm uuid_enc_le , uuid_dec_le , uuid_enc_be , uuid_dec_be
|
||||
.Nd Universally Unique Identifier routines
|
||||
.Sh SYNOPSIS
|
||||
.In uuid.h
|
||||
.Ft int32_t
|
||||
.Fn uuid_compare "const uuid_t *uuid1" "const 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 "const uuid_t *uuid1" "const 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 "const uuid_t *uuid" "uint32_t *status"
|
||||
.Ft int32_t
|
||||
.Fn uuid_is_nil "const uuid_t *uuid" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_to_string "const uuid_t *uuid" "char **str" "uint32_t *status"
|
||||
.Ft void
|
||||
.Fn uuid_enc_le "void *buf" "const uuid_t *uuid"
|
||||
.Ft void
|
||||
.Fn uuid_dec_le "const void *buf" "uuid_t *"
|
||||
.Ft void
|
||||
.Fn uuid_enc_be "void *buf" "const uuid_t *uuid"
|
||||
.Ft void
|
||||
.Fn uuid_dec_be "const void *buf" "uuid_t *"
|
||||
.Sh DESCRIPTION
|
||||
These routines provide for the creation and manipulation of Universally
|
||||
Unique Identifiers
|
||||
.Pq UUIDs ,
|
||||
also referred to as Globally Unique Identifiers
|
||||
.Pq GUIDs .
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_compare
|
||||
function compares two UUIDs.
|
||||
It returns \-1 if
|
||||
.Fa uuid1
|
||||
precedes
|
||||
.Fa uuid2 ,
|
||||
0 if they are equal, or 1 if
|
||||
.Fa uuid1
|
||||
follows
|
||||
.Fa uuid2 .
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_create
|
||||
function creates a new UUID.
|
||||
Storage for the new UUID must be pre-allocated by the caller.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_create_nil
|
||||
function creates a nil-valued UUID.
|
||||
Storage for the new UUID must be pre-allocated by the caller.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_equal
|
||||
function compares two UUIDs to determine if they are equal.
|
||||
It returns 1 if they are equal, and 0 if they are not equal.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_from_string
|
||||
function parses a 36-character string representation of a UUID and
|
||||
converts it to binary representation.
|
||||
Storage for the UUID must be pre-allocated by the caller.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_hash
|
||||
function generates a hash value for the specified UUID.
|
||||
Note that the hash value is not a cryptographic hash, and should not be
|
||||
assumed to be unique given two different UUIDs.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_is_nil
|
||||
function returns 1 if the UUID is nil-valued and 0 if it is not.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_to_string
|
||||
function converts a UUID from binary representation to string representation.
|
||||
Storage for the string is dynamically allocated and returned via the
|
||||
.Fa str
|
||||
argument.
|
||||
This pointer should be passed to
|
||||
.Xr free 3
|
||||
to release the allocated storage when it is no longer needed.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_enc_le
|
||||
and
|
||||
.Fn uuid_enc_be
|
||||
functions encode a binary representation of a UUID into an octet stream
|
||||
in little-endian and big-endian byte order, respectively.
|
||||
The destination buffer must be pre-allocated by the caller, and must be
|
||||
large enough to hold the 16-octet binary UUID.
|
||||
.Pp
|
||||
The
|
||||
.Fn uuid_dec_le
|
||||
and
|
||||
.Fn uuid_dec_be
|
||||
functions decode a UUID from an octet stream in little-endian and
|
||||
big-endian byte order, respectively.
|
||||
.Sh RETURN VALUES
|
||||
The
|
||||
.Fn uuid_compare ,
|
||||
.Fn uuid_create ,
|
||||
.Fn uuid_create_nil ,
|
||||
.Fn uuid_equal ,
|
||||
.Fn uuid_from_string ,
|
||||
.Fn uuid_hash ,
|
||||
.Fn uuid_is_nil ,
|
||||
and
|
||||
.Fn uuid_to_string
|
||||
functions return successful or unsuccessful completion status in the
|
||||
.Fa status
|
||||
argument.
|
||||
Possible values are:
|
||||
.Pp
|
||||
.Bl -tag -width ".Dv 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 a UUID is not valid.
|
||||
.It Dv uuid_s_no_memory
|
||||
Memory could not be allocated for the operation.
|
||||
.El
|
||||
.Sh SEE ALSO
|
||||
.Xr uuidgen 1
|
||||
.Sh STANDARDS
|
||||
The
|
||||
.Fn uuid_compare ,
|
||||
.Fn uuid_create ,
|
||||
.Fn uuid_create_nil ,
|
||||
.Fn uuid_equal ,
|
||||
.Fn uuid_from_string ,
|
||||
.Fn uuid_hash ,
|
||||
.Fn uuid_is_nil ,
|
||||
and
|
||||
.Fn uuid_to_string
|
||||
functions are compatible with the DCE 1.1 RPC specification.
|
83
lib/libc/uuid/uuid_compare.c
Normal file
83
lib/libc/uuid/uuid_compare.c
Normal file
@ -0,0 +1,83 @@
|
||||
/* $OpenBSD: uuid_compare.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_compare.c,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_compare.c,v 1.3 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_compare() - compare two UUIDs.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_compare.htm
|
||||
*
|
||||
* NOTE: Either UUID can be NULL, meaning a nil UUID. nil UUIDs are smaller
|
||||
* than any non-nil UUID.
|
||||
*/
|
||||
int32_t
|
||||
uuid_compare(const uuid_t *a, const 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);
|
||||
res = memcmp(a->node, b->node, sizeof(a->node));
|
||||
if (res)
|
||||
return ((res < 0) ? -1 : 1);
|
||||
return (0);
|
||||
}
|
61
lib/libc/uuid/uuid_create.c
Normal file
61
lib/libc/uuid/uuid_create.c
Normal file
@ -0,0 +1,61 @@
|
||||
/* $OpenBSD: uuid_create.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_create.c,v 1.1 2004/09/13 21:44:54 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_create.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_create() - create an UUID.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_create.htm and
|
||||
* RFC 4122
|
||||
*
|
||||
* Create a UUID from random number as defined in section 4.4 of RFC 4122
|
||||
*/
|
||||
void
|
||||
uuid_create(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
arc4random_buf(u, sizeof(uuid_t));
|
||||
|
||||
u->clock_seq_hi_and_reserved &= ~(1 << 6);
|
||||
u->clock_seq_hi_and_reserved |= (1 << 7);
|
||||
|
||||
u->time_hi_and_version &= ~(1 << 12);
|
||||
u->time_hi_and_version &= ~(1 << 13);
|
||||
u->time_hi_and_version |= (1 << 14);
|
||||
u->time_hi_and_version &= ~(1 << 15);
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
}
|
50
lib/libc/uuid/uuid_create_nil.c
Normal file
50
lib/libc/uuid/uuid_create_nil.c
Normal file
@ -0,0 +1,50 @@
|
||||
/* $OpenBSD: uuid_create_nil.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_create_nil.c,v 1.2 2005/02/09 21:35:47 kleink Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_create_nil.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_create_nil() - create a nil UUID.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_create_nil.htm
|
||||
*/
|
||||
void
|
||||
uuid_create_nil(uuid_t *u, uint32_t *status)
|
||||
{
|
||||
memset(u, 0, sizeof(*u));
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
}
|
59
lib/libc/uuid/uuid_equal.c
Normal file
59
lib/libc/uuid/uuid_equal.c
Normal file
@ -0,0 +1,59 @@
|
||||
/* $OpenBSD: uuid_equal.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_equal.c,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_equal.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_equal() - compare for equality.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_equal.htm
|
||||
*/
|
||||
int32_t
|
||||
uuid_equal(const uuid_t *a, const 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);
|
||||
}
|
97
lib/libc/uuid/uuid_from_string.c
Normal file
97
lib/libc/uuid/uuid_from_string.c
Normal file
@ -0,0 +1,97 @@
|
||||
/* $OpenBSD: uuid_from_string.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_from_string.c,v 1.1 2004/09/13 21:44:54 thorpej Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_from_string.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#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
|
||||
*
|
||||
* 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) != UUID_STR_LEN)
|
||||
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;
|
||||
}
|
||||
}
|
53
lib/libc/uuid/uuid_hash.c
Normal file
53
lib/libc/uuid/uuid_hash.c
Normal file
@ -0,0 +1,53 @@
|
||||
/* $OpenBSD: uuid_hash.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_hash.c,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_hash.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* uuid_hash() - generate a hash value.
|
||||
* See also:
|
||||
* http://www.opengroup.org/onlinepubs/009629399/uuid_hash.htm
|
||||
*/
|
||||
uint16_t
|
||||
uuid_hash(const 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 @@
|
||||
/* $OpenBSD: uuid_is_nil.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_is_nil.c,v 1.4 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_is_nil.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <string.h>
|
||||
#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
|
||||
*/
|
||||
int32_t
|
||||
uuid_is_nil(const uuid_t *u, uint32_t *status)
|
||||
{
|
||||
static const uuid_t nil = { .time_low = 0 };
|
||||
|
||||
if (status)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
if (!u)
|
||||
return (1);
|
||||
|
||||
return (memcmp(u, &nil, sizeof(uuid_t)) == 0 ? 1 : 0);
|
||||
}
|
114
lib/libc/uuid/uuid_stream.c
Normal file
114
lib/libc/uuid/uuid_stream.c
Normal file
@ -0,0 +1,114 @@
|
||||
/* $OpenBSD: uuid_stream.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_stream.c,v 1.3 2008/04/19 18:21:38 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002 Marcel Moolenaar
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <machine/endian.h>
|
||||
#include <uuid.h>
|
||||
|
||||
/*
|
||||
* Encode/Decode UUID into octet-stream.
|
||||
* http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt
|
||||
*
|
||||
* 0 1 2 3
|
||||
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | time_low |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | time_mid | time_hi_and_version |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* |clk_seq_hi_res | clk_seq_low | node (0-1) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
* | node (2-5) |
|
||||
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
||||
*
|
||||
* NOTE: These routines are not part of the DCE RPC API. There are
|
||||
* provided for convenience.
|
||||
*/
|
||||
|
||||
void
|
||||
uuid_enc_le(void *buf, const struct uuid *uuid)
|
||||
{
|
||||
uint8_t *p = buf;
|
||||
int i;
|
||||
|
||||
p[0] = htole32(uuid->time_low);
|
||||
p[4] = htole16(uuid->time_mid);
|
||||
p[6] = htole16(uuid->time_hi_and_version);
|
||||
p[8] = uuid->clock_seq_hi_and_reserved;
|
||||
p[9] = uuid->clock_seq_low;
|
||||
for (i = 0; i < _UUID_NODE_LEN; i++)
|
||||
p[10 + i] = uuid->node[i];
|
||||
}
|
||||
|
||||
void
|
||||
uuid_dec_le(void const *buf, struct uuid *uuid)
|
||||
{
|
||||
const uint8_t *p = buf;
|
||||
int i;
|
||||
|
||||
uuid->time_low = le32toh(*(uint32_t*)p);
|
||||
uuid->time_mid = le16toh(*(uint16_t*)(p + 4));
|
||||
uuid->time_hi_and_version = le16toh(*(uint16_t*)(p + 6));
|
||||
uuid->clock_seq_hi_and_reserved = p[8];
|
||||
uuid->clock_seq_low = p[9];
|
||||
for (i = 0; i < _UUID_NODE_LEN; i++)
|
||||
uuid->node[i] = p[10 + i];
|
||||
}
|
||||
|
||||
void
|
||||
uuid_enc_be(void *buf, const struct uuid *uuid)
|
||||
{
|
||||
uint8_t *p = buf;
|
||||
int i;
|
||||
|
||||
p[0] = htobe32(uuid->time_low);
|
||||
p[4] = htobe16(uuid->time_mid);
|
||||
p[6] = htobe16(uuid->time_hi_and_version);
|
||||
p[8] = uuid->clock_seq_hi_and_reserved;
|
||||
p[9] = uuid->clock_seq_low;
|
||||
for (i = 0; i < _UUID_NODE_LEN; i++)
|
||||
p[10 + i] = uuid->node[i];
|
||||
}
|
||||
|
||||
void
|
||||
uuid_dec_be(void const *buf, struct uuid *uuid)
|
||||
{
|
||||
const uint8_t *p = buf;
|
||||
int i;
|
||||
|
||||
uuid->time_low = be32toh(*(uint32_t*)p);
|
||||
uuid->time_mid = be16toh(*(uint16_t*)(p + 4));
|
||||
uuid->time_hi_and_version = be16toh(*(uint16_t*)(p + 6));
|
||||
uuid->clock_seq_hi_and_reserved = p[8];
|
||||
uuid->clock_seq_low = p[9];
|
||||
for (i = 0; i < _UUID_NODE_LEN; i++)
|
||||
uuid->node[i] = p[10 + i];
|
||||
}
|
71
lib/libc/uuid/uuid_to_string.c
Normal file
71
lib/libc/uuid/uuid_to_string.c
Normal file
@ -0,0 +1,71 @@
|
||||
/* $OpenBSD: uuid_to_string.c,v 1.1 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid_to_string.c,v 1.2 2008/04/23 07:52:32 plunky Exp $ */
|
||||
|
||||
/*
|
||||
* 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: src/lib/libc/uuid/uuid_to_string.c,v 1.2 2003/08/08 19:18:43 marcel Exp $
|
||||
*/
|
||||
|
||||
#include "namespace.h"
|
||||
|
||||
#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
|
||||
*
|
||||
* 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(const uuid_t *u, char **s, uint32_t *status)
|
||||
{
|
||||
int c;
|
||||
static const uuid_t nil = { .time_low = 0 };
|
||||
|
||||
if (status != NULL)
|
||||
*status = uuid_s_ok;
|
||||
|
||||
/* Why allow a NULL-pointer here? */
|
||||
if (s == NULL)
|
||||
return;
|
||||
|
||||
if (u == NULL)
|
||||
u = &nil;
|
||||
|
||||
c = 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 (c == -1 && status != NULL)
|
||||
*status = uuid_s_no_memory;
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: uuid.h,v 1.2 2014/07/15 23:10:27 miod Exp $ */
|
||||
/* $OpenBSD: uuid.h,v 1.3 2014/08/31 09:36:39 miod Exp $ */
|
||||
/* $NetBSD: uuid.h,v 1.5 2008/11/18 14:01:03 joerg Exp $ */
|
||||
|
||||
/*
|
||||
@ -68,7 +68,7 @@ void uuid_enc_le(void *, const struct uuid *);
|
||||
|
||||
#else /* _KERNEL */
|
||||
|
||||
/* typedef struct uuid uuid_t; */
|
||||
typedef struct uuid uuid_t;
|
||||
|
||||
#endif /* _KERNEL */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user