[v16,03/15] windows: add os shim for localtime_r

Message ID 20240327164726.68732-4-stephen@networkplumber.org (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series Logging unification and improvements |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Stephen Hemminger March 27, 2024, 4:45 p.m. UTC
  Windows does not have localtime_r but it does have a similar
function that can be used instead.

Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
---
 lib/eal/windows/include/rte_os_shim.h | 10 ++++++++++
 1 file changed, 10 insertions(+)
  

Comments

Tyler Retzlaff March 27, 2024, 4:56 p.m. UTC | #1
On Wed, Mar 27, 2024 at 09:45:21AM -0700, Stephen Hemminger wrote:
> Windows does not have localtime_r but it does have a similar
> function that can be used instead.
> 
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  lib/eal/windows/include/rte_os_shim.h | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
> index eda8113662..e9741a9df2 100644
> --- a/lib/eal/windows/include/rte_os_shim.h
> +++ b/lib/eal/windows/include/rte_os_shim.h
> @@ -110,4 +110,14 @@ rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
>  }
>  #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
>  
> +static inline struct tm *
> +rte_localtime_r(const time_t *timer, struct tm *buf)
> +{
> +	if (localtime_s(buf, timer) == 0)
> +		return buf;
> +	else
> +		return NULL;
> +}
> +#define localtime_r(timer, buf) rte_localtime_r(timer, buf)

hm, i'm always a bit concerned about expressing platform standard names
from dpdk api surface. i think we should just expose and use
rte_localtime_r() and not present localtime_r.

can be treated as a suggestion.

Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
  
Stephen Hemminger March 27, 2024, 5:30 p.m. UTC | #2
On Wed, 27 Mar 2024 09:56:59 -0700
Tyler Retzlaff <roretzla@linux.microsoft.com> wrote:

> On Wed, Mar 27, 2024 at 09:45:21AM -0700, Stephen Hemminger wrote:
> > Windows does not have localtime_r but it does have a similar
> > function that can be used instead.
> > 
> > Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> > ---
> >  lib/eal/windows/include/rte_os_shim.h | 10 ++++++++++
> >  1 file changed, 10 insertions(+)
> > 
> > diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
> > index eda8113662..e9741a9df2 100644
> > --- a/lib/eal/windows/include/rte_os_shim.h
> > +++ b/lib/eal/windows/include/rte_os_shim.h
> > @@ -110,4 +110,14 @@ rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
> >  }
> >  #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
> >  
> > +static inline struct tm *
> > +rte_localtime_r(const time_t *timer, struct tm *buf)
> > +{
> > +	if (localtime_s(buf, timer) == 0)
> > +		return buf;
> > +	else
> > +		return NULL;
> > +}
> > +#define localtime_r(timer, buf) rte_localtime_r(timer, buf)  
> 
> hm, i'm always a bit concerned about expressing platform standard names
> from dpdk api surface. i think we should just expose and use
> rte_localtime_r() and not present localtime_r.
> 
> can be treated as a suggestion.
> 
> Acked-by: Tyler Retzlaff <roretzla@linux.microsoft.com>
> 

I was just copying what clock_gettime was doing.
But yes, should really do global update to rte_localtime()
  

Patch

diff --git a/lib/eal/windows/include/rte_os_shim.h b/lib/eal/windows/include/rte_os_shim.h
index eda8113662..e9741a9df2 100644
--- a/lib/eal/windows/include/rte_os_shim.h
+++ b/lib/eal/windows/include/rte_os_shim.h
@@ -110,4 +110,14 @@  rte_clock_gettime(clockid_t clock_id, struct timespec *tp)
 }
 #define clock_gettime(clock_id, tp) rte_clock_gettime(clock_id, tp)
 
+static inline struct tm *
+rte_localtime_r(const time_t *timer, struct tm *buf)
+{
+	if (localtime_s(buf, timer) == 0)
+		return buf;
+	else
+		return NULL;
+}
+#define localtime_r(timer, buf) rte_localtime_r(timer, buf)
+
 #endif /* _RTE_OS_SHIM_ */