diff -cN /var/empty/Makefile.inc src/lib/libc/uuid/Makefile.inc *** /var/empty/Makefile.inc Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/Makefile.inc Fri Oct 25 19:59:19 2002 *************** *** 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 diff -cN /var/empty/uuid.3 src/lib/libc/uuid/uuid.3 *** /var/empty/uuid.3 Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid.3 Sat Oct 19 21:31:10 2002 *************** *** 0 **** --- 1,227 ---- + .\" Copyright (c) 2002 Hiten Pandya (hiten@uk.FreeBSD.org) + .\" 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 July 11, 2002 + .Dt UUID 3 + .Os + .Sh NAME + .Nm uuid + .Nd Universally Unique Identifiers (UUIDs) + .Sh SYNOPSIS + .In sys/types.h + .In uuid.h + .Ft void + .Fn uuid_unparse "struct uuid *uuid" "char *str" + .Ft void + .Fn uuid_print "struct uuid *uuid" + .Ft void + .Fn uuid_clear "struct uuid *uuid" + .Ft int + .Fn uuid_compare "struct uuid *a" "struct uuid *b" "uint32_t *status" + .Ft int + .Fn uuid_create "struct uuid *store" "int count" "uint32_t *status" + .Ft int + .Fn uuid_equal "struct uuid *a" "struct uuid *b" "uint32_t *status" + .Ft int + .Fn uuid_isnull "struct uuid *uuid" "uint32_t *status" + .Ft int + .Fn uuid_parse "char *str" "struct uuid *uuid" "uint32_t *status" + .Sh DESCRIPTION + Universally Unique Identifiers (UUID) are 128 bit values that may be + generated independently on seperate nodes (hosts), which, result in + globally unique strings without requiring the hosts to be in communication + with each other + to ensure uniqueness. + UUIDs are also known as Globaly Unique Identifiers (GUIDs). + .Pp + The mechanism used to guarantee that UUIDs are unique is through a combination + of hardware addresses, time stamps and random seeds. + There is a reference in the UUID to the MAC address of the first + Network Interface Card (NIC) on the node which generated the UUID. + This ensures the uniqueness, as MAC address of every NIC is assigned by a + single + .Qu global + authority. + .Pp + When an IEE 802 address is unavailable, a random multicast address is used. + Please refer to + .Xr uuidgen 2 , + for more information on the semantics. + .Pp + UUIDs are a part of the DCE specification. + They have been reimplemented in FreeBSD, but in accordance to the DCE + specification. + A UUID is represented by the + .Nm + data structure (DCE 1.1 compatible). + .Bd -literal + struct uuid { + uint32_t time_low; + uint16_t time_mid; + uint16_t time_hi_and_version; + uint8_t clock_seq_hi_and_reserved; + uint8_t clock_seq_low; + uint8_t node[_UUID_NODE_LEN]; + }; + + typedef struct uuid uuid_t; + .Ed + .Pp + The size of the + .Sy UUID + data structure is 16 octets (128 bits), and does not contain padding + between the fields. + All fields in the UUID data structure are unsigned types. + .Em time_low + is the low field of the timestamp, + .Em time_mid + is the middle field of the timestamp, + .Em time_hi_and_reserved + is the high field of the timestamp multiplexed with the version number, + .Em clock_seq_hi_and_reserved + is the high field of the clock sequence multiplexed with the variant, + .Em clock_seq_low + is the low field of the clock sequence + and + .Em node + is the spatially unique node identifier. Refer to the DCE specification + for more information about the fields in the UUID data stucture. + .Pp + Special subroutines exist for manipulating the UUID data structure. Most + store their return values in a + .Em status + parameter, which is a pointer to a 32 bit unsigned storage type. + .Pp + .Nm uuid_unparse + is used for converting the internal binary representation + of a UUID pointed by + .Em uuid + into a 36-byte string, which is stored into + .Em str . + .Pp + .Nm uuid_print + is used, for printing a UUID, pointed by + .Em uuid . + .Pp + .Nm uuid_clear + is used to reset the pointed structure, + .Em uuid . + This struct can than be used to reset other UUIDs. + Nothing is returned. + .Pp + .Nm uuid_compare + compares + .Em a + with + .Em b + and stores the return value in + .Em status . + The + .Em status + parameter will contain -1 if + .Em a + preceeds + .Em b , + 0 if + .Em a + is equal to + .Em b + and 1 if + .Em a + follows + .Em b . + .Pp + .Nm uuid_create + generates + .Em count + UUIDs and stores the return values in + .Em status . + The return value will be 0 upon successful completion, otherwise -1 is + returned and the global variable + .Em errno + is set to indicate the error. This function uses the + .Xr uuidgen 2 + system call for generating the UUIDs. + .Pp + .Nm uuid_equal + checks + .Em a + and + .Em b + for equality, and stores the return value in + .Em status . + The value 0 is stored and returned upon successful completion, otherwise a + non-zero value is stored and returned. + .Pp + .Nm uuid_isnull + is used to check if + .Em uuid + is nil, and store the return value in + .Em status . + The value 1 is returned if + .Em uuid + is null + and 0 if + .Em uuid + is not null. + .Pp + .Nm uuid_parse + can be used for converting a human readable UUID format (36-byte string) + located at + .Em str , + into an internal representation, which is then stored into + .Em uuid . + Upon suc + .Sh RETURN VALUES + Upon sucessfull completion, 0 is returned, and -1 on error. + This is different for the + .Nm uuid_compare + routine. + Please check the respective section for more information. + .Sh CONFORMS TO + .Pp + DCE 1.1 Specification. + .Sh SEE ALSO + .Xr uuidgen 2 , + .Xr uuidgen 1 + .Pp + Alternatively, please check the following World Wide Web addresses for + more information about Universally Unique Identifiers (UUIDs): + .Pp + http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + http://www.opengroup.org/onlinepubs/009629399/apdxa.html + http://www.dsps.net/uuid.html + .Sh AUTHORS + The + .Nm + library is written by Hiten Pandya and Marcel Moolenaar. + .Sh BUGS + .Pp + There are no known bugs in this implementation of UUIDs for + .Fx . + If you discover a bug, please submit a PR. + .Pp + Alternativally email Hiten Pandya or Marcel Moolenaar. diff -cN /var/empty/uuid.h src/lib/libc/uuid/uuid.h *** /var/empty/uuid.h Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid.h Fri Oct 25 19:49:40 2002 *************** *** 0 **** --- 1,58 ---- + /*- + * 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 + #include + + /* + * This implementation mostly conforms to the DCE 1.1 specification. + * + * See Also: + * http://www.opengroup.org/dce/info/draft-leach-uuids-guids-01.txt + * http://www.opengroup.org/onlinepubs/009629399/apdxa.htm + */ + + /* Status codes returned by the functions. */ + #define uuid_s_ok 0 + #define uuid_s_bad_version 1 + #define uuid_s_invalid_string_uuid 2 + + 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 *, const char **, uint32_t *); + + #endif /* _UUID_H_ */ diff -cN /var/empty/uuid_compare.c src/lib/libc/uuid/uuid_compare.c *** /var/empty/uuid_compare.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_compare.c Fri Oct 25 19:45:08 2002 *************** *** 0 **** --- 1,77 ---- + /*- + * 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 + #include + + /* + * uuid_compare() - compare two UUIDs + * Return values: + * -1 UUID a is smaller than UUID b. + * 0 UUID a is equal to UUID b. + * 1 UUID a is larger than UUID b. + * + * 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))); + } diff -cN /var/empty/uuid_create.c src/lib/libc/uuid/uuid_create.c *** /var/empty/uuid_create.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_create.c Fri Oct 25 19:45:15 2002 *************** *** 0 **** --- 1,43 ---- + /*- + * 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_create() - create an UUID + */ + void + uuid_create(uuid_t *u, uint32_t *status) + { + + if (status) + *status = uuid_s_ok; + + uuidgen(u, 1); + } diff -cN /var/empty/uuid_create_nil.c src/lib/libc/uuid/uuid_create_nil.c *** /var/empty/uuid_create_nil.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_create_nil.c Fri Oct 25 19:45:21 2002 *************** *** 0 **** --- 1,44 ---- + /*- + * 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 + #include + + /* + * uuid_create_nil() - create a nil UUID + */ + void + uuid_create_nil(uuid_t *u, uint32_t *status) + { + + if (status) + *status = uuid_s_ok; + + bzero(u, sizeof(*u)); + } diff -cN /var/empty/uuid_equal.c src/lib/libc/uuid/uuid_equal.c *** /var/empty/uuid_equal.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_equal.c Fri Oct 25 19:45:28 2002 *************** *** 0 **** --- 1,53 ---- + /*- + * 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 + #include + + /* + * uuid_equal() - compare for equality + */ + int + 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); + } diff -cN /var/empty/uuid_from_string.c src/lib/libc/uuid/uuid_from_string.c *** /var/empty/uuid_from_string.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_from_string.c Fri Oct 25 19:44:43 2002 *************** *** 0 **** --- 1,89 ---- + /*- + * 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 + #include + #include + + /* + * uuid_from_string() - convert a string representation of an UUID into + * a binary representation. + * Note that 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; + } + } diff -cN /var/empty/uuid_hash.c src/lib/libc/uuid/uuid_hash.c *** /var/empty/uuid_hash.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_hash.c Fri Oct 25 19:47:36 2002 *************** *** 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 + + /* + * uuid_hash() - generate a hash value + */ + 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->time_low & 0xffff); + } diff -cN /var/empty/uuid_is_nil.c src/lib/libc/uuid/uuid_is_nil.c *** /var/empty/uuid_is_nil.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_is_nil.c Fri Oct 25 19:48:20 2002 *************** *** 0 **** --- 1,52 ---- + /*- + * 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_is_nil() - return whether the UUID is a nil UUID + */ + 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); + } diff -cN /var/empty/uuid_to_string.c src/lib/libc/uuid/uuid_to_string.c *** /var/empty/uuid_to_string.c Wed Dec 31 16:00:00 1969 --- src/lib/libc/uuid/uuid_to_string.c Fri Oct 25 19:49:13 2002 *************** *** 0 **** --- 1,52 ---- + /*- + * 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 + #include + #include + + /* + * uuid_to_string() - Convert a binary UUID into a string representation + * NOTE: This function will return the string in an allocated buffer. + * The caller is responsible to free the memory. + */ + void + uuid_to_string(uuid_t *u, const char **s, uint32_t *status) + { + char buf[40]; + + if (status != NULL) + *status = uuid_s_ok; + + sprintf(buf, "%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]); + *s = strdup(buf); + }