From patchwork Tue Sep 18 21:04:54 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 29449 Received: (qmail 11003 invoked by alias); 18 Sep 2018 21:05:02 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 10955 invoked by uid 89); 18 Sep 2018 21:05:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-24.1 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_NUMSUBJECT, RCVD_IN_BL_SPAMCOP_NET, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=compared X-HELO: smtp3-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [PATCH] Y2038: add function __difftime64 Date: Tue, 18 Sep 2018 23:04:54 +0200 Message-Id: <20180918210454.30488-1-albert.aribaud@3adev.fr> * __difftime: provide a 64-bit-time version (but do not assume __time64_t is a signed int so that Gnulib can reuse the code) and make the 32-bit version a wrapper of it. --- This patch is part of the Y2038 patch series, which is available at . Warning: this branch may be rebased on current master and/or updated based on feedback from the list at any time. include/time.h | 6 ++++++ time/difftime.c | 31 ++++++++++++++++++++++--------- 2 files changed, 28 insertions(+), 9 deletions(-) diff --git a/include/time.h b/include/time.h index 62c0e11f18..0c5c00218a 100644 --- a/include/time.h +++ b/include/time.h @@ -125,6 +125,12 @@ extern char * __strptime_internal (const char *rp, const char *fmt, struct tm *tm, void *statep, locale_t locparam) attribute_hidden; +#if __TIMESIZE == 64 +# define __difftime64 __difftime +#else +extern double __difftime64 (__time64_t time1, __time64_t time0); +#endif + extern double __difftime (time_t time1, time_t time0); /* Use in the clock_* functions. Size of the field representing the diff --git a/time/difftime.c b/time/difftime.c index 7c5dd9898b..e3a4e57b44 100644 --- a/time/difftime.c +++ b/time/difftime.c @@ -31,9 +31,9 @@ time_t is known to be an integer type. */ static double -subtract (time_t time1, time_t time0) +subtract (__time64_t time1, __time64_t time0) { - if (! TYPE_SIGNED (time_t)) + if (! TYPE_SIGNED (__time64_t)) return time1 - time0; else { @@ -76,9 +76,9 @@ subtract (time_t time1, time_t time0) 1 is unsigned in C, so it need not be compared to zero. */ uintmax_t hdt = dt / 2; - time_t ht1 = time1 / 2; - time_t ht0 = time0 / 2; - time_t dht = ht1 - ht0; + __time64_t ht1 = time1 / 2; + __time64_t ht0 = time0 / 2; + __time64_t dht = ht1 - ht0; if (2 < dht - hdt + 1) { @@ -99,18 +99,18 @@ subtract (time_t time1, time_t time0) /* Return the difference between TIME1 and TIME0. */ double -__difftime (time_t time1, time_t time0) +__difftime64 (__time64_t time1, __time64_t time0) { /* Convert to double and then subtract if no double-rounding error could result. */ - if (TYPE_BITS (time_t) <= DBL_MANT_DIG - || (TYPE_FLOATING (time_t) && sizeof (time_t) < sizeof (long double))) + if (TYPE_BITS (__time64_t) <= DBL_MANT_DIG + || (TYPE_FLOATING (__time64_t) && sizeof (__time64_t) < sizeof (long double))) return (double) time1 - (double) time0; /* Likewise for long double. */ - if (TYPE_BITS (time_t) <= LDBL_MANT_DIG || TYPE_FLOATING (time_t)) + if (TYPE_BITS (__time64_t) <= LDBL_MANT_DIG || TYPE_FLOATING (__time64_t)) return (long double) time1 - (long double) time0; /* Subtract the smaller integer from the larger, convert the difference to @@ -118,4 +118,17 @@ __difftime (time_t time1, time_t time0) return time1 < time0 ? - subtract (time0, time1) : subtract (time1, time0); } + +/* Provide a 32-bit wrapper if needed */ + +#if __TIMESIZE != 64 + +double +__difftime (time_t time1, time_t time0) +{ + return __difftime64 (time1, time0); +} + +#endif + strong_alias (__difftime, difftime)