From patchwork Mon Oct 11 11:54:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alejandro Colomar X-Patchwork-Id: 46072 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 22812385800A for ; Mon, 11 Oct 2021 11:56:53 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 22812385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1633953413; bh=ITHh23oEa6sZ55dr+t7qBIafzJcvg+QdGAZDQadYP7E=; 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=p72746ZV2E2ofwnFuF7oBMjOi3sFcKWCKOG4kJp/RvurOAbl1Bi/ihGlm4Fln4GzZ Nukzb3++Af9QglGcGessj5xOkRVfGlII2qoeGwCjILTbQRvOtUgez96ynHiXZpdmXF jEr1yUJgDXt4v3U5OgGmZAUMA4gFG/sOBWSZRtt4= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by sourceware.org (Postfix) with ESMTPS id 669803858D28 for ; Mon, 11 Oct 2021 11:56:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 669803858D28 Received: by mail-wr1-x42e.google.com with SMTP id o20so55268320wro.3 for ; Mon, 11 Oct 2021 04:56:31 -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=ITHh23oEa6sZ55dr+t7qBIafzJcvg+QdGAZDQadYP7E=; b=qWEsB9PxtJVR+plQz9LFkUJ0DTiu8tJ1F3704xU0XJOqnP3+MeFHv3FPUT4pgD+5Iw WUTpsZXyLWn5Z3FEb5lyiGwU+7fAr6P6erWlr6rypUsUV+KNgYDcTyHngy4AraEsQ3vd rKsPo8+3sHIpyUqmseQssmDddQKm5s6n8XxwhBFuM5856Xq7edtnPYoe2xSe3nzZvvyi RiG6WxIQ2I+ImJZPKkcpYrttjldCQph+zDqpV3xc4KxZB2dWNY6aUS/Rt5uq6gVJ0+8p zdjFEDuUPErvxT26LeSXDK9yaIsnrt8GIsTaddO5mYIDisYYqvsQhiJVrGKv1Z0xaU/4 dflA== X-Gm-Message-State: AOAM531uuBUtXSJYsleYvgpk7Lixlqw+nvMZu1NxlbpMS710JFWcaKnK q4QDKuAas2QX8972qpk85VU= X-Google-Smtp-Source: ABdhPJwK7jDlACa54hSrQEPpw6yE2vsTUqTcuI1ymD506s1+2DmgiHMpAa5eNJTouFxscmjlPbbwOw== X-Received: by 2002:a05:600c:3b24:: with SMTP id m36mr6152375wms.176.1633953390501; Mon, 11 Oct 2021 04:56:30 -0700 (PDT) Received: from sqli.sqli.com ([195.53.121.100]) by smtp.googlemail.com with ESMTPSA id l16sm7912490wmj.33.2021.10.11.04.56.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Oct 2021 04:56:30 -0700 (PDT) To: mtk.manpages@gmail.com, linux-man@vger.kernel.org Subject: [PATCH v3 1/2] ctime.3: mktime() may modify tm_hour due to tm_isdst Date: Mon, 11 Oct 2021 13:54:06 +0200 Message-Id: <20211011115406.11430-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 itself). Consider the following solutions: For that, the easiest solution is to use timegm(3), which 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; } 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, especially in multi-threaded programs. 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