1073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller/* 2073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * Copyright (C) 2015 The Android Open Source Project 3073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * 4073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * Licensed under the Apache License, Version 2.0 (the "License"); 5073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * you may not use this file except in compliance with the License. 6073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * You may obtain a copy of the License at 7073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * 8073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * http://www.apache.org/licenses/LICENSE-2.0 9073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * 10073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * Unless required by applicable law or agreed to in writing, software 11073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * distributed under the License is distributed on an "AS IS" BASIS, 12073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * See the License for the specific language governing permissions and 14073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller * limitations under the License. 15073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller */ 16073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 17073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include "include/IcuUtils.h" 18073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 19073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include "unicode/putil.h" 20073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include "unicode/uclean.h" 21073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include "unicode/utypes.h" 22073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include "utils/Log.h" 23073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 24073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller#include <stdlib.h> 25073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 26073b22750e969e089422dde8c298e7d767ae69f8Neil Fullervoid InitializeIcuOrDie() { 27073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller const char* systemPathPrefix = getenv("ANDROID_ROOT"); 28073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller LOG_ALWAYS_FATAL_IF(systemPathPrefix == NULL, "ANDROID_ROOT environment variable not set"); 29073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 30073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller char buf[256]; 31073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller const int num_written = snprintf(buf, sizeof(buf), "%s/usr/icu/", systemPathPrefix); 32073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller LOG_ALWAYS_FATAL_IF((num_written < 0 || static_cast<size_t>(num_written) >= sizeof(buf)), 33073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller "Unable to construct ICU path."); 34073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 35073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller u_setDataDirectory(buf); 36073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller UErrorCode status = U_ZERO_ERROR; 37073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller 38073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller // u_setDataDirectory doesn't try doing anything with the directory we gave 39073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller // it, so we'll have to call u_init to make sure it was successful. 40073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller u_init(&status); 41073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller LOG_ALWAYS_FATAL_IF(!U_SUCCESS(status), "Failed to initialize ICU %s", u_errorName(status)); 42073b22750e969e089422dde8c298e7d767ae69f8Neil Fuller} 43