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)
 {
-- 
1.8.4.2


Reply via email to