1 .\" peter memishian -- meem@gnu.ai.mit.edu
2 .\" $Id: insque.3,v 1.2 1996/10/30 21:03:39 meem Exp meem $
3 .\" and Copyright (c) 2010, Michael Kerrisk <mtk.manpages@gmail.com>
5 .\" %%%LICENSE_START(VERBATIM)
6 .\" Permission is granted to make and distribute verbatim copies of this
7 .\" manual provided the copyright notice and this permission notice are
8 .\" preserved on all copies.
10 .\" Permission is granted to copy and distribute modified versions of this
11 .\" manual under the conditions for verbatim copying, provided that the
12 .\" entire resulting derived work is distributed under the terms of a
13 .\" permission notice identical to this one.
15 .\" Since the Linux kernel and libraries are constantly changing, this
16 .\" manual page may be incorrect or out-of-date. The author(s) assume no
17 .\" responsibility for errors or omissions, or for damages resulting from
18 .\" the use of the information contained herein. The author(s) may not
19 .\" have taken the same level of care in the production of this manual,
20 .\" which is licensed free of charge, as they might when working
23 .\" Formatted or processed versions of this manual, if unaccompanied by
24 .\" the source, must acknowledge the copyright and authors of this work.
27 .\" References consulted:
28 .\" Linux libc source code (5.4.7)
29 .\" Solaris 2.x, OSF/1, and HP-UX manpages
30 .\" Curry's "UNIX Systems Programming for SVR4" (O'Reilly & Associates 1996)
32 .\" Changed to POSIX, 2003-08-11, aeb+wh
33 .\" mtk, 2010-09-09: Noted glibc 2.4 bug, added info on circular
34 .\" lists, added example program
36 .\"*******************************************************************
38 .\" This file was generated with po4a. Translate the source file.
40 .\"*******************************************************************
41 .TH INSQUE 3 2010\-09\-09 "" "Linux Programmer's Manual"
43 insque, remque \- キューにアイテムを挿入/削除する
46 \fB#include <search.h>\fP
48 \fBvoid insque(void *\fP\fIelem\fP\fB, void *\fP\fIprev\fP\fB);\fP
50 \fBvoid remque(void *\fP\fIelem\fP\fB);\fP
54 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
58 \fBinsque\fP(), \fBremque\fP():
60 _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
64 関数 \fBinsque\fP() と \fBremque\fP() は双方向連結リスト (doubly\-linked list) を
65 操作する。リスト中のそれぞれの要素は、最初の二つの要素がそれぞれ次と前への
67 リンクリストは、線形 (linear) か環状 (circular) のどちらかになる
68 (線形の場合には、リストの末尾では次へのポインタが NULL になり、
69 リストの先頭では前へのポインタが NULL になる)。
71 \fBinsque\fP() 関数は \fIelem\fP で示される要素を \fIprev\fP で示される
74 リストが線形の場合、\fIinsque(elem, NULL)\fP を呼び出すと、
76 この呼び出しを行うと \fIelem\fP の次へのポインタと前へのポインタに
79 リストが環状の場合、呼び出す側が、最初の要素の次へのポインタと前へのポインタ
80 が自分自身を指し、また \fBinsque\fP() の呼び出しで \fIprev\fP 引き数が最初の要素
83 \fBremque\fP() 関数は \fIelem\fP で示される要素を双方向連結リストから取り除く。
87 伝統的に (SunOS, Linux libc 4,5 では) これらの関数の引き数は \fIstruct qelem
88 *\fP型であり、これは以下のように定義されている。
100 この定義は \fI<search.h>\fP をインクルードする前に \fB_GNU_SOURCE\fP を定義することで得られる。
102 これらの関数のプロトタイプの置かれる場所は、UNIX の種類により異なる。
103 上記は POSIX 版である。 \fI<string.h>\fP にあるシステムもある。
104 Linux libc4 と libc5 ではプロトタイプは \fI<stdlib.h>\fP に置かれている。
106 glibc 2.4 以前では \fIprev\fP に NULL を指定することができなかった。
107 その結果、線形のリストを作成するためには、
108 呼び出し側は、最初の呼び出しで、リストの最初の 2 つの要素を持ち、
109 各要素の次へのポインタと前へのポインタを適切に初期化したリストを
112 次のプログラムは \fBinsque\fP() の使用法を示したものである。
117 $ \fB./a.out \-c a b c\fP
118 Traversing completed list:
122 That was a circular list
134 struct element *forward;
135 struct element *backward;
139 static struct element *
144 e = malloc(sizeof(struct element));
146 fprintf(stderr, "malloc() failed\en");
154 main(int argc, char *argv[])
156 struct element *first, *elem, *prev;
157 int circular, opt, errfnd;
159 /* The "\-c" command\-line option can be used to specify that the
164 while ((opt = getopt(argc, argv, "c")) != \-1) {
175 if (errfnd || optind >= argc) {
176 fprintf(stderr, "Usage: %s [\-c] string...\en", argv[0]);
180 /* Create first element and place it in the linked list */
182 elem = new_element();
185 elem\->name = argv[optind];
188 elem\->forward = elem;
189 elem\->backward = elem;
195 /* Add remaining command\-line arguments as list elements */
197 while (++optind < argc) {
200 elem = new_element();
201 elem\->name = argv[optind];
205 /* Traverse the list from the start, printing element names */
207 printf("Traversing completed list:\en");
210 printf(" %s\en", elem\->name);
211 elem = elem\->forward;
212 } while (elem != NULL && elem != first);
215 printf("That was a circular list\en");
221 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.52 の一部
222 である。プロジェクトの説明とバグ報告に関する情報は
223 http://www.kernel.org/doc/man\-pages/ に書かれている。