Gisle Vanem <[EMAIL PROTECTED]> writes:

>> Another option was to simply set the (system) errno after the Winsock
>> operations, and have our own strerror that recognizes them.  (That
>> assumes that Winsock errno values don't conflict with the system ones,
>> which I believe is the case.)
>
> That assumption is wrong I think.
> Winsock errors are in range 10000 - 11004. Win32 API errors (from
> <WinErr.h>) and libc errors (from <errno.h>) *do* overlap. E.g. both
> EINTR and ERROR_TOO_MANY_OPEN_FILES both have the same value (4).

I'm not sure that we use the Win32 API calls and then check errno.  If
we're doing that, we can set errno to GetLastError() + some large
constant specific to Wget after the calls.

> We must therefore be careful using strerror() with errno codes only
> and FormatMessage() with GetLastError (and WSAGetLastError). *Or*
> cook up a smarter strerror() replacement.

I would lean toward a smarter strerror replacement.  I'll definitely
try to get it working before the release of 1.10 so we finally get
decent error messages on Windows.

> #undef strerror
> char *win_strerror (int err)
> {
>   static char buf[512];
>   char  *p;
>
>   if (err >= 0 && err < sys_nerr)
>     {
>       strncpy (buf, strerror(err), sizeof(buf)-1);
>       buf [sizeof(buf)-1] = '\0';
>     }
>   else
>     {
>       if (!get_winsock_error (err, buf, sizeof(buf)) &&
>           !FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
>                           LANG_NEUTRAL, buf, sizeof(buf)-1, NULL))
>        sprintf (buf, "Unknown error %d (%#x)", err, err);
>     }

This is a good start -- but doesn't it suffer from the confusion
between EINTR and ERROR_TOO_MANY_OPEN_FILES?

Reply via email to