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
11 +#include <arpa/inet.h>
13 +#include <sys/system_properties.h>
22 zone_info_unix (const gchar *identifier)
25 + /* Android does not have /etc/localtime but uses a system property for the
26 + the current timezone. There are no files under /usr/share/zoneinfo,
27 + instead a single /system/usr/share/zoneinfo/tzdata which are all zoneinfo
28 + files compiled together with the following tool:
29 + https://android.googlesource.com/platform/external/icu/+/master/tools/ZoneCompactor.java */
30 + struct tzdata_header {
32 + uint32_t index_offset, data_offset, zonetab_offset;
33 + } __attribute__((packed)) header;
35 + struct tzdata_index_entry {
37 + uint32_t offset, length, unused;
38 + } __attribute__((packed)) entry;
40 + char sys_timezone[PROP_VALUE_MAX];
41 + if (identifier == NULL) {
42 + if (__system_property_get("persist.sys.timezone", sys_timezone) < 1) {
43 + g_warning("__system_property_get(\"persist.sys.timezone\") failed\n");
46 + identifier = sys_timezone;
48 + if (identifier != NULL) {
49 + int tzdata_fd = open("/system/usr/share/zoneinfo/tzdata", O_RDONLY);
50 + if (tzdata_fd < 0) {
51 + g_warning("Failed opening tzdata");
54 + if (read(tzdata_fd, &header, sizeof(header)) < (ssize_t) sizeof(header)) {
55 + g_warning("Failed reading tzdata header");
58 + header.index_offset = htonl(header.index_offset);
59 + header.data_offset = htonl(header.data_offset);
61 + uint32_t current_offset = header.index_offset;
62 + while (current_offset < header.data_offset) {
63 + if (read(tzdata_fd, &entry, sizeof(entry)) < (ssize_t) sizeof(entry)) {
64 + g_warning("Failed reading tzdata index entry");
67 + if (strcmp(entry.name, identifier) == 0) {
68 + entry.offset = htonl(entry.offset);
69 + entry.length = htonl(entry.length);
70 + if (entry.length == 0) {
71 + g_warning("Invalid tzdata entry with length zero");
74 + if (lseek(tzdata_fd, header.data_offset + entry.offset, SEEK_SET) == -1) {
75 + g_warning("Failed seeking to tzdata entry");
78 + guint8* data = g_malloc(entry.length);
79 + if (read(tzdata_fd, data, entry.length) < entry.length) {
80 + g_warning("Failed reading tzdata entry");
85 + return g_bytes_new_take(data, entry.length);
94 GMappedFile *file = NULL;
95 GBytes *zoneinfo = NULL;