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 .\"*******************************************************************
42 .\" Japanese Version Copyright (c) 1998 AKAMATSU Kazuo
43 .\" all rights reserved.
44 .\" Translated Thu Jan 7 16:00 JST 1999
46 .\" Updated Sun Sep 14 JST 2003 by Kentaro Shirakata <argrath@ub32.org>
47 .\" Updated 2012-04-30, Akihiro MOTOKI <amotoki@gmail.com>
49 .TH INSQUE 3 2010\-09\-09 "" "Linux Programmer's Manual"
51 insque, remque \- キューにアイテムを挿入/削除する
54 \fB#include <search.h>\fP
56 \fBvoid insque(void *\fP\fIelem\fP\fB, void *\fP\fIprev\fP\fB);\fP
58 \fBvoid remque(void *\fP\fIelem\fP\fB);\fP
62 glibc 向けの機能検査マクロの要件 (\fBfeature_test_macros\fP(7) 参照):
66 \fBinsque\fP(), \fBremque\fP():
68 _SVID_SOURCE || _XOPEN_SOURCE\ >=\ 500 || _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
72 関数 \fBinsque\fP() と \fBremque\fP() は双方向連結リスト (doubly\-linked list) を
73 操作する。リスト中のそれぞれの要素は、最初の二つの要素がそれぞれ次と前への
75 リンクリストは、線形 (linear) か環状 (circular) のどちらかになる
76 (線形の場合には、リストの末尾では次へのポインタが NULL になり、
77 リストの先頭では前へのポインタが NULL になる)。
79 \fBinsque\fP() 関数は \fIelem\fP で示される要素を \fIprev\fP で示される
82 リストが線形の場合、\fIinsque(elem, NULL)\fP を呼び出すと、
84 この呼び出しを行うと \fIelem\fP の次へのポインタと前へのポインタに
87 リストが環状の場合、呼び出す側が、最初の要素の次へのポインタと前へのポインタ
88 が自分自身を指し、また \fBinsque\fP() の呼び出しで \fIprev\fP 引き数が最初の要素
91 \fBremque\fP() 関数は \fIelem\fP で示される要素を双方向連結リストから取り除く。
95 伝統的に (SunOS, Linux libc 4,5 では) これらの関数の引き数は \fIstruct qelem
96 *\fP型であり、これは以下のように定義されている。
101 struct qelem *q_forw;
102 struct qelem *q_back;
108 この定義は \fI<search.h>\fP をインクルードする前に \fB_GNU_SOURCE\fP を定義することで得られる。
110 これらの関数のプロトタイプの置かれる場所は、UNIX の種類により異なる。
111 上記は POSIX 版である。 \fI<string.h>\fP にあるシステムもある。
112 Linux libc4 と libc5 ではプロトタイプは \fI<stdlib.h>\fP に置かれている。
114 glibc 2.4 以前では \fIprev\fP に NULL を指定することができなかった。
115 その結果、線形のリストを作成するためには、
116 呼び出し側は、最初の呼び出しで、リストの最初の 2 つの要素を持ち、
117 各要素の次へのポインタと前へのポインタを適切に初期化したリストを
120 次のプログラムは \fBinsque\fP() の使用法を示したものである。
125 $ \fB./a.out \-c a b c\fP
126 Traversing completed list:
130 That was a circular list
142 struct element *forward;
143 struct element *backward;
147 static struct element *
152 e = malloc(sizeof(struct element));
154 fprintf(stderr, "malloc() failed\en");
162 main(int argc, char *argv[])
164 struct element *first, *elem, *prev;
165 int circular, opt, errfnd;
167 /* The "\-c" command\-line option can be used to specify that the
172 while ((opt = getopt(argc, argv, "c")) != \-1) {
183 if (errfnd || optind >= argc) {
184 fprintf(stderr, "Usage: %s [\-c] string...\en", argv[0]);
188 /* Create first element and place it in the linked list */
190 elem = new_element();
193 elem\->name = argv[optind];
196 elem\->forward = elem;
197 elem\->backward = elem;
203 /* Add remaining command\-line arguments as list elements */
205 while (++optind < argc) {
208 elem = new_element();
209 elem\->name = argv[optind];
213 /* Traverse the list from the start, printing element names */
215 printf("Traversing completed list:\en");
218 printf(" %s\en", elem\->name);
219 elem = elem\->forward;
220 } while (elem != NULL && elem != first);
223 printf("That was a circular list\en");
229 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.65 の一部
230 である。プロジェクトの説明とバグ報告に関する情報は
231 http://www.kernel.org/doc/man\-pages/ に書かれている。