From patchwork Mon Sep 30 13:31:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1169370 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-105474-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="B7tBTNuI"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 46hjxZ2BT4z9sDB for ; Mon, 30 Sep 2019 23:32:18 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; q=dns; s=default; b=Xhp OgpiVNsjlIAeiLbaJjtst5izDnKCDTnqVx7pMFZcHs3phAgz6PCBDCnGU9yhsXk1 r6BI00M86rz4S2Nf4DtFTK69Gp+3Bd4pAOtyv6aLXRadcKgGwv8TwXqCWqrpu6Q6 3u938tJRlk3Tx4ONaiAuBy9p4ht6zM+/XotMpAB4= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; s=default; bh=lZ96zXoH9 4thNUBx5V4Q6f8i45s=; b=B7tBTNuIsqe5ctSv3r3SD3lBud6iA1GwW8dAct1ap w6mXCQxPJD0vp+IhCNhUgfxtxnTRr+CTdpSCDdl7sqdDZT0OcVgGtA26XvS/l4it X85ypga66QQ+q2sAuOAF2myPu6Xr9Kq8P4JTnq8ClgtP9TsIe0LcGf2XHlCpNly8 qk= Received: (qmail 9773 invoked by alias); 30 Sep 2019 13:32:12 -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 9765 invoked by uid 89); 30 Sep 2019 13:32:11 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-19.0 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_NUMSUBJECT, RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 spammy=H*r:192.168.8, HContent-Transfer-Encoding:8bit X-HELO: mail-out.m-online.net From: Lukasz Majewski To: Joseph Myers , Paul Eggert Cc: Alistair Francis , Arnd Bergmann , Alistair Francis , GNU C Library , Adhemerval Zanella , Florian Weimer , Carlos O'Donell , Stepan Golosunov , Florian Weimer , Zack Weinberg , Lukasz Majewski Subject: [PATCH v10] y2038: Provide conversion helpers for struct __timespec64 Date: Mon, 30 Sep 2019 15:31:34 +0200 Message-Id: <20190930133134.14771-1-lukma@denx.de> MIME-Version: 1.0 Those functions allow easy conversion between Y2038 safe struct __timespec64 and other time related data structures (like struct timeval or struct timespec). * include/time.h (valid_timeval_to_timespec64): Add. * include/time.h (valid_timespec_to_timespec64): Likewise. * include/time.h (valid_timespec64_to_timespec): Likewise. * include/time.h (valid_timespec64_to_timeval): Likewise. --- Changes for v10: - Provide only conversion functions to work on "valid" time structures (no need to provide any excessive checks) - Return values instead of pointers Changes for v9: - Update comments to be more concise and describe return values from conversion functions (according to Joseph's request). Changes for v8: - None Changes for v7: - None Changes for v6: - Remove the #ifdef guard on __ASSUME_TIME64_SYSCALLS as those functions may be needed for fallback execution paths (on e.g. __clock_settime64). Changes for v5: - This code is now only compiled in when __ASSUME_TIME64_SYSCALLS is NOT defined. Previously it was depending on #if __TIMESIZE != 64. Changes for v4: - None Changes for v3: - Remove misleading comments regarding clearing tv_pad values during conversion (as Linux kernel on its own ignores upper 32 bits of tv_nsec). Changes for v3: - Remove timespec64_clear_padding function - as kernel ignores upper 32 bits of tv_nsec when passed via syscall to the Linux kernel Changes for v2: - Add timespec64_clear_padding function --- include/time.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/time.h b/include/time.h index 9727786634..9878c2b2ca 100644 --- a/include/time.h +++ b/include/time.h @@ -178,5 +178,54 @@ in_time_t_range (__time64_t t) return s == t; } +/* Convert a known valid struct timeval into a struct __timespec64. */ +static inline struct __timespec64 +valid_timeval_to_timespec64 (const struct timeval tv) +{ + struct __timespec64 ts64; + + ts64.tv_sec = tv.tv_sec; + ts64.tv_nsec = tv.tv_usec * 1000; + + return ts64; +} + +/* Convert a known valid struct timespec into a struct __timespec64. */ +static inline struct __timespec64 +valid_timespec_to_timespec64 (const struct timespec ts) +{ + struct __timespec64 ts64; + + ts64.tv_sec = ts.tv_sec; + ts64.tv_nsec = ts.tv_nsec; + + return ts64; +} + +/* Convert a valid and within range of struct timespec, struct + __timespec64 into a struct timespec. */ +static inline struct timespec +valid_timespec64_to_timespec (const struct __timespec64 ts64) +{ + struct timespec ts; + + ts.tv_sec = (time_t) ts64.tv_sec; + ts.tv_nsec = ts64.tv_nsec; + + return ts; +} + +/* Convert a valid and within range of struct timeval struct + __timespec64 into a struct timeval. */ +static inline struct timeval +valid_timespec64_to_timeval (const struct __timespec64 ts64) +{ + struct timeval tv; + + tv.tv_sec = (time_t) ts64.tv_sec; + tv.tv_usec = ts64.tv_nsec / 1000; + + return tv; +} #endif #endif