aboutsummaryrefslogtreecommitdiff
path: root/ja_JP.eucJP/man/man3/bitstring.3
blob: 5d4dfbd9ca3075a59ff82da9c32df2150f03d814 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
.\" Copyright (c) 1989, 1991, 1993
.\"	The Regents of the University of California.  All rights reserved.
.\"
.\" This code is derived from software contributed to Berkeley by
.\" Paul Vixie.
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\"    must display the following acknowledgement:
.\"	This product includes software developed by the University of
.\"	California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\"    may be used to endorse or promote products derived from this software
.\"    without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\"     @(#)bitstring.3	8.1 (Berkeley) 7/19/93
.\"	%Id: bitstring.3,v 1.4 1997/04/13 14:19:58 bde Exp %
.\"
.\" $FreeBSD$
.Dd July 19, 1993
.Dt BITSTRING 3
.Os BSD 4
.Sh 名称
.Nm bit_alloc ,
.Nm bit_clear ,
.Nm bit_decl ,
.Nm bit_ffs ,
.Nm bit_nclear ,
.Nm bit_nset,
.Nm bit_set ,
.Nm bitstr_size ,
.Nm bit_test
.Nd ビット列操作マクロ
.Sh 書式
.Fd #include <bitstring.h>
.Ft bitstr_t *
.Fn bit_alloc "int nbits"
.Ft void
.Fn bit_decl "bitstr_t *name" "int nbits"
.Ft void
.Fn bit_clear "bitstr_t *name" "int bit"
.Ft void
.Fn bit_ffc "bitstr_t *name" "int nbits" "int *value"
.Ft void
.Fn bit_ffs "bitstr_t *name" "int nbits" "int *value"
.Ft void
.Fn bit_nclear "bitstr_t *name" "int start" "int stop"
.Ft void
.Fn bit_nset "bitstr_t *name" "int start" "int stop"
.Ft void
.Fn bit_set "bitstr_t *name" "int bit"
.Ft int
.Fn bitstr_size "int nbits"
.Ft int
.Fn bit_test "bitstr_t *name" "int bit"
.Sh 解説
これらのマクロはビット列を操作します。
.Pp
マクロ
.Fn bit_alloc
は、
.Fa nbits
個のビットを格納するのに十分な空間を指す型
.Dq Fa "bitstr_t *"
のポインタを返します。または、空間が利用できない場合は
.Dv NULL
を返します。
.Pp
マクロ
.Fn bit_decl
は、
.Fa nbits
個のビットを格納するのに十分な空間をスタックに割り付けます。
.Pp
マクロ
.Fn bitstr_size
は、
.Fa nbits
個のビットを格納するのに必要な、型
.Fa bitstr_t
の要素の数を返します。これはビット列をコピーするのに便利です。
.Pp
マクロ
.Fn bit_clear
とマクロ
.Fn bit_set
は、ビット列
.Ar name
の中の、ゼロを起点として
.Fa bit
番目のビットをクリアまたは設定します。
.Pp
マクロ
.Fn bit_nset
とマクロ
.Fn bit_nclear
は、ビット列
.Ar name
の中の
.Fa start
から
.Fa stop
までの (ゼロを起点として番号付けした) ビットをセットまたは
クリアします。
.Pp
マクロ
.Fn bit_test
は、ビット列
.Ar name
内で、ゼロを起点として
.Fa bit
番目のビットがセットされている場合、評価結果はゼロでない値になり、
それ以外の場合はゼロと評価されます。
.Pp
マクロ
.Fn bit_ffs
は、
.Ar name
が参照する
.Fa nbits
ビットの配列のなかで、セットされたビットが最初に現れる位置を
ゼロを起点として番号付けした値を、
.Fa value
が参照する位置に格納します。どのビットも設定されていない場合、
.Fa value
が参照する位置に、-1 が設定されます。
.Pp
マクロ
.Fn bit_ffc
は、
.Ar name
が参照する
.Fa nbits
ビットの配列のなかで、セットされていないビットが最初に現れる位置を、
ゼロを起点として番号付けした値を、
.Fa value
が参照する位置に格納します。どのビットも設定されている場合、
.Fa value
が参照する位置に、-1 が設定されます。
.Pp
これらのマクロの引数は、
1 回だけ評価され、安全な副作用がある
可能性があります。
.Sh 例
.Bd -literal -offset indent
#include <limits.h>
#include <bitstring.h>

...
#define LPR_BUSY_BIT		0
#define LPR_FORMAT_BIT		1
#define LPR_DOWNLOAD_BIT	2
#define LPR_AVAILABLE_BIT	9
#define LPR_MAX_BITS		10

make_lpr_available()
{
	bitstr_t bit_decl(bitlist, LPR_MAX_BITS);
	...
	bit_nclear(bitlist, 0, LPR_MAX_BITS - 1);
	...
	if (!bit_test(bitlist, LPR_BUSY_BIT)) {
		bit_clear(bitlist, LPR_FORMAT_BIT);
		bit_clear(bitlist, LPR_DOWNLOAD_BIT);
		bit_set(bitlist, LPR_AVAILABLE_BIT);
	}
}
.Ed
.Sh 関連項目
.Xr malloc 3
.Pp
.Sh 歴史
.Nm bitstring
関数は最初に
.Bx 4.4
で現れました。
.\" kuma