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 2014\-08\-19 "" "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 .\" Linux libc4 and libc 5 placed them
111 .\" in \fI<stdlib.h>\fP.
112 これらの関数のプロトタイプの置かれる場所は、UNIX の種類により異なる。
113 上記は POSIX 版である。 \fI<string.h>\fP にあるシステムもある。
115 glibc 2.4 以前では \fIprev\fP に NULL を指定することができなかった。
116 その結果、線形のリストを作成するためには、
117 呼び出し側は、最初の呼び出しで、リストの最初の 2 つの要素を持ち、
118 各要素の次へのポインターと前へのポインターを適切に初期化したリストを
121 次のプログラムは \fBinsque\fP() の使用法を示したものである。
126 $ \fB./a.out \-c a b c\fP
127 Traversing completed list:
131 That was a circular list
143 struct element *forward;
144 struct element *backward;
148 static struct element *
153 e = malloc(sizeof(struct element));
155 fprintf(stderr, "malloc() failed\en");
163 main(int argc, char *argv[])
165 struct element *first, *elem, *prev;
166 int circular, opt, errfnd;
168 /* The "\-c" command\-line option can be used to specify that the
173 while ((opt = getopt(argc, argv, "c")) != \-1) {
184 if (errfnd || optind >= argc) {
185 fprintf(stderr, "Usage: %s [\-c] string...\en", argv[0]);
189 /* Create first element and place it in the linked list */
191 elem = new_element();
194 elem\->name = argv[optind];
197 elem\->forward = elem;
198 elem\->backward = elem;
204 /* Add remaining command\-line arguments as list elements */
206 while (++optind < argc) {
209 elem = new_element();
210 elem\->name = argv[optind];
214 /* Traverse the list from the start, printing element names */
216 printf("Traversing completed list:\en");
219 printf(" %s\en", elem\->name);
220 elem = elem\->forward;
221 } while (elem != NULL && elem != first);
224 printf("That was a circular list\en");
230 この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.79 の一部
231 である。プロジェクトの説明とバグ報告に関する情報は
232 http://www.kernel.org/doc/man\-pages/ に書かれている。