diff --git a/lib/libc/uuid/uuid_compare.c b/lib/libc/uuid/uuid_compare.c index 3ff0cdb99d20..9d1c3c606a5f 100644 --- a/lib/libc/uuid/uuid_compare.c +++ b/lib/libc/uuid/uuid_compare.c @@ -1,79 +1,78 @@ /*- * 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. * 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); res = memcmp(a->node, b->node, sizeof(a->node)); if (res) return ((res < 0) ? -1 : 1); return (0); } diff --git a/lib/libc/uuid/uuid_create.c b/lib/libc/uuid/uuid_create.c index a202e1a5d9a2..da3f1d39f78d 100644 --- a/lib/libc/uuid/uuid_create.c +++ b/lib/libc/uuid/uuid_create.c @@ -1,46 +1,45 @@ /*- * 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. * 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); } diff --git a/lib/libc/uuid/uuid_create_nil.c b/lib/libc/uuid/uuid_create_nil.c index f2a69ff1a2b6..6e85ae7fb768 100644 --- a/lib/libc/uuid/uuid_create_nil.c +++ b/lib/libc/uuid/uuid_create_nil.c @@ -1,47 +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 #include /* * 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)); } diff --git a/lib/libc/uuid/uuid_equal.c b/lib/libc/uuid/uuid_equal.c index 4d36b304c505..1f6328cd149e 100644 --- a/lib/libc/uuid/uuid_equal.c +++ b/lib/libc/uuid/uuid_equal.c @@ -1,56 +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 #include /* * 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); } diff --git a/lib/libc/uuid/uuid_from_string.c b/lib/libc/uuid/uuid_from_string.c index 322a4ed8cbd5..b09a04df875d 100644 --- a/lib/libc/uuid/uuid_from_string.c +++ b/lib/libc/uuid/uuid_from_string.c @@ -1,93 +1,92 @@ /*- * 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. * 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; } } diff --git a/lib/libc/uuid/uuid_hash.c b/lib/libc/uuid/uuid_hash.c index fade9ecd4a4f..4753a12756da 100644 --- a/lib/libc/uuid/uuid_hash.c +++ b/lib/libc/uuid/uuid_hash.c @@ -1,50 +1,49 @@ /*- * 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. * 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); } diff --git a/lib/libc/uuid/uuid_is_nil.c b/lib/libc/uuid/uuid_is_nil.c index eef235708238..d397f7a0a3cd 100644 --- a/lib/libc/uuid/uuid_is_nil.c +++ b/lib/libc/uuid/uuid_is_nil.c @@ -1,55 +1,54 @@ /*- * 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. * 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); } diff --git a/lib/libc/uuid/uuid_to_string.c b/lib/libc/uuid/uuid_to_string.c index fa2b8c227413..16bda3ac0ecf 100644 --- a/lib/libc/uuid/uuid_to_string.c +++ b/lib/libc/uuid/uuid_to_string.c @@ -1,68 +1,67 @@ /*- * 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. * 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; }