From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.7 required=3.0 tests=AWL,BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,SPF_PASS shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dcvr.yhbt.net (Postfix) with ESMTPS id 2592B1F4B4 for ; Sat, 2 Jan 2021 12:19:03 +0000 (UTC) Received: from localhost ([::1]:56916 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kvfs5-0006KG-Vi for normalperson@yhbt.net; Sat, 02 Jan 2021 07:19:02 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:43476) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvfry-0006K4-At for bug-gnulib@gnu.org; Sat, 02 Jan 2021 07:18:54 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([85.215.255.20]:21564) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kvfrs-0005Wd-Tr for bug-gnulib@gnu.org; Sat, 02 Jan 2021 07:18:54 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1609589924; s=strato-dkim-0002; d=clisp.org; h=Message-ID:Date:Subject:To:From:From:Subject:Sender; bh=DLg1kq5i9vbOCjSS2np8Dse+6XPPk/HuCkuRkWKoBpw=; b=PwJQQp4nQhEBiRwBZILFPg2FCMy3wu3OH8SEvwp9gUVFx4V/9TrSogsvNFPbcPMdgW teaysIQGfsu0iX/VAfFQbsbzI43wVse6Vk1JEcscQZZ8kCAGLA/GwDJkJd/ymSWdRFOE WDwJ1TEo2PG4x3u3U4tOAtbVRMNvhY4sdUprUI//a5nQM8cnWvTJ8dol7s0dPIMNECn0 WuWO0AhqIytoT0jRijVbGd/sgU4uufBC48U3zmgeVJl09snfE2LkgSpVkb+41Q9VfdqM GzoK+8IuLiePml+AeKqE++UD6WFbBgtQV78qdKoUrhTAUYtjH1IugHPILB9L3piXtGTz rSjA== X-RZG-AUTH: ":Ln4Re0+Ic/6oZXR1YgKryK8brlshOcZlIWs+iCP5vnk6shH+AHjwLuWOH6f3z/s=" X-RZG-CLASS-ID: mo00 Received: from bruno.haible.de by smtp.strato.de (RZmta 47.10.7 DYNA|AUTH) with ESMTPSA id e012d5x02CIhYiS (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve X9_62_prime256v1 with 256 ECDH bits, eq. 3072 bits RSA)) (Client did not present a certificate); Sat, 2 Jan 2021 13:18:43 +0100 (CET) From: Bruno Haible To: bug-gnulib@gnu.org Subject: new module 'timespec_get' Date: Sat, 02 Jan 2021 13:18:42 +0100 Message-ID: <9817572.ReJq3WGe1u@omega> User-Agent: KMail/5.1.3 (Linux/4.4.0-197-generic; KDE/5.18.0; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1615815.jIGf4Z3RxX" Content-Transfer-Encoding: 7Bit Received-SPF: none client-ip=85.215.255.20; envelope-from=bruno@clisp.org; helo=mo4-p00-ob.smtp.rzone.de X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H3=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_PASS=-0.001, SPF_NONE=0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: bug-gnulib@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Gnulib discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnulib-bounces+normalperson=yhbt.net@gnu.org Sender: "bug-gnulib" This is a multi-part message in MIME format. --nextPart1615815.jIGf4Z3RxX Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" One of the glibc functions that was added in 2012 already is actually specified in ISO C 11: 'timespec_get'. This set of patches implements it, as a thin wrapper around the 'gettime' module. 2021-01-02 Bruno Haible timespec_get: Add tests. * tests/test-timespec_get.c: New file. * modules/timespec_get-tests: New file. timespec_get: New module. * lib/time.in.h (timespec_get): New declaration. * lib/timespec_get.c: New file. * m4/timespec_get.m4: New file. * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET. * modules/time (Makefile.am): Substitute GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET. * modules/timespec_get: New file. * tests/test-time-c++.cc (timespec_get): Check signature. * doc/glibc-functions/timespec_get.texi: Mention the new module. 2021-01-01 Bruno Haible time: Define TIME_UTC. * lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros. * m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC. * modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC. * tests/test-time.c: Check that TIME_UTC is defined and a positive integer. * doc/posix-headers/time.texi: Mention TIME_UTC. --nextPart1615815.jIGf4Z3RxX Content-Disposition: attachment; filename="0001-time-Define-TIME_UTC.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0001-time-Define-TIME_UTC.patch" >From 2d4f9d5c5a0c6dbdc2fbe34c42fe9cd74f162af3 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 2 Jan 2021 00:14:05 +0100 Subject: [PATCH 1/3] time: Define TIME_UTC. * lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros. * m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC. * modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC. * tests/test-time.c: Check that TIME_UTC is defined and a positive integer. * doc/posix-headers/time.texi: Mention TIME_UTC. --- ChangeLog | 10 ++++++++++ doc/posix-headers/time.texi | 6 ++++-- lib/time.in.h | 8 ++++++++ m4/time_h.m4 | 18 +++++++++++++++++- modules/time | 1 + tests/test-time.c | 4 ++++ 6 files changed, 44 insertions(+), 3 deletions(-) diff --git a/ChangeLog b/ChangeLog index 16fafe4..f222500 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,15 @@ 2021-01-01 Bruno Haible + time: Define TIME_UTC. + * lib/time.in.h (TIME_UTC, GNULIB_defined_TIME_UTC): New macros. + * m4/time_h.m4 (gl_HEADER_TIME_H_BODY): Set TIME_H_DEFINES_TIME_UTC. + * modules/time (Makefile.am): Substitute TIME_H_DEFINES_TIME_UTC. + * tests/test-time.c: Check that TIME_UTC is defined and a positive + integer. + * doc/posix-headers/time.texi: Mention TIME_UTC. + +2021-01-01 Bruno Haible + stddef: Try harder to get max_align_t defined on OpenBSD, part 2. * modules/stddef (Depends-on): Add extensions. diff --git a/doc/posix-headers/time.texi b/doc/posix-headers/time.texi index 980212c..9d25ed2 100644 --- a/doc/posix-headers/time.texi +++ b/doc/posix-headers/time.texi @@ -9,11 +9,13 @@ Portability problems fixed by Gnulib: @itemize @item @samp{struct timespec} is not defined on some platforms. - +@item +The macro @code{TIME_UTC} is not defined on many platforms: +glibc 2.15, Mac OS X 10.13, FreeBSD 6.4, NetBSD 7.1, OpenBSD 6.0, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @item Some platforms provide a @code{NULL} macro that cannot be used in arbitrary expressions: -NetBSD 5.0 +NetBSD 5.0. @end itemize Portability problems not fixed by Gnulib: diff --git a/lib/time.in.h b/lib/time.in.h index 9ed57e4..33c4dad 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -101,6 +101,14 @@ struct __time_t_must_be_integral { # define GNULIB_defined_struct_time_t_must_be_integral 1 # endif +/* Define TIME_UTC, a positive integer constant used for timespec_get(). */ +# if ! @TIME_H_DEFINES_TIME_UTC@ +# if !GNULIB_defined_TIME_UTC +# define TIME_UTC 1 +# define GNULIB_defined_TIME_UTC 1 +# endif +# endif + /* Sleep for at least RQTP seconds unless interrupted, If interrupted, return -1 and store the remaining time into RMTP. See . */ diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 07e6967..439ee74 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -2,7 +2,7 @@ # Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc. -# serial 13 +# serial 14 # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -25,6 +25,22 @@ AC_DEFUN([gl_HEADER_TIME_H_BODY], AC_REQUIRE([gl_CHECK_TYPE_STRUCT_TIMESPEC]) AC_REQUIRE([AC_C_RESTRICT]) + + AC_CACHE_CHECK([for TIME_UTC in ], + [gl_cv_time_h_has_TIME_UTC], + [AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [[#include + ]], + [[static int x = TIME_UTC; x++;]])], + [gl_cv_time_h_has_TIME_UTC=yes], + [gl_cv_time_h_has_TIME_UTC=no])]) + if test $gl_cv_time_h_has_TIME_UTC = yes; then + TIME_H_DEFINES_TIME_UTC=1 + else + TIME_H_DEFINES_TIME_UTC=0 + fi + AC_SUBST([TIME_H_DEFINES_TIME_UTC]) ]) dnl Check whether 'struct timespec' is declared diff --git a/modules/time b/modules/time index 2f91fa3..2932375 100644 --- a/modules/time +++ b/modules/time @@ -58,6 +58,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''SYS_TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(SYS_TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ -e 's|@''TIME_H_DEFINES_STRUCT_TIMESPEC''@|$(TIME_H_DEFINES_STRUCT_TIMESPEC)|g' \ -e 's|@''UNISTD_H_DEFINES_STRUCT_TIMESPEC''@|$(UNISTD_H_DEFINES_STRUCT_TIMESPEC)|g' \ + -e 's|@''TIME_H_DEFINES_TIME_UTC''@|$(TIME_H_DEFINES_TIME_UTC)|g' \ -e '/definitions of _GL_FUNCDECL_RPL/r $(CXXDEFS_H)' \ -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \ -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \ diff --git a/tests/test-time.c b/tests/test-time.c index a3a3276..e5a4522 100644 --- a/tests/test-time.c +++ b/tests/test-time.c @@ -34,6 +34,10 @@ pid_t t2; per POSIX 2008. */ verify (sizeof NULL == sizeof (void *)); +/* Check that TIME_UTC is defined and a positive integer. */ +int t3 = TIME_UTC; +verify (TIME_UTC > 0); + int main (void) { -- 2.7.4 --nextPart1615815.jIGf4Z3RxX Content-Disposition: attachment; filename="0002-timespec_get-New-module.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0002-timespec_get-New-module.patch" >From caf114a384a66c506ad1304197264cfac64f1fbc Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 2 Jan 2021 13:14:08 +0100 Subject: [PATCH 2/3] timespec_get: New module. * lib/time.in.h (timespec_get): New declaration. * lib/timespec_get.c: New file. * m4/timespec_get.m4: New file. * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET. * modules/time (Makefile.am): Substitute GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET. * modules/timespec_get: New file. * tests/test-time-c++.cc (timespec_get): Check signature. * doc/glibc-functions/timespec_get.texi: Mention the new module. --- ChangeLog | 14 ++++++++++++++ doc/glibc-functions/timespec_get.texi | 8 ++++---- lib/time.in.h | 11 +++++++++++ lib/timespec_get.c | 33 +++++++++++++++++++++++++++++++++ m4/time_h.m4 | 4 +++- m4/timespec_get.m4 | 18 ++++++++++++++++++ modules/time | 2 ++ modules/timespec_get | 32 ++++++++++++++++++++++++++++++++ tests/test-time-c++.cc | 4 ++++ 9 files changed, 121 insertions(+), 5 deletions(-) create mode 100644 lib/timespec_get.c create mode 100644 m4/timespec_get.m4 create mode 100644 modules/timespec_get diff --git a/ChangeLog b/ChangeLog index f222500..899f7a1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2021-01-02 Bruno Haible + + timespec_get: New module. + * lib/time.in.h (timespec_get): New declaration. + * lib/timespec_get.c: New file. + * m4/timespec_get.m4: New file. + * m4/time_h.m4 (gl_HEADER_TIME_H_DEFAULTS): Initialize + GNULIB_TIMESPEC_GET, HAVE_TIMESPEC_GET. + * modules/time (Makefile.am): Substitute GNULIB_TIMESPEC_GET, + HAVE_TIMESPEC_GET. + * modules/timespec_get: New file. + * tests/test-time-c++.cc (timespec_get): Check signature. + * doc/glibc-functions/timespec_get.texi: Mention the new module. + 2021-01-01 Bruno Haible time: Define TIME_UTC. diff --git a/doc/glibc-functions/timespec_get.texi b/doc/glibc-functions/timespec_get.texi index 8113a9b..c5cf236 100644 --- a/doc/glibc-functions/timespec_get.texi +++ b/doc/glibc-functions/timespec_get.texi @@ -2,15 +2,15 @@ @subsection @code{timespec_get} @findex timespec_get -Gnulib module: --- +Gnulib module: timespec_get Portability problems fixed by Gnulib: @itemize +@item +This function is missing on many platforms: +glibc 2.15, Mac OS X 10.13, FreeBSD 6.4, NetBSD 7.1, OpenBSD 6.0, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @end itemize Portability problems not fixed by Gnulib: @itemize -@item -This function is missing on many platforms: -glibc 2.15, Mac OS X 10.13, FreeBSD 6.4, NetBSD 7.1, OpenBSD 6.0, Minix 3.1.8, AIX 7.1, HP-UX 11.31, IRIX 6.5, Solaris 11.3, Cygwin 2.9, mingw, MSVC 14, Android 9.0. @end itemize diff --git a/lib/time.in.h b/lib/time.in.h index 33c4dad..4da1172 100644 --- a/lib/time.in.h +++ b/lib/time.in.h @@ -109,6 +109,17 @@ struct __time_t_must_be_integral { # endif # endif +/* Set *TS to the current time, and return BASE. + Upon failure, return 0. */ +# if @GNULIB_TIMESPEC_GET@ +# if ! @HAVE_TIMESPEC_GET@ +_GL_FUNCDECL_SYS (timespec_get, int, (struct timespec *ts, int base) + _GL_ARG_NONNULL ((1))); +# endif +_GL_CXXALIAS_SYS (timespec_get, int, (struct timespec *ts, int base)); +_GL_CXXALIASWARN (timespec_get); +# endif + /* Sleep for at least RQTP seconds unless interrupted, If interrupted, return -1 and store the remaining time into RMTP. See . */ diff --git a/lib/timespec_get.c b/lib/timespec_get.c new file mode 100644 index 0000000..d738c12 --- /dev/null +++ b/lib/timespec_get.c @@ -0,0 +1,33 @@ +/* timespec_get() function. + Copyright (C) 2021 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +#include + +/* Specification. */ +#include + +#include "timespec.h" + +int +timespec_get (struct timespec *ts, int base) +{ + if (base == TIME_UTC) + { + gettime (ts); + return base; + } + return 0; +} diff --git a/m4/time_h.m4 b/m4/time_h.m4 index 439ee74..b6a1aa3 100644 --- a/m4/time_h.m4 +++ b/m4/time_h.m4 @@ -2,7 +2,7 @@ # Copyright (C) 2000-2001, 2003-2007, 2009-2021 Free Software Foundation, Inc. -# serial 14 +# serial 15 # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -129,6 +129,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], GNULIB_STRFTIME=0; AC_SUBST([GNULIB_STRFTIME]) GNULIB_STRPTIME=0; AC_SUBST([GNULIB_STRPTIME]) GNULIB_TIMEGM=0; AC_SUBST([GNULIB_TIMEGM]) + GNULIB_TIMESPEC_GET=0; AC_SUBST([GNULIB_TIMESPEC_GET]) GNULIB_TIME_R=0; AC_SUBST([GNULIB_TIME_R]) GNULIB_TIME_RZ=0; AC_SUBST([GNULIB_TIME_RZ]) GNULIB_TZSET=0; AC_SUBST([GNULIB_TZSET]) @@ -139,6 +140,7 @@ AC_DEFUN([gl_HEADER_TIME_H_DEFAULTS], HAVE_NANOSLEEP=1; AC_SUBST([HAVE_NANOSLEEP]) HAVE_STRPTIME=1; AC_SUBST([HAVE_STRPTIME]) HAVE_TIMEGM=1; AC_SUBST([HAVE_TIMEGM]) + HAVE_TIMESPEC_GET=1; AC_SUBST([HAVE_TIMESPEC_GET]) dnl Even GNU libc does not have timezone_t yet. HAVE_TIMEZONE_T=0; AC_SUBST([HAVE_TIMEZONE_T]) dnl If another module says to replace or to not replace, do that. diff --git a/m4/timespec_get.m4 b/m4/timespec_get.m4 new file mode 100644 index 0000000..a4a3b78 --- /dev/null +++ b/m4/timespec_get.m4 @@ -0,0 +1,18 @@ +# timespec_get.m4 serial 1 +dnl Copyright (C) 2021 Free Software Foundation, Inc. +dnl This file is free software; the Free Software Foundation +dnl gives unlimited permission to copy and/or distribute it, +dnl with or without modifications, as long as this notice is preserved. + +AC_DEFUN([gl_FUNC_TIMESPEC_GET], +[ + AC_REQUIRE([gl_HEADER_TIME_H_DEFAULTS]) + + dnl Persuade OpenBSD to declare timespec_get(). + AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS]) + + AC_CHECK_FUNCS_ONCE([timespec_get]) + if test $ac_cv_func_timespec_get != yes; then + HAVE_TIMESPEC_GET=0 + fi +]) diff --git a/modules/time b/modules/time index 2932375..c0fb27d 100644 --- a/modules/time +++ b/modules/time @@ -36,6 +36,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's/@''GNULIB_STRFTIME''@/$(GNULIB_STRFTIME)/g' \ -e 's/@''GNULIB_STRPTIME''@/$(GNULIB_STRPTIME)/g' \ -e 's/@''GNULIB_TIMEGM''@/$(GNULIB_TIMEGM)/g' \ + -e 's/@''GNULIB_TIMESPEC_GET''@/$(GNULIB_TIMESPEC_GET)/g' \ -e 's/@''GNULIB_TIME_R''@/$(GNULIB_TIME_R)/g' \ -e 's/@''GNULIB_TIME_RZ''@/$(GNULIB_TIME_RZ)/g' \ -e 's/@''GNULIB_TZSET''@/$(GNULIB_TZSET)/g' \ @@ -44,6 +45,7 @@ time.h: time.in.h $(top_builddir)/config.status $(CXXDEFS_H) $(ARG_NONNULL_H) $( -e 's|@''HAVE_NANOSLEEP''@|$(HAVE_NANOSLEEP)|g' \ -e 's|@''HAVE_STRPTIME''@|$(HAVE_STRPTIME)|g' \ -e 's|@''HAVE_TIMEGM''@|$(HAVE_TIMEGM)|g' \ + -e 's|@''HAVE_TIMESPEC_GET''@|$(HAVE_TIMESPEC_GET)|g' \ -e 's|@''HAVE_TIMEZONE_T''@|$(HAVE_TIMEZONE_T)|g' \ -e 's|@''REPLACE_CTIME''@|$(REPLACE_CTIME)|g' \ -e 's|@''REPLACE_GMTIME''@|$(REPLACE_GMTIME)|g' \ diff --git a/modules/timespec_get b/modules/timespec_get new file mode 100644 index 0000000..51efed3 --- /dev/null +++ b/modules/timespec_get @@ -0,0 +1,32 @@ +Description: +timespec_get() function: return the current time with up to nanosecond resolution + +Files: +lib/timespec_get.c +m4/timespec_get.m4 + +Depends-on: +time +extensions +gettime [test $HAVE_TIMESPEC_GET = 0] + +configure.ac: +gl_FUNC_TIMESPEC_GET +if test $HAVE_TIMESPEC_GET = 0; then + AC_LIBOBJ([timespec_get]) +fi +gl_TIME_MODULE_INDICATOR([timespec_get]) + +Makefile.am: + +Include: + + +Link: +$(LIB_CLOCK_GETTIME) + +License: +LGPL + +Maintainer: +all diff --git a/tests/test-time-c++.cc b/tests/test-time-c++.cc index 07fff99..cdcd61e 100644 --- a/tests/test-time-c++.cc +++ b/tests/test-time-c++.cc @@ -24,6 +24,10 @@ #include "signature.h" +#if GNULIB_TEST_TIMESPEC_GET +SIGNATURE_CHECK (GNULIB_NAMESPACE::timespec_get, int, (struct timespec *, int)); +#endif + #if GNULIB_TEST_NANOSLEEP SIGNATURE_CHECK (GNULIB_NAMESPACE::nanosleep, int, (struct timespec const *, struct timespec *)); -- 2.7.4 --nextPart1615815.jIGf4Z3RxX Content-Disposition: attachment; filename="0003-timespec_get-Add-tests.patch" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="0003-timespec_get-Add-tests.patch" >From 880a723a4976abf6ae22731bd75416b938157f30 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 2 Jan 2021 13:15:06 +0100 Subject: [PATCH 3/3] timespec_get: Add tests. * tests/test-timespec_get.c: New file. * modules/timespec_get-tests: New file. --- ChangeLog | 4 ++++ modules/timespec_get-tests | 13 +++++++++++ tests/test-timespec_get.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 modules/timespec_get-tests create mode 100644 tests/test-timespec_get.c diff --git a/ChangeLog b/ChangeLog index 899f7a1..5d5c05a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2021-01-02 Bruno Haible + timespec_get: Add tests. + * tests/test-timespec_get.c: New file. + * modules/timespec_get-tests: New file. + timespec_get: New module. * lib/time.in.h (timespec_get): New declaration. * lib/timespec_get.c: New file. diff --git a/modules/timespec_get-tests b/modules/timespec_get-tests new file mode 100644 index 0000000..f13e199 --- /dev/null +++ b/modules/timespec_get-tests @@ -0,0 +1,13 @@ +Files: +tests/test-timespec_get.c +tests/signature.h +tests/macros.h + +Depends-on: + +configure.ac: + +Makefile.am: +TESTS += test-timespec_get +check_PROGRAMS += test-timespec_get +test_timespec_get_LDADD = $(LDADD) @LIB_CLOCK_GETTIME@ diff --git a/tests/test-timespec_get.c b/tests/test-timespec_get.c new file mode 100644 index 0000000..65555b3 --- /dev/null +++ b/tests/test-timespec_get.c @@ -0,0 +1,54 @@ +/* Test of timespec_get() function. + Copyright (C) 2021 Free Software Foundation, Inc. + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . */ + +/* Written by Bruno Haible. */ + +#include + +#include + +#include "signature.h" +SIGNATURE_CHECK (timespec_get, int, (struct timespec *ts, int base)); + +#include "macros.h" + +int +main (void) +{ + struct timespec ts1; + time_t tt2; + struct timespec ts3; + time_t tt4; + + ASSERT (timespec_get (&ts1, TIME_UTC)); + tt2 = time (NULL); + ASSERT (timespec_get (&ts3, TIME_UTC)); + tt4 = time (NULL); + + /* Verify monotonicity of timespec_get(). */ + ASSERT (ts1.tv_sec < ts3.tv_sec + || (ts1.tv_sec == ts3.tv_sec && ts1.tv_nsec <= ts3.tv_nsec)); + + /* Verify monotonicity of time(). */ + ASSERT (tt2 <= tt4); + + /* Verify that the tv_sec field of the result is the same as time(NULL). */ + ASSERT (ts1.tv_sec <= tt2); + ASSERT (tt2 <= ts3.tv_sec); + ASSERT (ts3.tv_sec <= tt4); + + return 0; +} -- 2.7.4 --nextPart1615815.jIGf4Z3RxX--