diff mbox series

[v9,04/26] win32: Simplify gmtime_r detection direct base on _POSIX_THREAD_SAFE_FUNCTIONS.

Message ID 20200915121318.247-5-luoyonggang@gmail.com
State Superseded
Headers show
Series W32, W64 msys2/mingw patches | expand

Commit Message

罗勇刚(Yonggang Luo) Sept. 15, 2020, 12:12 p.m. UTC
First, this reduce the size of configure, configure are tending to removal in future,
and this didn't introduce any new feature or remove any exist feature.
Second, the current localtime_r detection are conflict with ncursesw detection in
mingw, when ncursesw detected, it will provide the following compile flags
pkg-config --cflags ncursesw
-D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw
And the compile flag _POSIX_C_SOURCE will always cause _POSIX_THREAD_SAFE_FUNCTIONS to
be defined, in new version of mingw, that's will cause localtime_r to be defined.
But the configure script didn't provide _POSIX_C_SOURCE macro, and that's will result
localtime_r not detected because localtime_r are defined in forceinline manner.

And finally cause conflict between QEMU defined localtime_r
struct tm *localtime_r(const time_t *timep, struct tm *result);
with mingw defined localtime_r

```
#if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)
#define _POSIX_THREAD_SAFE_FUNCTIONS 200112L
#endif

#ifdef _POSIX_THREAD_SAFE_FUNCTIONS
__forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {
  return localtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {
  return gmtime_s(_Tm, _Time) ? NULL : _Tm;
}
__forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {
  return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;
}
__forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {
  return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;
}
#endif
```

So I suggest remove this configure script, and restrict msys2/mingw version to easy to maintain.
And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart functions

Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>
---
 configure                 | 34 ----------------------------------
 include/sysemu/os-win32.h |  4 ++--
 util/oslib-win32.c        |  2 +-
 3 files changed, 3 insertions(+), 37 deletions(-)

Comments

Daniel P. Berrangé Sept. 15, 2020, 1 p.m. UTC | #1
On Tue, Sep 15, 2020 at 08:12:56PM +0800, Yonggang Luo wrote:
> First, this reduce the size of configure, configure are tending to removal in future,

> and this didn't introduce any new feature or remove any exist feature.

> Second, the current localtime_r detection are conflict with ncursesw detection in

> mingw, when ncursesw detected, it will provide the following compile flags

> pkg-config --cflags ncursesw

> -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw

> And the compile flag _POSIX_C_SOURCE will always cause _POSIX_THREAD_SAFE_FUNCTIONS to

> be defined, in new version of mingw, that's will cause localtime_r to be defined.

> But the configure script didn't provide _POSIX_C_SOURCE macro, and that's will result

> localtime_r not detected because localtime_r are defined in forceinline manner.


ncursesw is just one of the three curses impls we can select for
building against, so it doesn't feel right to make an assumption
that _POSIX_C_SOURCE is always defined.

> 

> And finally cause conflict between QEMU defined localtime_r

> struct tm *localtime_r(const time_t *timep, struct tm *result);

> with mingw defined localtime_r

> 

> ```

> #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)

> #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L

> #endif

> 

> #ifdef _POSIX_THREAD_SAFE_FUNCTIONS

> __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {

>   return localtime_s(_Tm, _Time) ? NULL : _Tm;

> }

> __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {

>   return gmtime_s(_Tm, _Time) ? NULL : _Tm;

> }

> __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {

>   return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;

> }

> __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {

>   return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;

> }

> #endif

> ```

> 

> So I suggest remove this configure script, and restrict msys2/mingw version to easy to maintain.

> And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart functions

> 

> Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

> ---

>  configure                 | 34 ----------------------------------

>  include/sysemu/os-win32.h |  4 ++--

>  util/oslib-win32.c        |  2 +-

>  3 files changed, 3 insertions(+), 37 deletions(-)

> 

> diff --git a/configure b/configure

> index dc4b7a2e55..bac48b5b49 100755

> --- a/configure

> +++ b/configure

> @@ -2496,37 +2496,6 @@ if test "$vhost_net" = ""; then

