From patchwork Wed Feb 19 18:10:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 38237 Received: (qmail 4725 invoked by alias); 19 Feb 2020 18:18:04 -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 4630 invoked by uid 89); 19 Feb 2020 18:18:03 -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: 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=1582136303; x=1613672303; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=2yDhuA+PRvltCcGwxjXRqdO79ywwWMRtMstYgyUy48Y=; b=kMhyYXFy0amNthLbvPn7wLGWrhLjv2eXJws31fKmHW5P9qeB8YE4kz1s 0nUWKPDTTkKvqF5/P16AYf43xyEZ9ppZE2LWSGXZ88ZX6lpeZGLHMt0GP gEHbW5le4MXjCQZthLjzmEYB/YkbMESz4wxwSmWjlpUoTCV6A5xDek9KU nXzdW78H2YO7i/PGxuIcnWKRgxrYeL3wVs3K02Df5+9eFaoziuYJUQWlw VjkuWGZ6rQnYKITF2ozcn+kh8kinxmuhusQk0OfdNXS9h7M7QXZxWOje2 xSCEw8IuvZUkiweEqx5W5aeSkOgjSrR0AxaoX/tgXrNJDRvTL+mjIRHjW Q==; IronPort-SDR: 0o0B0O1SaOr9dBXVNq3HAh2LPnOGTYv0hJc0Cmms241B8g1It63cOs9XSEytbqLN4EW+0ZVIeC lk58Rf/2Wn3KqMRl8R5YDp/UTHjj7w1W0iBdEMIfCL7k5F79M13j+tM51321p15p4HSLKanUgR vMcPVNzZJELRzGq6nuJHt8TNMib/18uccd2F9DtzdG81XjfV2Hq3I1awUpm88JdxN4tnDDx/uG jco16ctY4Y6e45h8A/WkfoCeOgDgNBBXfZFJpBqtcGhCD4V2NCwMbtpjw36vI/WkfTNHNbWhQn z5Y= IronPort-SDR: MkFDkmJEOjfdjyKPF2RY+gLxLI9cDXpVeYhlankGmlBx4UpKAgQ7O7UzhwQ6FEyKOMex+KXmLf 5cfUnnF9Y5arBI/2t/ZI1P5prV1hFztQ0r2lbHPXVw8p/HPJhIdntjpm/E1Y5iC5wxm/fo2jcK jTxxZp+Doa7pdFpOEyRtmNmiPjZ39l3SNgEVCw7n5VLtq3UoWccCa2I+2NTR+qnT9bSnGkBSuA F/e7cczvaP1Db/R7SZjcShXdkji9GsjByWES6sSVjK71RNDL+a8b+BZpjpoLkll8j5vAUKz1m2 fLFc3JxQkMOFAFEH3NYPyHJq IronPort-SDR: aFMy+DvaKKY1QOR7x0//5dXOp+adYBwk1KvijnmzP92dIFf93trK8vQkcQqxvPZShnMElWDTm2 NQ0AlRa+h1bbfS/tNUOpTBJP+lr1eQzzkeMmun7v+zjpv4+QL7POCcJbINA68UTbYp/tQyjRi+ Vfyd6vJz92mJZVwMu7K9zQtq7Tca/1ck+D1XHaKvn5Eov5jbCsi5aLbBYhSGJLKWuQpvt0u8Xo MCfSr1VfwdfM/0b+miMjbNMmYSDTFJa60WK1cAMIL5n/oznBOUOgHerhRtf+WRO5KmQ9mtxRtM 610= WDCIronportException: Internal From: Alistair Francis To: libc-alpha@sourceware.org Cc: alistair23@gmail.com, Alistair Francis , Lukasz Majewski Subject: [PATCH v4 2/8] time: Add a timeval with a 32-bit tv_sec and tv_usec Date: Wed, 19 Feb 2020 10:10:51 -0800 Message-Id: <20200219181057.10297-3-alistair.francis@wdc.com> In-Reply-To: <20200219181057.10297-1-alistair.francis@wdc.com> References: <20200219181057.10297-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 61806658e7..945650af5e 100644 --- a/include/time.h +++ b/include/time.h @@ -404,6 +404,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