bug-gnulib
[Top][All Lists]
Advanced

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

Re: (x)gethostname


From: Bruno Haible
Subject: Re: (x)gethostname
Date: Thu, 17 Jan 2008 02:31:31 +0100
User-agent: KMail/1.5.4

Simon Josefsson wrote:
> 2008-01-16  Simon Josefsson  <address@hidden>
> 
>       * lib/unistd.in.h: Include sys/socket.h, to get to winsock2.h,
>       which declares gethostname on MinGW.
> 
>       * modules/unistd (Depends-on): Add sys_socket.

Half OK. This patch does too much, IMO:

  - It wants to fix a problem on mingw, and ends up including <sys/socket.h>
    on cygwin also, and you don't know if it will work.

  - It wants to fix a problem for packages that need gethostname, and ends
    up forcing a sys/socket.h file and winsock2 related autoconf test into
    every package.

Especially <sys/socket.h> defines a lot of macros and types. For the sake
of namespace cleanliness, it's good to avoid including when possible.

Hence I'm in favour of limiting the effect through #ifdefs, like the
appended patch.

But this is still not complete: The doc/functions/gethostname.texi file
says that the problem is that mingw lacks a gethostname function. But
now you say that winsock2.h declares this function? So presumably this
function exists, and can return more meaningful values than the empty
string? To use this function, does a program need to link to non-default
libraries? How does m4/gethostname.m4 need to be rewritten? And it is
necessary to still override the function, in order to WSAStartup before?

Bruno


2008-01-16  Simon Josefsson  <address@hidden>
            Bruno Haible  <address@hidden>

        * lib/unistd.in.h: Include <sys/socket.h> conditionally.
        * modules/unistd (Makefile.am): Substitute GNULIB_GETHOSTNAME.
        * modules/gethostname (Depends-on): Add sys_socket.
        (configure.ac): Invoke gl_MODULE_INDICATOR.
        (Include): Document <unistd.h>.

*** lib/unistd.in.h.orig        2008-01-17 02:22:19.000000000 +0100
--- lib/unistd.in.h     2008-01-17 02:19:09.000000000 +0100
***************
*** 1,5 ****
  /* Substitute for and wrapper around <unistd.h>.
!    Copyright (C) 2004-2007 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
--- 1,5 ----
  /* Substitute for and wrapper around <unistd.h>.
!    Copyright (C) 2004-2008 Free Software Foundation, Inc.
  
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
***************
*** 33,38 ****
--- 33,43 ----
  /* mingw fails to declare _exit in <unistd.h>.  */
  #include <stdlib.h>
  
+ /* mingw fails to declare gethostname in <unistd.h>.  */
+ #if @GNULIB_GETHOSTNAME@ && ((defined _WIN32 || defined __WIN32__) && ! 
defined __CYGWIN__)
+ # include <sys/socket.h>
+ #endif
+ 
  /* The definition of GL_LINK_WARNING is copied here.  */
  
  
*** modules/gethostname.orig    2008-01-17 02:22:19.000000000 +0100
--- modules/gethostname 2008-01-17 02:19:02.000000000 +0100
***************
*** 6,18 ****
--- 6,21 ----
  m4/gethostname.m4
  
  Depends-on:
+ sys_socket
  
  configure.ac:
  gl_FUNC_GETHOSTNAME
+ gl_MODULE_INDICATOR([gethostname])
  
  Makefile.am:
  
  Include:
+ <unistd.h>
  
  License:
  LGPL
*** modules/unistd.orig 2008-01-17 02:22:19.000000000 +0100
--- modules/unistd      2008-01-17 02:18:46.000000000 +0100
***************
*** 28,33 ****
--- 28,34 ----
              -e 's|@''GNULIB_FCHDIR''@|$(GNULIB_FCHDIR)|g' \
              -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \
              -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \
+             -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \
              -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \
              -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \
              -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \





reply via email to

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