2020-10-20 21:30:59 +00:00
|
|
|
.\" Copyright (c) 1993
|
|
|
|
.\" The Regents of the University of California. All rights reserved.
|
|
|
|
.\" and Copyright (c) 2020 by Alejandro Colomar <colomar.6.4.3@gmail.com>
|
|
|
|
.\"
|
|
|
|
.\" %%%LICENSE_START(BSD_3_CLAUSE_UCB)
|
|
|
|
.\" 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.
|
|
|
|
.\" 3. Neither the name of the University nor the names of its contributors
|
|
|
|
.\" may be used to endorse or promote products derived from this software
|
|
|
|
.\" without specific prior written permission.
|
|
|
|
.\"
|
|
|
|
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
|
|
|
|
.\" %%%LICENSE_END
|
|
|
|
.\"
|
|
|
|
.\"
|
getent.1, access.2, cacheflush.2, chroot.2, clock_getres.2, fcntl.2, getrusage.2, io_cancel.2, io_destroy.2, io_getevents.2, io_setup.2, io_submit.2, link.2, llseek.2, mmap.2, mount.2, readv.2, restart_syscall.2, semctl.2, set_mempolicy.2, set_tid_address.2, shmctl.2, sigaction.2, sigaltstack.2, spu_create.2, statfs.2, subpage_prot.2, syscalls.2, timer_getoverrun.2, uselib.2, INFINITY.3, __ppc_set_ppr_med.3, bstring.3, btree.3, ctime.3, fgetc.3, fopen.3, getcontext.3, gethostbyname.3, getnetent.3, getprotoent.3, getservent.3, inet.3, j0.3, list.3, makecontext.3, nextafter.3, posix_memalign.3, profil.3, pthread_tryjoin_np.3, puts.3, rcmd.3, resolver.3, rtime.3, sigsetops.3, strnlen.3, tailq.3, elf.5, filesystems.5, nscd.conf.5, proc.5, utmp.5, attributes.7, ipv6.7, packet.7, pthreads.7, signal-safety.7, signal.7, spufs.7, system_data_types.7, tcp.7: tstamp
Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
2020-12-21 15:19:35 +00:00
|
|
|
.TH LIST 3 2020-12-21 "GNU" "Linux Programmer's Manual"
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH NAME
|
2020-10-20 21:31:05 +00:00
|
|
|
LIST_EMPTY,
|
|
|
|
LIST_ENTRY,
|
|
|
|
LIST_FIRST,
|
|
|
|
LIST_FOREACH,
|
|
|
|
.\"LIST_FOREACH_FROM,
|
|
|
|
.\"LIST_FOREACH_SAFE,
|
|
|
|
.\"LIST_FOREACH_FROM_SAFE,
|
|
|
|
LIST_HEAD,
|
|
|
|
LIST_HEAD_INITIALIZER,
|
|
|
|
LIST_INIT,
|
|
|
|
LIST_INSERT_AFTER,
|
|
|
|
LIST_INSERT_BEFORE,
|
|
|
|
LIST_INSERT_HEAD,
|
|
|
|
LIST_NEXT,
|
2020-11-16 06:53:47 +00:00
|
|
|
.\"LIST_PREV,
|
2020-10-20 21:31:05 +00:00
|
|
|
LIST_REMOVE
|
|
|
|
.\"LIST_SWAP
|
2020-10-25 11:23:43 +00:00
|
|
|
\- implementation of a doubly linked list
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH SYNOPSIS
|
2020-10-20 21:31:05 +00:00
|
|
|
.nf
|
|
|
|
.B #include <sys/queue.h>
|
|
|
|
.PP
|
|
|
|
.B LIST_ENTRY(TYPE);
|
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.B LIST_HEAD(HEADNAME, TYPE);
|
|
|
|
.BI "LIST_HEAD LIST_HEAD_INITIALIZER(LIST_HEAD " head );
|
|
|
|
.BI "void LIST_INIT(LIST_HEAD *" head );
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BI "int LIST_EMPTY(LIST_HEAD *" head );
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BI "void LIST_INSERT_HEAD(LIST_HEAD *" head ,
|
|
|
|
.BI " struct TYPE *" elm ", LIST_ENTRY " NAME );
|
|
|
|
.BI "void LIST_INSERT_BEFORE(struct TYPE *" listelm ,
|
|
|
|
.BI " struct TYPE *" elm ", LIST_ENTRY " NAME );
|
|
|
|
.BI "void LIST_INSERT_AFTER(struct TYPE *" listelm ,
|
|
|
|
.BI " struct TYPE *" elm ", LIST_ENTRY " NAME );
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BI "struct TYPE *LIST_FIRST(LIST_HEAD *" head );
|
|
|
|
.\" .BI "struct TYPE *LIST_PREV(struct TYPE *" elm ", LIST_HEAD *" head ,
|
|
|
|
.\" .BI " struct TYPE, LIST_ENTRY " NAME );
|
|
|
|
.BI "struct TYPE *LIST_NEXT(struct TYPE *" elm ", LIST_ENTRY " NAME );
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BI "LIST_FOREACH(struct TYPE *" var ", LIST_HEAD *" head ", LIST_ENTRY " NAME );
|
|
|
|
.\" .BI "LIST_FOREACH_FROM(struct TYPE *" var ", LIST_HEAD *" head ", LIST_ENTRY " NAME );
|
|
|
|
.\" .PP
|
|
|
|
.\" .BI "LIST_FOREACH_SAFE(struct TYPE *" var ", LIST_HEAD *" head ,
|
|
|
|
.\" .BI " LIST_ENTRY " NAME ", struct TYPE *" temp_var );
|
|
|
|
.\" .BI "LIST_FOREACH_FROM_SAFE(struct TYPE *" var ", LIST_HEAD *" head ,
|
|
|
|
.\" .BI " LIST_ENTRY " NAME ", struct TYPE *" temp_var );
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BI "void LIST_REMOVE(struct TYPE *" elm ", LIST_ENTRY " NAME );
|
|
|
|
.\" .PP
|
|
|
|
.\" .BI "void LIST_SWAP(LIST_HEAD *" head1 ", LIST_HEAD *" head2 ,
|
|
|
|
.\" .BI " struct TYPE, LIST_ENTRY " NAME );
|
2020-10-20 21:31:05 +00:00
|
|
|
.fi
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH DESCRIPTION
|
2020-10-25 11:23:43 +00:00
|
|
|
These macros define and operate on doubly linked lists.
|
2020-10-20 21:31:06 +00:00
|
|
|
.PP
|
2020-10-20 21:31:04 +00:00
|
|
|
In the macro definitions,
|
2020-10-20 21:31:05 +00:00
|
|
|
.I TYPE
|
2020-10-21 04:48:45 +00:00
|
|
|
is the name of a user-defined structure,
|
2020-10-20 21:31:04 +00:00
|
|
|
that must contain a field of type
|
2020-10-20 21:31:05 +00:00
|
|
|
.IR LIST_ENTRY ,
|
2020-10-20 21:31:04 +00:00
|
|
|
named
|
2020-10-20 21:31:05 +00:00
|
|
|
.IR NAME .
|
2020-10-20 21:31:04 +00:00
|
|
|
The argument
|
2020-10-20 21:31:05 +00:00
|
|
|
.IR HEADNAME
|
2021-01-05 22:39:57 +00:00
|
|
|
is the name of a user-defined structure
|
|
|
|
that must be declared using the macro
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_HEAD ().
|
2021-01-05 22:39:57 +00:00
|
|
|
.SS Creation
|
2020-10-20 21:31:02 +00:00
|
|
|
A list is headed by a structure defined by the
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_HEAD ()
|
2020-10-20 21:31:02 +00:00
|
|
|
macro.
|
2021-01-05 22:39:57 +00:00
|
|
|
This structure contains a single pointer to the first element on the list.
|
|
|
|
The elements are doubly linked
|
|
|
|
so that an arbitrary element can be removed without traversing the list.
|
|
|
|
New elements can be added to the list
|
|
|
|
after an existing element,
|
|
|
|
before an existing element,
|
|
|
|
or at the head of the list.
|
2020-10-20 21:31:02 +00:00
|
|
|
A
|
2020-10-20 21:31:05 +00:00
|
|
|
.I LIST_HEAD
|
2020-10-20 21:31:02 +00:00
|
|
|
structure is declared as follows:
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
|
|
|
.in +4
|
|
|
|
.EX
|
2020-10-20 21:31:02 +00:00
|
|
|
LIST_HEAD(HEADNAME, TYPE) head;
|
2020-10-20 21:31:05 +00:00
|
|
|
.EE
|
|
|
|
.in
|
|
|
|
.PP
|
2020-10-20 21:31:02 +00:00
|
|
|
where
|
2020-10-25 10:46:24 +00:00
|
|
|
.I struct HEADNAME
|
|
|
|
is the structure to be defined, and
|
|
|
|
.I struct TYPE
|
2020-10-20 21:31:02 +00:00
|
|
|
is the type of the elements to be linked into the list.
|
|
|
|
A pointer to the head of the list can later be declared as:
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
|
|
|
.in +4
|
|
|
|
.EX
|
2020-10-20 21:31:02 +00:00
|
|
|
struct HEADNAME *headp;
|
2020-10-20 21:31:05 +00:00
|
|
|
.EE
|
|
|
|
.in
|
|
|
|
.PP
|
2020-10-20 21:31:02 +00:00
|
|
|
(The names
|
2020-10-20 21:31:05 +00:00
|
|
|
.I head
|
2020-10-20 21:31:02 +00:00
|
|
|
and
|
2020-10-20 21:31:05 +00:00
|
|
|
.I headp
|
2020-10-20 21:31:02 +00:00
|
|
|
are user selectable.)
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BR LIST_ENTRY ()
|
|
|
|
declares a structure that connects the elements in the list.
|
|
|
|
.PP
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_HEAD_INITIALIZER ()
|
2020-10-20 21:31:02 +00:00
|
|
|
evaluates to an initializer for the list
|
2020-10-20 21:31:05 +00:00
|
|
|
.IR head .
|
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BR LIST_INIT ()
|
|
|
|
initializes the list referenced by
|
|
|
|
.IR head .
|
|
|
|
.PP
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_EMPTY ()
|
2020-10-20 21:31:02 +00:00
|
|
|
evaluates to true if there are no elements in the list.
|
2021-01-05 22:39:57 +00:00
|
|
|
.SS Insertion
|
|
|
|
.BR LIST_INSERT_HEAD ()
|
|
|
|
inserts the new element
|
|
|
|
.I elm
|
|
|
|
at the head of the list.
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BR LIST_INSERT_BEFORE ()
|
|
|
|
inserts the new element
|
|
|
|
.I elm
|
|
|
|
before the element
|
|
|
|
.IR listelm .
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
2021-01-05 22:39:57 +00:00
|
|
|
.BR LIST_INSERT_AFTER ()
|
|
|
|
inserts the new element
|
|
|
|
.I elm
|
|
|
|
after the element
|
|
|
|
.IR listelm .
|
|
|
|
.SS Traversal
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_FIRST ()
|
2021-01-05 22:39:57 +00:00
|
|
|
returns the first element in the list, or NULL if the list is empty.
|
|
|
|
.\" .PP
|
|
|
|
.\" .BR LIST_PREV ()
|
|
|
|
.\" returns the previous element in the list, or NULL if this is the first.
|
|
|
|
.\" List
|
|
|
|
.\" .I head
|
|
|
|
.\" must contain element
|
|
|
|
.\" .IR elm .
|
|
|
|
.PP
|
|
|
|
.BR LIST_NEXT ()
|
|
|
|
returns the next element in the list, or NULL if this is the last.
|
2020-10-20 21:31:05 +00:00
|
|
|
.PP
|
|
|
|
.BR LIST_FOREACH ()
|
2020-10-20 21:31:02 +00:00
|
|
|
traverses the list referenced by
|
2020-10-20 21:31:05 +00:00
|
|
|
.I head
|
2021-01-05 22:39:57 +00:00
|
|
|
in the forward direction,
|
|
|
|
assigning each element in turn to
|
2020-10-20 21:31:05 +00:00
|
|
|
.IR var .
|
|
|
|
.\" .PP
|
|
|
|
.\" .BR LIST_FOREACH_FROM ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" behaves identically to
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .BR LIST_FOREACH ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" when
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" is NULL, else it treats
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" as a previously found LIST element and begins the loop at
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" instead of the first element in the LIST referenced by
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .IR head .
|
|
|
|
.\" .PP
|
|
|
|
.\" .BR LIST_FOREACH_SAFE ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" traverses the list referenced by
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I head
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" in the forward direction, assigning each element in turn to
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .IR var .
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" However, unlike
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .BR LIST_FOREACH ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" here it is permitted to both remove
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" as well as free it from within the loop safely without interfering with the
|
|
|
|
.\" traversal.
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .PP
|
|
|
|
.\" .BR LIST_FOREACH_FROM_SAFE ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" behaves identically to
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .BR LIST_FOREACH_SAFE ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" when
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" is NULL, else it treats
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" as a previously found LIST element and begins the loop at
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I var
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" instead of the first element in the LIST referenced by
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .IR head .
|
2021-01-05 22:39:57 +00:00
|
|
|
.SS Removal
|
2020-10-20 21:31:05 +00:00
|
|
|
.BR LIST_REMOVE ()
|
2020-10-20 21:31:02 +00:00
|
|
|
removes the element
|
2020-10-20 21:31:05 +00:00
|
|
|
.I elm
|
2020-10-20 21:31:02 +00:00
|
|
|
from the list.
|
2021-01-05 22:39:57 +00:00
|
|
|
.\" .SS Other features
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .BR LIST_SWAP ()
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" swaps the contents of
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .I head1
|
2020-10-20 21:31:02 +00:00
|
|
|
.\" and
|
2020-10-20 21:31:05 +00:00
|
|
|
.\" .IR head2 .
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH RETURN VALUE
|
2020-10-20 21:31:06 +00:00
|
|
|
.BR LIST_EMPTY ()
|
2020-10-22 17:33:04 +00:00
|
|
|
returns nonzero if the list is empty,
|
2020-10-20 21:31:06 +00:00
|
|
|
and zero if the list contains at least one entry.
|
|
|
|
.PP
|
|
|
|
.BR LIST_FIRST (),
|
|
|
|
and
|
|
|
|
.BR LIST_NEXT ()
|
|
|
|
return a pointer to the first or next
|
2020-10-25 09:19:23 +00:00
|
|
|
.I TYPE
|
2020-10-21 04:42:08 +00:00
|
|
|
structure, respectively.
|
2020-10-20 21:31:06 +00:00
|
|
|
.PP
|
|
|
|
.BR LIST_HEAD_INITIALIZER ()
|
|
|
|
returns an initializer that can be assigned to the list
|
|
|
|
.IR head .
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH CONFORMING TO
|
2021-01-09 09:41:55 +00:00
|
|
|
Not in POSIX.1, POSIX.1-2001, or POSIX.1-2008.
|
2020-10-20 21:31:04 +00:00
|
|
|
Present on the BSDs
|
2020-10-20 21:31:05 +00:00
|
|
|
(LIST macros first appeared in 4.4BSD).
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH BUGS
|
2020-10-20 21:31:06 +00:00
|
|
|
.BR LIST_FOREACH ()
|
|
|
|
doesn't allow
|
|
|
|
.I var
|
|
|
|
to be removed or freed within the loop,
|
|
|
|
as it would interfere with the traversal.
|
|
|
|
.BR LIST_FOREACH_SAFE (),
|
2020-10-21 04:48:03 +00:00
|
|
|
which is present on the BSDs but is not present in glibc,
|
|
|
|
fixes this limitation by allowing
|
2020-10-20 21:31:06 +00:00
|
|
|
.I var
|
2020-10-21 04:48:03 +00:00
|
|
|
to safely be removed from the list and freed from within the loop
|
2020-10-20 21:31:06 +00:00
|
|
|
without interfering with the traversal.
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH EXAMPLES
|
2020-10-20 21:31:05 +00:00
|
|
|
.EX
|
2020-10-20 21:31:03 +00:00
|
|
|
#include <stddef.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/queue.h>
|
|
|
|
|
|
|
|
struct entry {
|
|
|
|
int data;
|
2020-12-23 13:17:30 +00:00
|
|
|
LIST_ENTRY(entry) entries; /* List */
|
2020-10-20 21:31:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
LIST_HEAD(listhead, entry);
|
|
|
|
|
|
|
|
int
|
|
|
|
main(void)
|
|
|
|
{
|
2020-10-21 04:41:39 +00:00
|
|
|
struct entry *n1, *n2, *n3, *np;
|
2020-12-23 13:17:30 +00:00
|
|
|
struct listhead head; /* List head */
|
2020-10-21 04:41:39 +00:00
|
|
|
int i;
|
2020-10-20 21:31:03 +00:00
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
LIST_INIT(&head); /* Initialize the list */
|
2020-10-20 21:31:03 +00:00
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
n1 = malloc(sizeof(struct entry)); /* Insert at the head */
|
2020-10-20 21:31:03 +00:00
|
|
|
LIST_INSERT_HEAD(&head, n1, entries);
|
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
n2 = malloc(sizeof(struct entry)); /* Insert after */
|
2020-10-20 21:31:03 +00:00
|
|
|
LIST_INSERT_AFTER(n1, n2, entries);
|
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
n3 = malloc(sizeof(struct entry)); /* Insert before */
|
2020-10-20 21:31:03 +00:00
|
|
|
LIST_INSERT_BEFORE(n2, n3, entries);
|
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
i = 0; /* Forward traversal */
|
2020-10-20 21:31:03 +00:00
|
|
|
LIST_FOREACH(np, &head, entries)
|
2021-01-09 22:21:02 +00:00
|
|
|
np\->data = i++;
|
2020-10-20 21:31:03 +00:00
|
|
|
|
2020-12-23 13:17:30 +00:00
|
|
|
LIST_REMOVE(n2, entries); /* Deletion */
|
2020-10-20 21:31:03 +00:00
|
|
|
free(n2);
|
2020-12-23 13:17:30 +00:00
|
|
|
/* Forward traversal */
|
2020-10-20 21:31:03 +00:00
|
|
|
LIST_FOREACH(np, &head, entries)
|
2021-01-09 22:21:02 +00:00
|
|
|
printf("%i\en", np\->data);
|
2020-12-23 13:20:50 +00:00
|
|
|
/* List deletion */
|
2020-10-20 21:31:03 +00:00
|
|
|
n1 = LIST_FIRST(&head);
|
|
|
|
while (n1 != NULL) {
|
|
|
|
n2 = LIST_NEXT(n1, entries);
|
|
|
|
free(n1);
|
|
|
|
n1 = n2;
|
|
|
|
}
|
|
|
|
LIST_INIT(&head);
|
|
|
|
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2020-10-20 21:31:05 +00:00
|
|
|
.EE
|
2020-10-20 21:30:59 +00:00
|
|
|
.SH SEE ALSO
|
2020-10-20 21:31:06 +00:00
|
|
|
.BR insque (3),
|
2020-10-25 20:46:18 +00:00
|
|
|
.BR queue (7)
|