[PATCH v3] getrandom system call wrapper [BZ #17252]

Florian Weimer fweimer@redhat.com
Sat Oct 8 10:33:00 GMT 2016


On 10/08/2016 01:00 AM, Paul Eggert wrote:
> On 09/12/2016 06:48 AM, Florian Weimer wrote:
>> +int getrandom (void *__buffer, size_t __length, unsigned int __flags)
>> +  __wur;
>
> In looking into implementing a Gnulib approximation to or wrapper for
> the getrandom proposal, I noticed that the most recent (Sept. 12)
> version the proposed getrandom returns int (like Solaris 11), whereas
> the previous version (Sept. 8) returned ssize_t (like 'read'). From the
> GNU point of view ssize_t makes more sense, as it avoids an arbitrary 2
> GiB limit on 64-bit hosts. I don't recall this change being discussed so
> I thought I'd ask what's up.

The return type does not avoid a limit as far as the implementation is 
concerned.  Both Solaris and Linux perform short reads long before 
reaching INT_MAX.

The manual page says the return type is int.  This could be considered a 
bug in the manual page.  I checked the Linux sources, and the kernel 
returns a ssize_t value converted to long.

I have no strong preference.  I do agree that using int instead of 
ssize_t looks like a bug at first glance, but due to the implementation 
limit, it does not really matter.

Comments?

Florian



More information about the Libc-alpha mailing list