OSDN Git Service

Convert release and draft pages to UTF-8.
[linuxjm/jm.git] / manual / LDP_man-pages / draft / man7 / feature_test_macros.7
1 .\" Hey Emacs! This file is -*- nroff -*- source.
2 .\"
3 .\" This manpage is Copyright (C) 2006, Michael Kerrisk
4 .\"
5 .\" Permission is granted to make and distribute verbatim copies of this
6 .\" manual provided the copyright notice and this permission notice are
7 .\" preserved on all copies.
8 .\"
9 .\" Permission is granted to copy and distribute modified versions of this
10 .\" manual under the conditions for verbatim copying, provided that the
11 .\" entire resulting derived work is distributed under the terms of a
12 .\" permission notice identical to this one.
13 .\"
14 .\" Since the Linux kernel and libraries are constantly changing, this
15 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
16 .\" responsibility for errors or omissions, or for damages resulting from
17 .\" the use of the information contained herein.  The author(s) may not
18 .\" have taken the same level of care in the production of this manual,
19 .\" which is licensed free of charge, as they might when working
20 .\" professionally.
21 .\"
22 .\" Formatted or processed versions of this manual, if unaccompanied by
23 .\" the source, must acknowledge the copyright and authors of this work.
24 .\"
25 .\" Japanese Version Copyright (c) 2006 Akihiro MOTOKI all rights reserved.
26 .\" Translated 2006-07-16, Akihiro MOTOKI <amotoki@dd.iij4u.or.jp>
27 .\" Updated 2007-05-01, Akihiro MOTOKI, LDP v2.46
28 .\" Updated 2007-09-08, Akihiro MOTOKI, LDP v2.64
29 .\" Updated 2009-04-23, Akihiro MOTOKI, LDP v3.21
30 .\"
31 .\"WORD:        feature test macro      機能検査マクロ
32 .\"WORD:        feature test macro requirements 機能検査マクロの要件
33 .\"
34 .TH FEATURE_TEST_MACROS 7 2010-09-10 "Linux" "Linux Programmer's Manual"
35 .\"O .SH NAME
36 .SH 名前
37 .\"O feature_test_macros \- feature test macros
38 feature_test_macros \- 機能検査マクロ
39 .\"O .SH SYNOPSIS
40 .SH 書式
41 .nf
42 .B #include <features.h>
43 .fi
44 .\"O .SH DESCRIPTION
45 .SH 説明
46 .\"O Feature test macros allow the programmer to control the definitions that
47 .\"O are exposed by system header files when a program is compiled.
48 機能検査マクロ (feature test macro) により、プログラマは
49 プログラムがコンパイルされる際にシステムのヘッダファイルにより
50 公開される定義を制御することができる。
51
52 .\"O .B NOTE:
53 .B 注意:
54 .\"O In order to be effective, a feature test macro
55 .\"O .IR "must be defined before including any header files" .
56 .\"O This can be done either in the compilation command
57 .\"O .RI ( "cc \-DMACRO=value" )
58 .\"O or by defining the macro within the source code before
59 .\"O including any headers.
60 機能検査マクロを機能させるには、機能検査マクロの定義を
61 「どのヘッダファイルのインクルードよりも前で」行わなければならない。
62 これを実現するには、
63 コンパイルコマンドで指定する方法
64 .RI ( "cc \-DMACRO=value" )
65 と、ソースコード内で必要なマクロの定義を
66 どのヘッダのインクルードよりも前で行う方法がある。
67
68 .\"O Some feature test macros are useful for creating portable applications,
69 .\"O by preventing nonstandard definitions from being exposed.
70 .\"O Other macros can be used to expose nonstandard definitions that
71 .\"O are not exposed by default.
72 .\"O The precise effects of each of the feature test macros described below
73 .\"O can be ascertained by inspecting the
74 .\"O .I <features.h>
75 .\"O header file.
76 機能検査マクロを使うと、非標準の定義が公開されないようにでき、
77 移植性のあるアプリケーションを作成するのに役立つ。
78 他のマクロを使うと、デフォルトでは公開されない非標準の定義を
79 公開することができる。
80 以下で説明する機能検査マクロのそれぞれの正確な影響を確認するには、
81 ヘッダファイル
82 .I <features.h>
83 を調べればよい。
84
85 .\"O .SS Specification of feature test macro requirements in manual pages
86 .SS マニュアルページでの機能検査マクロの要件の規定
87 .\"O When a function requires that a feature test macro is defined,
88 .\"O the manual page SYNOPSIS typically includes a note of the following form
89 .\"O (this example from the
90 .\"O .BR acct (2)
91 .\"O manual page):
92 関数が機能検査マクロの定義を必要とする場合、
93 マニュアルページの書式 (SYNOPSIS) の節に
94 以下の形式の注釈を入れる
95 (以下の例は
96 .BR acct (2)
97 のマニュアルページからの引用である)。
98 .RS 8
99 .sp
100 .B #include <unistd.h>
101 .sp
102 .BI "int acct(const char *" filename );
103 .sp
104 .nf
105 .in -4n
106 .\"O Feature Test Macro Requirements for glibc (see
107 .\"O .BR feature_test_macros (7)):
108 glibc 向けの機能検査マクロの要件
109 .RB ( feature_test_macros (7)
110 参照):
111 .fi
112 .in
113 .sp
114 .BR acct ():
115 _BSD_SOURCE || (_XOPEN_SOURCE && _XOPEN_SOURCE\ <\ 500)
116 .RE
117 .PP
118 .\"O The \fB||\fP means that in order to obtain the declaration of
119 .\"O .BR acct (2)
120 .\"O from
121 .\"O .IR <unistd.h> ,
122 .\"O \fIeither\fP of the following macro
123 .\"O definitions must be made before including any header files:
124 \fB||\fP は、
125 .BR acct (2)
126 の定義を
127 .I <unistd.h>
128 から得るには、以下のマクロの定義のいずれかを、どのヘッダファイルの
129 インクルードよりも前で行わなければならないことを意味する。
130 .RS
131 .nf
132
133 #define _BSD_SOURCE
134 #define _XOPEN_SOURCE        /* or any value < 500 */
135 .fi
136 .RE
137 .PP
138 .\"O Alternatively, equivalent definitions can be included in the
139 .\"O compilation command:
140 別の方法としては、等価な定義をコンパイル用のコマンドで
141 指定することもできる。
142 .RS
143 .nf
144
145 cc \-D_BSD_SOURCE
146 cc \-D_XOPEN_SOURCE           # Or any value < 500
147 .fi
148 .RE
149 .PP
150 .\"O Note that, as described below,
151 .\"O .BR "some feature test macros are defined by default" ,
152 .\"O so that it may not always be necessary to
153 .\"O explicitly specify the feature test macro(s) shown in the
154 .\"O SYNOPSIS.
155 後で述べるが、
156 .B 「いくつかの機能検査マクロはデフォルトで定義される」
157 点に注意すること。
158 このため、「書式」に記載された機能検査マクロを常に
159 明示的に指定する必要があるわけではない。
160
161 .\"O In a few cases, manual pages use a shorthand for expressing the
162 .\"O feature test macro requirements (this example from
163 .\"O .BR readahead (2)):
164 あまり多くないが、マニュアルページによっては、
165 機能検査マクロの要件を以下のように簡単な表現で記載する場合がある。
166 (以下の例は
167 .BR readahead (2)
168 のマニュアルページからの引用である)。
169 .RS
170 .nf
171
172 .B #define _GNU_SOURCE
173 .B #include <fcntl.h>
174 .sp
175 .BI "ssize_t readahead(int " fd ", off64_t *" offset ", size_t " count );
176 .fi
177 .RE
178 .PP
179 .\"O This format is employed in cases where only a single
180 .\"O feature test macro can be used to expose the function
181 .\"O declaration, and that macro is not defined by default.
182 関数定義の公開に使える機能検査マクロが一つだけで、
183 デフォルトではそのマクロが定義されない場合に、
184 この形式の表現を利用する。
185 .\"O .SS Feature test macros understood by glibc
186 .SS glibc が解釈する機能検査マクロ
187 .\"O The following paragraphs explain how feature test macros are handled
188 .\"O in Linux glibc 2.\fIx\fP, \fIx\fP > 0.
189 以下では、Linux glibc 2.\fIx\fP (\fIx\fP > 0) において、
190 機能検査マクロがどのように扱われるかを説明する。
191 .\" The details in glibc 2.0 are simpler, but combining a
192 .\" a description of them with the details in later glibc versions
193 .\" would make for a complicated description.
194
195 .\"O Linux glibc understands the following feature test macros:
196 Linux/glibc は以下の機能検査マクロを解釈する:
197 .TP
198 .B __STRICT_ANSI__
199 .\"O ISO Standard C.
200 .\"O This macro is implicitly defined by
201 .\"O .BR gcc (1)
202 .\"O when invoked with, for example, the
203 .\"O .I -std=c99
204 .\"O or
205 .\"O .I -ansi
206 .\"O flag.
207 ISO 標準の C。
208 .BR gcc (1)
209
210 .I -std=c99
211
212 .I -ansi
213 などのフラグを付けて起動した場合、
214 このマクロは暗黙のうちに定義される。
215 .TP
216 .B _POSIX_C_SOURCE
217 .\"O Defining this macro causes header files to expose definitions as follows:
218 このマクロを定義すると、ヘッダファイルで
219 以下の定義が公開される。
220 .RS
221 .IP \(bu 3
222 .\"O The value 1 exposes definitions conforming to POSIX.1-1990 and
223 .\"O ISO C (1990).
224 値が 1 の場合、POSIX.1-1990 と ISO C (1990) に準拠する定義が公開される。
225 .IP \(bu
226 .\"O The value 2 or greater additionally exposes
227 .\"O definitions for POSIX.2-1992.
228 値が 2 以上の場合、
229 POSIX.2-1992 関連の定義も追加で公開される。
230 .IP \(bu
231 .\"O The value 199309L or greater additionally exposes
232 .\"O definitions for POSIX.1b (real-time extensions).
233 値が 199309 以上の場合、
234 POSIX.1b (リアルタイム拡張) 関連の定義が追加で公開される。
235 .\" 199506L functionality is only available since glibc 2.1
236 .IP \(bu
237 .\"O The value 199506L or greater additionally exposes
238 .\"O definitions for POSIX.1c (threads).
239 値が 199506 以上の場合、
240 POSIX.1c (スレッド) 関連の定義が追加で公開される。
241 .IP \(bu
242 .\"O (Since glibc 2.3.3)
243 .\"O The value 200112L or greater exposes definitions corresponding
244 .\"O to the POSIX.1-2001 base specification (excluding the XSI extension).
245 (glibc 2.3.3 以降)
246 値が 200112L 以上の場合、
247 (XSI 拡張を除く) POSIX.1-2001 基本仕様に対応する定義が公開される。
248 .IP \(bu
249 .\"O (Since glibc 2.10)
250 .\"O The value 200809L or greater exposes definitions corresponding
251 .\"O to the POSIX.1-2008 base specification (excluding the XSI extension).
252 (glibc 2.10 以降)
253 値が 200809L 以上の場合、
254 (XSI 拡張を除く) POSIX.1-2008 基本仕様に対応する定義が公開される。
255 .RE
256 .TP
257 .B _POSIX_SOURCE
258 .\"O Defining this obsolete macro with any value is equivalent to defining
259 .\"O .B _POSIX_C_SOURCE
260 .\"O with the value 1.
261 このマクロは廃止予定である。
262 このマクロが定義されると、値に関わらず、
263 .B _POSIX_C_SOURCE
264 を値 1 で定義するのと等価となる。
265 .TP
266 .B _XOPEN_SOURCE
267 .\"O Defining this macro causes header files to expose definitions as follows:
268 このマクロを定義すると、ヘッダファイルで以下の定義が公開される。
269 .RS
270 .IP \(bu 3
271 .\"O Defining with any value exposes
272 .\"O definitions conforming to POSIX.1, POSIX.2, and XPG4.
273 どんな値でも、ヘッダファイルで
274 POSIX.1, POSIX.2, XPG4 に準拠する定義が公開される。
275 .IP \(bu
276 .\"O The value 500 or greater additionally exposes
277 .\"O definitions for SUSv2 (UNIX 98).
278 値が 500 以上の場合、
279 SUSv2 (UNIX 98) 関連の定義が追加で公開される。
280 .IP \(bu
281 .\"O (Since glibc 2.2) The value 600 or greater additionally exposes
282 .\"O definitions for SUSv3 (UNIX 03; i.e., the POSIX.1-2001 base specification
283 .\"O plus the XSI extension) and C99 definitions.
284 (glibc 2.2 以降)
285 値が 600 以上の場合、
286 SUSv3 (UNIX 03; POSIX.1-2001 基本仕様 + XSI 拡張と同じ)
287 関連の定義と C99 での定義が追加で公開される。
288 .IP \(bu
289 .\"O (Since glibc 2.10) The value 700 or greater additionally exposes
290 .\"O definitions for SUSv4 (i.e., the POSIX.1-2008 base specification
291 .\"O plus the XSI extension).
292 (glibc 2.10 以降)
293 値が 700 以上の場合、
294 SUSv4 (POSIX.1-2008 基本仕様 + XSI 拡張と同じ)
295 関連の定義が追加で公開される。
296 .RE
297 .TP
298 .B _XOPEN_SOURCE_EXTENDED
299 .\"O If this macro is defined, and
300 .\"O .B _XOPEN_SOURCE
301 .\"O is defined, then expose definitions corresponding to the XPG4v2
302 .\"O (SUSv1) UNIX extensions (UNIX 95).
303 .\"O This macro is also implicitly defined if
304 .\"O .B _XOPEN_SOURCE
305 .\"O is defined with a value of 500 or more.
306 このマクロが定義され、さらに
307 .B _XOPEN_SOURCE
308 が定義されていると、XPG4v2 (SUSv1) UNIX 拡張 (UNIX 95)
309 に対応する定義が公開される。
310 .B _XOPEN_SOURCE
311 が 500 以上の値で定義された場合、このマクロは暗黙のうちに定義される。
312 .TP
313 .B _ISOC99_SOURCE
314 .\"O Exposes C99 extensions to ISO C (1990).
315 ISO C (1990) の C99 拡張を公開する。
316 .\"O This macro is recognized since glibc 2.1.3;
317 このマクロは glibc 2.1.3 以降で認識される。
318 .\"O earlier glibc 2.1.x versions recognized an equivalent macro named
319 .\"O .B _ISOC9X_SOURCE
320 .\"O (because the C99 standard had not then been finalized).
321 .\"O Although the use of the latter macro is obsolete, glibc continues
322 .\"O to recognize it for backward compatibility.
323 初期のバージョン 2.1.x の glibc では、これと等価な
324 .B _ISOC9X_SOURCE
325 という名前のマクロが使われていた
326 (なぜなら、C99 標準はまだ確定していなかったからである)。
327 .B _ISOC9X_SOURCE
328 マクロの使用は廃止されているが、
329 glibc は過去との互換性のため今でもこのマクロを認識する。
330 .TP
331 .B _LARGEFILE64_SOURCE
332 .\"O Expose definitions for the alternative API specified by the
333 .\"O LFS (Large File Summit) as a "transitional extension" to the
334 .\"O Single UNIX Specification.
335 .\"O (See http://opengroup.org/platform/lfs.html.)
336 LFS (Large File Summit) により
337 "暫定拡張 (transitional extension)" Single UNIX Specification
338 として規定された代替 API (alternative API) に関する定義を公開する
339 (http://opengroup.org/platform/lfs.html 参照)。
340 .\"O The alternative API consists of a set of new objects
341 .\"O (i.e., functions and types) whose names are suffixed with "64"
342 .\"O (e.g.,
343 .\"O .I off64_t
344 .\"O versus
345 .\"O .IR off_t ,
346 .\"O .BR lseek64 ()
347 .\"O versus
348 .\"O .BR lseek (),
349 .\"O etc.).
350 代替 API は新規オブジェクト (関数と型) の集合で構成され、
351 その名前は "64" で終わる (例えば、
352 .I off_t
353 に対応するのは
354 .IR off64_t 、
355 .BR lseek ()
356 に対応するのは
357 .BR lseek64 ()
358 である)。
359 .\"O New programs should not employ this interface; instead
360 .\"O .I _FILE_OFFSET_BITS=64
361 .\"O should be employed.
362 新しいプログラムではこのインタフェースを利用しないこと。
363 代わりに
364 .I _FILE_OFFSET_BITS=64
365 を利用すること。
366 .TP
367 .B _FILE_OFFSET_BITS
368 .\"O Defining this macro with the value 64
369 .\"O automatically converts references to 32-bit functions and data types
370 .\"O related to file I/O and file system operations into references to
371 .\"O their 64-bit counterparts.
372 .\"O This is useful for performing I/O on large files (> 2 Gigabytes)
373 .\"O on 32-bit systems.
374 .\"O (Defining this macro permits correctly written programs to use
375 .\"O large files with only a recompilation being required.)
376 .\"O 64-bit systems naturally permit file sizes greater than 2 Gigabytes,
377 .\"O and on those systems this macro has no effect.
378 このマクロを値 64 で定義すると、ファイル I/O とファイルシステム操作に
379 関連する 32 ビット版の関数とデータタイプは自動的に 64 ビット版に
380 変換される。
381 これは、32 ビットシステムで大きなファイル (> 2 ギガバイト) の I/O
382 を実行する際に役立つ
383 (このマクロを定義すると、コンパイルし直すだけで大きなファイルを
384 扱えるプログラムを書くことができる)。
385 64 ビットシステムは、もともと 2 ギガバイトより大きなファイルを
386 扱えるので、64 ビットシステムではこのマクロは効果を持たない。
387 .TP
388 .B _BSD_SOURCE
389 .\"O Defining this macro with any value causes header files to expose
390 .\"O BSD-derived definitions.
391 .\"O Defining this macro also causes BSD definitions to be preferred in
392 .\"O some situations where standards conflict, unless one or more of
393 .\"O .BR _SVID_SOURCE ,
394 .\"O .BR _POSIX_SOURCE ,
395 .\"O .BR _POSIX_C_SOURCE ,
396 .\"O .BR _XOPEN_SOURCE ,
397 .\"O .BR _XOPEN_SOURCE_EXTENDED ,
398 .\"O or
399 .\"O .B _GNU_SOURCE
400 .\"O is defined, in which case BSD definitions are disfavored.
401 このマクロを定義すると (値に関わらず) ヘッダファイルで
402 BSD 由来の定義が公開される。
403 また、このマクロを定義すると、相容れない標準が存在する状況において
404 BSD 由来の定義を優先するようになる。
405 ただし、
406 .BR _SVID_SOURCE ,
407 .BR _POSIX_SOURCE ,
408 .BR _POSIX_C_SOURCE ,
409 .BR _XOPEN_SOURCE ,
410 .BR _XOPEN_SOURCE_EXTENDED ,
411 .B _GNU_SOURCE
412 が一つでも定義された場合には、BSD 由来の定義は優先されなくなる。
413 .TP
414 .B _SVID_SOURCE
415 .\"O Defining this macro with any value causes header files to expose
416 .\"O System V-derived definitions.
417 .\"O (SVID == System V Interface Definition; see
418 .\"O .BR standards (7).)
419 このマクロを定義すると (値に関わらず) ヘッダファイルで
420 System V 由来の定義が公開される
421 (SVID == System V Interface Definition;
422 .BR standards (7)
423 参照)。
424 .TP
425 .\"O .BR _ATFILE_SOURCE " (since glibc 2.4)"
426 .BR _ATFILE_SOURCE " (glibc 2.4 以降)"
427 .\"O Defining this macro with any value causes header files to expose
428 .\"O declarations of a range of functions with the suffix "at";
429 .\"O see
430 .\"O .BR openat (2).
431 .\"O Since glibc 2.10, this macro is also implicitly defined if
432 .\"O .BR _POSIX_C_SOURCE
433 .\"O is defined with a value greater than or equal to 200809L.
434 このマクロを定義すると (値に関わらず) ヘッダファイルで
435 名前の末尾が "at" の各種の関数の定義が公開される。
436 .BR openat (2)
437 参照。
438 glibc 2.10 以降では、
439 .B _POSIX_C_SOURCE
440 が 200809L 以上の値で定義された場合には、
441 このマクロも暗黙のうちに定義される。
442 .TP
443 .B _GNU_SOURCE
444 .\"O Defining this macro (with any value) is equivalent to defining
445 .\"O .BR _BSD_SOURCE ,
446 .\"O .BR _SVID_SOURCE ,
447 .\"O .BR _ATFILE_SOURCE ,
448 .\"O .BR _LARGEFILE64_SOURCE ,
449 .\"O .BR _ISOC99_SOURCE ,
450 .\"O .BR _XOPEN_SOURCE_EXTENDED ,
451 .\"O .BR _POSIX_SOURCE ,
452 .\"O .B _POSIX_C_SOURCE
453 .\"O with the value 200809L
454 .\"O (200112L in glibc versions before 2.10;
455 .\"O 199506L in glibc versions before 2.5;
456 .\"O 199309L in glibc versions before 2.1)
457 .\"O and
458 .\"O .B _XOPEN_SOURCE
459 .\"O with the value 700
460 .\"O (600 in glibc versions before 2.10;
461 .\"O 500 in glibc versions before 2.2).
462 .\"O In addition, various GNU-specific extensions are also exposed.
463 .\"O Where standards conflict, BSD definitions are disfavored.
464 このマクロを定義すると (値に関わらず) 以下のマクロを定義するのと
465 等価になる:
466 .BR _BSD_SOURCE ,
467 .BR _SVID_SOURCE ,
468 .BR _ATFILE_SOURCE ,
469 .BR _LARGEFILE64_SOURCE ,
470 .BR _ISOC99_SOURCE ,
471 .BR _XOPEN_SOURCE_EXTENDED ,
472 .BR _POSIX_SOURCE ,
473 値 200809L の
474 .B _POSIX_C_SOURCE
475 (バージョン 2.10 より前の glibc では値は 200112L、
476 バージョン 2.5 より前の glibc では値は 199506L、
477 バージョン 2.1 より前の glibc では値は 199309L),
478 値 700 の
479 .B _XOPEN_SOURCE
480 (バージョン 2.10 より前の glibc では値は 600、
481 バージョン 2.2 より前の glibc では値は 500)。
482 さらに、各種の GNU 固有の拡張も公開される。
483 指定された標準に矛盾があった場合は、
484 BSD 由来の定義が優先されなくなる。
485 .TP
486 .B _REENTRANT
487 .\"O Defining this macro exposes definitions of certain reentrant functions.
488 .\"O For multithreaded programs, use
489 .\"O .I "cc\ \-pthread"
490 .\"O instead.
491 このマクロを定義すると、いくつかのリエントラント (再入可能) な関数
492 定義が公開される。マルチスレッド・プログラムでは、この代わりに
493 .I "cc\ \-pthread"
494 を使用すること。
495 .TP
496 .B _THREAD_SAFE
497 .\"O Synonym for
498 .\"O .BR _REENTRANT ,
499 .\"O provided for compatibility with some other implementations.
500 .B _REENTRANT
501 の同義語。
502 他のいくつかの実装との互換性を提供するためのもの。
503 .TP
504 .\"O .BR _FORTIFY_SOURCE " (since glibc 2.3.4)"
505 .BR _FORTIFY_SOURCE " (glibc 2.3.4 以降)"
506 .\" For more detail, see:
507 .\" http://gcc.gnu.org/ml/gcc-patches/2004-09/msg02055.html
508 .\" [PATCH] Object size checking to prevent (some) buffer overflows
509 .\" * From: Jakub Jelinek <jakub at redhat dot com>
510 .\" * To: gcc-patches at gcc dot gnu dot org
511 .\" * Date: Tue, 21 Sep 2004 04:16:40 -0400
512 .\"O Defining this macro causes some lightweight checks to be performed
513 .\"O to detect some buffer overflow errors when employing
514 .\"O various string and memory manipulation functions.
515 .\"O Not all buffer overflows are detected, just some common cases.
516 このマクロを定義すると、文字列やメモリの操作を行う様々な関数を
517 使用する際にバッファオーバーフローを検出するための軽めのチェックが
518 実行されるようになる。すべてのバッファオーバーフローが検出される
519 わけではなく、あくまでよくある例についてだけである。
520 .\"O In the current implementation checks are added for
521 .\"O calls to
522 現在の実装では、以下の関数にチェックが追加されている:
523 .BR memcpy (3),
524 .BR mempcpy (3),
525 .BR memmove (3),
526 .BR memset (3),
527 .BR stpcpy (3),
528 .BR strcpy (3),
529 .BR strncpy (3),
530 .BR strcat (3),
531 .BR strncat (3),
532 .BR sprintf (3),
533 .BR snprintf (3),
534 .BR vsprintf (3),
535 .BR vsnprintf (3),
536 .\"O and
537 .BR gets (3).
538 .\"O If
539 .\"O .B _FORTIFY_SOURCE
540 .\"O is set to 1, with compiler optimization level 1
541 .\"O .RI ( "gcc\ \-O1" )
542 .\"O and above, checks that shouldn't change the behavior of
543 .\"O conforming programs are performed.
544 .\"O With
545 .\"O .B _FORTIFY_SOURCE
546 .\"O set to 2 some more checking is added, but
547 .\"O some conforming programs might fail.
548 .B _FORTIFY_SOURCE
549 が 1 に設定された場合、コンパイラの最適化レベルが 1
550 .RI ( "gcc\ \-O1" )
551 かそれ以上であれば、規格に準拠するプログラムの振る舞いを
552 変化させないようなチェックが実行される。
553 .B _FORTIFY_SOURCE
554 が 2 に設定された場合、さらなるチェックが追加されるが、
555 規格に準拠するプログラムのいくつかが失敗する可能性がある。
556 .\"O Some of the checks can be performed at compile time,
557 .\"O and result in compiler warnings;
558 .\"O other checks take place at run time,
559 .\"O and result in a run-time error if the check fails.
560 いくつかのチェックはコンパイル時に実行でき、コンパイラの警告として
561 表示される。他のチェックは実行時に行われ、チェックに失敗した場合
562 には実行時エラーとなる。
563 .\"O Use of this macro requires compiler support, available with
564 .\"O .BR gcc (1)
565 .\"O since version 4.0.
566 このマクロを使用するにはコンパイラの対応が必要であり、
567 バージョン 4.0 以降の
568 .BR gcc (1)
569 で利用できる。
570 .\"O .SS Default definitions, implicit definitions, and combining definitions
571 .SS デフォルトの定義、暗黙の定義、組み合わせ定義
572 .PP
573 .\"O If no feature test macros are explicitly defined,
574 .\"O then the following feature test macros are defined by default:
575 .\"O .BR _BSD_SOURCE ,
576 .\"O .BR _SVID_SOURCE ,
577 .\"O .BR _POSIX_SOURCE ,
578 .\"O and
579 .\"O .BR _POSIX_C_SOURCE =200809L
580 .\"O (200112L in glibc versions before 2.10;
581 .\"O 199506L in glibc versions before 2.4;
582 .\"O 199309L in glibc versions before 2.1).
583 機能検査マクロが一つも明示的に定義されなかった場合、
584 デフォルトで機能検査マクロ
585 .BR _BSD_SOURCE ,
586 .BR _SVID_SOURCE ,
587 .BR _POSIX_SOURCE ,
588 .BR _POSIX_C_SOURCE =200809L
589 が定義される
590 (バージョン 2.10 より前の glibc では値は 200112L、
591 バージョン 2.4 より前の glibc では値は 199506L、
592 バージョン 2.1 より前の glibc では値は 199309L)。
593 .PP
594 .\"O If any of
595 .\"O .BR __STRICT_ANSI__ ,
596 .\"O .BR _ISOC99_SOURCE ,
597 .\"O .BR _POSIX_SOURCE ,
598 .\"O .BR _POSIX_C_SOURCE  ,
599 .\"O .BR _XOPEN_SOURCE ,
600 .\"O .BR _XOPEN_SOURCE_EXTENDED ,
601 .\"O .BR _BSD_SOURCE ,
602 .\"O or
603 .\"O .B _SVID_SOURCE
604 .\"O is explicitly defined, then
605 .\"O .BR _BSD_SOURCE ,
606 .\"O and
607 .\"O .B _SVID_SOURCE
608 .\"O are not defined by default.
609 .BR __STRICT_ANSI__ ,
610 .BR _ISOC99_SOURCE ,
611 .BR _POSIX_SOURCE ,
612 .BR _POSIX_C_SOURCE  ,
613 .BR _XOPEN_SOURCE ,
614 .BR _XOPEN_SOURCE_EXTENDED ,
615 .BR _BSD_SOURCE ,
616 .B _SVID_SOURCE
617 のいずれかが明示的に定義された場合、
618 .B _BSD_SOURCE
619
620 .B _SVID_SOURCE
621 はデフォルトでは定義されない。
622
623 .\"O If
624 .\"O .B _POSIX_SOURCE
625 .\"O and
626 .\"O .B _POSIX_C_SOURCE
627 .\"O are not explicitly defined,
628 .\"O and either
629 .\"O .B __STRICT_ANSI__
630 .\"O is not defined or
631 .\"O .B _XOPEN_SOURCE
632 .\"O is defined with a value of 500 or more, then
633 .B _POSIX_SOURCE
634
635 .B _POSIX_C_SOURCE
636 が明示的に定義されない場合で、
637 .B __STRICT_ANSI__
638 が定義されない、もしくは
639 .B _XOPEN_SOURCE
640 が 500 以上の値で定義されたときには、
641 .RS 3
642 .IP * 3
643 .\"O .B _POSIX_SOURCE
644 .\"O is defined with the value 1; and
645 .B _POSIX_SOURCE
646 が値 1 で定義され、かつ
647 .IP *
648 .\"O .B _POSIX_C_SOURCE
649 .\"O is defined with one of the following values:
650 .B _POSIX_C_SOURCE
651 は以下の値のいずれか一つで定義される。
652 .RS 6
653 .IP \(bu 3
654 .\"O 2,
655 .\"O if
656 .\"O .B XOPEN_SOURCE
657 .\"O is defined with a value less than 500;
658 2
659 .RB ( _XOPEN_SOURCE
660 が 500 未満の値で定義された場合)
661 .IP \(bu
662 .\"O 199506L,
663 .\"O if
664 .\"O .B XOPEN_SOURCE
665 .\"O is defined with a value greater than or equal to 500 and less than 600;
666 .\"O or
667 199506L
668 .RB ( _XOPEN_SOURCE
669 が 500 以上 600 未満の値で定義された場合)
670 .IP \(bu
671 .\"O (since glibc 2.4) 200112L,
672 .\"O if
673 .\"O .B XOPEN_SOURCE
674 .\"O is defined with a value greater than or equal to 600 and less than 700.
675 (glibc 2.4 以降)
676 200112L
677 .RB ( XOPEN_SOURCE
678 が 600 以上 700 未満の値で定義された場合)
679 .IP \(bu
680 .\"O (Since glibc 2.10)
681 .\"O 200809L,
682 .\"O if
683 .\"O .B XOPEN_SOURCE
684 .\"O is defined with a value greater than or equal to 700.
685 (glibc 2.10 以降)
686 200809L
687 .RB ( XOPEN_SOURCE
688 が 700 以上の値で定義された場合)
689 .IP \(bu
690 .\"O Older versions of glibc do not know about the values
691 .\"O 200112L and 200809L for
692 .\"O .BR _POSIX_C_SOURCE ,
693 .\"O and the setting of this macro will depend on the glibc version.
694 古いバージョンの glibc では
695 .B _POSIX_C_SOURCE
696 の値として 200112L や 200809L は存在せず、
697 .B _POSIX_C_SOURCE
698 の値がどうなるかは glibc のバージョンにより異なる。
699 .IP \(bu
700 .\"O If
701 .\"O .B _XOPEN_SOURCE
702 .\"O is undefined, then the setting of
703 .\"O .B _POSIX_C_SOURCE
704 .\"O depends on the glibc version:
705 .\"O 199506L, in glibc versions before 2.4;
706 .\"O 200112L, in glibc 2.4 to 2.9; and
707 .\"O 200809L, since glibc 2.10.
708 .B _XOPEN_SOURCE
709 が未定義の場合、
710 .B _POSIX_C_SOURCE
711 の値は glibc のバージョンにより異なる。
712 バージョン 2.4 より前の glibc では 199506L、
713 バージョン 2.4 以降 2.9 未満では 200112L、
714 glibc 2.10 以降では 200809L となる。
715 .RE
716 .RE
717 .PP
718 .\"O Multiple macros can be defined; the results are additive.
719 また、複数のマクロを定義することもできる。
720 この場合、定義したマクロはすべて有効になる。
721 .\"O .SH CONFORMING TO
722 .SH 準拠
723 .\"O POSIX.1 specifies
724 .\"O .BR _POSIX_C_SOURCE ,
725 .\"O .BR _POSIX_SOURCE ,
726 .\"O and
727 .\"O .BR _XOPEN_SOURCE .
728 .\"O .B _XOPEN_SOURCE_EXTENDED
729 .\"O was specified by XPG4v2 (aka SUSv1).
730 POSIX.1 では
731 .BR _POSIX_C_SOURCE ,
732 .BR _POSIX_SOURCE ,
733 .B _XOPEN_SOURCE
734 が規定されている。
735 .B _XOPEN_SOURCE_EXTENDED
736 は XPG4v2 (別名 SUSv1) で規定されていた。
737
738 .\"O .B _FILE_OFFSET_BITS
739 .\"O is not specified by any standard,
740 .\"O but is employed on some other implementations.
741 .B _FILE_OFFSET_BITS
742 はどの標準でも規定されていないが、
743 他のいくつかの実装で採用されている。
744
745 .\"O .BR _BSD_SOURCE ,
746 .\"O .BR _SVID_SOURCE ,
747 .\"O .BR _ATFILE_SOURCE ,
748 .\"O .BR _GNU_SOURCE ,
749 .\"O .BR _FORTIFY_SOURCE ,
750 .\"O .BR _REENTRANT ,
751 .\"O and
752 .\"O .B _THREAD_SAFE
753 .\"O are specific to Linux (glibc).
754 .BR _BSD_SOURCE ,
755 .BR _SVID_SOURCE ,
756 .BR _ATFILE_SOURCE ,
757 .BR _GNU_SOURCE ,
758 .BR _FORTIFY_SOURCE ,
759 .BR _REENTRANT ,
760 .B _THREAD_SAFE
761 は Linux (glibc) 固有である。
762 .\"O .SH NOTES
763 .SH 注意
764 .\"O .I <features.h>
765 .\"O is a Linux/glibc-specific header file.
766 .\"O Other systems have an analogous file, but typically with a different name.
767 .\"O This header file is automatically included by other header files as
768 .\"O required: it is not necessary to explicitly include it in order to
769 .\"O employ feature test macros.
770 .I <features.h>
771 は Linux/glibc 固有のヘッダファイルである。
772 他のシステムにも同様の目的のファイルがあるが、普通は違う名前である。
773 このヘッダファイルは、他のヘッダファイルにより必要に応じて
774 自動的にインクルードされる。機能検査マクロを利用するために
775 明示的にインクルードする必要はない。
776
777 .\"O According to which of the above feature test macros are defined,
778 .\"O .I <features.h>
779 .\"O internally defines various other macros that are checked by
780 .\"O other glibc header files.
781 .\"O These macros have names prefixed by two underscores (e.g.,
782 .\"O .BR __USE_MISC ).
783 .\"O Programs should \fInever\fP define these macros directly:
784 .\"O instead, the appropriate feature test macro(s) from the
785 .\"O list above should be employed.
786 上記の機能検査マクロのうちどれが定義されたかにしたがって、
787 .I <features.h>
788 は、他の glibc ヘッダファイルでチェックされる各種の他のマクロを、
789 内部で定義する。これらのマクロの名前はアンダースコア 2つで始まる
790 (例えば
791 .BR __USE_MISC )。
792 ユーザプログラムはこれらのマクロを \fI決して\fP 直接定義すべきではない。
793 代わりに、上記のリストにある適切な機能検査マクロを利用すべきである。
794 .\"O .SH EXAMPLE
795 .SH 例
796 .\"O The program below can be used to explore how the various
797 .\"O feature test macros are set depending on the glibc version
798 .\"O and what feature test macros are explicitly set.
799 .\"O The following shell session, on a system with glibc 2.10,
800 .\"O shows some examples of what we would see:
801 下記のプログラムを使うと、各種の機能検査マクロが glibc のバージョン
802 に応じてどのように設定されるかや、どの機能検査マクロが明示的に
803 設定されるか、を調べることができる。
804 以下に示すシェル・セッションは、
805 glibc 2.10 のシステムでの実行結果の例である。
806 .in +4n
807 .nf
808
809 $ \fBcc ftm.c\fP
810 $ \fB./a.out\fP
811 _POSIX_SOURCE defined
812 _POSIX_C_SOURCE defined: 200809L
813 _BSD_SOURCE defined
814 _SVID_SOURCE defined
815 _ATFILE_SOURCE defined
816 $ \fBcc -D_XOPEN_SOURCE=500 ftm.c\fP
817 $ \fB./a.out\fP
818 _POSIX_SOURCE defined
819 _POSIX_C_SOURCE defined: 199506L
820 _XOPEN_SOURCE defined: 500
821 $ \fBcc -D_GNU_SOURCE ftm.c\fP
822 $ \fB./a.out\fP
823 _POSIX_SOURCE defined
824 _POSIX_C_SOURCE defined: 200809L
825 _ISOC99_SOURCE defined
826 _XOPEN_SOURCE defined: 700
827 _XOPEN_SOURCE_EXTENDED defined
828 _LARGEFILE64_SOURCE defined
829 _BSD_SOURCE defined
830 _SVID_SOURCE defined
831 _ATFILE_SOURCE defined
832 _GNU_SOURCE defined
833 .fi
834 .in
835 .SS Program source
836 \&
837 .nf
838 /* ftm.c */
839
840 #include <stdio.h>
841 #include <unistd.h>
842 #include <stdlib.h>
843
844 int
845 main(int argc, char *argv[])
846 {
847 #ifdef _POSIX_SOURCE
848     printf("_POSIX_SOURCE defined\\n");
849 #endif
850
851 #ifdef _POSIX_C_SOURCE
852     printf("_POSIX_C_SOURCE defined: %ldL\\n", (long) _POSIX_C_SOURCE);
853 #endif
854
855 #ifdef _ISOC99_SOURCE
856     printf("_ISOC99_SOURCE defined\\n");
857 #endif
858
859 #ifdef _XOPEN_SOURCE
860     printf("_XOPEN_SOURCE defined: %d\\n", _XOPEN_SOURCE);
861 #endif
862
863 #ifdef _XOPEN_SOURCE_EXTENDED
864     printf("_XOPEN_SOURCE_EXTENDED defined\\n");
865 #endif
866
867 #ifdef _LARGEFILE64_SOURCE
868     printf("_LARGEFILE64_SOURCE defined\\n");
869 #endif
870
871 #ifdef _FILE_OFFSET_BITS
872     printf("_FILE_OFFSET_BITS defined: %d\\n", _FILE_OFFSET_BITS);
873 #endif
874
875 #ifdef _BSD_SOURCE
876     printf("_BSD_SOURCE defined\\n");
877 #endif
878
879 #ifdef _SVID_SOURCE
880     printf("_SVID_SOURCE defined\\n");
881 #endif
882
883 #ifdef _ATFILE_SOURCE
884     printf("_ATFILE_SOURCE defined\\n");
885 #endif
886
887 #ifdef _GNU_SOURCE
888     printf("_GNU_SOURCE defined\\n");
889 #endif
890
891 #ifdef _REENTRANT
892     printf("_REENTRANT defined\\n");
893 #endif
894
895 #ifdef _THREAD_SAFE
896     printf("_THREAD_SAFE defined\\n");
897 #endif
898
899 #ifdef _FORTIFY_SOURCE
900     printf("_FORTIFY_SOURCE defined\\n");
901 #endif
902
903     exit(EXIT_SUCCESS);
904 }
905 .fi
906 .\"O .SH SEE ALSO
907 .SH 関連項目
908 .BR libc (7),
909 .BR standards (7)
910 .sp
911 .\"O The section "Feature Test Macros" under
912 .\"O .IR "info libc" .
913 .I "info libc"
914 の "Feature Test Macros" の節。
915 .\" But beware: the info libc document is out of date (Jul 07, mtk)
916 .sp
917 .I /usr/include/features.h