2017-12-09 02:05:00 +01:00
|
|
|
diff -u -r ../glib-2.54.2/glib/gtimezone.c ./glib/gtimezone.c
|
|
|
|
--- ../glib-2.54.2/glib/gtimezone.c 2017-07-14 01:03:39.000000000 +0200
|
2017-12-22 00:10:55 +01:00
|
|
|
+++ ./glib/gtimezone.c 2017-12-21 23:47:57.704190589 +0100
|
|
|
|
@@ -43,6 +43,10 @@
|
2016-09-12 23:57:40 +02:00
|
|
|
#include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
+#ifdef __ANDROID__
|
|
|
|
+#include <sys/system_properties.h>
|
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
/**
|
|
|
|
* SECTION:timezone
|
|
|
|
* @title: GTimeZone
|
2017-12-22 00:10:55 +01:00
|
|
|
@@ -392,7 +396,109 @@
|
2017-12-09 02:05:00 +01:00
|
|
|
gtz->transitions = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
-#ifdef G_OS_UNIX
|
2016-09-12 23:57:40 +02:00
|
|
|
+#ifdef __ANDROID__
|
2017-12-21 04:53:07 +01:00
|
|
|
+/* Android uses a 'persist.sys.timezone' system property for the
|
2017-12-21 13:42:24 +01:00
|
|
|
+ * current timezone instead of a /etc/localtime file:
|
|
|
|
+ * https://android.googlesource.com/platform/ndk/+/android-2.2_r1/docs/system/libc/OVERVIEW.TXT#67
|
|
|
|
+ *
|
|
|
|
+ * There are no files under /usr/share/zoneinfo - instead a single
|
|
|
|
+ * /system/usr/share/zoneinfo/tzdata file is used which contains all
|
|
|
|
+ * files compiled together with the following tool:
|
|
|
|
+ * https://android.googlesource.com/platform/system/timezone/+/master/zone_compactor/main/java/ZoneCompactor.java
|
|
|
|
+ */
|
|
|
|
+static GBytes *
|
2017-12-09 02:05:00 +01:00
|
|
|
+zone_info_android (const gchar *identifier)
|
|
|
|
+{
|
2016-10-16 02:02:32 +02:00
|
|
|
+ char sys_timezone[PROP_VALUE_MAX];
|
2017-12-22 00:10:55 +01:00
|
|
|
+ GMappedFile *file;
|
|
|
|
+ gchar *tzdata;
|
|
|
|
+ gsize tzdata_length;
|
|
|
|
+ const gsize index_entry_size = 52;
|
|
|
|
+ gint32 header_index_offset, header_data_offset;
|
|
|
|
+ gint32 entry_count, current_index;
|
|
|
|
+ char* entry_name;
|
|
|
|
+ gint32 entry_offset, entry_length;
|
|
|
|
+ GBytes *zoneinfo;
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
|
|
|
+ if (identifier == NULL)
|
|
|
|
+ {
|
2017-12-17 00:45:43 +01:00
|
|
|
+ if (__system_property_get ("persist.sys.timezone", sys_timezone) < 1)
|
2017-12-21 13:42:24 +01:00
|
|
|
+ {
|
|
|
|
+ g_warning ("__system_property_get(\"persist.sys.timezone\") failed");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
2017-12-09 02:05:00 +01:00
|
|
|
+ identifier = sys_timezone;
|
2016-09-12 23:57:40 +02:00
|
|
|
+ }
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ file = g_mapped_file_new ("/system/usr/share/zoneinfo/tzdata", FALSE, NULL);
|
|
|
|
+ if (file == NULL)
|
|
|
|
+ {
|
|
|
|
+ g_warning ("Failed mapping tzdata file");
|
|
|
|
+ return NULL;
|
|
|
|
+ }
|
2016-09-12 23:57:40 +02:00
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ tzdata = g_mapped_file_get_contents (file);
|
|
|
|
+ tzdata_length = g_mapped_file_get_length (file);
|
|
|
|
+ if (tzdata == NULL || tzdata_length < 24)
|
2017-12-09 02:05:00 +01:00
|
|
|
+ {
|
2017-12-22 00:10:55 +01:00
|
|
|
+ g_warning ("Too small tzdata file");
|
2017-12-09 02:05:00 +01:00
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ header_index_offset = gint32_from_be (*((gint32_be*) (tzdata + 12)));
|
|
|
|
+ header_data_offset = gint32_from_be (*((gint32_be*) (tzdata + 16)));
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ entry_count = (header_data_offset - header_index_offset) / index_entry_size;
|
|
|
|
+ if (entry_count < 1)
|
2017-12-09 02:05:00 +01:00
|
|
|
+ {
|
2017-12-22 00:10:55 +01:00
|
|
|
+ g_warning("No index entry found");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ current_index = 0;
|
|
|
|
+ while (current_index < entry_count)
|
|
|
|
+ {
|
|
|
|
+ entry_name = tzdata + header_index_offset + current_index * index_entry_size;
|
|
|
|
+ /* The name should be null terminated within the 40 chars. */
|
|
|
|
+ if (memchr (entry_name, 0, 40) == NULL)
|
2017-12-09 02:05:00 +01:00
|
|
|
+ {
|
2017-12-22 00:10:55 +01:00
|
|
|
+ g_warning("Invalid index entry");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ if (strcmp (entry_name, identifier) == 0)
|
|
|
|
+ {
|
|
|
|
+ entry_offset = gint32_from_be (*(gint32_be*) (entry_name + 40));
|
|
|
|
+ entry_length = gint32_from_be (*(gint32_be*) (entry_name + 44));
|
|
|
|
+ if (entry_length == 0)
|
2017-12-09 02:05:00 +01:00
|
|
|
+ {
|
2017-12-22 00:10:55 +01:00
|
|
|
+ g_warning ("Invalid tzdata entry with length zero");
|
2017-12-09 02:05:00 +01:00
|
|
|
+ goto error;
|
|
|
|
+ }
|
2017-12-22 00:10:55 +01:00
|
|
|
+ else if (entry_length > 65536 || header_data_offset + entry_offset + entry_length > tzdata_length)
|
2017-12-21 04:53:07 +01:00
|
|
|
+ {
|
2017-12-22 00:10:55 +01:00
|
|
|
+ /* Use a reasonable but arbitrary max length of an entry. */
|
2017-12-21 04:53:07 +01:00
|
|
|
+ g_warning ("Too large tzdata entry length");
|
|
|
|
+ goto error;
|
|
|
|
+ }
|
|
|
|
+
|
2017-12-22 00:10:55 +01:00
|
|
|
+ zoneinfo = g_bytes_new_with_free_func (tzdata + header_data_offset + entry_offset,
|
|
|
|
+ entry_length,
|
|
|
|
+ (GDestroyNotify)g_mapped_file_unref,
|
|
|
|
+ g_mapped_file_ref (file));
|
|
|
|
+ g_mapped_file_unref (file);
|
|
|
|
+ return zoneinfo;
|
2016-09-12 23:57:40 +02:00
|
|
|
+ }
|
2017-12-22 00:10:55 +01:00
|
|
|
+ current_index++;
|
2016-09-12 23:57:40 +02:00
|
|
|
+ }
|
2017-12-09 02:05:00 +01:00
|
|
|
+
|
2016-09-12 23:57:40 +02:00
|
|
|
+error:
|
2017-12-22 00:10:55 +01:00
|
|
|
+ g_mapped_file_unref (file);
|
2016-09-12 23:57:40 +02:00
|
|
|
+ return NULL;
|
2017-12-09 02:05:00 +01:00
|
|
|
+}
|
|
|
|
+
|
|
|
|
+#elif defined(G_OS_UNIX)
|
|
|
|
+
|
|
|
|
static GBytes*
|
|
|
|
zone_info_unix (const gchar *identifier)
|
|
|
|
{
|
2017-12-22 00:10:55 +01:00
|
|
|
@@ -436,6 +542,10 @@
|
2016-09-12 23:57:40 +02:00
|
|
|
return zoneinfo;
|
|
|
|
}
|
|
|
|
|
2017-12-09 02:05:00 +01:00
|
|
|
+#endif
|
|
|
|
+
|
|
|
|
+#ifdef G_OS_UNIX
|
|
|
|
+
|
2016-09-12 23:57:40 +02:00
|
|
|
static void
|
2017-12-09 02:05:00 +01:00
|
|
|
init_zone_from_iana_info (GTimeZone *gtz, GBytes *zoneinfo)
|
|
|
|
{
|
2017-12-22 00:10:55 +01:00
|
|
|
@@ -1387,7 +1497,11 @@
|
2017-12-09 02:05:00 +01:00
|
|
|
if (tz->t_info == NULL)
|
|
|
|
{
|
|
|
|
#ifdef G_OS_UNIX
|
|
|
|
+# ifdef __ANDROID__
|
|
|
|
+ GBytes *zoneinfo = zone_info_android (identifier);
|
|
|
|
+# else
|
|
|
|
GBytes *zoneinfo = zone_info_unix (identifier);
|
|
|
|
+# endif
|
|
|
|
if (!zoneinfo)
|
|
|
|
zone_for_constant_offset (tz, "UTC");
|
|
|
|
else
|