From patchwork Wed Mar 26 22:30:45 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Willmann X-Patchwork-Id: 334123 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ganesha.gnumonks.org (ganesha.gnumonks.org [IPv6:2001:780:45:1d:225:90ff:fe52:c662]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 1256414008A for ; Thu, 27 Mar 2014 09:32:43 +1100 (EST) Received: from localhost ([127.0.0.1] helo=ganesha.gnumonks.org) by ganesha.gnumonks.org with esmtp (Exim 4.72) (envelope-from ) id 1WSwN5-00024c-Oc; Wed, 26 Mar 2014 23:32:32 +0100 Received: from isonoe.totalueberwachung.de ([2a01:198:210:100::1]) by ganesha.gnumonks.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.72) (envelope-from ) id 1WSwLl-0001zz-Pu for openbsc@lists.osmocom.org; Wed, 26 Mar 2014 23:31:11 +0100 Received: from adrastea.totalueberwachung.de (p5099b351.dip0.t-ipconnect.de [80.153.179.81]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by isonoe.totalueberwachung.de (Postfix) with ESMTPSA id 55DB660055; Wed, 26 Mar 2014 23:31:09 +0100 (CET) Received: by adrastea.totalueberwachung.de (Postfix, from userid 1000) id E2D49220BC; Wed, 26 Mar 2014 23:31:06 +0100 (CET) From: Daniel Willmann To: OpenBSC Mailing List Subject: [PATCH 2/4] gsm0411_utils: Add helper function to get the gmt offset of a time_t Date: Wed, 26 Mar 2014 23:30:45 +0100 Message-Id: <96a6779baa1e1cc8bc1c05ce824928bbe7d240ed.1395872056.git.daniel@totalueberwachung.de> X-Mailer: git-send-email 1.8.4.2 In-Reply-To: <1395873047-28229-1-git-send-email-dwillmann@sysmocom.de> References: <1395873047-28229-1-git-send-email-dwillmann@sysmocom.de> In-Reply-To: <64c11ccd40489136537a1d3e804c18e0d66440f4.1395872056.git.daniel@totalueberwachung.de> References: <64c11ccd40489136537a1d3e804c18e0d66440f4.1395872056.git.daniel@totalueberwachung.de> X-Spam-Score: -0.0 (/) Cc: Daniel Willmann X-BeenThere: openbsc@lists.osmocom.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Development of the OpenBSC GSM base station controller List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: openbsc-bounces@lists.osmocom.org Errors-To: openbsc-bounces@lists.osmocom.org The function uses localtime as well as gmtime to calculate the timezone offset at a specific time. This is useful for the *_scts functions so we're not dependent on non-portable features (tm_gmtoff). --- src/gsm/gsm0411_utils.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/gsm/gsm0411_utils.c b/src/gsm/gsm0411_utils.c index ad9753e..d857e41 100644 --- a/src/gsm/gsm0411_utils.c +++ b/src/gsm/gsm0411_utils.c @@ -72,6 +72,24 @@ uint8_t gsm411_unbcdify(uint8_t value) return ret; } +/* Figure out the timezone offset in a portable way. + * The idea is to convert the time_t into local and UTC struct tm + * representations and then calculate the difference of both. */ +static time_t gmtoffset_from_ts(time_t time) +{ + struct tm tm_local, tm_utc; + time_t ts_local, ts_utc; + + localtime_r(&time, &tm_local); + gmtime_r(&time, &tm_utc); + tm_utc.tm_isdst = 0; + tm_local.tm_isdst = 0; + ts_utc = mktime(&tm_utc); + ts_local = mktime(&tm_local); + + return ts_local - ts_utc; +} + /* Generate 03.40 TP-SCTS */ void gsm340_gen_scts(uint8_t *scts, time_t time) {