From patchwork Fri Feb 14 16:31:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38077 Received: (qmail 68721 invoked by alias); 14 Feb 2020 16:39:36 -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 63441 invoked by uid 89); 14 Feb 2020 16:38:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.5 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3 autolearn=ham version=3.3.1 spammy=HContent-Transfer-Encoding:8bit X-HELO: esa4.hgst.iphmx.com DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1581698316; x=1613234316; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=UYimL3lIqE6a22oSp7ufiT5HFLQdylknsWZk8FY/zbs=; b=bgxxxT0dOV3tvW3QbV/ZobMsUWuaURvPh3vJIiN/oQUAi/F69AuZy+8I 29jdihw0aSghI2cQN2oUfViF+VV++RtojU2VAuDmIcmw2OgQ0xd96NK5V QHK/s/hUDO3UQRZ9HE1PJ0wzD0U67qn8AutBOXth9NtmYv1jOInPgSgqF xPclCG+g4ElX/44RZ6dyQtvSyGawLFJT6iKtTdwa1atzFhnWyjRuCS7FB Ys0mbYwdywbCG6P8Ia4QbWQ/+qDbZbAg6BYdcBN4DVzvkmaKG9U2wGq1X n+CjX7KCbvdd/A3QmqyU5XPCd4IKoU/ImVqTluv/Ms6eAV0BVuQrxfXBy A==; IronPort-SDR: m0Tmr6IL4In9YvXKHNjHhBKWuLtqUkyfCL9sTUQfjsnUZyp1HiJ65DY1evCdkjR1IhTkvlJObm 74ZyKiJKIB+23etE3doNGS236xqLIJu5uFuIz24bzqN1S+ujEqbEUDwI79WHpfKD0SmvlmTBJe py/taXXuD8MNtkiiA8lBlu0oLXAIkc5KjKunC4ahejDca5s16i78n49duEvkF7ASxlDcVjLWQC OY66om0ZTeuKlqajTJJ/LcfMOieC8dpaRZGmnakXWB5VhOHR83b+P+86yFDOfZpuLViKda3iHU XZ4= IronPort-SDR: f4JxoD/kaSxO2RCj0vl/NWgEwxAQkwBGTasKaB38v6+qAYOewJYJaBCNrHPqXVc+XaoSsqN0LU INjNJ7B2QnfI6nRVWL0JM8et8qxmB8TukZfvvWxvPwrTvgR9BRqAn6xHZT8hQ7lh5ExuyMgLpZ x17p/3g+f4C5fwEPG+LI24fLZgWGB8ns78BiopOF0C70TV4dJS3NtWxa1TavklHvP91mzcmyWb MGheF2y5w7O96rlcTwO8pzOCt+VYXkyJrZf90X1GACtgNiDurfSH0d48HfCc93TRDNdL4eFNDX HnhbbWHnPkKxN+JQcImxTDbS IronPort-SDR: fx7xBn/+x4U3/IwJsEzopSa0IvS9u0ScYhLQErbyWh7TrjzKK/7Rl5bArPVbsghzzqSzQnwRnS suqBhuedgQ9xJTZB5A0bgjWj1JVS1X+3nSjZdDfAHQ1NCrkVoJISQ/fUwESAMZ0HEYj7UwvAzr TSG37rMwa27uY1w3U7lKpZUA9AHBBViGsZL3uo5oo+RzWiewHMhv+RR2QXHzxF57RDDx/ffj2T cglD/yQ5ChrFBPnSQZHYFP96SLnc4Jj4DRZr5WlCX+QmBmTE6vLY2VnrGb0qLyuGnQl1UViKUw XRw= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v3 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Date: Fri, 14 Feb 2020 08:31:28 -0800 Message-Id: <20200214163134.31601-3-alistair.francis@wdc.com> In-Reply-To: <20200214163134.31601-1-alistair.francis@wdc.com> References: <20200214163134.31601-1-alistair.francis@wdc.com> MIME-Version: 1.0 On y2038 safe 32-bit systems the Linux kernel expects itimerval to use a 32-bit time_t, even though the other time_t's are 64-bit. To address this let's add a __timeval32 struct to be used internally. Reviewed-by: Lukasz Majewski --- include/time.h | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/include/time.h b/include/time.h index 73f66277ac..ddc0ded640 100644 --- a/include/time.h +++ b/include/time.h @@ -400,6 +400,51 @@ timespec64_to_timeval64 (const struct __timespec64 ts64) return tv64; } +/* A version of 'struct timeval' with 32-bit time_t + and suseconds_t. */ +struct __timeval32 +{ + __int32_t tv_sec; /* Seconds. */ + __int32_t tv_usec; /* Microseconds. */ +}; + +/* Conversion functions for converting to/from __timeval32 */ +static inline struct __timeval64 +valid_timeval32_to_timeval64 (const struct __timeval32 tv) +{ + return (struct __timeval64) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct __timeval32 +valid_timeval64_to_timeval32 (const struct __timeval64 tv64) +{ + return (struct __timeval32) { tv64.tv_sec, tv64.tv_usec }; +} + +static inline struct timeval +valid_timeval32_to_timeval (const struct __timeval32 tv) +{ + return (struct timeval) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct __timeval32 +valid_timeval_to_timeval32 (const struct timeval tv) +{ + return (struct __timeval32) { tv.tv_sec, tv.tv_usec }; +} + +static inline struct timespec +valid_timeval32_to_timespec (const struct __timeval32 tv) +{ + return (struct timespec) { tv.tv_sec, tv.tv_usec * 1000 }; +} + +static inline struct __timeval32 +valid_timespec_to_timeval32 (const struct timespec ts) +{ + return (struct __timeval32) { (time_t) ts.tv_sec, ts.tv_nsec / 1000 }; +} + /* Check if a value is in the valid nanoseconds range. Return true if it is, false otherwise. */ static inline bool