>    test "$vhost_kernel" = "yes" && vhost_net=yes

>  fi

>  

> -##########################################

> -# MinGW / Mingw-w64 localtime_r/gmtime_r check

> -

> -if test "$mingw32" = "yes"; then

> -    # Some versions of MinGW / Mingw-w64 lack localtime_r

> -    # and gmtime_r entirely.

> -    #

> -    # Some versions of Mingw-w64 define a macro for

> -    # localtime_r/gmtime_r.

> -    #

> -    # Some versions of Mingw-w64 will define functions

> -    # for localtime_r/gmtime_r, but only if you have

> -    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun

> -    # though, unistd.h and pthread.h both define

> -    # that for you.

> -    #

> -    # So this #undef localtime_r and #include <unistd.h>

> -    # are not in fact redundant.

> -cat > $TMPC << EOF

> -#include <unistd.h>

> -#include <time.h>

> -#undef localtime_r

> -int main(void) { localtime_r(NULL, NULL); return 0; }

> -EOF

> -    if compile_prog "" "" ; then

> -        localtime_r="yes"

> -    else

> -        localtime_r="no"

> -    fi

> -fi

> -

>  ##########################################

>  # pkg-config probe

>  

> @@ -7088,9 +7057,6 @@ if [ "$bsd" = "yes" ] ; then

>    echo "CONFIG_BSD=y" >> $config_host_mak

>  fi

>  

> -if test "$localtime_r" = "yes" ; then

> -  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak

> -fi

>  if test "$qom_cast_debug" = "yes" ; then

>    echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak

>  fi

> diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h

> index d8978e28c0..3ac8a53bac 100644

> --- a/include/sysemu/os-win32.h

> +++ b/include/sysemu/os-win32.h

> @@ -48,12 +48,12 @@

>  #define siglongjmp(env, val) longjmp(env, val)

>  

>  /* Missing POSIX functions. Don't use MinGW-w64 macros. */

> -#ifndef CONFIG_LOCALTIME_R

> +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS

>  #undef gmtime_r

>  struct tm *gmtime_r(const time_t *timep, struct tm *result);

>  #undef localtime_r

>  struct tm *localtime_r(const time_t *timep, struct tm *result);

> -#endif /* CONFIG_LOCALTIME_R */

> +#endif

>  

>  static inline void os_setup_signal_handling(void) {}

>  static inline void os_daemonize(void) {}

> diff --git a/util/oslib-win32.c b/util/oslib-win32.c

> index c654dafd93..f2fa9a3549 100644

> --- a/util/oslib-win32.c

> +++ b/util/oslib-win32.c

> @@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)

>      }

>  }

>  

> -#ifndef CONFIG_LOCALTIME_R

> +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS

>  /* FIXME: add proper locking */

>  struct tm *gmtime_r(const time_t *timep, struct tm *result)

