From patchwork Wed Apr 18 20:17:18 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Albert ARIBAUD X-Patchwork-Id: 26781 Received: (qmail 97251 invoked by alias); 18 Apr 2018 20:18:43 -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 97139 invoked by uid 89); 18 Apr 2018 20:18:42 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-24.8 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_DNSWL_LOW, RCVD_IN_RP_RNBL autolearn=ham version=3.3.2 spammy=counterpart X-HELO: smtp3-g21.free.fr From: "Albert ARIBAUD (3ADEV)" To: libc-alpha@sourceware.org Cc: "Albert ARIBAUD (3ADEV)" Subject: [[PATCH RFC 2] 02/63] Y2038: add function __difftime64 Date: Wed, 18 Apr 2018 22:17:18 +0200 Message-Id: <20180418201819.15952-3-albert.aribaud@3adev.fr> In-Reply-To: <20180418201819.15952-2-albert.aribaud@3adev.fr> References: <20180418201819.15952-1-albert.aribaud@3adev.fr> <20180418201819.15952-2-albert.aribaud@3adev.fr> Note: 1. The implementation expects __time64_t arguments, and could, in theory, require 64 bits to express the difference accurately; but it returns a double, which only provides about 55 significant bits. We could make it return a long double, which would be more than enough for 64 bits accuracy. But then, existing source code which uses difftime, and therefore stores difftime results in doubles, would need to change to long doubles. However, we want 64-bit time support to work without any application source code change. Besides, 55 bits allow for counting seconds accurately over 417 billion years, which is arguably enough for most actual uses of difftime. 2. The implementation is simpler than its 32-bit counterpart, as it assumes that all __time64_t implementations are 64-bit integers. --- include/time.h | 2 ++ time/Versions | 3 +++ time/difftime.c | 9 +++++++++ 3 files changed, 14 insertions(+) diff --git a/include/time.h b/include/time.h index 7eda265a66..ba2c67a829 100644 --- a/include/time.h +++ b/include/time.h @@ -98,6 +98,8 @@ extern char * __strptime_internal (const char *rp, const char *fmt, extern double __difftime (time_t time1, time_t time0); +extern double __difftime64 (__time64_t time1, __time64_t time0); + /* Use in the clock_* functions. Size of the field representing the actual clock ID. */ #define CLOCK_IDFIELD_SIZE 3 diff --git a/time/Versions b/time/Versions index fd838181e4..57314b98c8 100644 --- a/time/Versions +++ b/time/Versions @@ -65,4 +65,7 @@ libc { GLIBC_2.16 { timespec_get; } + GLIBC_2.27 { + __difftime64; + } } diff --git a/time/difftime.c b/time/difftime.c index 7c5dd9898b..e68b9a2c81 100644 --- a/time/difftime.c +++ b/time/difftime.c @@ -119,3 +119,12 @@ __difftime (time_t time1, time_t time0) return time1 < time0 ? - subtract (time0, time1) : subtract (time1, time0); } strong_alias (__difftime, difftime) + +/* Return the difference between 64-bit TIME1 and TIME0. */ +double +__difftime64 (__time64_t time1, __time64_t time0) +{ + /* Subtract the smaller integer from the larger, convert the difference to + double, and then negate if needed. */ + return time1 < time0 ? - (time0 - time1) : (time1 - time0); +}