OSDN Git Service

8d818bbf5608cb386fcba54ac251b6e305eb7631
[linuxjm/LDP_man-pages.git] / release / man2 / getpagesize.2
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" Permission is granted to make and distribute verbatim copies of this
4 .\" manual provided the copyright notice and this permission notice are
5 .\" preserved on all copies.
6 .\"
7 .\" Permission is granted to copy and distribute modified versions of this
8 .\" manual under the conditions for verbatim copying, provided that the
9 .\" entire resulting derived work is distributed under the terms of a
10 .\" permission notice identical to this one.
11 .\"
12 .\" Since the Linux kernel and libraries are constantly changing, this
13 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
14 .\" responsibility for errors or omissions, or for damages resulting from
15 .\" the use of the information contained herein.  The author(s) may not
16 .\" have taken the same level of care in the production of this manual,
17 .\" which is licensed free of charge, as they might when working
18 .\" professionally.
19 .\"
20 .\" Formatted or processed versions of this manual, if unaccompanied by
21 .\" the source, must acknowledge the copyright and authors of this work.
22 .\"
23 .\" Japanese Version Copyright (c) 1997 HANATAKA Shinya
24 .\"         all rights reserved.
25 .\" Translated 2002-04-14, HANATAKA Shinya <hanataka@abyss.rim.or.jp>
26 .\" Updated 2003-07-03, Akihiro Motoki <amotoki@dd.iij4u.or.jp>
27 .\" Updated 2007-01-07, Akihiro MOTOKI, catch up to LDP v2.43
28 .\"
29 .\"WORD:        page                    ページ
30 .\"WORD:        legacy                  過去の遺物
31 .\"
32 .TH GETPAGESIZE 2 2010-09-20 "Linux" "Linux Programmer's Manual"
33 .SH 名前
34 getpagesize \- メモリのページ・サイズを取得する
35 .SH 書式
36 .B #include <unistd.h>
37 .sp
38 .B int getpagesize(void);
39 .sp
40 .in -4n
41 glibc 向けの機能検査マクロの要件
42 .RB ( feature_test_macros (7)
43 参照):
44 .in
45 .sp
46 .BR getpagesize ():
47 .ad l
48 .RS 4
49 .PD 0
50 .TP 4
51 glibc 2.12 以降:
52 .nf
53 _BSD_SOURCE ||
54     !(_POSIX_C_SOURCE\ >=\ 200112L || _XOPEN_SOURCE\ >=\ 600)
55 .fi
56 .TP 4
57 glibc 2.12 より前:
58 _BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
59 _XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
60 .PD
61 .RE
62 .ad b
63 .SH 説明
64 .BR getpagesize ()
65 関数はページの大きさをバイト数で返す。ここでの「ページ」は
66 .BR mmap (2)
67 の説明の中で使用されているもので、
68 .BR mmap ()
69 はこのページサイズの単位でファイルをマップする。
70
71 .BR mmap (2)
72 が使用するページサイズは以下のようにして知ることができる。
73
74 .in +4n
75 .nf
76 #include <unistd.h>
77 long sz = sysconf(_SC_PAGESIZE);
78 .fi
79 .in
80
81 (ほとんどのシステムでは
82 .B _SC_PAGESIZE
83 の同義語として
84 .B _SC_PAGE_SIZE
85 を使用することができる)、もしくは以下のようにする:
86
87 .in +4n
88 .nf
89 #include <unistd.h>
90 int sz = getpagesize();
91 .fi
92 .in
93 .\" .SH 歴史
94 .\" このシステムコールは 4.2BSD で初めて登場した。
95 .SH 準拠
96 SVr4, 4.4BSD, SUSv2.
97 SUSv2 では
98 .BR getpagesize ()
99 システムコールは「過去の遺物 (LEGACY)」とされており、
100 POSIX.1-2001 からは外されている。
101 HP-UX にはこのシステムコールは存在しない。
102 移植性が必要なアプリケーションでは、このシステムコールの代わりに
103 .I sysconf(_SC_PAGESIZE)
104 を利用すべきである。
105 .SH 注意
106 .BR getpagesize ()
107 が Linux のシステムコールとして存在するかどうかは、そのアーキテクチャに
108 依存している。
109 システムコールとして存在する場合には、カーネルシンボルの
110 .B PAGE_SIZE
111 を返す。
112 .B PAGE_SIZE
113 の値は、アーキテクチャとマシンモデルに依存する。
114 一般に、バイナリは、アーキテクチャごとに1つのバイナリ配布で済ませるために、
115 アーキテクチャには依存しているがマシンモデルには依存していない。
116 つまり、ユーザプログラムはコンパイル時にヘッダーファイルから
117 .B PAGE_SIZE
118 を見つけて使用すべきではない。
119 少なくとも、マシンモデルについても依存性が存在する (sun4 のような)
120 アーキテクチャにおいては本物のシステムコールを使用する必要がある。
121 尚、 libc4, libc5, glibc 2.0 では、
122 .BR getpagesize ()
123 がシステム・コールを使用せず、固定の値を返すために、この方法は
124 失敗する。glibc 2.1 では大丈夫である。
125 .SH 関連項目
126 .BR mmap (2),
127 .BR sysconf (3)