Openwall GNU/*/Linux - a small security-enhanced Linux distro for servers
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date: Thu, 18 Jan 2018 16:25:07 +0000
From: Adrián López Tejedor <>
Subject: Differences between strftime in musl and glibc


I was having a problem parsing dates with python in an Alpine container and
after some time digging I have found a difference in how musl and
glibc calculate the unix Epoch using strftime.

The format specifier to get the unix epoch is "%s", which is an extension
of GNU (

In Glibc they use mktime (, being
this function aware of time zone.

In musl is calculated without mktime, adding the seconds of each part of
the tm struct (
and substracting the GMT offset. This method is unaware of the TZ data (I
have not seen how to define that gmt offset when using strptime).

Calling directly to musl/mktime work as expected.

I have attached a small program which shows the difference between musl and

Compiled with glibc:
$ TZ=Europe/Madrid ./a.out
strftime: -3600
mktime: -3600
$ TZ=America/New_York ./a.out
strftime: 18000
mktime: 18000

Compiled with musl:
$ TZ=Europe/Madrid ./a.out
strftime: 0
mktime: -3600
$ TZ=America/New_York ./a.out
strftime: 0
mktime: 18000


Content of type "text/html" skipped

View attachment "date_musl_glibc.c" of type "text/x-csrc" (498 bytes)

Powered by blists - more mailing lists

Your e-mail address:

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.