Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does getpagesize() return an int?

Why does the syscall getpagesize() return an int and not an unsigned int or a size_t?

Prototype and short description below:

GETPAGESIZE(2)                                                             
    NAME
           getpagesize - get memory page size
    SYNOPSIS
           #include <unistd.h>
           int getpagesize(void);
like image 327
Oscar Avatar asked Jan 27 '17 09:01

Oscar


People also ask

What does Getpagesize return?

The getpagesize() function returns the current page size. The getpagesize() function is equivalent to sysconf(_SC_PAGE_SIZE) and sysconf(_SC_PAGESIZE). Note: This function is kept for historical reasons.

How do I find the page size?

Check it online There are online tools to check a web page's size. For example, you can do it using https://tools.pingdom.com. Type or paste in the URL of the page you want to check and there you go. You will get a lot of data, among which the size of the page.


1 Answers

int was probably sufficient when it was invented. But it's no longer an issue because the getpagesize() has been removed from POSIX standard since 2001 and has been superseded by sysconf(). You should use sysconf(_SC_PAGESIZE).

getpagesize() returning an int was one of the major reasons why it was removed:

getpagesize

The getpagesize( ) function returns the current page size. It is equivalent to sysconf (_SC_PAGE_SIZE) and sysconf (_SC_PAGESIZE). This interface, returning an int, may have problems representing appropriate values in the future. Also the behaviour is not specified for this interface on systems that support variable size pages. On variable page size systems, a page can be extremely large (theoretically, up to the size of memory). This allows very efficient address translations for large segments of memory that have common page attributes. A note about this has been added to Application Usage, and the interface marked Legacy, with the recommendation that applications should use the sysconf() interface instead.

(emphasis mine).

like image 151
P.P Avatar answered Oct 09 '22 16:10

P.P