Debian Codegraph @

psutil/arch/posix/init.c

raw
1 /*
2 * Copyright (c) 2009, Giampaolo Rodola'. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7 #include <Python.h>
8 #include <sys/resource.h>
9 #include <sys/socket.h>
10
11 /*
12 * From "man getpagesize" on Linux, https://linux.die.net/man/2/getpagesize:
13 *
14 * > In SUSv2 the getpagesize() call is labeled LEGACY, and in POSIX.1-2001
15 * > it has been dropped.
16 * > Portable applications should employ sysconf(_SC_PAGESIZE) instead
17 * > of getpagesize().
18 * > Most systems allow the synonym _SC_PAGE_SIZE for _SC_PAGESIZE.
19 * > Whether getpagesize() is present as a Linux system call depends on the
20 * > architecture.
21 */
22 long
23 psutil_getpagesize(void) {
24 #ifdef _SC_PAGESIZE
25 // recommended POSIX
26 return sysconf(_SC_PAGESIZE);
27 #elif _SC_PAGE_SIZE
28 // alias
29 return sysconf(_SC_PAGE_SIZE);
30 #else
31 // legacy
32 return (long) getpagesize();
33 #endif
34 }
35
36
37 // Exposed so we can test it against Python's stdlib.
38 PyObject *
39 psutil_getpagesize_pywrapper(PyObject *self, PyObject *args) {
40 return Py_BuildValue("l", psutil_getpagesize());
41 }