aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <colomar.6.4.3@gmail.com>2020-10-25 10:36:47 +0100
committerMichael Kerrisk <mtk.manpages@gmail.com>2020-10-25 10:42:31 +0100
commit7b8d4bbf32a9182b7da8a070484d368f56b831a1 (patch)
tree8f7a69e159f03b29a3108268c94cef30a6ee6aca
parent32d12807a8ad62da0de72d726cfc742a430dd01a (diff)
downloadman-pages-7b8d4bbf32a9182b7da8a070484d368f56b831a1.tar.gz
queue.3, tailq.3: EXAMPLES: Move code from queue.3 to tailq.3
Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com> Signed-off-by: Michael Kerrisk <mtk.manpages@gmail.com>
-rw-r--r--man3/queue.356
-rw-r--r--man3/tailq.356
2 files changed, 56 insertions, 56 deletions
diff --git a/man3/queue.3 b/man3/queue.3
index f6e3b9369b..4c597e1231 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -170,62 +170,6 @@ The termination condition for traversal is more complex.
Code size is about 40% greater and operations run about 45% slower than lists.
.El
.Sh EXAMPLES
-.Ss Tail queue example
-.Bd -literal
-#include <stddef.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/queue.h>
-
-struct entry {
- int data;
- TAILQ_ENTRY(entry) entries; /* Tail queue. */
-};
-
-TAILQ_HEAD(tailhead, entry);
-
-int
-main(void)
-{
- struct entry *n1, *n2, *n3, *np;
- struct tailhead head; /* Tail queue head. */
- int i;
-
- TAILQ_INIT(&head); /* Initialize the queue. */
-
- n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
- TAILQ_INSERT_HEAD(&head, n1, entries);
-
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
- TAILQ_INSERT_TAIL(&head, n1, entries);
-
- n2 = malloc(sizeof(struct entry)); /* Insert after. */
- TAILQ_INSERT_AFTER(&head, n1, n2, entries);
-
- n3 = malloc(sizeof(struct entry)); /* Insert before. */
- TAILQ_INSERT_BEFORE(n2, n3, entries);
-
- TAILQ_REMOVE(&head, n2, entries); /* Deletion. */
- free(n2);
- /* Forward traversal. */
- i = 0;
- TAILQ_FOREACH(np, &head, entries)
- np->data = i++;
- /* Reverse traversal. */
- TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries)
- printf("%i\en", np->data);
- /* TailQ Deletion. */
- n1 = TAILQ_FIRST(&head);
- while (n1 != NULL) {
- n2 = TAILQ_NEXT(n1, entries);
- free(n1);
- n1 = n2;
- }
- TAILQ_INIT(&head);
-
- exit(EXIT_SUCCESS);
-}
-.Ed
.Sh CONFORMING TO
Not in POSIX.1, POSIX.1-2001 or POSIX.1-2008.
Present on the BSDs.
diff --git a/man3/tailq.3 b/man3/tailq.3
index 144a86f3fb..28a7ac509f 100644
--- a/man3/tailq.3
+++ b/man3/tailq.3
@@ -323,4 +323,60 @@ See the EXAMPLES section below for an example program using a tail queue.
.SH CONFORMING TO
.SH BUGS
.SH EXAMPLES
+.Ss Tail queue example
+.Bd -literal
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/queue.h>
+
+struct entry {
+ int data;
+ TAILQ_ENTRY(entry) entries; /* Tail queue. */
+};
+
+TAILQ_HEAD(tailhead, entry);
+
+int
+main(void)
+{
+ struct entry *n1, *n2, *n3, *np;
+ struct tailhead head; /* Tail queue head. */
+ int i;
+
+ TAILQ_INIT(&head); /* Initialize the queue. */
+
+ n1 = malloc(sizeof(struct entry)); /* Insert at the head. */
+ TAILQ_INSERT_HEAD(&head, n1, entries);
+
+ n1 = malloc(sizeof(struct entry)); /* Insert at the tail. */
+ TAILQ_INSERT_TAIL(&head, n1, entries);
+
+ n2 = malloc(sizeof(struct entry)); /* Insert after. */
+ TAILQ_INSERT_AFTER(&head, n1, n2, entries);
+
+ n3 = malloc(sizeof(struct entry)); /* Insert before. */
+ TAILQ_INSERT_BEFORE(n2, n3, entries);
+
+ TAILQ_REMOVE(&head, n2, entries); /* Deletion. */
+ free(n2);
+ /* Forward traversal. */
+ i = 0;
+ TAILQ_FOREACH(np, &head, entries)
+ np->data = i++;
+ /* Reverse traversal. */
+ TAILQ_FOREACH_REVERSE(np, &head, tailhead, entries)
+ printf("%i\en", np->data);
+ /* TailQ Deletion. */
+ n1 = TAILQ_FIRST(&head);
+ while (n1 != NULL) {
+ n2 = TAILQ_NEXT(n1, entries);
+ free(n1);
+ n1 = n2;
+ }
+ TAILQ_INIT(&head);
+
+ exit(EXIT_SUCCESS);
+}
+.Ed
.SH SEE ALSO