bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: declare sethostname if unistd.h doesn't


From: Bruno Haible
Subject: Re: declare sethostname if unistd.h doesn't
Date: Wed, 30 Nov 2011 02:18:26 +0100
User-agent: KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; )

Hello Ben,

> If it would help and people wouldn't mind, I'll post the current patch
> series for review so that if I'm off track I can correct before
> implementing the remaining bits (including the tests).

Cool. Yes, please, show it!

> On cygwin, the sethostname function is included in libgnu.a
> although I don't currently have a usable SetComputerNameEx handler and
> rely on -1/ENOSYS there still.  This is on my todo list still.

It can also be done later by someone else who is more familiar with
Win32 programming. We prefer a module with missing mingw or Cygwin
support to a module that does not exist at all.

> What I'm not sure about now is the gnulib way to provide a declaration
> that will be valid for Solaris.  Is it better to simply ifdef the
> declaration in unistd.h to be Solaris specific or is an alternate
> wrapper function the way to go?

Good question. Let's see the facts:
  - On Solaris 11, <unistd.h> declares sethostname(), with a second parameter
    of type 'int'.
  - But we want the same prototype on all platforms, that is, 'size_t' as
    second parameter.
  - The question is therefore: Is it dangerous to pass a 'size_t' value
    to a function that originally was defined with an 'int' parameter?
    Negative values of values beyond INT_MAX make no sense, since the
    parameter denotes the length of a string.
  - So, considering only how nonnegative values are passed.
    On 32-bit platforms, 'size_t' is 'unsigned int', which is not
    distinguishable from 'int' in the ABI.
    On 64-bit platforms, that is - for Solaris - SPARC64 and x86_64, the first
    two arguments (and more) are passed in 64-bit registers, not on the stack.
    Passing a 64-bit 'size_t' in place of a 32-bit 'int' is therefore OK.

In summary, here you don't need the wrapper function when the function is not
already declared.

If it is declared and has the wrong parameter type, you need a wrapper. See
e.g. in gettimeofday.c or ioctl.c for how we write such wrappers. This is the
case where you set REPLACE_SETHOSTNAME to 1.

Bruno
-- 
In memoriam Willy Cohn <http://de.wikipedia.org/wiki/Willy_Cohn>



reply via email to

[Prev in Thread] Current Thread [Next in Thread]