Sets the loading path for tzdata

Fuchsia has a fixed path in which tzdata is offered to
running programs.  This change sets the env variables
that point to the data.

Fixes #39861

Change-Id: Idf669fa72bda3278bfbdae2a95b0381769f6e698
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/129301
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Filip Filmar 2020-01-10 21:53:02 +00:00 committed by commit-bot@chromium.org
parent 763b682963
commit 63d4797fbe

View file

@ -8,6 +8,9 @@
#include "vm/os.h"
#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <fuchsia/deprecatedtimezone/cpp/fidl.h>
#include <lib/sys/cpp/service_directory.h>
#include <zircon/process.h>
@ -20,6 +23,27 @@
namespace dart {
// The data directory containing ICU timezone data files.
static constexpr char kICUTZDataDir[] = "/config/data/tzdata/icu/44/le";
// Initializes the source of timezone data if available. Timezone data file in
// Fuchsia is at a fixed directory path. Returns true on success.
bool InitializeTZData() {
// Try opening the path to check if present. No need to verify that it is a
// directory since ICU loading will return an error if the TZ data path is
// wrong.
int fd = openat(AT_FDCWD, kICUTZDataDir, O_RDONLY);
if (fd < 0) {
return false;
}
// 0 == Not overwriting the env var if already set.
setenv("ICU_TIMEZONE_FILES_DIR", kICUTZDataDir, 0);
if (!close(fd)) {
return false;
}
return true;
}
#ifndef PRODUCT
DEFINE_FLAG(bool,
@ -239,6 +263,7 @@ void OS::PrintErr(const char* format, ...) {
}
void OS::Init() {
InitializeTZData();
auto services = sys::ServiceDirectory::CreateFromNamespace();
services->Connect(tz.NewRequest());
}