ioctl_tty.2: Update DTR example
[man-pages.git] / man2 / getpagesize.2
blobbde300162c5c6d5a035072fc6979a16583d24c95
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date.  The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein.  The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .TH GETPAGESIZE 2 2021-03-22 "Linux" "Linux Programmer's Manual"
26 .SH NAME
27 getpagesize \- get memory page size
28 .SH SYNOPSIS
29 .nf
30 .B #include <unistd.h>
31 .PP
32 .B int getpagesize(void);
33 .fi
34 .PP
35 .RS -4
36 Feature Test Macro Requirements for glibc (see
37 .BR feature_test_macros (7)):
38 .RE
39 .PP
40 .BR getpagesize ():
41 .nf
42     Since glibc 2.20:
43         _DEFAULT_SOURCE || ! (_POSIX_C_SOURCE >= 200112L)
44     Glibc 2.12 to 2.19:
45         _BSD_SOURCE || ! (_POSIX_C_SOURCE >= 200112L)
46     Before glibc 2.12:
47         _BSD_SOURCE || _XOPEN_SOURCE >= 500
48 .\"        || _XOPEN_SOURCE && _XOPEN_SOURCE_EXTENDED
49 .fi
50 .SH DESCRIPTION
51 The function
52 .BR getpagesize ()
53 returns the number of bytes in a memory page,
54 where "page" is a fixed-length block,
55 the unit for memory allocation and file mapping performed by
56 .BR mmap (2).
57 .\" .SH HISTORY
58 .\" This call first appeared in 4.2BSD.
59 .SH CONFORMING TO
60 SVr4, 4.4BSD, SUSv2.
61 In SUSv2 the
62 .BR getpagesize ()
63 call is labeled LEGACY, and in POSIX.1-2001
64 it has been dropped;
65 HP-UX does not have this call.
66 .SH NOTES
67 Portable applications should employ
68 .I sysconf(_SC_PAGESIZE)
69 instead of
70 .BR getpagesize ():
71 .PP
72 .in +4n
73 .EX
74 #include <unistd.h>
75 long sz = sysconf(_SC_PAGESIZE);
76 .EE
77 .in
78 .PP
79 (Most systems allow the synonym
80 .B _SC_PAGE_SIZE
81 for
82 .BR _SC_PAGESIZE .)
83 .PP
84 Whether
85 .BR getpagesize ()
86 is present as a Linux system call depends on the architecture.
87 If it is, it returns the kernel symbol
88 .BR PAGE_SIZE ,
89 whose value depends on the architecture and machine model.
90 Generally, one uses binaries that are dependent on the architecture but not
91 on the machine model, in order to have a single binary
92 distribution per architecture.
93 This means that a user program
94 should not find
95 .B PAGE_SIZE
96 at compile time from a header file,
97 but use an actual system call, at least for those architectures
98 (like sun4) where this dependency exists.
99 Here glibc 2.0 fails because its
100 .BR getpagesize ()
101 returns a statically derived value, and does not use a system call.
102 Things are OK in glibc 2.1.
103 .SH SEE ALSO
104 .BR mmap (2),
105 .BR sysconf (3)