From patchwork Sun Jan 5 05:57:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paul Eggert X-Patchwork-Id: 104092 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AA5D53858C51 for ; Sun, 5 Jan 2025 06:48:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org AA5D53858C51 Authentication-Results: sourceware.org; dkim=pass (2048-bit key, unprotected) header.d=cs.ucla.edu header.i=@cs.ucla.edu header.a=rsa-sha256 header.s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C header.b=FJIPKJ/Y X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail.cs.ucla.edu (mail.cs.ucla.edu [131.179.128.66]) by sourceware.org (Postfix) with ESMTPS id EEF5A3858423 for ; Sun, 5 Jan 2025 06:00:04 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EEF5A3858423 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=cs.ucla.edu Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=cs.ucla.edu ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EEF5A3858423 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=131.179.128.66 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056805; cv=none; b=XdQPKk7cue3RhbWzXlJfgwvXGrmHAKnZXG3f8J1CZHaAFRYEVnNr0nnhHTpUkC4pxVwNDUAjTrQiR913ZAWGFfGkDzhgvEdsKERDbi7dv8AO/qs0LmnJl10HOLTuyHlWUJDbbkRkElFPQsaWgK2Ll9Lh8VDFYxIjmEficvvAB58= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1736056805; c=relaxed/simple; bh=N6s8aNO54J0iI6GJDY5Jk0CUuPS2+rEGLLVwoeafVC4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=ZsMUjPUKvPAWVnGLSpYhV14GsASYKrs/qG8EJx2+P09agQ0OK5HAoaKfGSflElmD83ybsBcDoXFXWNxaJHJR4r1Kw01O2HfBvm0uCM0xJCpqKTKcWpYotqTqG3+UBTxk7I0LmxdbCB3SUk2eT85FJd7hsfaviGkkkddf2Ae7ZlI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EEF5A3858423 Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id 6F5F63C12385E for ; Sat, 4 Jan 2025 22:00:04 -0800 (PST) Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10032) with ESMTP id OEkSoj3Wjq4E; Sat, 4 Jan 2025 22:00:04 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mail.cs.ucla.edu (Postfix) with ESMTP id F24153C123844; Sat, 4 Jan 2025 22:00:03 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.10.3 mail.cs.ucla.edu F24153C123844 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cs.ucla.edu; s=9D0B346E-2AEB-11ED-9476-E14B719DCE6C; t=1736056804; bh=AlAFCY850XYLwr/7FrRXkPmF+H/w6pZ97erZLkwf+nA=; h=From:To:Date:Message-ID:MIME-Version; b=FJIPKJ/YMi1Ed36zRRVivI3OFzdzQJrte8T/JyFNLaI0trfMe8NZowR55gk0alq4b Qngkrpjdiw5HPq5H6jf0/D+dSta/500eUr4BZ6Ybhqp2G5qylybRAanFkzbnVIQk8L tB/zytN1neIYICiFtb6MHAupxeJsch569r37sDIMP5aUSUtoJ61DsEtJK5o2U0km7A 76jwN0CLKygc4EnkmrAqKSnn/XHPnarHRKLgEG8128EWEim/CtP72vlfpJ4n5qFlBk ki+We5U246azODiKBL/KZL23zzCXo5gaph4oVObGDfP328mtSwQgwURwv1lrcVPsB3 j84ZvotW7IIiw== X-Virus-Scanned: amavis at mail.cs.ucla.edu Received: from mail.cs.ucla.edu ([127.0.0.1]) by localhost (mail.cs.ucla.edu [127.0.0.1]) (amavis, port 10026) with ESMTP id FrVz7h7GWVck; Sat, 4 Jan 2025 22:00:03 -0800 (PST) Received: from wing.home (unknown [47.154.28.214]) by mail.cs.ucla.edu (Postfix) with ESMTPSA id D2BAC3C082EB9; Sat, 4 Jan 2025 22:00:03 -0800 (PST) From: Paul Eggert To: libc-alpha@sourceware.org Cc: Paul Eggert Subject: [PATCH 42/59] __offtime now returns struct tm * Date: Sat, 4 Jan 2025 21:57:17 -0800 Message-ID: <20250105055750.1668721-43-eggert@cs.ucla.edu> X-Mailer: git-send-email 2.45.2 In-Reply-To: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> References: <01207110-bd60-46ae-9c08-fb39c2011067@cs.ucla.edu> MIME-Version: 1.0 X-Spam-Status: No, score=-10.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, GIT_PATCH_0, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patchwork=sourceware.org@sourceware.org * time/offtime.c (__offtime): Refactor by returning struct tm * instead of int. All callers changed. --- include/time.h | 8 ++++---- time/offtime.c | 8 ++++---- time/tzfile.c | 2 +- time/tzset.c | 7 +++---- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/include/time.h b/include/time.h index e9c083646a..186ea657cb 100644 --- a/include/time.h +++ b/include/time.h @@ -250,10 +250,10 @@ libc_hidden_proto (__gettimeofday64) /* Compute the `struct tm' representation of T, offset OFFSET seconds east of UTC, and store year, yday, mon, mday, wday, hour, min, sec into *TP. - Return nonzero if successful. */ -extern int __offtime (__time64_t __timer, - long int __offset, - struct tm *__tp) attribute_hidden; + Return TP if successful, a null pointer otherwise. */ +extern struct tm *__offtime (__time64_t __timer, + long int __offset, + struct tm *__tp) attribute_hidden; extern char *__asctime_r (const struct tm *__tp, char *__buf) attribute_hidden; diff --git a/time/offtime.c b/time/offtime.c index c94573e931..89cdcc4b15 100644 --- a/time/offtime.c +++ b/time/offtime.c @@ -24,8 +24,8 @@ /* Compute the `struct tm' representation of T, offset OFFSET seconds east of UTC, and store year, yday, mon, mday, wday, hour, min, sec into *TP. - Return nonzero if successful. */ -int + Return TP if successful, a null pointer otherwise. */ +struct tm * __offtime (__time64_t t, long int offset, struct tm *tp) { __time64_t days, rem, y; @@ -73,7 +73,7 @@ __offtime (__time64_t t, long int offset, struct tm *tp) { /* The year cannot be represented due to overflow. */ __set_errno (EOVERFLOW); - return 0; + return NULL; } tp->tm_yday = days; ip = __mon_yday[__isleap(y)]; @@ -82,5 +82,5 @@ __offtime (__time64_t t, long int offset, struct tm *tp) days -= ip[y]; tp->tm_mon = y; tp->tm_mday = days + 1; - return 1; + return tp; } diff --git a/time/tzfile.c b/time/tzfile.c index 3ca08d16d4..9c05811e22 100644 --- a/time/tzfile.c +++ b/time/tzfile.c @@ -648,7 +648,7 @@ __tzfile_compute (__time64_t timer, int use_localtime, /* Convert to broken down structure. If this fails do not use the string. */ - if (__glibc_unlikely (! __offtime (timer, 0, tp))) + if (__glibc_unlikely (__offtime (timer, 0, tp) == NULL)) goto use_last; /* Use the rules from the TZ string to compute the change. */ diff --git a/time/tzset.c b/time/tzset.c index 90ecdf4210..671394f02d 100644 --- a/time/tzset.c +++ b/time/tzset.c @@ -610,9 +610,8 @@ __tz_convert (__time64_t timer, int use_localtime, struct tm *tp) &leap_extra_sec, tp); else { - if (! __offtime (timer, 0, tp)) - tp = NULL; - else if (use_localtime) + tp = __offtime (timer, 0, tp); + if (tp && use_localtime) __tz_compute (timer, tp); leap_correction = 0; leap_extra_sec = false; @@ -627,7 +626,7 @@ __tz_convert (__time64_t timer, int use_localtime, struct tm *tp) tp->tm_gmtoff = 0L; } - if (__offtime (timer, tp->tm_gmtoff - leap_correction, tp)) + if (__offtime (timer, tp->tm_gmtoff - leap_correction, tp) != NULL) { /* This assumes leap seconds can occur only when the local time offset from UTC is a multiple of 60 seconds,