From patchwork Mon Oct 11 11:12:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 46069 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 B43FF385800E for ; Mon, 11 Oct 2021 11:14:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B43FF385800E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633950862; bh=FavOfjqhpgqKuDJNPO3xb2CZQhpGYoxtLCiCHCkGnfk=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=BbptQTcDpYYHAXTJXy+Vraf/8qjg4VAm/WIij7+3W20m6NVkP/uaB15ybIVt5u0V3 OlgtHCO3KWQ04LY2SZGCp0Jmjc6LJYRoUCr9HNgtFOH42/El/ucLJT9zovQnC+9dWJ zg5DDFuKmWuqckzfsaAMoQ2DlJNgwNyhJ5l7lKoI= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by sourceware.org (Postfix) with ESMTPS id 186A83858D28 for ; Mon, 11 Oct 2021 11:14:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 186A83858D28 Received: by mail-wr1-x430.google.com with SMTP id r7so54984586wrc.10 for ; Mon, 11 Oct 2021 04:14:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FavOfjqhpgqKuDJNPO3xb2CZQhpGYoxtLCiCHCkGnfk=; b=MFHx93PwGp4DFTcFCYBcRKyQhut7i0Kbbvjys7EREujrl8YlsYbuhntznrL0jwKls1 JZMNPg2v+9xt+Uku8j+yNdbJlh1F3lo6LbpS6rbqKy+VG7AXl/i4mofGOeQAnlI5QXj/ iokWIUITsIBOJ2GPf4CcAPTD8T4U7THJR5qZd8p158GCGCM1aaDqF4AGoxRrb057C6dJ vJztKtsl6Z/vNz83iACoVFnYC8kLOcN3CutJ7SG2V2MkeqA/o9odF2wedzVSPjrGRZ+c ybYz+HNBwEGI0sLVdbMsO/0QU7LzZ9vhYcPJEylQmSomJzBh0Gp33zFHwBHWPpWQthxE L7iw== X-Gm-Message-State: AOAM530ji4lomr4Cs7eXi9HQcY9Fe2qvEPcGDv/rLPY1PebBQ9SHRH/7 KC10hPVbc6j9zyHfdwpZCHM= X-Google-Smtp-Source: ABdhPJxoqSPCnxx8sziYRzpTQLlrMfXCtKkrMsvUWtQt22WiDoo1salDUr5YWHMZjSTJVOD8L6yOiQ== X-Received: by 2002:adf:bbc8:: with SMTP id z8mr24436143wrg.281.1633950841182; Mon, 11 Oct 2021 04:14:01 -0700 (PDT) Received: from sqli.sqli.com ([195.53.121.100]) by smtp.googlemail.com with ESMTPSA id p17sm1215746wrx.33.2021.10.11.04.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Oct 2021 04:14:00 -0700 (PDT) To: mtk.manpages@gmail.com, linux-man@vger.kernel.org Subject: [PATCH v2 1/2] ctime.3: mktime() may modify tm_hour due to tm_isdst Date: Mon, 11 Oct 2021 13:12:37 +0200 Message-Id: <20211011111237.9414-1-alx.manpages@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alejandro Colomar via Libc-alpha From: Alejandro Colomar Reply-To: Alejandro Colomar Cc: Alejandro Colomar , libc-alpha@sourceware.org Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" If the input DST value is the opposite of the one that mktime() uses, which comes from the current system timezone (see tzset(3)), mktime() will modify the hour (and if it's in a day limit, it may carry up to modify other fields) to normalize the time to the correct DST. If a user wants to avoid this, the user probably wants to use UTC time. mktime(3) uses local time, so it's not suitable for that (by default). Consider the following solutions: For that, the recommended solution is to use timegm(3), which sadly is non-portable (it is present in Linux and the BSDs, but not in POSIX). A portable solution (untested) might be to implement your own timegm(3): time_t portable_timegm(struct tm *tm) { tm->tm_isdst = 0; return mktime(tm) - timezone; } and assuming no other thread will change the current timezone during this call. Another portable solution would involve setting the timezone explicitly to UTC+0 with setenv() (see tzset(3)). But this forces all of the program to use UTC time, which might not be desirable. Cc: Paul Eggert Signed-off-by: Alejandro Colomar --- man3/ctime.3 | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/man3/ctime.3 b/man3/ctime.3 index 0e2068a09..7a5714be8 100644 --- a/man3/ctime.3 +++ b/man3/ctime.3 @@ -260,6 +260,13 @@ normalized (so that, for example, 40 October is changed into 9 November); is set (regardless of its initial value) to a positive value or to 0, respectively, to indicate whether DST is or is not in effect at the specified time. +If the initial value of +.I tm_isdst +is inconsistent with the one set by +.BR mktime (), +.I tm_hour +(and possibly other fields) +will be modified to normalize the time to the correct DST. Calling .BR mktime () also sets the external variable \fItzname\fP with