>  {

> -- 

> 2.28.0.windows.1

> 

> 


Regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|
罗勇刚(Yonggang Luo) Sept. 15, 2020, 1:23 p.m. UTC | #2
On Tue, Sep 15, 2020 at 9:00 PM Daniel P. Berrangé <berrange@redhat.com>
wrote:
>

> On Tue, Sep 15, 2020 at 08:12:56PM +0800, Yonggang Luo wrote:

> > First, this reduce the size of configure, configure are tending to

removal in future,
> > and this didn't introduce any new feature or remove any exist feature.

> > Second, the current localtime_r detection are conflict with ncursesw

detection in
> > mingw, when ncursesw detected, it will provide the following compile

flags
> > pkg-config --cflags ncursesw

> > -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L

-IC:/CI-Tools/msys64/mingw64/include/ncursesw
> > And the compile flag _POSIX_C_SOURCE will always cause

_POSIX_THREAD_SAFE_FUNCTIONS to
> > be defined, in new version of mingw, that's will cause localtime_r to

be defined.
> > But the configure script didn't provide _POSIX_C_SOURCE macro, and

that's will result
> > localtime_r not detected because localtime_r are defined in forceinline

manner.
>

> ncursesw is just one of the three curses impls we can select for

> building against, so it doesn't feel right to make an assumption

> that _POSIX_C_SOURCE is always defined.


That's what I am trying to do, not depends on if  _POSIX_C_SOURCE are
defined.
After this patch, whenever   ncursesw or other  curses lib trying define or
not define  _POSIX_C_SOURCE, the source will building properly
Because now, we don't make any assumption about  _POSIX_C_SOURCE, but
before this patch,
The configure always assume msys2/mingw `not define _POSIX_C_SOURCE ` at
all.
Now this restriction are removed, only depends on mingw related
_POSIX_THREAD_SAFE_FUNCTIONS
>

> >

> > And finally cause conflict between QEMU defined localtime_r

> > struct tm *localtime_r(const time_t *timep, struct tm *result);

> > with mingw defined localtime_r

> >

> > ```

> > #if defined(_POSIX_C_SOURCE) && !defined(_POSIX_THREAD_SAFE_FUNCTIONS)

> > #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L

> > #endif

> >

> > #ifdef _POSIX_THREAD_SAFE_FUNCTIONS

> > __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time,

struct tm *_Tm) {
> >   return localtime_s(_Tm, _Time) ? NULL : _Tm;

> > }

> > __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct

tm *_Tm) {
> >   return gmtime_s(_Tm, _Time) ? NULL : _Tm;

> > }

> > __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {

> >   return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;

> > }

> > __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char *

_Str) {
> >   return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;

> > }

> > #endif

> > ```

> >

> > So I suggest remove this configure script, and restrict msys2/mingw

version to easy to maintain.
> > And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and

counterpart functions
> >

> > Signed-off-by: Yonggang Luo <luoyonggang@gmail.com>

> > ---

> >  configure                 | 34 ----------------------------------

> >  include/sysemu/os-win32.h |  4 ++--

> >  util/oslib-win32.c        |  2 +-

> >  3 files changed, 3 insertions(+), 37 deletions(-)

> >

> > diff --git a/configure b/configure

> > index dc4b7a2e55..bac48b5b49 100755

> > --- a/configure

> > +++ b/configure

> > @@ -2496,37 +2496,6 @@ if test "$vhost_net" = ""; then

> >    test "$vhost_kernel" = "yes" && vhost_net=yes

> >  fi

> >

> > -##########################################

> > -# MinGW / Mingw-w64 localtime_r/gmtime_r check

> > -

> > -if test "$mingw32" = "yes"; then

> > -    # Some versions of MinGW / Mingw-w64 lack localtime_r

> > -    # and gmtime_r entirely.

> > -    #

> > -    # Some versions of Mingw-w64 define a macro for

> > -    # localtime_r/gmtime_r.

> > -    #

> > -    # Some versions of Mingw-w64 will define functions

> > -    # for localtime_r/gmtime_r, but only if you have

> > -    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun

> > -    # though, unistd.h and pthread.h both define

> > -    # that for you.

> > -    #

> > -    # So this #undef localtime_r and #include <unistd.h>

> > -    # are not in fact redundant.

> > -cat > $TMPC << EOF

> > -#include <unistd.h>

> > -#include <time.h>

> > -#undef localtime_r

> > -int main(void) { localtime_r(NULL, NULL); return 0; }

> > -EOF

> > -    if compile_prog "" "" ; then

> > -        localtime_r="yes"

> > -    else

> > -        localtime_r="no"

> > -    fi

> > -fi

> > -

> >  ##########################################

> >  # pkg-config probe

> >

> > @@ -7088,9 +7057,6 @@ if [ "$bsd" = "yes" ] ; then

> >    echo "CONFIG_BSD=y" >> $config_host_mak

> >  fi

> >

> > -if test "$localtime_r" = "yes" ; then

> > -  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak

> > -fi

> >  if test "$qom_cast_debug" = "yes" ; then

> >    echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak

> >  fi

> > diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h

> > index d8978e28c0..3ac8a53bac 100644

> > --- a/include/sysemu/os-win32.h

> > +++ b/include/sysemu/os-win32.h

> > @@ -48,12 +48,12 @@

> >  #define siglongjmp(env, val) longjmp(env, val)

> >

> >  /* Missing POSIX functions. Don't use MinGW-w64 macros. */

> > -#ifndef CONFIG_LOCALTIME_R

> > +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS

> >  #undef gmtime_r

> >  struct tm *gmtime_r(const time_t *timep, struct tm *result);

> >  #undef localtime_r

> >  struct tm *localtime_r(const time_t *timep, struct tm *result);

> > -#endif /* CONFIG_LOCALTIME_R */

> > +#endif

> >

> >  static inline void os_setup_signal_handling(void) {}

> >  static inline void os_daemonize(void) {}

> > diff --git a/util/oslib-win32.c b/util/oslib-win32.c

> > index c654dafd93..f2fa9a3549 100644

> > --- a/util/oslib-win32.c

> > +++ b/util/oslib-win32.c

> > @@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)

