MGE General C Library - Full Internal Documentation  v1.3.5
Library of general C functions.
sllist.c File Reference

Builds, traverses and releases a singly linked list. More...

#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sllist-internal.h"
#include <mge-errno.h>
#include <sllist.h>
Include dependency graph for sllist.c:

Functions

struct sllistnodeadd_head_sll_node (struct sllistnode *head, const void *object, size_t objsize)
 Add a node to the start of the singly linked list. More...
 
struct sllistnodeadd_tail_sll_node (struct sllistnode *head, const void *object, size_t objsize)
 Add a node to the tail of the singly linked list. More...
 
void * find_sll_node (struct sllistnode *head, const void *searchobj, int(*comp)(const void *, const void *))
 Find a node. More...
 
struct sllistnodefree_sllist (struct sllistnode *head)
 Free the entire list. More...
 
static void free_sll_node (struct sllistnode *focus)
 Free memory allocated to the node. More...
 

Detailed Description

Builds, traverses and releases a singly linked list.

Build, manipulate and traverse functionality for singly linked lists.

Author
Copyright (C) 2016-2020 Mark Grant

Released under the GPLv3 only.
SPDX-License-Identifier: GPL-3.0

Version
v1.0.11 ==== 29/06/2020

Function Documentation

◆ add_head_sll_node()

struct sllistnode* add_head_sll_node ( struct sllistnode head,
const void *  object,
size_t  objsize 
)

Add a node to the start of the singly linked list.

On error mge_errno will be set.

Parameters
headA pointer to the current root node or NULL if the list is not yet started.
objectThe object to attach to the node.
objsizeThe size of the attached object.
Returns
head, a pointer to the new root node or NULL on error

◆ add_tail_sll_node()

struct sllistnode* add_tail_sll_node ( struct sllistnode head,
const void *  object,
size_t  objsize 
)

Add a node to the tail of the singly linked list.

On error mge_errno will be set.

Parameters
headA pointer to the root node or NULL if the list is not yet started.
objectThe object to attach to the node.
objsizeThe size of the attached object.
Returns
head, a pointer to the root node or NULL on error

◆ find_sll_node()

void* find_sll_node ( struct sllistnode head,
const void *  searchobj,
int(*)(const void *, const void *)  comp 
)

Find a node.

On error mge_errno will be set, otherwise it will be 0.

Parameters
headA pointer to the current root node.
searchobjThe object to find. It does not need to be a fully populated object. It only needs enough inforamtion to support the comparison function, eg a key.
compA pointer to the comparison function to be used. This must have the same shape as strcmp.
Returns
A pointer to the object found, (the fully populated object), or NULL if not found or an error was encountered.

◆ free_sll_node()

static void free_sll_node ( struct sllistnode focus)
static

Free memory allocated to the node.

(Both node and object).

Parameters
focusThe node to free.

◆ free_sllist()

struct sllistnode* free_sllist ( struct sllistnode head)

Free the entire list.

Walks the list deleting nodes.

Parameters
headThe root node.
Returns
NULL