From patchwork Thu Oct 22 12:38:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 40817 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 902C93985448; Thu, 22 Oct 2020 12:39:00 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 902C93985448 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1603370340; bh=ddGWzuHkDSKUhi6Epxfke/finPszjX3ZPwD4o070Q6k=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=n4SyBjkuKJfKcB7hEZV0OSGi13Hd1hGNP16rsk9/Pbrw7Hrd8/MmqYZ+Y6x/NtRL7 G8f5TgxLtjJkWCL8iGv7qqUV9QIQUoqq0PL/kppFcJFFFi++0+JNovHSBnMSlqc/ZO Y8K/UVJyuN9EHAjuSfe/HNMDZa+YBm9tjdH6pDWU= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id C09CE398400B for ; Thu, 22 Oct 2020 12:38:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org C09CE398400B Received: by mail-wr1-x434.google.com with SMTP id n6so2164928wrm.13 for ; Thu, 22 Oct 2020 05:38:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ddGWzuHkDSKUhi6Epxfke/finPszjX3ZPwD4o070Q6k=; b=iavMZAQZDOHDcxQC0LdTS7Vr7wq4qTa1w0RXVNTRiYbWX9l1if7kKaBpX1iw3YDuz5 q210mnhinN/H7WTAJEmZl+lgMhGVHg0SxwsjdNV60iO94etAlvYHvVMbNUdE2zNuoFiY lzLxJrhwYpHEWRjsie5ABgQ6+O6PX3sXwl87PYz075uGDNeUiwf1AsElu/yzdR4ndXDE phADHqkL+BX65nxr73rRItGVzV6+GuPAv37FhKzAUZs0EOt7uh4E0PDnT9WsdAnNq7HT mE3hsgiSXqCSf2mjsgK2yuRzXzI133BssBY2vVxnzlhDznYWrZGYK0GB1jpf6N3gvb/2 kCzQ== X-Gm-Message-State: AOAM531l5oKkDil6Zmoa/5q7phmRfpY2LTIAcAN1muCbpTndzpygf30l whTyauXODZCfD+w/uyth/uyOa63Rt80= X-Google-Smtp-Source: ABdhPJzuJJfkePorPKIc90dHZBXPg77lgK6ueomIcxGaQGO9PHBp8WF421Nf5M0WPRUM5u68vFbaMA== X-Received: by 2002:a5d:424e:: with SMTP id s14mr2769752wrr.149.1603370335771; Thu, 22 Oct 2020 05:38:55 -0700 (PDT) Received: from debian-VLC.home ([170.253.60.68]) by smtp.googlemail.com with ESMTPSA id m1sm3573883wme.48.2020.10.22.05.38.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 05:38:55 -0700 (PDT) To: mtk.manpages@gmail.com Subject: [PATCH 05/10] queue.3, slist.3: EXAMPLES: Move example program from queue.3 to slist.3 Date: Thu, 22 Oct 2020 14:38:17 +0200 Message-Id: <20201022123821.22602-6-colomar.6.4.3@gmail.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20201022123821.22602-1-colomar.6.4.3@gmail.com> References: <20201022123821.22602-1-colomar.6.4.3@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-10.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_NUMSUBJECT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alejandro Colomar via Libc-alpha From: Alejandro Colomar Reply-To: Alejandro Colomar Cc: Alejandro Colomar , linux-man@vger.kernel.org, libc-alpha@sourceware.org Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Signed-off-by: Alejandro Colomar --- man3/queue.3 | 57 ---------------------------------------------------- man3/slist.3 | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 57 deletions(-) diff --git a/man3/queue.3 b/man3/queue.3 index cf5ab60b2..6cf13beb7 100644 --- a/man3/queue.3 +++ b/man3/queue.3 @@ -847,63 +847,6 @@ removes the element .Fa elm from the circular queue. .Sh EXAMPLES -.Ss Singly-linked list example -.Bd -literal - -#include -#include -#include -#include - -struct entry { - int data; - SLIST_ENTRY(entry) entries; /* Singly-linked List. */ -}; - -SLIST_HEAD(slisthead, entry); - -int -main(void) -{ - struct entry *n1, *n2, *n3, *np; - struct slisthead head; /* Singly-linked List - head. */ - - SLIST_INIT(&head); /* Initialize the queue. */ - - n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ - SLIST_INSERT_HEAD(&head, n1, entries); - - n2 = malloc(sizeof(struct entry)); /* Insert after. */ - SLIST_INSERT_AFTER(n1, n2, entries); - - SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ - free(n2); - - n3 = SLIST_FIRST(&head); - SLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head. */ - free(n3); - - for (int i = 0; i < 5; i++) { - n1 = malloc(sizeof(struct entry)); - SLIST_INSERT_HEAD(&head, n1, entries); - n1->data = i; - } - - /* Forward traversal. */ - SLIST_FOREACH(np, &head, entries) - printf("%i\en", np->data); - - while (!SLIST_EMPTY(&head)) { /* List Deletion. */ - n1 = SLIST_FIRST(&head); - SLIST_REMOVE_HEAD(&head, entries); - free(n1); - } - SLIST_INIT(&head); - - exit(EXIT_SUCCESS); -} -.Ed .Ss Singly-linked tail queue example .Bd -literal #include diff --git a/man3/slist.3 b/man3/slist.3 index e29953a1d..291c8753b 100644 --- a/man3/slist.3 +++ b/man3/slist.3 @@ -227,4 +227,61 @@ See the EXAMPLES section below for an example program using a singly-linked list .SH CONFORMING TO .SH BUGS .SH EXAMPLES +.Ss Singly-linked list example +.Bd -literal + +#include +#include +#include +#include + +struct entry { + int data; + SLIST_ENTRY(entry) entries; /* Singly-linked List. */ +}; + +SLIST_HEAD(slisthead, entry); + +int +main(void) +{ + struct entry *n1, *n2, *n3, *np; + struct slisthead head; /* Singly-linked List + head. */ + + SLIST_INIT(&head); /* Initialize the queue. */ + + n1 = malloc(sizeof(struct entry)); /* Insert at the head. */ + SLIST_INSERT_HEAD(&head, n1, entries); + + n2 = malloc(sizeof(struct entry)); /* Insert after. */ + SLIST_INSERT_AFTER(n1, n2, entries); + + SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */ + free(n2); + + n3 = SLIST_FIRST(&head); + SLIST_REMOVE_HEAD(&head, entries); /* Deletion from the head. */ + free(n3); + + for (int i = 0; i < 5; i++) { + n1 = malloc(sizeof(struct entry)); + SLIST_INSERT_HEAD(&head, n1, entries); + n1->data = i; + } + + /* Forward traversal. */ + SLIST_FOREACH(np, &head, entries) + printf("%i\en", np->data); + + while (!SLIST_EMPTY(&head)) { /* List Deletion. */ + n1 = SLIST_FIRST(&head); + SLIST_REMOVE_HEAD(&head, entries); + free(n1); + } + SLIST_INIT(&head); + + exit(EXIT_SUCCESS); +} +.Ed .SH SEE ALSO