Blame


1 db83f7cf 2023-02-26 thomas /*
2 db83f7cf 2023-02-26 thomas * Copyright (c) 2002,2005 Marcel Moolenaar
3 db83f7cf 2023-02-26 thomas * Copyright (c) 2002 Hiten Mahesh Pandya
4 db83f7cf 2023-02-26 thomas * All rights reserved.
5 db83f7cf 2023-02-26 thomas *
6 db83f7cf 2023-02-26 thomas * Redistribution and use in source and binary forms, with or without
7 db83f7cf 2023-02-26 thomas * modification, are permitted provided that the following conditions
8 db83f7cf 2023-02-26 thomas * are met:
9 db83f7cf 2023-02-26 thomas * 1. Redistributions of source code must retain the above copyright
10 db83f7cf 2023-02-26 thomas * notice, this list of conditions and the following disclaimer.
11 db83f7cf 2023-02-26 thomas * 2. Redistributions in binary form must reproduce the above copyright
12 db83f7cf 2023-02-26 thomas * notice, this list of conditions and the following disclaimer in the
13 db83f7cf 2023-02-26 thomas * documentation and/or other materials provided with the distribution.
14 db83f7cf 2023-02-26 thomas *
15 db83f7cf 2023-02-26 thomas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 db83f7cf 2023-02-26 thomas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 db83f7cf 2023-02-26 thomas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 db83f7cf 2023-02-26 thomas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 db83f7cf 2023-02-26 thomas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 db83f7cf 2023-02-26 thomas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 db83f7cf 2023-02-26 thomas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 db83f7cf 2023-02-26 thomas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 db83f7cf 2023-02-26 thomas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 db83f7cf 2023-02-26 thomas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 db83f7cf 2023-02-26 thomas * SUCH DAMAGE.
26 db83f7cf 2023-02-26 thomas */
27 db83f7cf 2023-02-26 thomas
28 dd038bc6 2021-09-21 thomas.ad #include <stdlib.h>
29 dd038bc6 2021-09-21 thomas.ad #include <string.h>
30 dd038bc6 2021-09-21 thomas.ad #include <stdint.h>
31 dd038bc6 2021-09-21 thomas.ad #include <uuid/uuid.h>
32 dd038bc6 2021-09-21 thomas.ad
33 dd038bc6 2021-09-21 thomas.ad #include "got_compat.h"
34 dd038bc6 2021-09-21 thomas.ad
35 dd038bc6 2021-09-21 thomas.ad
36 dd038bc6 2021-09-21 thomas.ad int32_t uuid_equal(struct uuid* a, struct uuid* b, uint32_t* unused)
37 dd038bc6 2021-09-21 thomas.ad {
38 dd038bc6 2021-09-21 thomas.ad return (uuid_compare(*(uuid_t *)a, *(uuid_t *)b) == 0);
39 dd038bc6 2021-09-21 thomas.ad }
40 dd038bc6 2021-09-21 thomas.ad int32_t uuid_is_nil(struct uuid* uuid, uint32_t* unused)
41 dd038bc6 2021-09-21 thomas.ad {
42 dd038bc6 2021-09-21 thomas.ad return uuid_is_null(*(uuid_t *)uuid);
43 dd038bc6 2021-09-21 thomas.ad }
44 dd038bc6 2021-09-21 thomas.ad void uuid_create(uuid_t *uuid, uint32_t* status)
45 dd038bc6 2021-09-21 thomas.ad {
46 dd038bc6 2021-09-21 thomas.ad *status = uuid_s_ok;
47 dd038bc6 2021-09-21 thomas.ad return uuid_generate(*(uuid_t *)uuid);
48 dd038bc6 2021-09-21 thomas.ad }
49 dd038bc6 2021-09-21 thomas.ad void uuid_create_nil(struct uuid* uuid, uint32_t* unused)
50 dd038bc6 2021-09-21 thomas.ad {
51 dd038bc6 2021-09-21 thomas.ad return uuid_clear(*(uuid_t *)uuid);
52 dd038bc6 2021-09-21 thomas.ad }
53 dd038bc6 2021-09-21 thomas.ad void uuid_from_string(const char* s, uuid_t *uuid, uint32_t *status)
54 dd038bc6 2021-09-21 thomas.ad {
55 dd038bc6 2021-09-21 thomas.ad *status = uuid_parse(s, *(uuid_t *)uuid);
56 dd038bc6 2021-09-21 thomas.ad }
57 dd038bc6 2021-09-21 thomas.ad void uuid_to_string(uuid_t *uuid, char** s, uint32_t *status)
58 dd038bc6 2021-09-21 thomas.ad {
59 dd038bc6 2021-09-21 thomas.ad *s = malloc(36 + 1); /* 36 byte uuid plus '\0' */
60 dd038bc6 2021-09-21 thomas.ad if (*s == NULL) {
61 dd038bc6 2021-09-21 thomas.ad fprintf(stderr, "uuid_to_string: fatal: malloc\n");
62 dd038bc6 2021-09-21 thomas.ad exit (1);
63 dd038bc6 2021-09-21 thomas.ad }
64 dd038bc6 2021-09-21 thomas.ad uuid_unparse(*(uuid_t *)uuid, *s);
65 dd038bc6 2021-09-21 thomas.ad *status = uuid_s_ok;
66 dd038bc6 2021-09-21 thomas.ad }