From patchwork Mon Feb 10 17:43:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 37859 Received: (qmail 55570 invoked by alias); 10 Feb 2020 17:50:24 -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 55471 invoked by uid 89); 10 Feb 2020 17:50:23 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.6 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=nanoseconds, HContent-Transfer-Encoding:8bit X-HELO: esa2.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=1581357024; x=1612893024; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OCu/dxGkF8LlE03N2mrqBoD7DIkCxVfIrXMZT5SnG5o=; b=RLjuDhdY5wS2BwoPtwVfXqPCL9gD0Ti6Ix6dksD/sCwcDo6mxoan3Y8X bm30bWH67atuhS2u3C9s+gVJ2vvaHthA0ch53njUE1WqoVHeY9EJ1Y+Qs n4D+yLzTJuLMdXIjIfxnkfg+d7eeLz8vJS8XMkocWdqqoLLjOkUgQz+Jl WrweTQMyotkSE8AMi8LLlIUXumYA8V/Zg/6TlJQiUdLggwBlCqO1U3rhr xMfqUDK0qoGeKZh8f+R1Dv2j01TS0gdZBR2zuoL9qM67l7E7EiBQY98xw 96f9ztBIQrH30sJwB4yy1FbnvPEPW0NhGtnKBU9Jdst1SdQuA9LfHn/+c Q==; IronPort-SDR: MgFh3ruLabIHs4oA95KzyhpSibuV9yMQN5cwjS1k4IhoA8gEENNayrwSM9jXg5QXNO97T5ahF5 K91x7gydDDFrZUw9wFgcl6DIwKBDwBtjUdQqMjGGQ+Lp3iuIJkuOJ76e8NPI0Mg3yWvstzkGcI oXhtGWxZVzKpDPcopo/8zaP8DkoFI3uZTnFLtbwCiM4skhdUfZKrXvJzkguVnZDuJmy3vD3VWg GGrgtJGEHS1h0HUpC2Ka3gHZdaIwwuu0dfCl/21voDj5pRBwViyVtGUFqMgeY3k2SAeKgdtfb6 CRI= IronPort-SDR: /JSsuvhQo44Uo52r0ok6Q2ESP6ywVViBCtMZh3bSYFmrz8c2KeAt+fwozyxxVMzZEjJrstuw2q NseVFpufIsxalPVuD6nSsygQkNJj0H94VdtN7wNSP5ccLG6QwlgW1ricXSHQJCLMDRXHd+2GYt hTryQzw5iSczRXDHpAKfz8ItyRZH+1UlRfBRJsO3SVnneY8c/F3OgbtyqoVVsNM7fmtBqA7THW dVMpFqfg9cFdKAe63CjsKBLhcDe8pA6D5TkAkcWEbewqWdjoIrwG5l6YaADIn3GX5f+us5umFR NGClfGcz4spi4TLuL0NWUxzK IronPort-SDR: 4AEoMHipJyQss8cW58DZVAMw3RGXzPspR/WEU1lI2qc9ZqLwND0VoaARy2hEvGSB3eh9+jgYb8 6YwMqeK5YCZIIWw6AWy92z/9PJIcbct/mH66VGGB6khtDdlJOTxW9/mGI7jw9ILZ9oXXU4pnSS 53numUxxdUAOkPN8p8aNIUFTQc5mFT8EQvN6ZqgFW2CiPUHPYFCpBrrKpmQcluFXv/z86TDhpr RPZAGMXBUSZXo8IHj8LSz6GoFv7/ussFE9/iX/fmknTf+NCEpo+23LZ/Fs/sQGOUfOznnHQqyI zak= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis Subject: [PATCH v2 2/6] time: Add a timeval with a long tv_sec and tv_usec Date: Mon, 10 Feb 2020 09:43:21 -0800 Message-Id: <20200210174325.6566-3-alistair.francis@wdc.com> In-Reply-To: <20200210174325.6566-1-alistair.francis@wdc.com> References: <20200210174325.6566-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. --- include/time.h | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/include/time.h b/include/time.h index 73f66277ac..f22abc13f4 100644 --- a/include/time.h +++ b/include/time.h @@ -400,6 +400,47 @@ timespec64_to_timeval64 (const struct __timespec64 ts64) return tv64; } +/* A version of 'struct timeval' with `long` time_t + and suseconds_t. */ +struct __timeval32 +{ + long tv_sec; /* Seconds. */ + long tv_usec; /* Microseconds. */ +}; + +/* Conversion functions for converting to/from __timeval32 +. If the seconds field of a __timeval32 would + overflow, they write { INT32_MAX, 999999 } to the output. */ +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 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