Thread (1 message) 1 message, 1 author, 2016-10-08

Re: Return type of getrandom(2)

From: Theodore Ts'o <hidden>
Date: 2016-10-08 19:40:05
Also in: linux-man

On Sat, Oct 08, 2016 at 02:28:27PM +0200, Florian Weimer wrote:
The manual page says the return type of getrandom(2) is int, but
ssize_t would be more natural (see read(2) for comparison).  The
kernel uses ssize_t internally, which is converted to long on the
system call boundary.

The difference does not currently matter because the return value is
limited to much less than INT_MAX in the implementation.

Should we use int or ssize_t in the glibc system call wrapper?
I'd suggest keeping it as an int since (a) OpenBSD's getentropy(2)
returns an int, and part of the orignal design goal is to be able to
emulate OpenBSD's getentropy(2) system call via:

int getentropy(void *buf, size_t buflen)
{
	return getrandom(buf, buflen, 0);
}

and (b) the maximum number of bytes returned will *always* be well
under INT_MAX.  I can't forsee at any point in any future or alternate
universe where getrandom() would need to return anywhere near
SHORT_MAX, let alone INT_MAX.

Cheers,

					- Ted
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help