Implement UUID generation in addPersonToList and ensure uniqueness across existing nodes
This commit is contained in:
+27
-2
@@ -9,11 +9,35 @@
|
||||
#include <termios.h>
|
||||
#include <string.h>
|
||||
|
||||
int addPersonToList(
|
||||
uint16_t generateUUID
|
||||
(
|
||||
node_t *_head
|
||||
)
|
||||
{
|
||||
uint16_t uuid = rand() % (UINT16_MAX - 1 + 1) + 1;
|
||||
node_t *current = _head;
|
||||
while (current != NULL)
|
||||
{
|
||||
if (current->user.uuid == uuid)
|
||||
{
|
||||
uuid = rand() % (UINT16_MAX - 1 + 1) + 1;
|
||||
current = _head;
|
||||
}
|
||||
else
|
||||
{
|
||||
current = current->next;
|
||||
}
|
||||
}
|
||||
return uuid;
|
||||
}
|
||||
|
||||
int addPersonToList
|
||||
(
|
||||
node_t **_head,
|
||||
char *_name,
|
||||
char *_surname,
|
||||
uint32_t _department)
|
||||
uint32_t _department
|
||||
)
|
||||
{
|
||||
node_t *new_node = (node_t *)malloc(sizeof(node_t));
|
||||
if (new_node == NULL)
|
||||
@@ -26,6 +50,7 @@ int addPersonToList(
|
||||
return 0;
|
||||
}
|
||||
|
||||
new_node->user.uuid = generateUUID(*_head);
|
||||
new_node->user.name = (char *)malloc(strlen(_name) + 1);
|
||||
new_node->user.surname = (char *)malloc(strlen(_surname) + 1);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user