pkg-config libdivecomputer / subsurface makefile / confusion

Jef Driesen jefdriesen at telenet.be
Thu Jul 12 12:33:17 PDT 2012


On 2012-07-11 11:00, Linus Torvalds wrote:
> On Tue, Jul 10, 2012 at 11:19 PM, Jef Driesen <jefdriesen at telenet.be>
> wrote:
>>
>> On my linux system, the manpages contain a function prototype that
>> matches
>> the Open Group specification:
>>
>> int ioctl(int d, int request, ...);
>>
>> But the function prototype in the <sys/ioctl.h> header also has an
>> "unsigned
>> long" parameter:
>>
>> extern int ioctl (int __fd, unsigned long int __request, ...)
>> __THROW;
>
> In Linux, the kernel will truncate things internally, so passing an
> "int" or "long" doesn't actually matter - sign (or zero-) extension
> will be undone by the kernel, and it will be treated as "int" inside
> the kernel (actually, the Linux kernel will make it unsigned, but
> that's an internal implementation detail, and what matters is that it
> matches the bits in an "int").

Using an unsigned integer type is indeed the right choice if only the actual 
bits are important. There would have been no issues with sign extension in the 
first place.

I guess most code isn't affected because they pass the constants directly to 
ioctl, without storing it into an intermediate variable first.

> That said, that header should be fixed, it's wrong, even if it
> doesn't
> cause any problems because the kernel itself isn't wrong.

It was indeed very confusing.

Jef


More information about the subsurface mailing list