> >      }

> >  }

> >

> > -#ifndef CONFIG_LOCALTIME_R

> > +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS

> >  /* FIXME: add proper locking */

> >  struct tm *gmtime_r(const time_t *timep, struct tm *result)

> >  {

> > --

> > 2.28.0.windows.1

> >

> >

>

> Regards,

> Daniel

> --

> |: https://berrange.com      -o-

https://www.flickr.com/photos/dberrange :|
> |: https://libvirt.org         -o-

https://fstop138.berrange.com :|
> |: https://entangle-photo.org    -o-

https://www.instagram.com/dberrange :|
>



--
         此致
礼
罗勇刚
Yours
    sincerely,
Yonggang Luo
<div dir="ltr"><br><br>On Tue, Sep 15, 2020 at 9:00 PM Daniel P. Berrangé &lt;<a href="mailto:berrange@redhat.com">berrange@redhat.com</a>&gt; wrote:<br>&gt;<br>&gt; On Tue, Sep 15, 2020 at 08:12:56PM +0800, Yonggang Luo wrote:<br>&gt; &gt; First, this reduce the size of configure, configure are tending to removal in future,<br>&gt; &gt; and this didn&#39;t introduce any new feature or remove any exist feature.<br>&gt; &gt; Second, the current localtime_r detection are conflict with ncursesw detection in<br>&gt; &gt; mingw, when ncursesw detected, it will provide the following compile flags<br>&gt; &gt; pkg-config --cflags ncursesw<br>&gt; &gt; -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L -IC:/CI-Tools/msys64/mingw64/include/ncursesw<br>&gt; &gt; And the compile flag _POSIX_C_SOURCE will always cause _POSIX_THREAD_SAFE_FUNCTIONS to<br>&gt; &gt; be defined, in new version of mingw, that&#39;s will cause localtime_r to be defined.<br>&gt; &gt; But the configure script didn&#39;t provide _POSIX_C_SOURCE macro, and that&#39;s will result<br>&gt; &gt; localtime_r not detected because localtime_r are defined in forceinline manner.<br>&gt;<br>&gt; ncursesw is just one of the three curses impls we can select for<br>&gt; building against, so it doesn&#39;t feel right to make an assumption<br>&gt; that _POSIX_C_SOURCE is always defined.<br><br>That&#39;s what I am trying to do, not depends on if  _POSIX_C_SOURCE are defined.<br>After this patch, whenever   ncursesw or other  curses lib trying define or not define  _POSIX_C_SOURCE, the source will building properly<br>Because now, we don&#39;t make any assumption about 

_POSIX_C_SOURCE, but before this patch,<div>The configure always assume msys2/mingw `not define _POSIX_C_SOURCE ` at all.</div><div>Now this restriction are removed, only depends on mingw related 

_POSIX_THREAD_SAFE_FUNCTIONS 

<br>&gt;<br>&gt; &gt;<br>&gt; &gt; And finally cause conflict between QEMU defined localtime_r<br>&gt; &gt; struct tm *localtime_r(const time_t *timep, struct tm *result);<br>&gt; &gt; with mingw defined localtime_r<br>&gt; &gt;<br>&gt; &gt; ```<br>&gt; &gt; #if defined(_POSIX_C_SOURCE) &amp;&amp; !defined(_POSIX_THREAD_SAFE_FUNCTIONS)<br>&gt; &gt; #define _POSIX_THREAD_SAFE_FUNCTIONS 200112L<br>&gt; &gt; #endif<br>&gt; &gt;<br>&gt; &gt; #ifdef _POSIX_THREAD_SAFE_FUNCTIONS<br>&gt; &gt; __forceinline struct tm *__CRTDECL localtime_r(const time_t *_Time, struct tm *_Tm) {<br>&gt; &gt;   return localtime_s(_Tm, _Time) ? NULL : _Tm;<br>&gt; &gt; }<br>&gt; &gt; __forceinline struct tm *__CRTDECL gmtime_r(const time_t *_Time, struct tm *_Tm) {<br>&gt; &gt;   return gmtime_s(_Tm, _Time) ? NULL : _Tm;<br>&gt; &gt; }<br>&gt; &gt; __forceinline char *__CRTDECL ctime_r(const time_t *_Time, char *_Str) {<br>&gt; &gt;   return ctime_s(_Str, 0x7fffffff, _Time) ? NULL : _Str;<br>&gt; &gt; }<br>&gt; &gt; __forceinline char *__CRTDECL asctime_r(const struct tm *_Tm, char * _Str) {<br>&gt; &gt;   return asctime_s(_Str, 0x7fffffff, _Tm) ? NULL : _Str;<br>&gt; &gt; }<br>&gt; &gt; #endif<br>&gt; &gt; ```<br>&gt; &gt;<br>&gt; &gt; So I suggest remove this configure script, and restrict msys2/mingw version to easy to maintain.<br>&gt; &gt; And use _POSIX_THREAD_SAFE_FUNCTIONS to guard the localtime_r and counterpart functions<br>&gt; &gt;<br>&gt; &gt; Signed-off-by: Yonggang Luo &lt;<a href="mailto:luoyonggang@gmail.com">luoyonggang@gmail.com</a>&gt;<br>&gt; &gt; ---<br>&gt; &gt;  configure                 | 34 ----------------------------------<br>&gt; &gt;  include/sysemu/os-win32.h |  4 ++--<br>&gt; &gt;  util/oslib-win32.c        |  2 +-<br>&gt; &gt;  3 files changed, 3 insertions(+), 37 deletions(-)<br>&gt; &gt;<br>&gt; &gt; diff --git a/configure b/configure<br>&gt; &gt; index dc4b7a2e55..bac48b5b49 100755<br>&gt; &gt; --- a/configure<br>&gt; &gt; +++ b/configure<br>&gt; &gt; @@ -2496,37 +2496,6 @@ if test &quot;$vhost_net&quot; = &quot;&quot;; then<br>&gt; &gt;    test &quot;$vhost_kernel&quot; = &quot;yes&quot; &amp;&amp; vhost_net=yes<br>&gt; &gt;  fi<br>&gt; &gt; <br>&gt; &gt; -##########################################<br>&gt; &gt; -# MinGW / Mingw-w64 localtime_r/gmtime_r check<br>&gt; &gt; -<br>&gt; &gt; -if test &quot;$mingw32&quot; = &quot;yes&quot;; then<br>&gt; &gt; -    # Some versions of MinGW / Mingw-w64 lack localtime_r<br>&gt; &gt; -    # and gmtime_r entirely.<br>&gt; &gt; -    #<br>&gt; &gt; -    # Some versions of Mingw-w64 define a macro for<br>&gt; &gt; -    # localtime_r/gmtime_r.<br>&gt; &gt; -    #<br>&gt; &gt; -    # Some versions of Mingw-w64 will define functions<br>&gt; &gt; -    # for localtime_r/gmtime_r, but only if you have<br>&gt; &gt; -    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun<br>&gt; &gt; -    # though, unistd.h and pthread.h both define<br>&gt; &gt; -    # that for you.<br>&gt; &gt; -    #<br>&gt; &gt; -    # So this #undef localtime_r and #include &lt;unistd.h&gt;<br>&gt; &gt; -    # are not in fact redundant.<br>&gt; &gt; -cat &gt; $TMPC &lt;&lt; EOF<br>&gt; &gt; -#include &lt;unistd.h&gt;<br>&gt; &gt; -#include &lt;time.h&gt;<br>&gt; &gt; -#undef localtime_r<br>&gt; &gt; -int main(void) { localtime_r(NULL, NULL); return 0; }<br>&gt; &gt; -EOF<br>&gt; &gt; -    if compile_prog &quot;&quot; &quot;&quot; ; then<br>&gt; &gt; -        localtime_r=&quot;yes&quot;<br>&gt; &gt; -    else<br>&gt; &gt; -        localtime_r=&quot;no&quot;<br>&gt; &gt; -    fi<br>&gt; &gt; -fi<br>&gt; &gt; -<br>&gt; &gt;  ##########################################<br>&gt; &gt;  # pkg-config probe<br>&gt; &gt; <br>&gt; &gt; @@ -7088,9 +7057,6 @@ if [ &quot;$bsd&quot; = &quot;yes&quot; ] ; then<br>&gt; &gt;    echo &quot;CONFIG_BSD=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;  fi<br>&gt; &gt; <br>&gt; &gt; -if test &quot;$localtime_r&quot; = &quot;yes&quot; ; then<br>&gt; &gt; -  echo &quot;CONFIG_LOCALTIME_R=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt; -fi<br>&gt; &gt;  if test &quot;$qom_cast_debug&quot; = &quot;yes&quot; ; then<br>&gt; &gt;    echo &quot;CONFIG_QOM_CAST_DEBUG=y&quot; &gt;&gt; $config_host_mak<br>&gt; &gt;  fi<br>&gt; &gt; diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h<br>&gt; &gt; index d8978e28c0..3ac8a53bac 100644<br>&gt; &gt; --- a/include/sysemu/os-win32.h<br>&gt; &gt; +++ b/include/sysemu/os-win32.h<br>&gt; &gt; @@ -48,12 +48,12 @@<br>&gt; &gt;  #define siglongjmp(env, val) longjmp(env, val)<br>&gt; &gt; <br>&gt; &gt;  /* Missing POSIX functions. Don&#39;t use MinGW-w64 macros. */<br>&gt; &gt; -#ifndef CONFIG_LOCALTIME_R<br>&gt; &gt; +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS<br>&gt; &gt;  #undef gmtime_r<br>&gt; &gt;  struct tm *gmtime_r(const time_t *timep, struct tm *result);<br>&gt; &gt;  #undef localtime_r<br>&gt; &gt;  struct tm *localtime_r(const time_t *timep, struct tm *result);<br>&gt; &gt; -#endif /* CONFIG_LOCALTIME_R */<br>&gt; &gt; +#endif<br>&gt; &gt; <br>&gt; &gt;  static inline void os_setup_signal_handling(void) {}<br>&gt; &gt;  static inline void os_daemonize(void) {}<br>&gt; &gt; diff --git a/util/oslib-win32.c b/util/oslib-win32.c<br>&gt; &gt; index c654dafd93..f2fa9a3549 100644<br>&gt; &gt; --- a/util/oslib-win32.c<br>&gt; &gt; +++ b/util/oslib-win32.c<br>&gt; &gt; @@ -106,7 +106,7 @@ void qemu_anon_ram_free(void *ptr, size_t size)<br>&gt; &gt;      }<br>&gt; &gt;  }<br>&gt; &gt; <br>&gt; &gt; -#ifndef CONFIG_LOCALTIME_R<br>&gt; &gt; +#ifndef _POSIX_THREAD_SAFE_FUNCTIONS<br>&gt; &gt;  /* FIXME: add proper locking */<br>&gt; &gt;  struct tm *gmtime_r(const time_t *timep, struct tm *result)<br>&gt; &gt;  {<br>&gt; &gt; --<br>&gt; &gt; 2.28.0.windows.1<br>&gt; &gt;<br>&gt; &gt;<br>&gt;<br>&gt; Regards,<br>&gt; Daniel<br>&gt; --<br>&gt; |: <a href="https://berrange.com">https://berrange.com</a>      -o-    <a href="https://www.flickr.com/photos/dberrange">https://www.flickr.com/photos/dberrange</a> :|<br>&gt; |: <a href="https://libvirt.org">https://libvirt.org</a>         -o-            <a href="https://fstop138.berrange.com">https://fstop138.berrange.com</a> :|<br>&gt; |: <a href="https://entangle-photo.org">https://entangle-photo.org</a>    -o-    <a href="https://www.instagram.com/dberrange">https://www.instagram.com/dberrange</a> :|<br>&gt;<br><br><br>--<br>         此致<br>礼<br>罗勇刚<br>Yours<br>    sincerely,<br>Yonggang Luo</div></div>
diff mbox series

Patch

diff --git a/configure b/configure
index dc4b7a2e55..bac48b5b49 100755
--- a/configure
+++ b/configure
@@ -2496,37 +2496,6 @@  if test "$vhost_net" = ""; then
   test "$vhost_kernel" = "yes" && vhost_net=yes
 fi
 
-##########################################
-# MinGW / Mingw-w64 localtime_r/gmtime_r check
-
-if test "$mingw32" = "yes"; then
-    # Some versions of MinGW / Mingw-w64 lack localtime_r
-    # and gmtime_r entirely.
-    #
-    # Some versions of Mingw-w64 define a macro for
-    # localtime_r/gmtime_r.
-    #
-    # Some versions of Mingw-w64 will define functions
-    # for localtime_r/gmtime_r, but only if you have
-    # _POSIX_THREAD_SAFE_FUNCTIONS defined. For fun
-    # though, unistd.h and pthread.h both define
-    # that for you.
-    #
-    # So this #undef localtime_r and #include <unistd.h>
-    # are not in fact redundant.
-cat > $TMPC << EOF
-#include <unistd.h>
-#include <time.h>
-#undef localtime_r
-int main(void) { localtime_r(NULL, NULL); return 0; }
-EOF
-    if compile_prog "" "" ; then
-        localtime_r="yes"
-    else
-        localtime_r="no"
-    fi
-fi
-
 ##########################################
 # pkg-config probe
 
@@ -7088,9 +7057,6 @@  if [ "$bsd" = "yes" ] ; then
   echo "CONFIG_BSD=y" >> $config_host_mak
 fi
 
-if test "$localtime_r" = "yes" ; then
-  echo "CONFIG_LOCALTIME_R=y" >> $config_host_mak
-fi
 if test "$qom_cast_debug" = "yes" ; then
   echo "CONFIG_QOM_CAST_DEBUG=y" >> $config_host_mak
 fi
diff --git a/include/sysemu/os-win32.h b/include/sysemu/os-win32.h
index d8978e28c0..3ac8a53bac 100644
--- a/include/sysemu/os-win32.h
+++ b/include/sysemu/os-win32.h
@@ -48,12 +48,12 @@ 
 #define siglongjmp(env, val) longjmp(env, val)
 
 /* Missing POSIX functions. Don't use MinGW-w64 macros. */
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 #undef gmtime_r
 struct tm *gmtime_r(const time_t *timep, struct tm *result);
 #undef localtime_r
 struct tm *localtime_r(const time_t *timep, struct tm *result);
-#endif /* CONFIG_LOCALTIME_R */
+#endif
 
 static inline void os_setup_signal_handling(void) {}
 static inline void os_daemonize(void) {}
diff --git a/util/oslib-win32.c b/util/oslib-win32.c
index c654dafd93..f2fa9a3549 100644
--- a/util/oslib-win32.c
+++ b/util/oslib-win32.c
@@ -106,7 +106,7 @@  void qemu_anon_ram_free(void *ptr, size_t size)
     }
 }
 
-#ifndef CONFIG_LOCALTIME_R
+#ifndef _POSIX_THREAD_SAFE_FUNCTIONS
 /* FIXME: add proper locking */
 struct tm *gmtime_r(const time_t *timep, struct tm *result)
 {