Man page - insque(3)

Packages contains this manual

Available languages:

en fr ja ru ro

Manual

INSQUE

名 前
書 式
説 明
属 性
準 拠
注 意
バ グ
EXAMPLES
プ ロ グ ラ ム の ソ ー ス
SEE ALSO
こ の 文 書 に つ い て

名 前

insque, remque - キ ュ ー に ア イ テ ム を 挿 入 /削 除 す る

書 式

#include <search.h>

void insque(void * elem , void * prev );

void remque(void * elem );

glibc 向 け の 機 能 検 査 マ ク ロ の 要 件 ( feature_test_macros (7) 参 照 ):

insque (), remque ():

_XOPEN_SOURCE >= 500
|| /* Glibc since 2.19: */ _DEFAULT_SOURCE
|| /* Glibc versions <= 2.19: */ _SVID_SOURCE

説 明

The insque () and remque () functions manipulate doubly linked lists. Each element in the list is a structure of which the first two elements are a forward and a backward pointer. The linked list may be linear (i.e., NULL forward pointer at the end of the list and NULL backward pointer at the start of the list) or circular.

insque () 関 数 は elem で 示 さ れ る 要 素 を prev で 示 さ れ る 要 素 の 直 後 に 挿 入 す る 。

リ ス ト が 線 形 の 場 合 、 insque(elem, NULL) を 呼 び 出 す と 、 リ ス ト の 最 初 の 要 素 を 挿 入 す る こ と が で き る 。 こ の 呼 び 出 し を 行 う と elem の 次 へ の ポ イ ン タ ー と 前 へ の ポ イ ン タ ー に 共 に NULL が 設 定 さ れ る 。

リ ス ト が 環 状 の 場 合 、 呼 び 出 す 側 が 、 最 初 の 要 素 の 次 へ の ポ イ ン タ ー と 前 へ の ポ イ ン タ ー が 自 分 自 身 を 指 し 、 ま た insque () の 呼 び 出 し で prev 引 数 が 最 初 の 要 素 を 指 す よ う に 保 証 し な け れ ば な ら な い 。

The remque () function removes the element pointed to by elem from the doubly linked list.

属 性

こ の 節 で 使 用 さ れ て い る 用 語 の 説 明 に つ い て は 、 attributes (7) を 参 照 。

Image grohtml-33953-1.png

準 拠

POSIX.1-2001, POSIX.1-2008.

注 意

On ancient systems, the arguments of these functions were of type struct qelem * , defined as:

struct qelem {
struct qelem *q_forw;
struct qelem *q_back;
char q_data[1];
};

こ の 定 義 は <search.h> を イ ン ク ル ー ド す る 前 に _GNU_SOURCE を 定 義 す る こ と で 得 ら れ る 。

こ れ ら の 関 数 の プ ロ ト タ イ プ の 置 か れ る 場 所 は 、 UNIX の 種 類 に よ り 異 な る 。 上 記 は POSIX 版 で あ る 。 <string.h> に あ る シ ス テ ム も あ る 。

バ グ

glibc 2.4 以 前 で は prev に NULL を 指 定 す る こ と が で き な か っ た 。 そ の 結 果 、 線 形 の リ ス ト を 作 成 す る た め に は 、 呼 び 出 し 側 は 、 最 初 の 呼 び 出 し で 、 リ ス ト の 最 初 の 2 つ の 要 素 を 持 ち 、 各 要 素 の 次 へ の ポ イ ン タ ー と 前 へ の ポ イ ン タ ー を 適 切 に 初 期 化 し た リ ス ト を 作 成 し な け れ ば な ら な か っ た 。

EXAMPLES

次 の プ ロ グ ラ ム は insque () の 使 用 法 を 示 し た も の で あ る 。 下 記 は プ ロ グ ラ ム の 実 行 例 で あ る 。

$ ./a.out -c a b c
Traversing completed list:
a
b
c
That was a circular list

プ ロ グ ラ ム の ソ ー ス

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <search.h>

struct element {
struct element *forward;
struct element *backward;
char *name;
};

static struct element *
new_element(void)
{
struct element *e = malloc(sizeof(*e));
if (e == NULL) {
fprintf(stderr, "malloc() failed\n");
exit(EXIT_FAILURE);
}

return e;
}

int
main(int argc, char *argv[])
{
struct element *first, *elem, *prev;
int circular, opt, errfnd;

/* The "-c" command-line option can be used to specify that the
list is circular */

errfnd = 0;
circular = 0;
while ((opt = getopt(argc, argv, "c")) != -1) {
switch (opt) {
case 'c':
circular = 1;
break;
default:
errfnd = 1;
break;
}
}

if (errfnd || optind >= argc) {
fprintf(stderr, "Usage: %s [-c] string...\n", argv[0]);
exit(EXIT_FAILURE);
}

/* Create first element and place it in the linked list */

elem = new_element();
first = elem;

elem->name = argv[optind];

if (circular) {
elem->forward = elem;
elem->backward = elem;
insque(elem, elem);
} else {
insque(elem, NULL);
}

/* Add remaining command-line arguments as list elements */

while (++optind < argc) {
prev = elem;

elem = new_element();
elem->name = argv[optind];
insque(elem, prev);
}

/* Traverse the list from the start, printing element names */

printf("Traversing completed list:\n");
elem = first;
do {
printf(" %s\n", elem->name);
elem = elem->forward;
} while (elem != NULL && elem != first);

if (elem == first)
printf("That was a circular list\n");

exit(EXIT_SUCCESS);
}

SEE ALSO

queue (7)

こ の 文 書 に つ い て

こ の man ペ ー ジ は Linux man-pages プ ロ ジ ェ ク ト の リ リ ー ス 5.10 の 一 部 で あ る 。 プ ロ ジ ェ ク ト の 説 明 と バ グ 報 告 に 関 す る 情 報 は https://www.kernel.org/doc/man-pages/ に 書 か れ て い る 。