1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
|
/* SPDX-FileCopyrightText: 2009-2023 Greenbone AG
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
/**
* @file
* @brief UUID creation.
*/
#include "uuidutils.h"
#include <glib.h>
#include <stdlib.h>
#include <uuid/uuid.h>
#undef G_LOG_DOMAIN
/**
* @brief GLib logging domain.
*/
#define G_LOG_DOMAIN "libgvm util"
/**
* @brief Make a new universal identifier.
*
* @return A newly allocated string holding the identifier, which the
* caller must free, or NULL on failure.
*/
char *
gvm_uuid_make (void)
{
char *id;
uuid_t uuid;
/* Generate an UUID. */
uuid_generate (uuid);
if (uuid_is_null (uuid) == 1)
{
g_warning ("%s: failed to generate UUID", __func__);
return NULL;
}
/* Allocate mem for string to hold UUID. */
id = g_malloc0 (sizeof (char) * 37);
if (id == NULL)
{
g_warning ("%s: Cannot export UUID to text: out of memory", __func__);
return NULL;
}
/* Export the UUID to text. */
uuid_unparse (uuid, id);
return id;
}
|