1 Patch submitted at https://bugzilla.gnome.org/show_bug.cgi?id=771304
3 diff -u -r ../glib-2.48.2/glib/gtimezone.c ./glib/gtimezone.c
4 --- ../glib-2.48.2/glib/gtimezone.c 2016-08-17 12:07:29.000000000 -0400
5 +++ ./glib/gtimezone.c 2016-09-12 16:52:41.864974630 -0400
12 +#include <sys/system_properties.h>
20 zone_info_unix (const gchar *identifier)
23 + /* Android does not have /etc/localtime but uses a system property for the
24 + the current timezone. There are no files under /usr/share/zoneinfo,
25 + instead a single /system/usr/share/zoneinfo/tzdata which are all zoneinfo
26 + files compiled together with the following tool:
27 + https://android.googlesource.com/platform/external/icu/+/master/tools/ZoneCompactor.java */
28 + struct tzdata_header {
30 + uint32_t index_offset, data_offset, zonetab_offset;
31 + } __attribute__((packed)) header;
33 + struct tzdata_index_entry {
35 + uint32_t offset, length, unused;
36 + } __attribute__((packed)) entry;
38 + char sys_timezone[PROP_VALUE_MAX];
39 + if (identifier == NULL) {
40 + if (__system_property_get("persist.sys.timezone", sys_timezone) < 1) {
41 + g_warning("__system_property_get(\"persist.sys.timezone\") failed\n");
44 + identifier = sys_timezone;
46 + if (identifier != NULL) {
47 + int tzdata_fd = open("/system/usr/share/zoneinfo/tzdata", O_RDONLY);
48 + if (tzdata_fd < 0) {
49 + g_warning("Failed opening tzdata");
52 + if (read(tzdata_fd, &header, sizeof(header)) < (ssize_t) sizeof(header)) {
53 + g_warning("Failed reading tzdata header");
56 + header.index_offset = htonl(header.index_offset);
57 + header.data_offset = htonl(header.data_offset);
59 + uint32_t current_offset = header.index_offset;
60 + while (current_offset < header.data_offset) {
61 + if (read(tzdata_fd, &entry, sizeof(entry)) < (ssize_t) sizeof(entry)) {
62 + g_warning("Failed reading tzdata index entry");
65 + if (strcmp(entry.name, identifier) == 0) {
66 + entry.offset = htonl(entry.offset);
67 + entry.length = htonl(entry.length);
68 + if (entry.length == 0) {
69 + g_warning("Invalid tzdata entry with length zero");
72 + if (lseek(tzdata_fd, header.data_offset + entry.offset, SEEK_SET) == -1) {
73 + g_warning("Failed seeking to tzdata entry");
76 + guint8* data = g_malloc(entry.length);
77 + if (read(tzdata_fd, data, entry.length) < entry.length) {
78 + g_warning("Failed reading tzdata entry");
83 + return g_bytes_new_take(data, entry.length);
92 GMappedFile *file = NULL;
93 GBytes *zoneinfo = NULL;