From patchwork Wed Jan 29 12:59:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lukasz Majewski X-Patchwork-Id: 1230882 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-109020-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.a=rsa-sha1 header.s=default header.b=XgP3LbD5; 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 4873WF1tqLz9sPK for ; Thu, 30 Jan 2020 00:00:41 +1100 (AEDT) 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:in-reply-to :references:mime-version:content-transfer-encoding; q=dns; s= default; b=BxD20c/ZKDKq9/MCz7akiUfyJL0WufAtEkFjeEd8kYgRV1/7IY14v +VOgzyWL80P4pRja2lM9R4X8YQjtri8p/LA9yLgTLMW1F5t/o5YNt0OW7pwrmmWm ys8C3kQHRSjnI500zm5idoaTfUrq/KeWPR0WSJ/sRyX/AFrQy7/BiM= 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:in-reply-to :references:mime-version:content-transfer-encoding; s=default; bh=53uOtq7sikQpimdnlTlt8CwPm94=; b=XgP3LbD50latTmNFiymQnnfNIWqN nP2zO4kqe5aHacCtuc7WbbuqYrGFgp2R8Hj9iwDLybuuRl2mD7GsldhNUlbr/MTv I2DreBwkCr44fMwx64PI73yiFXpscbzZsAWruhtIV3vSpC+UnW7K8x8XnWY6H+vJ RJG2fBTS/5x/Y+Q= Received: (qmail 31513 invoked by alias); 29 Jan 2020 12:59:47 -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 31453 invoked by uid 89); 29 Jan 2020 12:59:47 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-21.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= X-HELO: mail-out.m-online.net From: Lukasz Majewski To: Joseph Myers , Paul Eggert , Adhemerval Zanella Cc: Alistair Francis , Alistair Francis , GNU C Library , Siddhesh Poyarekar , Florian Weimer , Florian Weimer , Zack Weinberg , Carlos O'Donell , Andreas Schwab , Lukasz Majewski Subject: [PATCH v3 5/7] y2038: Provide conversion helpers for struct __timeval64 Date: Wed, 29 Jan 2020 13:59:12 +0100 Message-Id: <20200129125914.11221-5-lukma@denx.de> In-Reply-To: <20200129125914.11221-1-lukma@denx.de> References: <20200129125914.11221-1-lukma@denx.de> MIME-Version: 1.0 Those functions allow easy conversion between Y2038 safe, glibc internal struct __timeval64 and other time related data structures (like struct timeval or struct __timespec64). Build tests: ./src/scripts/build-many-glibcs.py glibcs Reviewed-by: Alistair Francis Reviewed-by: Adhemerval Zanella --- Chanes for v3: - Provide new helper function - valid_timeval64_to_timeval Changes for v2: - None --- include/time.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/include/time.h b/include/time.h index 99492a1577..8617114052 100644 --- a/include/time.h +++ b/include/time.h @@ -304,6 +304,43 @@ valid_timeval_to_timespec64 (const struct timeval tv) return ts64; } +/* Convert a known valid struct timeval into a struct __timeval64. */ +static inline struct __timeval64 +valid_timeval_to_timeval64 (const struct timeval tv) +{ + struct __timeval64 tv64; + + tv64.tv_sec = tv.tv_sec; + tv64.tv_usec = tv.tv_usec; + + return tv64; +} + +/* Convert a valid and within range of struct timeval, struct + __timeval64 into a struct timeval. */ +static inline struct timeval +valid_timeval64_to_timeval (const struct __timeval64 tv64) +{ + struct timeval tv; + + tv.tv_sec = (time_t) tv64.tv_sec; + tv.tv_usec = (suseconds_t) tv64.tv_usec; + + return tv; +} + +/* Convert a struct __timeval64 into a struct __timespec64. */ +static inline struct __timespec64 +timeval64_to_timespec64 (const struct __timeval64 tv64) +{ + struct __timespec64 ts64; + + ts64.tv_sec = tv64.tv_sec; + ts64.tv_nsec = tv64.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) @@ -342,6 +379,18 @@ valid_timespec64_to_timeval (const struct __timespec64 ts64) return tv; } +/* Convert a struct __timespec64 into a struct __timeval64. */ +static inline struct __timeval64 +timespec64_to_timeval64 (const struct __timespec64 ts64) +{ + struct __timeval64 tv64; + + tv64.tv_sec = ts64.tv_sec; + tv64.tv_usec = ts64.tv_nsec / 1000; + + return tv64; +} + /* Check if a value is in the valid nanoseconds range. Return true if it is, false otherwise. */ static inline bool