delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2000/01/26/19:14:07

Mailing-List: contact cygwin-help AT sourceware DOT cygnus DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT sourceware DOT cygnus DOT com>
List-Archive: <http://sourceware.cygnus.com/ml/cygwin/>
List-Post: <mailto:cygwin AT sourceware DOT cygnus DOT com>
List-Help: <mailto:cygwin-help AT sourceware DOT cygnus DOT com>, <http://sourceware.cygnus.com/ml/#faqs>
Sender: cygwin-owner AT sourceware DOT cygnus DOT com
Delivered-To: mailing list cygwin AT sourceware DOT cygnus DOT com
X-Authentication-Warning: hp2.xraylith.wisc.edu: khan owned process doing -bs
Date: Wed, 26 Jan 2000 18:14:48 -0600 (CST)
From: Mumit Khan <khan AT NanoTech DOT Wisc DOT EDU>
To: Glenn Spell <glenn AT gs DOT fay DOT nc DOT us>
cc: cygwin AT sourceware DOT cygnus DOT com
Subject: Using h_errno, errno etc Cygwin DLL globals [Re: Making wget]
In-Reply-To: <20000126133618.A13948@shell4.ba.best.com>
Message-ID: <Pine.HPP.3.96.1000126180905.15827C-100000@hp2.xraylith.wisc.edu>
MIME-Version: 1.0

On Wed, 26 Jan 2000, Glenn Spell wrote:

> On 26 Jan 2000 around 9:38AM (-0000) Norling,
> Gunnar wrote:
> > Some days ago there where a discussion involving the wget program.
> >
> > ftp.o(.text+0x848):ftp.c: undefined reference to `h_errno'
> > http.o(.text+0x750):http.c: undefined reference to `h_errno'
> >
> > This is my versions:
> > gcc --version: 2.95.2
> > uname -a: CYGWIN_NT-4.0 <machine> 1.1.0(0.16/3/2) 2000-01-20
> > 00:22:41 i686 unknown
> 
> I get the same results. I'm using gcc-2.95 with the 1999-12-05
> dll (the newer dlls crash on me) on Win95.
> 
> The following patch worked for me. I gleaned the information
> from /usr/include/netdb.h.
> 
> I have no idea why this is necessary for some and not for others.

Here's why: older versions of Cygnus didn't add the DATA tag when
exporting h_errno, and so linking worked even for incorrect code;
however, you'll get an ACCESS_VIOLATION or segfault when you try
to access or assign to h_errno. Newer Cygwin snapshots enforce the
correct behaviour so that you have to import it explicitly. Consider
the following code:
  
  void
  foo ()
  {
    extern int h_errno;

    h_errno = 5;
  }

This code is incorrect, but would have linked correctly with older
versions of Cygwin (eg., b20.1), and you'll surely get a crash if
`foo' is ever called.

The correct way:
  
  #include <netdb.h>

  void
  foo ()
  {
    h_errno = 5;
  }

The same thing applies to all the other imported data symbols (ie.,
global variables) from Cygwin DLL, such as errno, etc.

> 
> -------------------------------------------------
> --- src/ftp.c.orig       Thu Sep 10 09:21:36 1998
> +++ src/ftp.c            Wed Jan 26 12:39:46 2000
> @@ -52,3 +52,8 @@
>  #ifndef h_errno
> +# ifdef __CYGWIN__
> +extern int * __imp_h_errno;
> +#  define h_errno (*__imp_h_errno)
> +# else
>  extern int h_errno;
> +# endif
>  #endif

If <netdb.h> is not included for some reason, the better way is to 
do the following:
  
  #ifdef __CYGWIN__
    __declspec(dllimport) int h_errno;
  #endif

But of course, one should be including <netdb.h> instead. Ah, the joys
of choosing among so many Unix misfeatures -- some don't declare it, 
some do and so on ;-)

Regards,
Mumit



--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe AT sourceware DOT cygnus DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019