1999-11-22 19:43:01 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2015-07-15 22:09:25 +00:00
|
|
|
* Copyright (C) 1999-2015, International Business Machines
|
2000-01-13 23:54:23 +00:00
|
|
|
* Corporation and others. All Rights Reserved.
|
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2010-06-15 21:19:16 +00:00
|
|
|
* file name: udata.cpp
|
1999-11-22 19:43:01 +00:00
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 1999oct25
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#include "unicode/utypes.h" /* U_PLATFORM etc. */
|
2010-01-15 20:47:28 +00:00
|
|
|
|
2011-07-23 00:10:30 +00:00
|
|
|
#ifdef __GNUC__
|
2010-01-15 20:47:28 +00:00
|
|
|
/* if gcc
|
|
|
|
#define ATTRIBUTE_WEAK __attribute__ ((weak))
|
|
|
|
might have to #include some other header
|
|
|
|
*/
|
|
|
|
#endif
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/putil.h"
|
|
|
|
#include "unicode/udata.h"
|
2001-07-26 21:55:49 +00:00
|
|
|
#include "unicode/uversion.h"
|
2010-05-21 04:39:19 +00:00
|
|
|
#include "charstr.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
2015-07-15 22:09:25 +00:00
|
|
|
#include "mutex.h"
|
2004-10-18 02:43:33 +00:00
|
|
|
#include "putilimp.h"
|
2013-06-01 03:37:16 +00:00
|
|
|
#include "uassert.h"
|
2010-05-21 04:39:19 +00:00
|
|
|
#include "ucln_cmn.h"
|
|
|
|
#include "ucmndata.h"
|
2001-09-07 18:42:29 +00:00
|
|
|
#include "udatamem.h"
|
2010-05-21 04:39:19 +00:00
|
|
|
#include "uhash.h"
|
2001-09-07 18:42:29 +00:00
|
|
|
#include "umapfile.h"
|
2010-05-21 04:39:19 +00:00
|
|
|
#include "umutex.h"
|
2000-11-22 01:24:40 +00:00
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Notes on the organization of the ICU data implementation
|
|
|
|
*
|
|
|
|
* All of the public API is defined in udata.h
|
|
|
|
*
|
|
|
|
* The implementation is split into several files...
|
|
|
|
*
|
|
|
|
* - udata.c (this file) contains higher level code that knows about
|
|
|
|
* the search paths for locating data, caching opened data, etc.
|
|
|
|
*
|
|
|
|
* - umapfile.c contains the low level platform-specific code for actually loading
|
|
|
|
* (memory mapping, file reading, whatever) data into memory.
|
|
|
|
*
|
|
|
|
* - ucmndata.c deals with the tables of contents of ICU data items within
|
|
|
|
* an ICU common format data file. The implementation includes
|
|
|
|
* an abstract interface and support for multiple TOC formats.
|
|
|
|
* All knowledge of any specific TOC format is encapsulated here.
|
|
|
|
*
|
|
|
|
* - udatamem.c has code for managing UDataMemory structs. These are little
|
|
|
|
* descriptor objects for blocks of memory holding ICU data of
|
|
|
|
* various types.
|
2001-09-25 16:43:20 +00:00
|
|
|
*/
|
2000-12-05 02:28:32 +00:00
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/* configuration ---------------------------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-01-19 07:23:50 +00:00
|
|
|
/* If you are excruciatingly bored turn this on .. */
|
2000-05-03 23:11:04 +00:00
|
|
|
/* #define UDATA_DEBUG 1 */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
|
|
|
#if defined(UDATA_DEBUG)
|
2000-05-03 23:11:04 +00:00
|
|
|
# include <stdio.h>
|
1999-11-22 19:43:01 +00:00
|
|
|
#endif
|
|
|
|
|
2010-06-15 21:19:16 +00:00
|
|
|
U_NAMESPACE_USE
|
|
|
|
|
2011-07-13 04:49:45 +00:00
|
|
|
/*
|
|
|
|
* Forward declarations
|
|
|
|
*/
|
|
|
|
static UDataMemory *udata_findCachedData(const char *path);
|
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* static (Global) data
|
|
|
|
*
|
|
|
|
************************************************************************/
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2010-01-15 20:47:28 +00:00
|
|
|
/*
|
|
|
|
* Pointers to the common ICU data.
|
|
|
|
*
|
|
|
|
* We store multiple pointers to ICU data packages and iterate through them
|
|
|
|
* when looking for a data item.
|
|
|
|
*
|
|
|
|
* It is possible to combine this with dependency inversion:
|
|
|
|
* One or more data package libraries may export
|
|
|
|
* functions that each return a pointer to their piece of the ICU data,
|
|
|
|
* and this file would import them as weak functions, without a
|
|
|
|
* strong linker dependency from the common library on the data library.
|
|
|
|
*
|
|
|
|
* Then we can have applications depend on only that part of ICU's data
|
|
|
|
* that they really need, reducing the size of binaries that take advantage
|
|
|
|
* of this.
|
|
|
|
*/
|
2015-07-15 22:09:25 +00:00
|
|
|
static UDataMemory *gCommonICUDataArray[10] = { NULL }; // Access protected by icu global mutex.
|
2010-01-15 20:47:28 +00:00
|
|
|
|
2015-07-15 22:09:25 +00:00
|
|
|
static u_atomic_int32_t gHaveTriedToLoadCommonData = ATOMIC_INT32_T_INITIALIZER(0); // See extendICUData().
|
2001-09-17 22:57:38 +00:00
|
|
|
|
|
|
|
static UHashtable *gCommonDataCache = NULL; /* Global hash table of opened ICU data files. */
|
2013-09-10 00:34:12 +00:00
|
|
|
static icu::UInitOnce gCommonDataCacheInitOnce = U_INITONCE_INITIALIZER;
|
2000-11-04 02:16:12 +00:00
|
|
|
|
2015-07-15 22:09:25 +00:00
|
|
|
static UDataFileAccess gDataFileAccess = UDATA_DEFAULT_ACCESS; // Access not synchronized.
|
|
|
|
// Modifying is documented as thread-unsafe.
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2004-10-06 23:10:53 +00:00
|
|
|
static UBool U_CALLCONV
|
|
|
|
udata_cleanup(void)
|
2001-09-07 18:42:29 +00:00
|
|
|
{
|
2010-01-15 20:47:28 +00:00
|
|
|
int32_t i;
|
|
|
|
|
2001-10-10 18:05:10 +00:00
|
|
|
if (gCommonDataCache) { /* Delete the cache of user data mappings. */
|
|
|
|
uhash_close(gCommonDataCache); /* Table owns the contents, and will delete them. */
|
|
|
|
gCommonDataCache = NULL; /* Cleanup is not thread safe. */
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
gCommonDataCacheInitOnce.reset();
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2014-08-28 22:13:45 +00:00
|
|
|
for (i = 0; i < UPRV_LENGTHOF(gCommonICUDataArray) && gCommonICUDataArray[i] != NULL; ++i) {
|
2010-01-15 20:47:28 +00:00
|
|
|
udata_close(gCommonICUDataArray[i]);
|
|
|
|
gCommonICUDataArray[i] = NULL;
|
2001-09-17 22:57:38 +00:00
|
|
|
}
|
2015-07-15 22:09:25 +00:00
|
|
|
gHaveTriedToLoadCommonData = 0;
|
2000-11-04 02:16:12 +00:00
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
return TRUE; /* Everything was cleaned up */
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2011-07-13 04:49:45 +00:00
|
|
|
static UBool U_CALLCONV
|
|
|
|
findCommonICUDataByName(const char *inBasename)
|
|
|
|
{
|
|
|
|
UBool found = FALSE;
|
|
|
|
int32_t i;
|
|
|
|
|
|
|
|
UDataMemory *pData = udata_findCachedData(inBasename);
|
|
|
|
if (pData == NULL)
|
|
|
|
return FALSE;
|
|
|
|
|
2015-07-15 22:09:25 +00:00
|
|
|
{
|
|
|
|
Mutex lock;
|
|
|
|
for (i = 0; i < UPRV_LENGTHOF(gCommonICUDataArray); ++i) {
|
|
|
|
if ((gCommonICUDataArray[i] != NULL) && (gCommonICUDataArray[i]->pHeader == pData->pHeader)) {
|
|
|
|
/* The data pointer is already in the array. */
|
|
|
|
found = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
2011-07-13 04:49:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return found;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
|
|
|
|
2001-08-30 18:41:30 +00:00
|
|
|
/*
|
|
|
|
* setCommonICUData. Set a UDataMemory to be the global ICU Data
|
|
|
|
*/
|
2010-01-15 20:47:28 +00:00
|
|
|
static UBool
|
2001-08-30 18:41:30 +00:00
|
|
|
setCommonICUData(UDataMemory *pData, /* The new common data. Belongs to caller, we copy it. */
|
|
|
|
UBool warn, /* If true, set USING_DEFAULT warning if ICUData was */
|
|
|
|
/* changed by another thread before we got to it. */
|
|
|
|
UErrorCode *pErr)
|
|
|
|
{
|
|
|
|
UDataMemory *newCommonData = UDataMemory_createNewInstance(pErr);
|
2010-01-15 20:47:28 +00:00
|
|
|
int32_t i;
|
|
|
|
UBool didUpdate = FALSE;
|
2001-08-30 18:41:30 +00:00
|
|
|
if (U_FAILURE(*pErr)) {
|
2010-01-15 20:47:28 +00:00
|
|
|
return FALSE;
|
2001-08-30 18:41:30 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2001-08-30 18:41:30 +00:00
|
|
|
/* For the assignment, other threads must cleanly see either the old */
|
|
|
|
/* or the new, not some partially initialized new. The old can not be */
|
|
|
|
/* deleted - someone may still have a pointer to it lying around in */
|
|
|
|
/* their locals. */
|
|
|
|
UDatamemory_assign(newCommonData, pData);
|
2000-05-03 23:11:04 +00:00
|
|
|
umtx_lock(NULL);
|
2014-08-28 22:13:45 +00:00
|
|
|
for (i = 0; i < UPRV_LENGTHOF(gCommonICUDataArray); ++i) {
|
2010-01-15 20:47:28 +00:00
|
|
|
if (gCommonICUDataArray[i] == NULL) {
|
|
|
|
gCommonICUDataArray[i] = newCommonData;
|
|
|
|
didUpdate = TRUE;
|
|
|
|
break;
|
|
|
|
} else if (gCommonICUDataArray[i]->pHeader == pData->pHeader) {
|
|
|
|
/* The same data pointer is already in the array. */
|
|
|
|
break;
|
2001-08-30 18:41:30 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
2010-01-15 20:47:28 +00:00
|
|
|
|
2014-08-28 22:13:45 +00:00
|
|
|
if (i == UPRV_LENGTHOF(gCommonICUDataArray) && warn) {
|
2010-01-15 20:47:28 +00:00
|
|
|
*pErr = U_USING_DEFAULT_WARNING;
|
|
|
|
}
|
2014-04-23 23:22:13 +00:00
|
|
|
if (didUpdate) {
|
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UDATA, udata_cleanup);
|
|
|
|
} else {
|
2010-01-15 20:47:28 +00:00
|
|
|
uprv_free(newCommonData);
|
|
|
|
}
|
|
|
|
return didUpdate;
|
|
|
|
}
|
|
|
|
|
|
|
|
static UBool
|
2010-05-21 04:39:19 +00:00
|
|
|
setCommonICUDataPointer(const void *pData, UBool /*warn*/, UErrorCode *pErrorCode) {
|
2010-01-15 20:47:28 +00:00
|
|
|
UDataMemory tData;
|
|
|
|
UDataMemory_init(&tData);
|
2013-08-15 00:01:20 +00:00
|
|
|
UDataMemory_setData(&tData, pData);
|
2010-01-15 20:47:28 +00:00
|
|
|
udata_checkCommonData(&tData, pErrorCode);
|
|
|
|
return setCommonICUData(&tData, FALSE, pErrorCode);
|
1999-12-01 01:02:06 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static const char *
|
|
|
|
findBasename(const char *path) {
|
|
|
|
const char *basename=uprv_strrchr(path, U_FILE_SEP_CHAR);
|
|
|
|
if(basename==NULL) {
|
|
|
|
return path;
|
|
|
|
} else {
|
|
|
|
return basename+1;
|
1999-12-01 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-08-11 22:16:29 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2002-07-17 03:01:45 +00:00
|
|
|
static const char *
|
|
|
|
packageNameFromPath(const char *path)
|
|
|
|
{
|
|
|
|
if((path == NULL) || (*path == 0)) {
|
|
|
|
return U_ICUDATA_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
path = findBasename(path);
|
|
|
|
|
|
|
|
if((path == NULL) || (*path == 0)) {
|
|
|
|
return U_ICUDATA_NAME;
|
|
|
|
}
|
|
|
|
|
|
|
|
return path;
|
|
|
|
}
|
2004-08-11 22:16:29 +00:00
|
|
|
#endif
|
2001-07-26 21:55:49 +00:00
|
|
|
|
2001-08-10 20:50:07 +00:00
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* Cache for common data *
|
|
|
|
* Functions for looking up or adding entries to a cache of *
|
|
|
|
* data that has been previously opened. Avoids a potentially *
|
|
|
|
* expensive operation of re-opening the data for subsequent *
|
|
|
|
* uses. *
|
|
|
|
* *
|
|
|
|
* Data remains cached for the duration of the process. *
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
typedef struct DataCacheElement {
|
2001-08-29 22:57:37 +00:00
|
|
|
char *name;
|
2001-09-07 18:42:29 +00:00
|
|
|
UDataMemory *item;
|
2001-08-10 20:50:07 +00:00
|
|
|
} DataCacheElement;
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-08-15 23:27:38 +00:00
|
|
|
* Deleter function for DataCacheElements.
|
2001-08-15 22:39:42 +00:00
|
|
|
* udata cleanup function closes the hash table; hash table in turn calls back to
|
|
|
|
* here for each entry.
|
|
|
|
*/
|
2005-07-07 17:50:37 +00:00
|
|
|
static void U_CALLCONV DataCacheElement_deleter(void *pDCEl) {
|
2001-08-15 22:39:42 +00:00
|
|
|
DataCacheElement *p = (DataCacheElement *)pDCEl;
|
2001-09-07 18:42:29 +00:00
|
|
|
udata_close(p->item); /* unmaps storage */
|
2001-08-29 22:57:37 +00:00
|
|
|
uprv_free(p->name); /* delete the hash key string. */
|
2001-08-15 22:39:42 +00:00
|
|
|
uprv_free(pDCEl); /* delete 'this' */
|
|
|
|
}
|
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
static void udata_initHashTable() {
|
|
|
|
UErrorCode err = U_ZERO_ERROR;
|
|
|
|
U_ASSERT(gCommonDataCache == NULL);
|
|
|
|
gCommonDataCache = uhash_open(uhash_hashChars, uhash_compareChars, NULL, &err);
|
|
|
|
if (U_FAILURE(err)) {
|
|
|
|
// TODO: handle errors better.
|
|
|
|
gCommonDataCache = NULL;
|
2008-01-16 22:24:05 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
if (gCommonDataCache != NULL) {
|
|
|
|
uhash_setValueDeleter(gCommonDataCache, DataCacheElement_deleter);
|
2004-10-06 23:10:53 +00:00
|
|
|
ucln_common_registerCleanup(UCLN_COMMON_UDATA, udata_cleanup);
|
2001-08-10 20:50:07 +00:00
|
|
|
}
|
2013-06-01 03:37:16 +00:00
|
|
|
}
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2013-06-01 03:37:16 +00:00
|
|
|
/* udata_getCacheHashTable()
|
|
|
|
* Get the hash table used to store the data cache entries.
|
|
|
|
* Lazy create it if it doesn't yet exist.
|
|
|
|
*/
|
|
|
|
static UHashtable *udata_getHashTable() {
|
|
|
|
umtx_initOnce(gCommonDataCacheInitOnce, &udata_initHashTable);
|
2001-09-07 18:42:29 +00:00
|
|
|
return gCommonDataCache;
|
2001-08-10 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static UDataMemory *udata_findCachedData(const char *path)
|
|
|
|
{
|
2001-08-15 22:39:42 +00:00
|
|
|
UHashtable *htable;
|
|
|
|
UDataMemory *retVal = NULL;
|
|
|
|
DataCacheElement *el;
|
2001-08-29 22:57:37 +00:00
|
|
|
const char *baseName;
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2001-08-30 02:59:19 +00:00
|
|
|
baseName = findBasename(path); /* Cache remembers only the base name, not the full path. */
|
2001-08-10 20:50:07 +00:00
|
|
|
htable = udata_getHashTable();
|
2001-08-15 23:27:38 +00:00
|
|
|
umtx_lock(NULL);
|
2001-08-29 22:57:37 +00:00
|
|
|
el = (DataCacheElement *)uhash_get(htable, baseName);
|
2001-08-10 20:50:07 +00:00
|
|
|
umtx_unlock(NULL);
|
2001-08-15 22:39:42 +00:00
|
|
|
if (el != NULL) {
|
2001-09-07 18:42:29 +00:00
|
|
|
retVal = el->item;
|
2001-08-15 22:39:42 +00:00
|
|
|
}
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "Cache: [%s] -> %p\n", baseName, retVal);
|
|
|
|
#endif
|
2001-08-10 20:50:07 +00:00
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
static UDataMemory *udata_cacheDataItem(const char *path, UDataMemory *item, UErrorCode *pErr) {
|
2001-08-10 20:50:07 +00:00
|
|
|
DataCacheElement *newElement;
|
2001-08-29 22:57:37 +00:00
|
|
|
const char *baseName;
|
2002-04-30 21:03:00 +00:00
|
|
|
int32_t nameLen;
|
2001-08-15 22:39:42 +00:00
|
|
|
UHashtable *htable;
|
2009-10-07 22:06:24 +00:00
|
|
|
DataCacheElement *oldValue = NULL;
|
2004-01-20 21:36:37 +00:00
|
|
|
UErrorCode subErr = U_ZERO_ERROR;
|
2001-08-15 22:39:42 +00:00
|
|
|
|
|
|
|
if (U_FAILURE(*pErr)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-10 20:50:07 +00:00
|
|
|
|
|
|
|
/* Create a new DataCacheElement - the thingy we store in the hash table -
|
|
|
|
* and copy the supplied path and UDataMemoryItems into it.
|
|
|
|
*/
|
2010-05-21 04:39:19 +00:00
|
|
|
newElement = (DataCacheElement *)uprv_malloc(sizeof(DataCacheElement));
|
2001-08-15 22:39:42 +00:00
|
|
|
if (newElement == NULL) {
|
|
|
|
*pErr = U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-09-07 18:42:29 +00:00
|
|
|
newElement->item = UDataMemory_createNewInstance(pErr);
|
|
|
|
if (U_FAILURE(*pErr)) {
|
2006-03-28 08:51:19 +00:00
|
|
|
uprv_free(newElement);
|
2001-09-07 18:42:29 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
UDatamemory_assign(newElement->item, item);
|
2001-08-29 22:57:37 +00:00
|
|
|
|
|
|
|
baseName = findBasename(path);
|
2002-04-30 21:03:00 +00:00
|
|
|
nameLen = (int32_t)uprv_strlen(baseName);
|
2010-05-21 04:39:19 +00:00
|
|
|
newElement->name = (char *)uprv_malloc(nameLen+1);
|
2001-08-29 22:57:37 +00:00
|
|
|
if (newElement->name == NULL) {
|
2001-08-15 22:39:42 +00:00
|
|
|
*pErr = U_MEMORY_ALLOCATION_ERROR;
|
2006-03-28 08:51:19 +00:00
|
|
|
uprv_free(newElement->item);
|
|
|
|
uprv_free(newElement);
|
2001-08-15 22:39:42 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-29 22:57:37 +00:00
|
|
|
uprv_strcpy(newElement->name, baseName);
|
2001-08-10 20:50:07 +00:00
|
|
|
|
|
|
|
/* Stick the new DataCacheElement into the hash table.
|
|
|
|
*/
|
2001-08-15 22:39:42 +00:00
|
|
|
htable = udata_getHashTable();
|
2001-08-15 23:27:38 +00:00
|
|
|
umtx_lock(NULL);
|
2009-10-07 22:06:24 +00:00
|
|
|
oldValue = (DataCacheElement *)uhash_get(htable, path);
|
2001-08-15 22:39:42 +00:00
|
|
|
if (oldValue != NULL) {
|
2004-01-20 21:41:23 +00:00
|
|
|
subErr = U_USING_DEFAULT_WARNING;
|
|
|
|
}
|
2001-08-15 22:39:42 +00:00
|
|
|
else {
|
2001-08-15 23:27:38 +00:00
|
|
|
uhash_put(
|
2001-08-15 22:39:42 +00:00
|
|
|
htable,
|
2001-08-29 22:57:37 +00:00
|
|
|
newElement->name, /* Key */
|
2001-08-15 22:39:42 +00:00
|
|
|
newElement, /* Value */
|
2004-01-20 21:36:37 +00:00
|
|
|
&subErr);
|
2001-08-15 22:39:42 +00:00
|
|
|
}
|
2001-08-10 20:50:07 +00:00
|
|
|
umtx_unlock(NULL);
|
2001-08-15 22:39:42 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2004-01-20 21:36:37 +00:00
|
|
|
fprintf(stderr, "Cache: [%s] <<< %p : %s. vFunc=%p\n", newElement->name,
|
|
|
|
newElement->item, u_errorName(subErr), newElement->item->vFuncs);
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
|
|
|
|
2004-01-20 21:36:37 +00:00
|
|
|
if (subErr == U_USING_DEFAULT_WARNING || U_FAILURE(subErr)) {
|
|
|
|
*pErr = subErr; /* copy sub err unto fillin ONLY if something happens. */
|
2001-08-29 22:57:37 +00:00
|
|
|
uprv_free(newElement->name);
|
2001-11-28 23:19:56 +00:00
|
|
|
uprv_free(newElement->item);
|
2001-08-15 22:39:42 +00:00
|
|
|
uprv_free(newElement);
|
2009-10-07 22:06:24 +00:00
|
|
|
return oldValue ? oldValue->item : NULL;
|
2001-08-15 22:39:42 +00:00
|
|
|
}
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
return newElement->item;
|
2001-08-10 20:50:07 +00:00
|
|
|
}
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/*----------------------------------------------------------------------*==============
|
|
|
|
* *
|
|
|
|
* Path management. Could be shared with other tools/etc if need be *
|
|
|
|
* later on. *
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
|
|
|
|
2003-06-26 00:06:49 +00:00
|
|
|
#define U_DATA_PATHITER_BUFSIZ 128 /* Size of local buffer for paths */
|
|
|
|
/* Overflow causes malloc of larger buf */
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-06-23 00:38:51 +00:00
|
|
|
U_NAMESPACE_BEGIN
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
class UDataPathIterator
|
2002-07-17 03:01:45 +00:00
|
|
|
{
|
2010-05-21 04:39:19 +00:00
|
|
|
public:
|
|
|
|
UDataPathIterator(const char *path, const char *pkg,
|
|
|
|
const char *item, const char *suffix, UBool doCheckLastFour,
|
|
|
|
UErrorCode *pErrorCode);
|
|
|
|
const char *next(UErrorCode *pErrorCode);
|
|
|
|
|
|
|
|
private:
|
2002-07-17 03:01:45 +00:00
|
|
|
const char *path; /* working path (u_icudata_Dir) */
|
|
|
|
const char *nextPath; /* path following this one */
|
|
|
|
const char *basename; /* item's basename (icudt22e_mt.res)*/
|
|
|
|
const char *suffix; /* item suffix (can be null) */
|
|
|
|
|
2003-06-26 00:06:49 +00:00
|
|
|
uint32_t basenameLen; /* length of basename */
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
CharString itemPath; /* path passed in with item name */
|
|
|
|
CharString pathBuffer; /* output path for this it'ion */
|
|
|
|
CharString packageStub; /* example: "/icudt28b". Will ignore that leaf in set paths. */
|
2004-04-14 19:58:08 +00:00
|
|
|
|
2003-06-26 00:06:49 +00:00
|
|
|
UBool checkLastFour; /* if TRUE then allow paths such as '/foo/myapp.dat'
|
|
|
|
* to match, checks last 4 chars of suffix with
|
|
|
|
* last 4 of path, then previous chars. */
|
2010-05-21 04:39:19 +00:00
|
|
|
};
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
/**
|
2002-07-17 03:01:45 +00:00
|
|
|
* @param iter The iterator to be initialized. Its current state does not matter.
|
|
|
|
* @param path The full pathname to be iterated over. If NULL, defaults to U_ICUDATA_NAME
|
2004-04-14 19:58:08 +00:00
|
|
|
* @param pkg Package which is being searched for, ex "icudt28l". Will ignore leave directories such as /icudt28l
|
2002-07-17 03:01:45 +00:00
|
|
|
* @param item Item to be searched for. Can include full path, such as /a/b/foo.dat
|
2003-06-26 00:06:49 +00:00
|
|
|
* @param suffix Optional item suffix, if not-null (ex. ".dat") then 'path' can contain 'item' explicitly.
|
|
|
|
* Ex: 'stuff.dat' would be found in '/a/foo:/tmp/stuff.dat:/bar/baz' as item #2.
|
|
|
|
* '/blarg/stuff.dat' would also be found.
|
2002-07-17 03:01:45 +00:00
|
|
|
*/
|
2010-05-21 04:39:19 +00:00
|
|
|
UDataPathIterator::UDataPathIterator(const char *inPath, const char *pkg,
|
|
|
|
const char *item, const char *inSuffix, UBool doCheckLastFour,
|
|
|
|
UErrorCode *pErrorCode)
|
2002-07-17 03:01:45 +00:00
|
|
|
{
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "SUFFIX1=%s PATH=%s\n", inSuffix, inPath);
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
|
|
|
/** Path **/
|
2010-05-21 04:39:19 +00:00
|
|
|
if(inPath == NULL) {
|
|
|
|
path = u_getDataDirectory();
|
2002-07-17 03:01:45 +00:00
|
|
|
} else {
|
2010-05-21 04:39:19 +00:00
|
|
|
path = inPath;
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
|
|
|
|
2004-04-14 19:58:08 +00:00
|
|
|
/** Package **/
|
2010-05-21 04:39:19 +00:00
|
|
|
if(pkg != NULL) {
|
|
|
|
packageStub.append(U_FILE_SEP_CHAR, *pErrorCode).append(pkg, *pErrorCode);
|
2004-04-14 19:58:08 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "STUB=%s [%d]\n", packageStub.data(), packageStub.length());
|
2004-04-14 19:58:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/** Item **/
|
2010-05-21 04:39:19 +00:00
|
|
|
basename = findBasename(item);
|
|
|
|
basenameLen = (int32_t)uprv_strlen(basename);
|
2002-07-17 03:01:45 +00:00
|
|
|
|
|
|
|
/** Item path **/
|
2010-05-21 04:39:19 +00:00
|
|
|
if(basename == item) {
|
|
|
|
nextPath = path;
|
|
|
|
} else {
|
|
|
|
itemPath.append(item, (int32_t)(basename-item), *pErrorCode);
|
|
|
|
nextPath = itemPath.data();
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "SUFFIX=%s [%p]\n", inSuffix, inSuffix);
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
|
2003-06-26 00:06:49 +00:00
|
|
|
/** Suffix **/
|
2010-05-21 04:39:19 +00:00
|
|
|
if(inSuffix != NULL) {
|
|
|
|
suffix = inSuffix;
|
2002-07-17 03:01:45 +00:00
|
|
|
} else {
|
2010-05-21 04:39:19 +00:00
|
|
|
suffix = "";
|
2003-06-26 00:06:49 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
checkLastFour = doCheckLastFour;
|
|
|
|
|
|
|
|
/* pathBuffer will hold the output path strings returned by this iterator */
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "%p: init %s -> [path=%s], [base=%s], [suff=%s], [itempath=%s], [nextpath=%s], [checklast4=%s]\n",
|
|
|
|
iter,
|
|
|
|
item,
|
2010-05-21 04:39:19 +00:00
|
|
|
path,
|
|
|
|
basename,
|
|
|
|
suffix,
|
|
|
|
itemPath.data(),
|
|
|
|
nextPath,
|
|
|
|
checkLastFour?"TRUE":"false");
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the next path on the list.
|
|
|
|
*
|
|
|
|
* @param iter The Iter to be used
|
|
|
|
* @param len If set, pointer to the length of the returned path, for convenience.
|
|
|
|
* @return Pointer to the next path segment, or NULL if there are no more.
|
|
|
|
*/
|
2010-05-21 04:39:19 +00:00
|
|
|
const char *UDataPathIterator::next(UErrorCode *pErrorCode)
|
2002-07-17 03:01:45 +00:00
|
|
|
{
|
2010-05-21 04:39:19 +00:00
|
|
|
if(U_FAILURE(*pErrorCode)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *currentPath = NULL;
|
|
|
|
int32_t pathLen = 0;
|
2002-07-17 03:01:45 +00:00
|
|
|
const char *pathBasename;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2010-05-21 04:39:19 +00:00
|
|
|
if( nextPath == NULL ) {
|
2006-03-30 19:43:46 +00:00
|
|
|
break;
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
2010-05-21 04:39:19 +00:00
|
|
|
currentPath = nextPath;
|
|
|
|
|
|
|
|
if(nextPath == itemPath.data()) { /* we were processing item's path. */
|
|
|
|
nextPath = path; /* start with regular path next tm. */
|
|
|
|
pathLen = (int32_t)uprv_strlen(currentPath);
|
2002-07-17 03:01:45 +00:00
|
|
|
} else {
|
|
|
|
/* fix up next for next time */
|
2010-05-21 04:39:19 +00:00
|
|
|
nextPath = uprv_strchr(currentPath, U_PATH_SEP_CHAR);
|
|
|
|
if(nextPath == NULL) {
|
2002-07-17 03:01:45 +00:00
|
|
|
/* segment: entire path */
|
2010-05-21 04:39:19 +00:00
|
|
|
pathLen = (int32_t)uprv_strlen(currentPath);
|
2002-07-17 03:01:45 +00:00
|
|
|
} else {
|
|
|
|
/* segment: until next segment */
|
2010-05-21 04:39:19 +00:00
|
|
|
pathLen = (int32_t)(nextPath - currentPath);
|
|
|
|
/* skip divider */
|
|
|
|
nextPath ++;
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pathLen == 0) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "rest of path (IDD) = %s\n", currentPath);
|
2002-07-17 03:01:45 +00:00
|
|
|
fprintf(stderr, " ");
|
|
|
|
{
|
2004-04-14 19:58:08 +00:00
|
|
|
uint32_t qqq;
|
2002-07-17 03:01:45 +00:00
|
|
|
for(qqq=0;qqq<pathLen;qqq++)
|
|
|
|
{
|
|
|
|
fprintf(stderr, " ");
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr, "^\n");
|
|
|
|
}
|
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
pathBuffer.clear().append(currentPath, pathLen, *pErrorCode);
|
2002-07-17 03:01:45 +00:00
|
|
|
|
|
|
|
/* check for .dat files */
|
2010-05-21 04:39:19 +00:00
|
|
|
pathBasename = findBasename(pathBuffer.data());
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
if(checkLastFour == TRUE &&
|
2003-04-18 00:15:33 +00:00
|
|
|
(pathLen>=4) &&
|
2010-05-21 04:39:19 +00:00
|
|
|
uprv_strncmp(pathBuffer.data() +(pathLen-4), suffix, 4)==0 && /* suffix matches */
|
|
|
|
uprv_strncmp(findBasename(pathBuffer.data()), basename, basenameLen)==0 && /* base matches */
|
|
|
|
uprv_strlen(pathBasename)==(basenameLen+4)) { /* base+suffix = full len */
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "Have %s file on the path: %s\n", suffix, pathBuffer.data());
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
|
|
|
/* do nothing */
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{ /* regular dir path */
|
2010-05-21 04:39:19 +00:00
|
|
|
if(pathBuffer[pathLen-1] != U_FILE_SEP_CHAR) {
|
2003-04-18 00:15:33 +00:00
|
|
|
if((pathLen>=4) &&
|
2010-05-21 04:39:19 +00:00
|
|
|
uprv_strncmp(pathBuffer.data()+(pathLen-4), ".dat", 4) == 0)
|
2003-04-18 00:15:33 +00:00
|
|
|
{
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "skipping non-directory .dat file %s\n", pathBuffer.data());
|
2003-04-18 00:15:33 +00:00
|
|
|
#endif
|
2003-06-10 22:10:47 +00:00
|
|
|
continue;
|
2003-04-18 00:15:33 +00:00
|
|
|
}
|
2004-04-14 19:58:08 +00:00
|
|
|
|
|
|
|
/* Check if it is a directory with the same name as our package */
|
2010-05-21 04:39:19 +00:00
|
|
|
if(!packageStub.isEmpty() &&
|
|
|
|
(pathLen > packageStub.length()) &&
|
|
|
|
!uprv_strcmp(pathBuffer.data() + pathLen - packageStub.length(), packageStub.data())) {
|
2004-04-14 19:58:08 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, "Found stub %s (will add package %s of len %d)\n", packageStub.data(), basename, basenameLen);
|
2004-04-14 19:58:08 +00:00
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
pathBuffer.truncate(pathLen - packageStub.length());
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
2010-05-21 04:39:19 +00:00
|
|
|
pathBuffer.append(U_FILE_SEP_CHAR, *pErrorCode);
|
|
|
|
}
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
/* + basename */
|
|
|
|
pathBuffer.append(packageStub.data()+1, packageStub.length()-1, *pErrorCode);
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
if(*suffix) /* tack on suffix */
|
2002-07-17 03:01:45 +00:00
|
|
|
{
|
2010-05-21 04:39:19 +00:00
|
|
|
pathBuffer.append(suffix, *pErrorCode);
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, " --> %s\n", pathBuffer.data());
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
return pathBuffer.data();
|
2002-07-17 03:01:45 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
} while(path);
|
2002-07-17 03:01:45 +00:00
|
|
|
|
|
|
|
/* fell way off the end */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-06-23 00:38:51 +00:00
|
|
|
U_NAMESPACE_END
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/* ==================================================================================*/
|
|
|
|
|
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* *
|
2001-09-07 18:42:29 +00:00
|
|
|
* Add a static reference to the common data library *
|
2002-12-20 16:41:57 +00:00
|
|
|
* Unless overridden by an explicit udata_setCommonData, this will be *
|
2001-09-07 18:42:29 +00:00
|
|
|
* our common data. *
|
2001-08-15 22:39:42 +00:00
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
2010-05-24 23:43:14 +00:00
|
|
|
extern "C" const DataHeader U_DATA_API U_ICUDATA_ENTRY_POINT;
|
2001-07-26 21:55:49 +00:00
|
|
|
|
2010-01-15 20:47:28 +00:00
|
|
|
/*
|
|
|
|
* This would be a good place for weak-linkage declarations of
|
|
|
|
* partial-data-library access functions where each returns a pointer
|
|
|
|
* to its data package, if it is linked in.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
extern const void *uprv_getICUData_collation(void) ATTRIBUTE_WEAK;
|
|
|
|
extern const void *uprv_getICUData_conversion(void) ATTRIBUTE_WEAK;
|
|
|
|
*/
|
2001-08-10 20:50:07 +00:00
|
|
|
|
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* openCommonData Attempt to open a common format (.dat) file *
|
|
|
|
* Map it into memory (if it's not there already) *
|
|
|
|
* and return a UDataMemory object for it. *
|
2001-09-07 18:42:29 +00:00
|
|
|
* *
|
|
|
|
* If the requested data is already open and cached *
|
|
|
|
* just return the cached UDataMem object. *
|
2001-08-10 20:50:07 +00:00
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
1999-11-22 19:43:01 +00:00
|
|
|
static UDataMemory *
|
2005-06-24 20:56:17 +00:00
|
|
|
openCommonData(const char *path, /* Path from OpenChoice? */
|
2010-01-15 20:47:28 +00:00
|
|
|
int32_t commonDataIndex, /* ICU Data (index >= 0) if path == NULL */
|
2001-08-10 20:50:07 +00:00
|
|
|
UErrorCode *pErrorCode)
|
2001-08-15 22:39:42 +00:00
|
|
|
{
|
2002-07-17 03:01:45 +00:00
|
|
|
UDataMemory tData;
|
|
|
|
const char *pathBuffer;
|
2000-05-03 23:11:04 +00:00
|
|
|
const char *inBasename;
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-10 20:50:07 +00:00
|
|
|
UDataMemory_init(&tData);
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/* ??????? TODO revisit this */
|
2010-01-15 20:47:28 +00:00
|
|
|
if (commonDataIndex >= 0) {
|
2001-08-15 22:39:42 +00:00
|
|
|
/* "mini-cache" for common ICU data */
|
2014-08-28 22:13:45 +00:00
|
|
|
if(commonDataIndex >= UPRV_LENGTHOF(gCommonICUDataArray)) {
|
2010-01-15 20:47:28 +00:00
|
|
|
return NULL;
|
2001-08-15 22:39:42 +00:00
|
|
|
}
|
2015-07-15 22:09:25 +00:00
|
|
|
{
|
|
|
|
Mutex lock;
|
|
|
|
if(gCommonICUDataArray[commonDataIndex] != NULL) {
|
|
|
|
return gCommonICUDataArray[commonDataIndex];
|
|
|
|
}
|
2010-01-15 20:47:28 +00:00
|
|
|
int32_t i;
|
|
|
|
for(i = 0; i < commonDataIndex; ++i) {
|
|
|
|
if(gCommonICUDataArray[i]->pHeader == &U_ICUDATA_ENTRY_POINT) {
|
|
|
|
/* The linked-in data is already in the list. */
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
2015-07-15 22:09:25 +00:00
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2015-07-15 22:09:25 +00:00
|
|
|
/* Add the linked-in data to the list. */
|
|
|
|
/*
|
|
|
|
* This is where we would check and call weakly linked partial-data-library
|
|
|
|
* access functions.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
if (uprv_getICUData_collation) {
|
|
|
|
setCommonICUDataPointer(uprv_getICUData_collation(), FALSE, pErrorCode);
|
|
|
|
}
|
|
|
|
if (uprv_getICUData_conversion) {
|
|
|
|
setCommonICUDataPointer(uprv_getICUData_conversion(), FALSE, pErrorCode);
|
|
|
|
}
|
|
|
|
*/
|
|
|
|
setCommonICUDataPointer(&U_ICUDATA_ENTRY_POINT, FALSE, pErrorCode);
|
|
|
|
{
|
|
|
|
Mutex lock;
|
|
|
|
return gCommonICUDataArray[commonDataIndex];
|
2010-01-15 20:47:28 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
|
|
|
|
2001-10-18 16:36:48 +00:00
|
|
|
/* request is NOT for ICU Data. */
|
|
|
|
|
|
|
|
/* Find the base name portion of the supplied path. */
|
|
|
|
/* inBasename will be left pointing somewhere within the original path string. */
|
2002-07-17 03:01:45 +00:00
|
|
|
inBasename = findBasename(path);
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "inBasename = %s\n", inBasename);
|
|
|
|
#endif
|
|
|
|
|
2001-10-18 16:36:48 +00:00
|
|
|
if(*inBasename==0) {
|
|
|
|
/* no basename. This will happen if the original path was a directory name, */
|
|
|
|
/* like "a/b/c/". (Fallback to separate files will still work.) */
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "ocd: no basename in %s, bailing.\n", path);
|
|
|
|
#endif
|
2001-10-18 16:36:48 +00:00
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Is the requested common data file already open and cached? */
|
|
|
|
/* Note that the cache is keyed by the base name only. The rest of the path, */
|
|
|
|
/* if any, is not considered. */
|
|
|
|
{
|
2001-09-07 18:42:29 +00:00
|
|
|
UDataMemory *dataToReturn = udata_findCachedData(inBasename);
|
2001-08-10 20:50:07 +00:00
|
|
|
if (dataToReturn != NULL) {
|
|
|
|
return dataToReturn;
|
|
|
|
}
|
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
/* Requested item is not in the cache.
|
2002-07-17 03:01:45 +00:00
|
|
|
* Hunt it down, trying all the path locations
|
2001-08-15 22:39:42 +00:00
|
|
|
*/
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
UDataPathIterator iter(u_getDataDirectory(), inBasename, path, ".dat", TRUE, pErrorCode);
|
2001-10-18 16:36:48 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
while((UDataMemory_isLoaded(&tData)==FALSE) && (pathBuffer = iter.next(pErrorCode)) != NULL)
|
2002-07-17 03:01:45 +00:00
|
|
|
{
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "ocd: trying path %s - ", pathBuffer);
|
|
|
|
#endif
|
|
|
|
uprv_mapFile(&tData, pathBuffer);
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "%s\n", UDataMemory_isLoaded(&tData)?"LOADED":"not loaded");
|
|
|
|
#endif
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2002-08-09 18:17:39 +00:00
|
|
|
#if defined(OS390_STUBDATA) && defined(OS390BATCH)
|
|
|
|
if (!UDataMemory_isLoaded(&tData)) {
|
|
|
|
char ourPathBuffer[1024];
|
|
|
|
/* One more chance, for extendCommonData() */
|
|
|
|
uprv_strncpy(ourPathBuffer, path, 1019);
|
|
|
|
ourPathBuffer[1019]=0;
|
|
|
|
uprv_strcat(ourPathBuffer, ".dat");
|
|
|
|
uprv_mapFile(&tData, ourPathBuffer);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
if (!UDataMemory_isLoaded(&tData)) {
|
2001-08-15 22:39:42 +00:00
|
|
|
/* no common data */
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
/* we have mapped a file, check its header */
|
2001-10-05 21:46:52 +00:00
|
|
|
udata_checkCommonData(&tData, pErrorCode);
|
2001-08-15 23:27:38 +00:00
|
|
|
|
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
/* Cache the UDataMemory struct for this .dat file,
|
|
|
|
* so we won't need to hunt it down and map it again next time
|
|
|
|
* something is needed from it. */
|
2001-09-07 18:42:29 +00:00
|
|
|
return udata_cacheDataItem(inBasename, &tData, pErrorCode);
|
2001-08-15 22:39:42 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2001-08-17 00:00:55 +00:00
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* extendICUData If the full set of ICU data was not loaded at *
|
|
|
|
* program startup, load it now. This function will *
|
|
|
|
* be called when the lookup of an ICU data item in *
|
|
|
|
* the common ICU data fails. *
|
|
|
|
* *
|
|
|
|
* return true if new data is loaded, false otherwise.*
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
2010-01-15 20:47:28 +00:00
|
|
|
static UBool extendICUData(UErrorCode *pErr)
|
2001-08-17 00:00:55 +00:00
|
|
|
{
|
2001-08-30 18:41:30 +00:00
|
|
|
UDataMemory *pData;
|
2001-10-08 17:41:04 +00:00
|
|
|
UDataMemory copyPData;
|
2010-01-15 20:47:28 +00:00
|
|
|
UBool didUpdate = FALSE;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* There is a chance for a race condition here.
|
|
|
|
* Normally, ICU data is loaded from a DLL or via mmap() and
|
|
|
|
* setCommonICUData() will detect if the same address is set twice.
|
|
|
|
* If ICU is built with data loading via fread() then the address will
|
|
|
|
* be different each time the common data is loaded and we may add
|
|
|
|
* multiple copies of the data.
|
|
|
|
* In this case, use a mutex to prevent the race.
|
|
|
|
* Use a specific mutex to avoid nested locks of the global mutex.
|
|
|
|
*/
|
|
|
|
#if MAP_IMPLEMENTATION==MAP_STDIO
|
2012-10-05 21:22:02 +00:00
|
|
|
static UMutex extendICUDataMutex = U_MUTEX_INITIALIZER;
|
2010-01-15 20:47:28 +00:00
|
|
|
umtx_lock(&extendICUDataMutex);
|
|
|
|
#endif
|
2015-07-15 22:09:25 +00:00
|
|
|
if(!umtx_loadAcquire(gHaveTriedToLoadCommonData)) {
|
2010-01-15 20:47:28 +00:00
|
|
|
/* See if we can explicitly open a .dat file for the ICUData. */
|
|
|
|
pData = openCommonData(
|
|
|
|
U_ICUDATA_NAME, /* "icudt20l" , for example. */
|
|
|
|
-1, /* Pretend we're not opening ICUData */
|
|
|
|
pErr);
|
|
|
|
|
|
|
|
/* How about if there is no pData, eh... */
|
|
|
|
|
|
|
|
UDataMemory_init(©PData);
|
|
|
|
if(pData != NULL) {
|
|
|
|
UDatamemory_assign(©PData, pData);
|
|
|
|
copyPData.map = 0; /* The mapping for this data is owned by the hash table */
|
|
|
|
copyPData.mapAddr = 0; /* which will unmap it when ICU is shut down. */
|
|
|
|
/* CommonICUData is also unmapped when ICU is shut down.*/
|
|
|
|
/* To avoid unmapping the data twice, zero out the map */
|
|
|
|
/* fields in the UDataMemory that we're assigning */
|
|
|
|
/* to CommonICUData. */
|
|
|
|
|
2011-07-13 04:49:45 +00:00
|
|
|
didUpdate = /* no longer using this result */
|
2010-01-15 20:47:28 +00:00
|
|
|
setCommonICUData(©PData,/* The new common data. */
|
|
|
|
FALSE, /* No warnings if write didn't happen */
|
|
|
|
pErr); /* setCommonICUData honors errors; NOP if error set */
|
|
|
|
}
|
2011-07-13 04:49:45 +00:00
|
|
|
|
2015-07-15 22:09:25 +00:00
|
|
|
umtx_storeRelease(gHaveTriedToLoadCommonData, 1);
|
2001-10-06 04:54:29 +00:00
|
|
|
}
|
2011-07-13 04:49:45 +00:00
|
|
|
|
|
|
|
didUpdate = findCommonICUDataByName(U_ICUDATA_NAME); /* Return 'true' when a racing writes out the extended */
|
|
|
|
/* data after another thread has failed to see it (in openCommonData), so */
|
|
|
|
/* extended data can be examined. */
|
|
|
|
/* Also handles a race through here before gHaveTriedToLoadCommonData is set. */
|
|
|
|
|
2010-01-15 20:47:28 +00:00
|
|
|
#if MAP_IMPLEMENTATION==MAP_STDIO
|
|
|
|
umtx_unlock(&extendICUDataMutex);
|
|
|
|
#endif
|
|
|
|
return didUpdate; /* Return true if ICUData pointer was updated. */
|
2001-08-30 18:41:30 +00:00
|
|
|
/* (Could potentialy have been done by another thread racing */
|
|
|
|
/* us through here, but that's fine, we still return true */
|
|
|
|
/* so that current thread will also examine extended data. */
|
2001-08-17 00:00:55 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/*----------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* udata_setCommonData *
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------*/
|
2000-05-03 23:11:04 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udata_setCommonData(const void *data, UErrorCode *pErrorCode) {
|
2001-08-15 22:39:42 +00:00
|
|
|
UDataMemory dataMemory;
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return;
|
|
|
|
}
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(data==NULL) {
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/* set the data pointer and test for validity */
|
2001-08-15 22:39:42 +00:00
|
|
|
UDataMemory_init(&dataMemory);
|
2001-09-07 18:42:29 +00:00
|
|
|
UDataMemory_setData(&dataMemory, data);
|
2001-10-05 21:46:52 +00:00
|
|
|
udata_checkCommonData(&dataMemory, pErrorCode);
|
2001-08-15 22:39:42 +00:00
|
|
|
if (U_FAILURE(*pErrorCode)) {return;}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-30 18:41:30 +00:00
|
|
|
/* we have good data */
|
|
|
|
/* Set it up as the ICU Common Data. */
|
2010-01-15 20:47:28 +00:00
|
|
|
setCommonICUData(&dataMemory, TRUE, pErrorCode);
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2001-08-10 20:50:07 +00:00
|
|
|
/*---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* udata_setAppData
|
|
|
|
*
|
|
|
|
*---------------------------------------------------------------------------- */
|
2001-08-15 23:27:38 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
2001-08-10 20:50:07 +00:00
|
|
|
udata_setAppData(const char *path, const void *data, UErrorCode *err)
|
|
|
|
{
|
2001-08-15 22:39:42 +00:00
|
|
|
UDataMemory udm;
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
if(err==NULL || U_FAILURE(*err)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if(data==NULL) {
|
|
|
|
*err=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
UDataMemory_init(&udm);
|
2009-01-30 17:59:33 +00:00
|
|
|
UDataMemory_setData(&udm, data);
|
2001-10-05 21:46:52 +00:00
|
|
|
udata_checkCommonData(&udm, err);
|
2001-08-15 22:39:42 +00:00
|
|
|
udata_cacheDataItem(path, &udm, err);
|
2001-08-17 00:18:49 +00:00
|
|
|
}
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2001-08-17 00:18:49 +00:00
|
|
|
/*----------------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* checkDataItem Given a freshly located/loaded data item, either *
|
|
|
|
* an entry in a common file or a separately loaded file, *
|
|
|
|
* sanity check its header, and see if the data is *
|
|
|
|
* acceptable to the app. *
|
|
|
|
* If the data is good, create and return a UDataMemory *
|
|
|
|
* object that can be returned to the application. *
|
|
|
|
* Return NULL on any sort of failure. *
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------------*/
|
2001-08-15 22:39:42 +00:00
|
|
|
static UDataMemory *
|
2001-08-15 23:27:38 +00:00
|
|
|
checkDataItem
|
2001-08-15 22:39:42 +00:00
|
|
|
(
|
|
|
|
const DataHeader *pHeader, /* The data item to be checked. */
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, /* App's call-back function */
|
|
|
|
void *context, /* pass-thru param for above. */
|
|
|
|
const char *type, /* pass-thru param for above. */
|
|
|
|
const char *name, /* pass-thru param for above. */
|
|
|
|
UErrorCode *nonFatalErr, /* Error code if this data was not acceptable */
|
|
|
|
/* but openChoice should continue with */
|
|
|
|
/* trying to get data from fallback path. */
|
|
|
|
UErrorCode *fatalErr /* Bad error, caller should return immediately */
|
|
|
|
)
|
|
|
|
{
|
|
|
|
UDataMemory *rDataMem = NULL; /* the new UDataMemory, to be returned. */
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
if (U_FAILURE(*fatalErr)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(pHeader->dataHeader.magic1==0xda &&
|
|
|
|
pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
(isAcceptable==NULL || isAcceptable(context, type, name, &pHeader->info))
|
2003-11-21 18:35:16 +00:00
|
|
|
) {
|
2001-08-15 22:39:42 +00:00
|
|
|
rDataMem=UDataMemory_createNewInstance(fatalErr);
|
|
|
|
if (U_FAILURE(*fatalErr)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
rDataMem->pHeader = pHeader;
|
|
|
|
} else {
|
|
|
|
/* the data is not acceptable, look further */
|
|
|
|
/* If we eventually find something good, this errorcode will be */
|
|
|
|
/* cleared out. */
|
|
|
|
*nonFatalErr=U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
|
|
|
return rDataMem;
|
|
|
|
}
|
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/**
|
|
|
|
* @return 0 if not loaded, 1 if loaded or err
|
|
|
|
*/
|
2006-02-24 19:47:47 +00:00
|
|
|
static UDataMemory *doLoadFromIndividualFiles(const char *pkgName,
|
2006-02-25 00:18:07 +00:00
|
|
|
const char *dataPath, const char *tocEntryPathSuffix,
|
2005-06-24 20:56:17 +00:00
|
|
|
/* following arguments are the same as doOpenChoice itself */
|
|
|
|
const char *path, const char *type, const char *name,
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, void *context,
|
|
|
|
UErrorCode *subErrorCode,
|
|
|
|
UErrorCode *pErrorCode)
|
|
|
|
{
|
2006-02-24 19:47:47 +00:00
|
|
|
const char *pathBuffer;
|
|
|
|
UDataMemory dataMemory;
|
|
|
|
UDataMemory *pEntryData;
|
2005-06-24 20:56:17 +00:00
|
|
|
|
2006-02-24 19:47:47 +00:00
|
|
|
/* look in ind. files: package\nam.typ ========================= */
|
|
|
|
/* init path iterator for individual files */
|
2010-05-21 04:39:19 +00:00
|
|
|
UDataPathIterator iter(dataPath, pkgName, path, tocEntryPathSuffix, FALSE, pErrorCode);
|
2001-08-10 20:50:07 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
while((pathBuffer = iter.next(pErrorCode)))
|
2006-02-24 19:47:47 +00:00
|
|
|
{
|
2005-06-24 20:56:17 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2006-02-24 19:47:47 +00:00
|
|
|
fprintf(stderr, "UDATA: trying individual file %s\n", pathBuffer);
|
2005-06-24 20:56:17 +00:00
|
|
|
#endif
|
2006-02-25 00:18:07 +00:00
|
|
|
if(uprv_mapFile(&dataMemory, pathBuffer))
|
2005-06-24 20:56:17 +00:00
|
|
|
{
|
2006-02-24 19:47:47 +00:00
|
|
|
pEntryData = checkDataItem(dataMemory.pHeader, isAcceptable, context, type, name, subErrorCode, pErrorCode);
|
|
|
|
if (pEntryData != NULL) {
|
|
|
|
/* Data is good.
|
|
|
|
* Hand off ownership of the backing memory to the user's UDataMemory.
|
|
|
|
* and return it. */
|
|
|
|
pEntryData->mapAddr = dataMemory.mapAddr;
|
|
|
|
pEntryData->map = dataMemory.map;
|
2005-06-24 20:56:17 +00:00
|
|
|
|
|
|
|
#ifdef UDATA_DEBUG
|
2006-02-24 19:47:47 +00:00
|
|
|
fprintf(stderr, "** Mapped file: %s\n", pathBuffer);
|
2005-06-24 20:56:17 +00:00
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
return pEntryData;
|
2006-02-24 19:47:47 +00:00
|
|
|
}
|
2005-06-24 20:56:17 +00:00
|
|
|
|
2006-02-24 19:47:47 +00:00
|
|
|
/* the data is not acceptable, or some error occured. Either way, unmap the memory */
|
|
|
|
udata_close(&dataMemory);
|
2005-06-24 20:56:17 +00:00
|
|
|
|
2006-02-24 19:47:47 +00:00
|
|
|
/* If we had a nasty error, bail out completely. */
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
2010-05-21 04:39:19 +00:00
|
|
|
return NULL;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
2006-02-24 19:47:47 +00:00
|
|
|
|
|
|
|
/* Otherwise remember that we found data but didn't like it for some reason */
|
|
|
|
*subErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
2005-06-24 20:56:17 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2006-02-24 19:47:47 +00:00
|
|
|
fprintf(stderr, "%s\n", UDataMemory_isLoaded(&dataMemory)?"LOADED":"not loaded");
|
2005-06-24 20:56:17 +00:00
|
|
|
#endif
|
2006-02-24 19:47:47 +00:00
|
|
|
}
|
2010-05-21 04:39:19 +00:00
|
|
|
return NULL;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @return 0 if not loaded, 1 if loaded or err
|
|
|
|
*/
|
2010-05-21 04:39:19 +00:00
|
|
|
static UDataMemory *doLoadFromCommonData(UBool isICUData, const char * /*pkgName*/,
|
|
|
|
const char * /*dataPath*/, const char * /*tocEntryPathSuffix*/, const char *tocEntryName,
|
2005-06-24 20:56:17 +00:00
|
|
|
/* following arguments are the same as doOpenChoice itself */
|
|
|
|
const char *path, const char *type, const char *name,
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, void *context,
|
|
|
|
UErrorCode *subErrorCode,
|
|
|
|
UErrorCode *pErrorCode)
|
|
|
|
{
|
|
|
|
UDataMemory *pEntryData;
|
|
|
|
const DataHeader *pHeader;
|
|
|
|
UDataMemory *pCommonData;
|
2010-01-15 20:47:28 +00:00
|
|
|
int32_t commonDataIndex;
|
2011-07-13 04:49:45 +00:00
|
|
|
UBool checkedExtendedICUData = FALSE;
|
2005-06-24 20:56:17 +00:00
|
|
|
/* try to get common data. The loop is for platforms such as the 390 that do
|
|
|
|
* not initially load the full set of ICU data. If the lookup of an ICU data item
|
|
|
|
* fails, the full (but slower to load) set is loaded, the and the loop repeats,
|
|
|
|
* trying the lookup again. Once the full set of ICU data is loaded, the loop wont
|
|
|
|
* repeat because the full set will be checked the first time through.
|
|
|
|
*
|
|
|
|
* The loop also handles the fallback to a .dat file if the application linked
|
|
|
|
* to the stub data library rather than a real library.
|
|
|
|
*/
|
2010-01-15 20:47:28 +00:00
|
|
|
for (commonDataIndex = isICUData ? 0 : -1;;) {
|
|
|
|
pCommonData=openCommonData(path, commonDataIndex, subErrorCode); /** search for pkg **/
|
2005-06-24 20:56:17 +00:00
|
|
|
|
2010-01-15 20:47:28 +00:00
|
|
|
if(U_SUCCESS(*subErrorCode) && pCommonData!=NULL) {
|
2005-06-24 20:56:17 +00:00
|
|
|
int32_t length;
|
|
|
|
|
|
|
|
/* look up the data piece in the common data */
|
|
|
|
pHeader=pCommonData->vFuncs->Lookup(pCommonData, tocEntryName, &length, subErrorCode);
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "%s: pHeader=%p - %s\n", tocEntryName, pHeader, u_errorName(*subErrorCode));
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(pHeader!=NULL) {
|
|
|
|
pEntryData = checkDataItem(pHeader, isAcceptable, context, type, name, subErrorCode, pErrorCode);
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "pEntryData=%p\n", pEntryData);
|
|
|
|
#endif
|
|
|
|
if (U_FAILURE(*pErrorCode)) {
|
2010-01-15 20:47:28 +00:00
|
|
|
return NULL;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
|
|
|
if (pEntryData != NULL) {
|
|
|
|
pEntryData->length = length;
|
2010-01-15 20:47:28 +00:00
|
|
|
return pEntryData;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* Data wasn't found. If we were looking for an ICUData item and there is
|
|
|
|
* more data available, load it and try again,
|
|
|
|
* otherwise break out of this loop. */
|
2010-01-15 20:47:28 +00:00
|
|
|
if (!isICUData) {
|
|
|
|
return NULL;
|
|
|
|
} else if (pCommonData != NULL) {
|
|
|
|
++commonDataIndex; /* try the next data package */
|
2011-07-13 04:49:45 +00:00
|
|
|
} else if ((!checkedExtendedICUData) && extendICUData(subErrorCode)) {
|
|
|
|
checkedExtendedICUData = TRUE;
|
2010-01-15 20:47:28 +00:00
|
|
|
/* try this data package slot again: it changed from NULL to non-NULL */
|
|
|
|
} else {
|
|
|
|
return NULL;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2001-08-15 22:39:42 +00:00
|
|
|
|
2014-09-04 01:07:38 +00:00
|
|
|
/*
|
|
|
|
* Identify the Time Zone resources that are subject to special override data loading.
|
|
|
|
*/
|
|
|
|
static UBool isTimeZoneFile(const char *name, const char *type) {
|
|
|
|
return ((uprv_strcmp(type, "res") == 0) &&
|
|
|
|
(uprv_strcmp(name, "zoneinfo64") == 0 ||
|
|
|
|
uprv_strcmp(name, "timezoneTypes") == 0 ||
|
|
|
|
uprv_strcmp(name, "windowsZones") == 0 ||
|
|
|
|
uprv_strcmp(name, "metaZones") == 0));
|
|
|
|
}
|
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
/*
|
|
|
|
* A note on the ownership of Mapped Memory
|
|
|
|
*
|
|
|
|
* For common format files, ownership resides with the UDataMemory object
|
|
|
|
* that lives in the cache of opened common data. These UDataMemorys are private
|
|
|
|
* to the udata implementation, and are never seen directly by users.
|
|
|
|
*
|
|
|
|
* The UDataMemory objects returned to users will have the address of some desired
|
|
|
|
* data within the mapped region, but they wont have the mapping info itself, and thus
|
|
|
|
* won't cause anything to be removed from memory when they are closed.
|
|
|
|
*
|
|
|
|
* For individual data files, the UDataMemory returned to the user holds the
|
|
|
|
* information necessary to unmap the data on close. If the user independently
|
|
|
|
* opens the same data file twice, two completely independent mappings will be made.
|
2001-09-07 18:42:29 +00:00
|
|
|
* (There is no cache of opened data items from individual files, only a cache of
|
|
|
|
* opened Common Data files, that is, files containing a collection of data items.)
|
2001-08-15 22:39:42 +00:00
|
|
|
*
|
|
|
|
* For common data passed in from the user via udata_setAppData() or
|
|
|
|
* udata_setCommonData(), ownership remains with the user.
|
|
|
|
*
|
|
|
|
* UDataMemory objects themselves, as opposed to the memory they describe,
|
2001-08-15 23:27:38 +00:00
|
|
|
* can be anywhere - heap, stack/local or global.
|
2001-09-07 18:42:29 +00:00
|
|
|
* They have a flag to indicate when they're heap allocated and thus
|
2001-08-15 22:39:42 +00:00
|
|
|
* must be deleted when closed.
|
|
|
|
*/
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
/*----------------------------------------------------------------------------*
|
|
|
|
* *
|
|
|
|
* main data loading functions *
|
|
|
|
* *
|
|
|
|
*----------------------------------------------------------------------------*/
|
2000-05-03 23:11:04 +00:00
|
|
|
static UDataMemory *
|
|
|
|
doOpenChoice(const char *path, const char *type, const char *name,
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, void *context,
|
2001-08-15 23:27:38 +00:00
|
|
|
UErrorCode *pErrorCode)
|
2001-08-15 22:39:42 +00:00
|
|
|
{
|
2003-12-11 07:21:36 +00:00
|
|
|
UDataMemory *retVal = NULL;
|
2004-04-14 19:58:08 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
const char *dataPath;
|
|
|
|
|
2003-12-11 07:21:36 +00:00
|
|
|
int32_t tocEntrySuffixIndex;
|
2004-04-14 19:58:08 +00:00
|
|
|
const char *tocEntryPathSuffix;
|
2005-06-24 20:56:17 +00:00
|
|
|
UErrorCode subErrorCode=U_ZERO_ERROR;
|
2004-04-14 19:58:08 +00:00
|
|
|
const char *treeChar;
|
2003-12-11 21:07:32 +00:00
|
|
|
|
2004-05-18 02:02:39 +00:00
|
|
|
UBool isICUData = FALSE;
|
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
|
|
|
|
/* Is this path ICU data? */
|
2004-05-18 02:02:39 +00:00
|
|
|
if(path == NULL ||
|
2005-06-24 20:56:17 +00:00
|
|
|
!strcmp(path, U_ICUDATA_ALIAS) || /* "ICUDATA" */
|
|
|
|
!uprv_strncmp(path, U_ICUDATA_NAME U_TREE_SEPARATOR_STRING, /* "icudt26e-" */
|
|
|
|
uprv_strlen(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING)) ||
|
|
|
|
!uprv_strncmp(path, U_ICUDATA_ALIAS U_TREE_SEPARATOR_STRING, /* "ICUDATA-" */
|
2004-05-18 02:02:39 +00:00
|
|
|
uprv_strlen(U_ICUDATA_ALIAS U_TREE_SEPARATOR_STRING))) {
|
|
|
|
isICUData = TRUE;
|
|
|
|
}
|
2004-04-22 23:27:20 +00:00
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
#if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) /* Windows: try "foo\bar" and "foo/bar" */
|
2004-04-22 23:27:20 +00:00
|
|
|
/* remap from alternate path char to the main one */
|
2010-05-21 04:39:19 +00:00
|
|
|
CharString altSepPath;
|
2004-04-22 23:27:20 +00:00
|
|
|
if(path) {
|
2010-05-21 22:45:05 +00:00
|
|
|
if(uprv_strchr(path,U_FILE_ALT_SEP_CHAR) != NULL) {
|
2010-05-21 04:39:19 +00:00
|
|
|
altSepPath.append(path, *pErrorCode);
|
2010-05-21 22:45:05 +00:00
|
|
|
char *p;
|
2010-05-21 04:39:19 +00:00
|
|
|
while((p=uprv_strchr(altSepPath.data(), U_FILE_ALT_SEP_CHAR))) {
|
2004-04-22 23:27:20 +00:00
|
|
|
*p = U_FILE_SEP_CHAR;
|
|
|
|
}
|
|
|
|
#if defined (UDATA_DEBUG)
|
|
|
|
fprintf(stderr, "Changed path from [%s] to [%s]\n", path, altSepPath.s);
|
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
path = altSepPath.data();
|
2004-04-22 23:27:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
CharString tocEntryName; /* entry name in tree format. ex: 'icudt28b/coll/ar.res' */
|
|
|
|
CharString tocEntryPath; /* entry name in path format. ex: 'icudt28b\\coll\\ar.res' */
|
2003-12-11 21:07:32 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
CharString pkgName;
|
|
|
|
CharString treeName;
|
2004-04-14 19:58:08 +00:00
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/* ======= Set up strings */
|
2004-04-14 19:58:08 +00:00
|
|
|
if(path==NULL) {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(U_ICUDATA_NAME, *pErrorCode);
|
2004-04-14 19:58:08 +00:00
|
|
|
} else {
|
|
|
|
const char *pkg;
|
|
|
|
const char *first;
|
|
|
|
pkg = uprv_strrchr(path, U_FILE_SEP_CHAR);
|
|
|
|
first = uprv_strchr(path, U_FILE_SEP_CHAR);
|
2004-11-04 21:51:57 +00:00
|
|
|
if(uprv_pathIsAbsolute(path) || (pkg != first)) { /* more than one slash in the path- not a tree name */
|
|
|
|
/* see if this is an /absolute/path/to/package path */
|
|
|
|
if(pkg) {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(pkg+1, *pErrorCode);
|
2004-11-04 21:51:57 +00:00
|
|
|
} else {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(path, *pErrorCode);
|
2004-11-04 21:51:57 +00:00
|
|
|
}
|
2004-05-18 02:02:39 +00:00
|
|
|
} else {
|
2004-11-04 21:51:57 +00:00
|
|
|
treeChar = uprv_strchr(path, U_TREE_SEPARATOR);
|
|
|
|
if(treeChar) {
|
2010-05-21 04:39:19 +00:00
|
|
|
treeName.append(treeChar+1, *pErrorCode); /* following '-' */
|
2005-01-07 06:05:44 +00:00
|
|
|
if(isICUData) {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(U_ICUDATA_NAME, *pErrorCode);
|
2005-01-07 06:05:44 +00:00
|
|
|
} else {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(path, (int32_t)(treeChar-path), *pErrorCode);
|
2005-01-07 06:05:44 +00:00
|
|
|
if (first == NULL) {
|
|
|
|
/*
|
|
|
|
This user data has no path, but there is a tree name.
|
|
|
|
Look up the correct path from the data cache later.
|
|
|
|
*/
|
2010-05-21 04:39:19 +00:00
|
|
|
path = pkgName.data();
|
2005-01-07 06:05:44 +00:00
|
|
|
}
|
2004-11-04 21:51:57 +00:00
|
|
|
}
|
|
|
|
} else {
|
2005-01-07 06:05:44 +00:00
|
|
|
if(isICUData) {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(U_ICUDATA_NAME, *pErrorCode);
|
2005-01-07 06:05:44 +00:00
|
|
|
} else {
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.append(path, *pErrorCode);
|
2004-11-04 21:51:57 +00:00
|
|
|
}
|
|
|
|
}
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, " P=%s T=%s\n", pkgName.data(), treeName.data());
|
2004-04-14 19:58:08 +00:00
|
|
|
#endif
|
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/* setting up the entry name and file name
|
|
|
|
* Make up a full name by appending the type to the supplied
|
2001-09-07 18:42:29 +00:00
|
|
|
* name, assuming that a type was supplied.
|
|
|
|
*/
|
2002-07-17 03:01:45 +00:00
|
|
|
|
|
|
|
/* prepend the package */
|
2010-05-21 04:39:19 +00:00
|
|
|
tocEntryName.append(pkgName, *pErrorCode);
|
|
|
|
tocEntryPath.append(pkgName, *pErrorCode);
|
|
|
|
tocEntrySuffixIndex = tocEntryName.length();
|
2004-04-14 19:58:08 +00:00
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
if(!treeName.isEmpty()) {
|
|
|
|
tocEntryName.append(U_TREE_ENTRY_SEP_CHAR, *pErrorCode).append(treeName, *pErrorCode);
|
|
|
|
tocEntryPath.append(U_FILE_SEP_CHAR, *pErrorCode).append(treeName, *pErrorCode);
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
tocEntryName.append(U_TREE_ENTRY_SEP_CHAR, *pErrorCode).append(name, *pErrorCode);
|
|
|
|
tocEntryPath.append(U_FILE_SEP_CHAR, *pErrorCode).append(name, *pErrorCode);
|
2001-09-07 18:42:29 +00:00
|
|
|
if(type!=NULL && *type!=0) {
|
2010-05-21 04:39:19 +00:00
|
|
|
tocEntryName.append(".", *pErrorCode).append(type, *pErrorCode);
|
|
|
|
tocEntryPath.append(".", *pErrorCode).append(type, *pErrorCode);
|
2001-09-07 18:42:29 +00:00
|
|
|
}
|
2010-05-21 04:39:19 +00:00
|
|
|
tocEntryPathSuffix = tocEntryPath.data()+tocEntrySuffixIndex; /* suffix starts here */
|
2000-12-05 02:28:32 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2010-05-21 04:39:19 +00:00
|
|
|
fprintf(stderr, " tocEntryName = %s\n", tocEntryName.data());
|
|
|
|
fprintf(stderr, " tocEntryPath = %s\n", tocEntryName.data());
|
|
|
|
#endif
|
2001-08-15 23:27:38 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
if(path == NULL) {
|
2005-06-24 20:56:17 +00:00
|
|
|
path = COMMON_DATA_NAME; /* "icudt26e" */
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/************************ Begin loop looking for ind. files ***************/
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2008-09-15 19:36:19 +00:00
|
|
|
fprintf(stderr, "IND: inBasename = %s, pkg=%s\n", "(n/a)", packageNameFromPath(path));
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2002-07-17 03:01:45 +00:00
|
|
|
/* End of dealing with a null basename */
|
|
|
|
dataPath = u_getDataDirectory();
|
2000-05-03 23:11:04 +00:00
|
|
|
|
2014-09-04 01:07:38 +00:00
|
|
|
/**** Time zone individual files override */
|
|
|
|
if (isTimeZoneFile(name, type) && isICUData) {
|
|
|
|
const char *tzFilesDir = u_getTimeZoneFilesDirectory(pErrorCode);
|
|
|
|
if (tzFilesDir[0] != 0) {
|
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "Trying Time Zone Files directory = %s\n", tzFilesDir);
|
|
|
|
#endif
|
|
|
|
retVal = doLoadFromIndividualFiles(/* pkgName.data() */ "", tzFilesDir, tocEntryPathSuffix,
|
|
|
|
/* path */ "", type, name, isAcceptable, context, &subErrorCode, pErrorCode);
|
|
|
|
if((retVal != NULL) || U_FAILURE(*pErrorCode)) {
|
|
|
|
return retVal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/**** COMMON PACKAGE - only if packages are first. */
|
|
|
|
if(gDataFileAccess == UDATA_PACKAGES_FIRST) {
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2005-06-24 20:56:17 +00:00
|
|
|
fprintf(stderr, "Trying packages (UDATA_PACKAGES_FIRST)\n");
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
2005-06-24 20:56:17 +00:00
|
|
|
/* #2 */
|
|
|
|
retVal = doLoadFromCommonData(isICUData,
|
2010-05-21 04:39:19 +00:00
|
|
|
pkgName.data(), dataPath, tocEntryPathSuffix, tocEntryName.data(),
|
2005-06-24 20:56:17 +00:00
|
|
|
path, type, name, isAcceptable, context, &subErrorCode, pErrorCode);
|
|
|
|
if((retVal != NULL) || U_FAILURE(*pErrorCode)) {
|
2010-05-21 04:39:19 +00:00
|
|
|
return retVal;
|
2004-10-11 21:21:55 +00:00
|
|
|
}
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
2010-05-21 04:39:19 +00:00
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/**** INDIVIDUAL FILES */
|
|
|
|
if((gDataFileAccess==UDATA_PACKAGES_FIRST) ||
|
|
|
|
(gDataFileAccess==UDATA_FILES_FIRST)) {
|
2004-04-14 19:58:08 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2005-06-24 20:56:17 +00:00
|
|
|
fprintf(stderr, "Trying individual files\n");
|
2004-04-14 19:58:08 +00:00
|
|
|
#endif
|
2005-06-24 20:56:17 +00:00
|
|
|
/* Check to make sure that there is a dataPath to iterate over */
|
|
|
|
if ((dataPath && *dataPath) || !isICUData) {
|
2010-05-21 04:39:19 +00:00
|
|
|
retVal = doLoadFromIndividualFiles(pkgName.data(), dataPath, tocEntryPathSuffix,
|
2005-06-24 20:56:17 +00:00
|
|
|
path, type, name, isAcceptable, context, &subErrorCode, pErrorCode);
|
|
|
|
if((retVal != NULL) || U_FAILURE(*pErrorCode)) {
|
2010-05-21 04:39:19 +00:00
|
|
|
return retVal;
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
2004-10-11 21:21:55 +00:00
|
|
|
}
|
2004-04-14 19:58:08 +00:00
|
|
|
}
|
|
|
|
|
2005-06-24 20:56:17 +00:00
|
|
|
/**** COMMON PACKAGE */
|
|
|
|
if((gDataFileAccess==UDATA_ONLY_PACKAGES) ||
|
|
|
|
(gDataFileAccess==UDATA_FILES_FIRST)) {
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2005-06-24 20:56:17 +00:00
|
|
|
fprintf(stderr, "Trying packages (UDATA_ONLY_PACKAGES || UDATA_FILES_FIRST)\n");
|
2004-04-14 19:58:08 +00:00
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
retVal = doLoadFromCommonData(isICUData,
|
|
|
|
pkgName.data(), dataPath, tocEntryPathSuffix, tocEntryName.data(),
|
2005-06-24 20:56:17 +00:00
|
|
|
path, type, name, isAcceptable, context, &subErrorCode, pErrorCode);
|
|
|
|
if((retVal != NULL) || U_FAILURE(*pErrorCode)) {
|
2010-05-21 04:39:19 +00:00
|
|
|
return retVal;
|
2005-06-24 20:56:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Load from DLL. If we haven't attempted package load, we also haven't had any chance to
|
|
|
|
try a DLL (static or setCommonData/etc) load.
|
|
|
|
If we ever have a "UDATA_ONLY_FILES", add it to the or list here. */
|
|
|
|
if(gDataFileAccess==UDATA_NO_FILES) {
|
2002-07-17 03:01:45 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2005-06-24 20:56:17 +00:00
|
|
|
fprintf(stderr, "Trying common data (UDATA_NO_FILES)\n");
|
2002-07-17 03:01:45 +00:00
|
|
|
#endif
|
2010-05-21 04:39:19 +00:00
|
|
|
retVal = doLoadFromCommonData(isICUData,
|
|
|
|
pkgName.data(), "", tocEntryPathSuffix, tocEntryName.data(),
|
2005-06-24 20:56:17 +00:00
|
|
|
path, type, name, isAcceptable, context, &subErrorCode, pErrorCode);
|
|
|
|
if((retVal != NULL) || U_FAILURE(*pErrorCode)) {
|
2010-05-21 04:39:19 +00:00
|
|
|
return retVal;
|
2002-07-17 03:01:45 +00:00
|
|
|
}
|
2002-11-30 04:41:53 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
|
|
|
/* data not found */
|
|
|
|
if(U_SUCCESS(*pErrorCode)) {
|
2005-06-24 20:56:17 +00:00
|
|
|
if(U_SUCCESS(subErrorCode)) {
|
1999-11-22 19:53:19 +00:00
|
|
|
/* file not found */
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
} else {
|
|
|
|
/* entry point not found or rejected */
|
2005-06-24 20:56:17 +00:00
|
|
|
*pErrorCode=subErrorCode;
|
1999-11-22 19:53:19 +00:00
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2003-12-11 07:21:36 +00:00
|
|
|
return retVal;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2001-08-15 22:39:42 +00:00
|
|
|
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* API ---------------------------------------------------------------------- */
|
|
|
|
|
|
|
|
U_CAPI UDataMemory * U_EXPORT2
|
|
|
|
udata_open(const char *path, const char *type, const char *name,
|
|
|
|
UErrorCode *pErrorCode) {
|
2000-05-30 21:47:19 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2004-04-14 19:58:08 +00:00
|
|
|
fprintf(stderr, "udata_open(): Opening: %s : %s . %s\n", (path?path:"NULL"), name, type);
|
2000-12-05 02:28:32 +00:00
|
|
|
fflush(stderr);
|
2000-05-30 21:47:19 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return NULL;
|
|
|
|
} else if(name==NULL || *name==0) {
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
} else {
|
|
|
|
return doOpenChoice(path, type, name, NULL, NULL, pErrorCode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-09-07 18:42:29 +00:00
|
|
|
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
U_CAPI UDataMemory * U_EXPORT2
|
|
|
|
udata_openChoice(const char *path, const char *type, const char *name,
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, void *context,
|
|
|
|
UErrorCode *pErrorCode) {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2004-04-14 19:58:08 +00:00
|
|
|
fprintf(stderr, "udata_openChoice(): Opening: %s : %s . %s\n", (path?path:"NULL"), name, type);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pErrorCode==NULL || U_FAILURE(*pErrorCode)) {
|
|
|
|
return NULL;
|
|
|
|
} else if(name==NULL || *name==0 || isAcceptable==NULL) {
|
|
|
|
*pErrorCode=U_ILLEGAL_ARGUMENT_ERROR;
|
1999-11-22 19:43:01 +00:00
|
|
|
return NULL;
|
2000-05-03 23:11:04 +00:00
|
|
|
} else {
|
|
|
|
return doOpenChoice(path, type, name, isAcceptable, context, pErrorCode);
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udata_getInfo(UDataMemory *pData, UDataInfo *pInfo) {
|
|
|
|
if(pInfo!=NULL) {
|
|
|
|
if(pData!=NULL && pData->pHeader!=NULL) {
|
|
|
|
const UDataInfo *info=&pData->pHeader->info;
|
2003-11-21 18:35:16 +00:00
|
|
|
uint16_t dataInfoSize=udata_getInfoSize(info);
|
|
|
|
if(pInfo->size>dataInfoSize) {
|
|
|
|
pInfo->size=dataInfoSize;
|
|
|
|
}
|
|
|
|
uprv_memcpy((uint16_t *)pInfo+1, (const uint16_t *)info+1, pInfo->size-2);
|
|
|
|
if(info->isBigEndian!=U_IS_BIG_ENDIAN) {
|
|
|
|
/* opposite endianness */
|
|
|
|
uint16_t x=info->reservedWord;
|
|
|
|
pInfo->reservedWord=(uint16_t)((x<<8)|(x>>8));
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pInfo->size=0;
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2005-06-02 21:00:00 +00:00
|
|
|
|
|
|
|
|
2010-05-21 04:39:19 +00:00
|
|
|
U_CAPI void U_EXPORT2 udata_setFileAccess(UDataFileAccess access, UErrorCode * /*status*/)
|
2005-06-02 21:00:00 +00:00
|
|
|
{
|
2015-07-15 22:09:25 +00:00
|
|
|
// Note: this function is documented as not thread safe.
|
2005-06-24 21:50:36 +00:00
|
|
|
gDataFileAccess = access;
|
2005-06-02 21:00:00 +00:00
|
|
|
}
|