curl-library
Re: Question about some platform updates to Windows
Date: Thu, 24 Oct 2013 9:17:04 -0700
---- Gisle Vanem <gvanem_at_yahoo.no> wrote:
> "Myria" <myriachan_at_cox.net> wrote:
>
> > I noticed that Windows does not define HAVE_GMTIME_R or HAVE_LOCALTIME_R.
> > It is true that Visual Studio's C runtime library doesn't have gmtime_r, but
> > it has a somewhat-equivalent API, gmtime_s. gmtime_s's prototype is
> > different, reversing the order of the two parameters and returning an errno
> > error code instead of the tm* parameter. (gmtime_s took its reentrancy more
> > seriously than gmtime_r, and doesn't modify the thread-local variable
> > errno.) The same applies to localtime_r existing in Visual Studio as
> > localtime_s.
>
> Without opening a can of worms [*] by using this new _gmtime64_s() function,
> we could make a thread-safe Curl_gmtime() in libcurl too? It shouldn't be that
> hard; a call to gmtime64() protected inside a critical-section and with a push/pop
> of errno.
A push/pop of errno isn't required; gmtime_r on Ljnux and Darwin both set errno on failure but not success in my experiments.
> localtime_r() isn't used anywhere AFAICS. So what's this HAVE_LOCALTIME_R
> all about?
Vestigial to the curl project, I suppose, then.
> By "worms", I mean using a MSVCRT.DLL function in e.g. Vista that isn't available
> in Win-XP. So a libcurl.dll would not work everwhere.
This is only true of mingw, due to not having its own runtime. If you build with Visual Studio 2005 or later, you're either going to link against 2005's static runtime, which has the gmtime_s family, or you're going to link against the dynamic runtime msvcrt80.dll, which exports the gmtime_s family.
Another alternative, by the way, is to use neither. You can do some simple arithmetic to convert a time_t to a FILETIME, then use FileTimeToSystemTime to split into components. Subtract 1900 from year then write to tm_year, for example -- write our own gmtime() based on the Win32 API.
> --gv
Melissa
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2013-10-24