2 ******************************************************************************
4 * Copyright (C) 1999-2016, International Business Machines
5 * Corporation and others. All Rights Reserved.
7 ******************************************************************************
10 * tab size: 8 (not used)
13 * created on: 1999oct25
14 * created by: Markus W. Scherer
17 #include "unicode/utypes.h" /* U_PLATFORM etc. */
21 #define ATTRIBUTE_WEAK __attribute__ ((weak))
22 might have to #include some other header
26 #include "unicode/putil.h"
27 #include "unicode/udata.h"
28 #include "unicode/uversion.h"
42 /***********************************************************************
44 * Notes on the organization of the ICU data implementation
46 * All of the public API is defined in udata.h
48 * The implementation is split into several files...
50 * - udata.c (this file) contains higher level code that knows about
51 * the search paths for locating data, caching opened data, etc.
53 * - umapfile.c contains the low level platform-specific code for actually loading
54 * (memory mapping, file reading, whatever) data into memory.
56 * - ucmndata.c deals with the tables of contents of ICU data items within
57 * an ICU common format data file. The implementation includes
58 * an abstract interface and support for multiple TOC formats.
59 * All knowledge of any specific TOC format is encapsulated here.
61 * - udatamem.c has code for managing UDataMemory structs. These are little
62 * descriptor objects for blocks of memory holding ICU data of
66 /* configuration ---------------------------------------------------------- */
68 /* If you are excruciatingly bored turn this on .. */
69 /* #define UDATA_DEBUG 1 */
70 /* For debugging use of timezone data in a separate file */
71 /* #define UDATA_TZFILES_DEBUG 1 */
73 #if defined(UDATA_DEBUG) || defined(UDATA_TZFILES_DEBUG)
80 * Forward declarations
82 static UDataMemory
*udata_findCachedData(const char *path
);
84 /***********************************************************************
86 * static (Global) data
88 ************************************************************************/
91 * Pointers to the common ICU data.
93 * We store multiple pointers to ICU data packages and iterate through them
94 * when looking for a data item.
96 * It is possible to combine this with dependency inversion:
97 * One or more data package libraries may export
98 * functions that each return a pointer to their piece of the ICU data,
99 * and this file would import them as weak functions, without a
100 * strong linker dependency from the common library on the data library.
102 * Then we can have applications depend on only that part of ICU's data
103 * that they really need, reducing the size of binaries that take advantage
106 static UDataMemory
*gCommonICUDataArray
[10] = { NULL
}; // Access protected by icu global mutex.
108 static u_atomic_int32_t gHaveTriedToLoadCommonData
= ATOMIC_INT32_T_INITIALIZER(0); // See extendICUData().
110 static UHashtable
*gCommonDataCache
= NULL
; /* Global hash table of opened ICU data files. */
111 static icu::UInitOnce gCommonDataCacheInitOnce
= U_INITONCE_INITIALIZER
;
113 static UDataFileAccess gDataFileAccess
= UDATA_DEFAULT_ACCESS
; // Access not synchronized.
114 // Modifying is documented as thread-unsafe.
116 static UBool U_CALLCONV
121 if (gCommonDataCache
) { /* Delete the cache of user data mappings. */
122 uhash_close(gCommonDataCache
); /* Table owns the contents, and will delete them. */
123 gCommonDataCache
= NULL
; /* Cleanup is not thread safe. */
125 gCommonDataCacheInitOnce
.reset();
127 for (i
= 0; i
< UPRV_LENGTHOF(gCommonICUDataArray
) && gCommonICUDataArray
[i
] != NULL
; ++i
) {
128 udata_close(gCommonICUDataArray
[i
]);
129 gCommonICUDataArray
[i
] = NULL
;
131 gHaveTriedToLoadCommonData
= 0;
133 return TRUE
; /* Everything was cleaned up */
136 static UBool U_CALLCONV
137 findCommonICUDataByName(const char *inBasename
)
142 UDataMemory
*pData
= udata_findCachedData(inBasename
);
148 for (i
= 0; i
< UPRV_LENGTHOF(gCommonICUDataArray
); ++i
) {
149 if ((gCommonICUDataArray
[i
] != NULL
) && (gCommonICUDataArray
[i
]->pHeader
== pData
->pHeader
)) {
150 /* The data pointer is already in the array. */
161 * setCommonICUData. Set a UDataMemory to be the global ICU Data
164 setCommonICUData(UDataMemory
*pData
, /* The new common data. Belongs to caller, we copy it. */
165 UBool warn
, /* If true, set USING_DEFAULT warning if ICUData was */
166 /* changed by another thread before we got to it. */
169 UDataMemory
*newCommonData
= UDataMemory_createNewInstance(pErr
);
171 UBool didUpdate
= FALSE
;
172 if (U_FAILURE(*pErr
)) {
176 /* For the assignment, other threads must cleanly see either the old */
177 /* or the new, not some partially initialized new. The old can not be */
178 /* deleted - someone may still have a pointer to it lying around in */
180 UDatamemory_assign(newCommonData
, pData
);
182 for (i
= 0; i
< UPRV_LENGTHOF(gCommonICUDataArray
); ++i
) {
183 if (gCommonICUDataArray
[i
] == NULL
) {
184 gCommonICUDataArray
[i
] = newCommonData
;
187 } else if (gCommonICUDataArray
[i
]->pHeader
== pData
->pHeader
) {
188 /* The same data pointer is already in the array. */
194 if (i
== UPRV_LENGTHOF(gCommonICUDataArray
) && warn
) {
195 *pErr
= U_USING_DEFAULT_WARNING
;
198 ucln_common_registerCleanup(UCLN_COMMON_UDATA
, udata_cleanup
);
200 uprv_free(newCommonData
);
206 setCommonICUDataPointer(const void *pData
, UBool
/*warn*/, UErrorCode
*pErrorCode
) {
208 UDataMemory_init(&tData
);
209 UDataMemory_setData(&tData
, pData
);
210 udata_checkCommonData(&tData
, pErrorCode
);
211 return setCommonICUData(&tData
, FALSE
, pErrorCode
);
215 findBasename(const char *path
) {
216 const char *basename
=uprv_strrchr(path
, U_FILE_SEP_CHAR
);
226 packageNameFromPath(const char *path
)
228 if((path
== NULL
) || (*path
== 0)) {
229 return U_ICUDATA_NAME
;
232 path
= findBasename(path
);
234 if((path
== NULL
) || (*path
== 0)) {
235 return U_ICUDATA_NAME
;
242 /*----------------------------------------------------------------------*
244 * Cache for common data *
245 * Functions for looking up or adding entries to a cache of *
246 * data that has been previously opened. Avoids a potentially *
247 * expensive operation of re-opening the data for subsequent *
250 * Data remains cached for the duration of the process. *
252 *----------------------------------------------------------------------*/
254 typedef struct DataCacheElement
{
262 * Deleter function for DataCacheElements.
263 * udata cleanup function closes the hash table; hash table in turn calls back to
264 * here for each entry.
266 static void U_CALLCONV
DataCacheElement_deleter(void *pDCEl
) {
267 DataCacheElement
*p
= (DataCacheElement
*)pDCEl
;
268 udata_close(p
->item
); /* unmaps storage */
269 uprv_free(p
->name
); /* delete the hash key string. */
270 uprv_free(pDCEl
); /* delete 'this' */
273 static void udata_initHashTable() {
274 UErrorCode err
= U_ZERO_ERROR
;
275 U_ASSERT(gCommonDataCache
== NULL
);
276 gCommonDataCache
= uhash_open(uhash_hashChars
, uhash_compareChars
, NULL
, &err
);
277 if (U_FAILURE(err
)) {
278 // TODO: handle errors better.
279 gCommonDataCache
= NULL
;
281 if (gCommonDataCache
!= NULL
) {
282 uhash_setValueDeleter(gCommonDataCache
, DataCacheElement_deleter
);
283 ucln_common_registerCleanup(UCLN_COMMON_UDATA
, udata_cleanup
);
287 /* udata_getCacheHashTable()
288 * Get the hash table used to store the data cache entries.
289 * Lazy create it if it doesn't yet exist.
291 static UHashtable
*udata_getHashTable() {
292 umtx_initOnce(gCommonDataCacheInitOnce
, &udata_initHashTable
);
293 return gCommonDataCache
;
298 static UDataMemory
*udata_findCachedData(const char *path
)
301 UDataMemory
*retVal
= NULL
;
302 DataCacheElement
*el
;
303 const char *baseName
;
305 baseName
= findBasename(path
); /* Cache remembers only the base name, not the full path. */
306 htable
= udata_getHashTable();
308 el
= (DataCacheElement
*)uhash_get(htable
, baseName
);
314 fprintf(stderr
, "Cache: [%s] -> %p\n", baseName
, retVal
);
320 static UDataMemory
*udata_cacheDataItem(const char *path
, UDataMemory
*item
, UErrorCode
*pErr
) {
321 DataCacheElement
*newElement
;
322 const char *baseName
;
325 DataCacheElement
*oldValue
= NULL
;
326 UErrorCode subErr
= U_ZERO_ERROR
;
328 if (U_FAILURE(*pErr
)) {
332 /* Create a new DataCacheElement - the thingy we store in the hash table -
333 * and copy the supplied path and UDataMemoryItems into it.
335 newElement
= (DataCacheElement
*)uprv_malloc(sizeof(DataCacheElement
));
336 if (newElement
== NULL
) {
337 *pErr
= U_MEMORY_ALLOCATION_ERROR
;
340 newElement
->item
= UDataMemory_createNewInstance(pErr
);
341 if (U_FAILURE(*pErr
)) {
342 uprv_free(newElement
);
345 UDatamemory_assign(newElement
->item
, item
);
347 baseName
= findBasename(path
);
348 nameLen
= (int32_t)uprv_strlen(baseName
);
349 newElement
->name
= (char *)uprv_malloc(nameLen
+1);
350 if (newElement
->name
== NULL
) {
351 *pErr
= U_MEMORY_ALLOCATION_ERROR
;
352 uprv_free(newElement
->item
);
353 uprv_free(newElement
);
356 uprv_strcpy(newElement
->name
, baseName
);
358 /* Stick the new DataCacheElement into the hash table.
360 htable
= udata_getHashTable();
362 oldValue
= (DataCacheElement
*)uhash_get(htable
, path
);
363 if (oldValue
!= NULL
) {
364 subErr
= U_USING_DEFAULT_WARNING
;
369 newElement
->name
, /* Key */
370 newElement
, /* Value */
376 fprintf(stderr
, "Cache: [%s] <<< %p : %s. vFunc=%p\n", newElement
->name
,
377 newElement
->item
, u_errorName(subErr
), newElement
->item
->vFuncs
);
380 if (subErr
== U_USING_DEFAULT_WARNING
|| U_FAILURE(subErr
)) {
381 *pErr
= subErr
; /* copy sub err unto fillin ONLY if something happens. */
382 uprv_free(newElement
->name
);
383 uprv_free(newElement
->item
);
384 uprv_free(newElement
);
385 return oldValue
? oldValue
->item
: NULL
;
388 return newElement
->item
;
391 /*----------------------------------------------------------------------*==============
393 * Path management. Could be shared with other tools/etc if need be *
396 *----------------------------------------------------------------------*/
398 #define U_DATA_PATHITER_BUFSIZ 128 /* Size of local buffer for paths */
399 /* Overflow causes malloc of larger buf */
403 class UDataPathIterator
406 UDataPathIterator(const char *path
, const char *pkg
,
407 const char *item
, const char *suffix
, UBool doCheckLastFour
,
408 UErrorCode
*pErrorCode
);
409 const char *next(UErrorCode
*pErrorCode
);
412 const char *path
; /* working path (u_icudata_Dir) */
413 const char *nextPath
; /* path following this one */
414 const char *basename
; /* item's basename (icudt22e_mt.res)*/
415 const char *suffix
; /* item suffix (can be null) */
417 uint32_t basenameLen
; /* length of basename */
419 CharString itemPath
; /* path passed in with item name */
420 CharString pathBuffer
; /* output path for this it'ion */
421 CharString packageStub
; /* example: "/icudt28b". Will ignore that leaf in set paths. */
423 UBool checkLastFour
; /* if TRUE then allow paths such as '/foo/myapp.dat'
424 * to match, checks last 4 chars of suffix with
425 * last 4 of path, then previous chars. */
429 * @param iter The iterator to be initialized. Its current state does not matter.
430 * @param path The full pathname to be iterated over. If NULL, defaults to U_ICUDATA_NAME
431 * @param pkg Package which is being searched for, ex "icudt28l". Will ignore leave directories such as /icudt28l
432 * @param item Item to be searched for. Can include full path, such as /a/b/foo.dat
433 * @param suffix Optional item suffix, if not-null (ex. ".dat") then 'path' can contain 'item' explicitly.
434 * Ex: 'stuff.dat' would be found in '/a/foo:/tmp/stuff.dat:/bar/baz' as item #2.
435 * '/blarg/stuff.dat' would also be found.
437 UDataPathIterator::UDataPathIterator(const char *inPath
, const char *pkg
,
438 const char *item
, const char *inSuffix
, UBool doCheckLastFour
,
439 UErrorCode
*pErrorCode
)
442 fprintf(stderr
, "SUFFIX1=%s PATH=%s\n", inSuffix
, inPath
);
446 path
= u_getDataDirectory();
453 packageStub
.append(U_FILE_SEP_CHAR
, *pErrorCode
).append(pkg
, *pErrorCode
);
455 fprintf(stderr
, "STUB=%s [%d]\n", packageStub
.data(), packageStub
.length());
460 basename
= findBasename(item
);
461 basenameLen
= (int32_t)uprv_strlen(basename
);
464 if(basename
== item
) {
467 itemPath
.append(item
, (int32_t)(basename
-item
), *pErrorCode
);
468 nextPath
= itemPath
.data();
471 fprintf(stderr
, "SUFFIX=%s [%p]\n", inSuffix
, inSuffix
);
475 if(inSuffix
!= NULL
) {
481 checkLastFour
= doCheckLastFour
;
483 /* pathBuffer will hold the output path strings returned by this iterator */
486 fprintf(stderr
, "%p: init %s -> [path=%s], [base=%s], [suff=%s], [itempath=%s], [nextpath=%s], [checklast4=%s]\n",
494 checkLastFour
?"TRUE":"false");
499 * Get the next path on the list.
501 * @param iter The Iter to be used
502 * @param len If set, pointer to the length of the returned path, for convenience.
503 * @return Pointer to the next path segment, or NULL if there are no more.
505 const char *UDataPathIterator::next(UErrorCode
*pErrorCode
)
507 if(U_FAILURE(*pErrorCode
)) {
511 const char *currentPath
= NULL
;
513 const char *pathBasename
;
517 if( nextPath
== NULL
) {
520 currentPath
= nextPath
;
522 if(nextPath
== itemPath
.data()) { /* we were processing item's path. */
523 nextPath
= path
; /* start with regular path next tm. */
524 pathLen
= (int32_t)uprv_strlen(currentPath
);
526 /* fix up next for next time */
527 nextPath
= uprv_strchr(currentPath
, U_PATH_SEP_CHAR
);
528 if(nextPath
== NULL
) {
529 /* segment: entire path */
530 pathLen
= (int32_t)uprv_strlen(currentPath
);
532 /* segment: until next segment */
533 pathLen
= (int32_t)(nextPath
- currentPath
);
544 fprintf(stderr
, "rest of path (IDD) = %s\n", currentPath
);
545 fprintf(stderr
, " ");
548 for(qqq
=0;qqq
<pathLen
;qqq
++)
550 fprintf(stderr
, " ");
553 fprintf(stderr
, "^\n");
556 pathBuffer
.clear().append(currentPath
, pathLen
, *pErrorCode
);
558 /* check for .dat files */
559 pathBasename
= findBasename(pathBuffer
.data());
561 if(checkLastFour
== TRUE
&&
563 uprv_strncmp(pathBuffer
.data() +(pathLen
-4), suffix
, 4)==0 && /* suffix matches */
564 uprv_strncmp(findBasename(pathBuffer
.data()), basename
, basenameLen
)==0 && /* base matches */
565 uprv_strlen(pathBasename
)==(basenameLen
+4)) { /* base+suffix = full len */
568 fprintf(stderr
, "Have %s file on the path: %s\n", suffix
, pathBuffer
.data());
573 { /* regular dir path */
574 if(pathBuffer
[pathLen
-1] != U_FILE_SEP_CHAR
) {
576 uprv_strncmp(pathBuffer
.data()+(pathLen
-4), ".dat", 4) == 0)
579 fprintf(stderr
, "skipping non-directory .dat file %s\n", pathBuffer
.data());
584 /* Check if it is a directory with the same name as our package */
585 if(!packageStub
.isEmpty() &&
586 (pathLen
> packageStub
.length()) &&
587 !uprv_strcmp(pathBuffer
.data() + pathLen
- packageStub
.length(), packageStub
.data())) {
589 fprintf(stderr
, "Found stub %s (will add package %s of len %d)\n", packageStub
.data(), basename
, basenameLen
);
591 pathBuffer
.truncate(pathLen
- packageStub
.length());
593 pathBuffer
.append(U_FILE_SEP_CHAR
, *pErrorCode
);
597 pathBuffer
.append(packageStub
.data()+1, packageStub
.length()-1, *pErrorCode
);
599 if(*suffix
) /* tack on suffix */
601 pathBuffer
.append(suffix
, *pErrorCode
);
606 fprintf(stderr
, " --> %s\n", pathBuffer
.data());
609 return pathBuffer
.data();
613 /* fell way off the end */
619 /* ==================================================================================*/
622 /*----------------------------------------------------------------------*
624 * Add a static reference to the common data library *
625 * Unless overridden by an explicit udata_setCommonData, this will be *
628 *----------------------------------------------------------------------*/
629 extern "C" const DataHeader U_DATA_API U_ICUDATA_ENTRY_POINT
;
632 * This would be a good place for weak-linkage declarations of
633 * partial-data-library access functions where each returns a pointer
634 * to its data package, if it is linked in.
637 extern const void *uprv_getICUData_collation(void) ATTRIBUTE_WEAK;
638 extern const void *uprv_getICUData_conversion(void) ATTRIBUTE_WEAK;
641 /*----------------------------------------------------------------------*
643 * openCommonData Attempt to open a common format (.dat) file *
644 * Map it into memory (if it's not there already) *
645 * and return a UDataMemory object for it. *
647 * If the requested data is already open and cached *
648 * just return the cached UDataMem object. *
650 *----------------------------------------------------------------------*/
652 openCommonData(const char *path
, /* Path from OpenChoice? */
653 int32_t commonDataIndex
, /* ICU Data (index >= 0) if path == NULL */
654 UErrorCode
*pErrorCode
)
657 const char *pathBuffer
;
658 const char *inBasename
;
660 if (U_FAILURE(*pErrorCode
)) {
664 UDataMemory_init(&tData
);
666 /* ??????? TODO revisit this */
667 if (commonDataIndex
>= 0) {
668 /* "mini-cache" for common ICU data */
669 if(commonDataIndex
>= UPRV_LENGTHOF(gCommonICUDataArray
)) {
674 if(gCommonICUDataArray
[commonDataIndex
] != NULL
) {
675 return gCommonICUDataArray
[commonDataIndex
];
678 for(i
= 0; i
< commonDataIndex
; ++i
) {
679 if(gCommonICUDataArray
[i
]->pHeader
== &U_ICUDATA_ENTRY_POINT
) {
680 /* The linked-in data is already in the list. */
686 /* Add the linked-in data to the list. */
688 * This is where we would check and call weakly linked partial-data-library
692 if (uprv_getICUData_collation) {
693 setCommonICUDataPointer(uprv_getICUData_collation(), FALSE, pErrorCode);
695 if (uprv_getICUData_conversion) {
696 setCommonICUDataPointer(uprv_getICUData_conversion(), FALSE, pErrorCode);
699 setCommonICUDataPointer(&U_ICUDATA_ENTRY_POINT
, FALSE
, pErrorCode
);
702 return gCommonICUDataArray
[commonDataIndex
];
707 /* request is NOT for ICU Data. */
709 /* Find the base name portion of the supplied path. */
710 /* inBasename will be left pointing somewhere within the original path string. */
711 inBasename
= findBasename(path
);
713 fprintf(stderr
, "inBasename = %s\n", inBasename
);
717 /* no basename. This will happen if the original path was a directory name, */
718 /* like "a/b/c/". (Fallback to separate files will still work.) */
720 fprintf(stderr
, "ocd: no basename in %s, bailing.\n", path
);
722 *pErrorCode
=U_FILE_ACCESS_ERROR
;
726 /* Is the requested common data file already open and cached? */
727 /* Note that the cache is keyed by the base name only. The rest of the path, */
728 /* if any, is not considered. */
730 UDataMemory
*dataToReturn
= udata_findCachedData(inBasename
);
731 if (dataToReturn
!= NULL
) {
736 /* Requested item is not in the cache.
737 * Hunt it down, trying all the path locations
740 UDataPathIterator
iter(u_getDataDirectory(), inBasename
, path
, ".dat", TRUE
, pErrorCode
);
742 while((UDataMemory_isLoaded(&tData
)==FALSE
) && (pathBuffer
= iter
.next(pErrorCode
)) != NULL
)
745 fprintf(stderr
, "ocd: trying path %s - ", pathBuffer
);
747 uprv_mapFile(&tData
, pathBuffer
);
749 fprintf(stderr
, "%s\n", UDataMemory_isLoaded(&tData
)?"LOADED":"not loaded");
753 #if defined(OS390_STUBDATA) && defined(OS390BATCH)
754 if (!UDataMemory_isLoaded(&tData
)) {
755 char ourPathBuffer
[1024];
756 /* One more chance, for extendCommonData() */
757 uprv_strncpy(ourPathBuffer
, path
, 1019);
758 ourPathBuffer
[1019]=0;
759 uprv_strcat(ourPathBuffer
, ".dat");
760 uprv_mapFile(&tData
, ourPathBuffer
);
764 if (!UDataMemory_isLoaded(&tData
)) {
766 *pErrorCode
=U_FILE_ACCESS_ERROR
;
770 /* we have mapped a file, check its header */
771 udata_checkCommonData(&tData
, pErrorCode
);
774 /* Cache the UDataMemory struct for this .dat file,
775 * so we won't need to hunt it down and map it again next time
776 * something is needed from it. */
777 return udata_cacheDataItem(inBasename
, &tData
, pErrorCode
);
781 /*----------------------------------------------------------------------*
783 * extendICUData If the full set of ICU data was not loaded at *
784 * program startup, load it now. This function will *
785 * be called when the lookup of an ICU data item in *
786 * the common ICU data fails. *
788 * return true if new data is loaded, false otherwise.*
790 *----------------------------------------------------------------------*/
791 static UBool
extendICUData(UErrorCode
*pErr
)
794 UDataMemory copyPData
;
795 UBool didUpdate
= FALSE
;
798 * There is a chance for a race condition here.
799 * Normally, ICU data is loaded from a DLL or via mmap() and
800 * setCommonICUData() will detect if the same address is set twice.
801 * If ICU is built with data loading via fread() then the address will
802 * be different each time the common data is loaded and we may add
803 * multiple copies of the data.
804 * In this case, use a mutex to prevent the race.
805 * Use a specific mutex to avoid nested locks of the global mutex.
807 #if MAP_IMPLEMENTATION==MAP_STDIO
808 static UMutex extendICUDataMutex
= U_MUTEX_INITIALIZER
;
809 umtx_lock(&extendICUDataMutex
);
811 if(!umtx_loadAcquire(gHaveTriedToLoadCommonData
)) {
812 /* See if we can explicitly open a .dat file for the ICUData. */
813 pData
= openCommonData(
814 U_ICUDATA_NAME
, /* "icudt20l" , for example. */
815 -1, /* Pretend we're not opening ICUData */
818 /* How about if there is no pData, eh... */
820 UDataMemory_init(©PData
);
822 UDatamemory_assign(©PData
, pData
);
823 copyPData
.map
= 0; /* The mapping for this data is owned by the hash table */
824 copyPData
.mapAddr
= 0; /* which will unmap it when ICU is shut down. */
825 /* CommonICUData is also unmapped when ICU is shut down.*/
826 /* To avoid unmapping the data twice, zero out the map */
827 /* fields in the UDataMemory that we're assigning */
828 /* to CommonICUData. */
830 didUpdate
= /* no longer using this result */
831 setCommonICUData(©PData
,/* The new common data. */
832 FALSE
, /* No warnings if write didn't happen */
833 pErr
); /* setCommonICUData honors errors; NOP if error set */
836 umtx_storeRelease(gHaveTriedToLoadCommonData
, 1);
839 didUpdate
= findCommonICUDataByName(U_ICUDATA_NAME
); /* Return 'true' when a racing writes out the extended */
840 /* data after another thread has failed to see it (in openCommonData), so */
841 /* extended data can be examined. */
842 /* Also handles a race through here before gHaveTriedToLoadCommonData is set. */
844 #if MAP_IMPLEMENTATION==MAP_STDIO
845 umtx_unlock(&extendICUDataMutex
);
847 return didUpdate
; /* Return true if ICUData pointer was updated. */
848 /* (Could potentialy have been done by another thread racing */
849 /* us through here, but that's fine, we still return true */
850 /* so that current thread will also examine extended data. */
853 /*----------------------------------------------------------------------*
855 * udata_setCommonData *
857 *----------------------------------------------------------------------*/
858 U_CAPI
void U_EXPORT2
859 udata_setCommonData(const void *data
, UErrorCode
*pErrorCode
) {
860 UDataMemory dataMemory
;
862 if(pErrorCode
==NULL
|| U_FAILURE(*pErrorCode
)) {
867 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
871 /* set the data pointer and test for validity */
872 UDataMemory_init(&dataMemory
);
873 UDataMemory_setData(&dataMemory
, data
);
874 udata_checkCommonData(&dataMemory
, pErrorCode
);
875 if (U_FAILURE(*pErrorCode
)) {return;}
877 /* we have good data */
878 /* Set it up as the ICU Common Data. */
879 setCommonICUData(&dataMemory
, TRUE
, pErrorCode
);
882 /*---------------------------------------------------------------------------
886 *---------------------------------------------------------------------------- */
887 U_CAPI
void U_EXPORT2
888 udata_setAppData(const char *path
, const void *data
, UErrorCode
*err
)
892 if(err
==NULL
|| U_FAILURE(*err
)) {
896 *err
=U_ILLEGAL_ARGUMENT_ERROR
;
900 UDataMemory_init(&udm
);
901 UDataMemory_setData(&udm
, data
);
902 udata_checkCommonData(&udm
, err
);
903 udata_cacheDataItem(path
, &udm
, err
);
906 /*----------------------------------------------------------------------------*
908 * checkDataItem Given a freshly located/loaded data item, either *
909 * an entry in a common file or a separately loaded file, *
910 * sanity check its header, and see if the data is *
911 * acceptable to the app. *
912 * If the data is good, create and return a UDataMemory *
913 * object that can be returned to the application. *
914 * Return NULL on any sort of failure. *
916 *----------------------------------------------------------------------------*/
920 const DataHeader
*pHeader
, /* The data item to be checked. */
921 UDataMemoryIsAcceptable
*isAcceptable
, /* App's call-back function */
922 void *context
, /* pass-thru param for above. */
923 const char *type
, /* pass-thru param for above. */
924 const char *name
, /* pass-thru param for above. */
925 UErrorCode
*nonFatalErr
, /* Error code if this data was not acceptable */
926 /* but openChoice should continue with */
927 /* trying to get data from fallback path. */
928 UErrorCode
*fatalErr
/* Bad error, caller should return immediately */
931 UDataMemory
*rDataMem
= NULL
; /* the new UDataMemory, to be returned. */
933 if (U_FAILURE(*fatalErr
)) {
937 if(pHeader
->dataHeader
.magic1
==0xda &&
938 pHeader
->dataHeader
.magic2
==0x27 &&
939 (isAcceptable
==NULL
|| isAcceptable(context
, type
, name
, &pHeader
->info
))
941 rDataMem
=UDataMemory_createNewInstance(fatalErr
);
942 if (U_FAILURE(*fatalErr
)) {
945 rDataMem
->pHeader
= pHeader
;
947 /* the data is not acceptable, look further */
948 /* If we eventually find something good, this errorcode will be */
950 *nonFatalErr
=U_INVALID_FORMAT_ERROR
;
956 * @return 0 if not loaded, 1 if loaded or err
958 static UDataMemory
*doLoadFromIndividualFiles(const char *pkgName
,
959 const char *dataPath
, const char *tocEntryPathSuffix
,
960 /* following arguments are the same as doOpenChoice itself */
961 const char *path
, const char *type
, const char *name
,
962 UDataMemoryIsAcceptable
*isAcceptable
, void *context
,
963 UErrorCode
*subErrorCode
,
964 UErrorCode
*pErrorCode
)
966 const char *pathBuffer
;
967 UDataMemory dataMemory
;
968 UDataMemory
*pEntryData
;
970 /* look in ind. files: package\nam.typ ========================= */
971 /* init path iterator for individual files */
972 UDataPathIterator
iter(dataPath
, pkgName
, path
, tocEntryPathSuffix
, FALSE
, pErrorCode
);
974 while((pathBuffer
= iter
.next(pErrorCode
)))
977 fprintf(stderr
, "UDATA: trying individual file %s\n", pathBuffer
);
979 if(uprv_mapFile(&dataMemory
, pathBuffer
))
981 pEntryData
= checkDataItem(dataMemory
.pHeader
, isAcceptable
, context
, type
, name
, subErrorCode
, pErrorCode
);
982 if (pEntryData
!= NULL
) {
984 * Hand off ownership of the backing memory to the user's UDataMemory.
986 pEntryData
->mapAddr
= dataMemory
.mapAddr
;
987 pEntryData
->map
= dataMemory
.map
;
990 fprintf(stderr
, "** Mapped file: %s\n", pathBuffer
);
995 /* the data is not acceptable, or some error occured. Either way, unmap the memory */
996 udata_close(&dataMemory
);
998 /* If we had a nasty error, bail out completely. */
999 if (U_FAILURE(*pErrorCode
)) {
1003 /* Otherwise remember that we found data but didn't like it for some reason */
1004 *subErrorCode
=U_INVALID_FORMAT_ERROR
;
1007 fprintf(stderr
, "%s\n", UDataMemory_isLoaded(&dataMemory
)?"LOADED":"not loaded");
1014 * @return 0 if not loaded, 1 if loaded or err
1016 static UDataMemory
*doLoadFromCommonData(UBool isICUData
, const char * /*pkgName*/,
1017 const char * /*dataPath*/, const char * /*tocEntryPathSuffix*/, const char *tocEntryName
,
1018 /* following arguments are the same as doOpenChoice itself */
1019 const char *path
, const char *type
, const char *name
,
1020 UDataMemoryIsAcceptable
*isAcceptable
, void *context
,
1021 UErrorCode
*subErrorCode
,
1022 UErrorCode
*pErrorCode
)
1024 UDataMemory
*pEntryData
;
1025 const DataHeader
*pHeader
;
1026 UDataMemory
*pCommonData
;
1027 int32_t commonDataIndex
;
1028 UBool checkedExtendedICUData
= FALSE
;
1029 /* try to get common data. The loop is for platforms such as the 390 that do
1030 * not initially load the full set of ICU data. If the lookup of an ICU data item
1031 * fails, the full (but slower to load) set is loaded, the and the loop repeats,
1032 * trying the lookup again. Once the full set of ICU data is loaded, the loop wont
1033 * repeat because the full set will be checked the first time through.
1035 * The loop also handles the fallback to a .dat file if the application linked
1036 * to the stub data library rather than a real library.
1038 for (commonDataIndex
= isICUData
? 0 : -1;;) {
1039 pCommonData
=openCommonData(path
, commonDataIndex
, subErrorCode
); /** search for pkg **/
1041 if(U_SUCCESS(*subErrorCode
) && pCommonData
!=NULL
) {
1044 /* look up the data piece in the common data */
1045 pHeader
=pCommonData
->vFuncs
->Lookup(pCommonData
, tocEntryName
, &length
, subErrorCode
);
1047 fprintf(stderr
, "%s: pHeader=%p - %s\n", tocEntryName
, pHeader
, u_errorName(*subErrorCode
));
1051 pEntryData
= checkDataItem(pHeader
, isAcceptable
, context
, type
, name
, subErrorCode
, pErrorCode
);
1053 fprintf(stderr
, "pEntryData=%p\n", pEntryData
);
1055 if (U_FAILURE(*pErrorCode
)) {
1058 if (pEntryData
!= NULL
) {
1059 pEntryData
->length
= length
;
1064 /* Data wasn't found. If we were looking for an ICUData item and there is
1065 * more data available, load it and try again,
1066 * otherwise break out of this loop. */
1069 } else if (pCommonData
!= NULL
) {
1070 ++commonDataIndex
; /* try the next data package */
1071 } else if ((!checkedExtendedICUData
) && extendICUData(subErrorCode
)) {
1072 checkedExtendedICUData
= TRUE
;
1073 /* try this data package slot again: it changed from NULL to non-NULL */
1081 * Identify the Time Zone resources that are subject to special override data loading.
1083 static UBool
isTimeZoneFile(const char *name
, const char *type
) {
1084 return ((uprv_strcmp(type
, "res") == 0) &&
1085 (uprv_strcmp(name
, "zoneinfo64") == 0 ||
1086 uprv_strcmp(name
, "timezoneTypes") == 0 ||
1087 uprv_strcmp(name
, "windowsZones") == 0 ||
1088 uprv_strcmp(name
, "metaZones") == 0));
1092 * A note on the ownership of Mapped Memory
1094 * For common format files, ownership resides with the UDataMemory object
1095 * that lives in the cache of opened common data. These UDataMemorys are private
1096 * to the udata implementation, and are never seen directly by users.
1098 * The UDataMemory objects returned to users will have the address of some desired
1099 * data within the mapped region, but they wont have the mapping info itself, and thus
1100 * won't cause anything to be removed from memory when they are closed.
1102 * For individual data files, the UDataMemory returned to the user holds the
1103 * information necessary to unmap the data on close. If the user independently
1104 * opens the same data file twice, two completely independent mappings will be made.
1105 * (There is no cache of opened data items from individual files, only a cache of
1106 * opened Common Data files, that is, files containing a collection of data items.)
1108 * For common data passed in from the user via udata_setAppData() or
1109 * udata_setCommonData(), ownership remains with the user.
1111 * UDataMemory objects themselves, as opposed to the memory they describe,
1112 * can be anywhere - heap, stack/local or global.
1113 * They have a flag to indicate when they're heap allocated and thus
1114 * must be deleted when closed.
1118 /*----------------------------------------------------------------------------*
1120 * main data loading functions *
1122 *----------------------------------------------------------------------------*/
1123 static UDataMemory
*
1124 doOpenChoice(const char *path
, const char *type
, const char *name
,
1125 UDataMemoryIsAcceptable
*isAcceptable
, void *context
,
1126 UErrorCode
*pErrorCode
)
1128 UDataMemory
*retVal
= NULL
;
1130 const char *dataPath
;
1132 int32_t tocEntrySuffixIndex
;
1133 const char *tocEntryPathSuffix
;
1134 UErrorCode subErrorCode
=U_ZERO_ERROR
;
1135 const char *treeChar
;
1137 UBool isICUData
= FALSE
;
1140 /* Is this path ICU data? */
1142 !strcmp(path
, U_ICUDATA_ALIAS
) || /* "ICUDATA" */
1143 !uprv_strncmp(path
, U_ICUDATA_NAME U_TREE_SEPARATOR_STRING
, /* "icudt26e-" */
1144 uprv_strlen(U_ICUDATA_NAME U_TREE_SEPARATOR_STRING
)) ||
1145 !uprv_strncmp(path
, U_ICUDATA_ALIAS U_TREE_SEPARATOR_STRING
, /* "ICUDATA-" */
1146 uprv_strlen(U_ICUDATA_ALIAS U_TREE_SEPARATOR_STRING
))) {
1150 #if (U_FILE_SEP_CHAR != U_FILE_ALT_SEP_CHAR) /* Windows: try "foo\bar" and "foo/bar" */
1151 /* remap from alternate path char to the main one */
1152 CharString altSepPath
;
1154 if(uprv_strchr(path
,U_FILE_ALT_SEP_CHAR
) != NULL
) {
1155 altSepPath
.append(path
, *pErrorCode
);
1157 while((p
=uprv_strchr(altSepPath
.data(), U_FILE_ALT_SEP_CHAR
))) {
1158 *p
= U_FILE_SEP_CHAR
;
1160 #if defined (UDATA_DEBUG)
1161 fprintf(stderr
, "Changed path from [%s] to [%s]\n", path
, altSepPath
.s
);
1163 path
= altSepPath
.data();
1168 CharString tocEntryName
; /* entry name in tree format. ex: 'icudt28b/coll/ar.res' */
1169 CharString tocEntryPath
; /* entry name in path format. ex: 'icudt28b\\coll\\ar.res' */
1172 CharString treeName
;
1174 /* ======= Set up strings */
1176 pkgName
.append(U_ICUDATA_NAME
, *pErrorCode
);
1180 pkg
= uprv_strrchr(path
, U_FILE_SEP_CHAR
);
1181 first
= uprv_strchr(path
, U_FILE_SEP_CHAR
);
1182 if(uprv_pathIsAbsolute(path
) || (pkg
!= first
)) { /* more than one slash in the path- not a tree name */
1183 /* see if this is an /absolute/path/to/package path */
1185 pkgName
.append(pkg
+1, *pErrorCode
);
1187 pkgName
.append(path
, *pErrorCode
);
1190 treeChar
= uprv_strchr(path
, U_TREE_SEPARATOR
);
1192 treeName
.append(treeChar
+1, *pErrorCode
); /* following '-' */
1194 pkgName
.append(U_ICUDATA_NAME
, *pErrorCode
);
1196 pkgName
.append(path
, (int32_t)(treeChar
-path
), *pErrorCode
);
1197 if (first
== NULL
) {
1199 This user data has no path, but there is a tree name.
1200 Look up the correct path from the data cache later.
1202 path
= pkgName
.data();
1207 pkgName
.append(U_ICUDATA_NAME
, *pErrorCode
);
1209 pkgName
.append(path
, *pErrorCode
);
1216 fprintf(stderr
, " P=%s T=%s\n", pkgName
.data(), treeName
.data());
1219 /* setting up the entry name and file name
1220 * Make up a full name by appending the type to the supplied
1221 * name, assuming that a type was supplied.
1224 /* prepend the package */
1225 tocEntryName
.append(pkgName
, *pErrorCode
);
1226 tocEntryPath
.append(pkgName
, *pErrorCode
);
1227 tocEntrySuffixIndex
= tocEntryName
.length();
1229 if(!treeName
.isEmpty()) {
1230 tocEntryName
.append(U_TREE_ENTRY_SEP_CHAR
, *pErrorCode
).append(treeName
, *pErrorCode
);
1231 tocEntryPath
.append(U_FILE_SEP_CHAR
, *pErrorCode
).append(treeName
, *pErrorCode
);
1234 tocEntryName
.append(U_TREE_ENTRY_SEP_CHAR
, *pErrorCode
).append(name
, *pErrorCode
);
1235 tocEntryPath
.append(U_FILE_SEP_CHAR
, *pErrorCode
).append(name
, *pErrorCode
);
1236 if(type
!=NULL
&& *type
!=0) {
1237 tocEntryName
.append(".", *pErrorCode
).append(type
, *pErrorCode
);
1238 tocEntryPath
.append(".", *pErrorCode
).append(type
, *pErrorCode
);
1240 tocEntryPathSuffix
= tocEntryPath
.data()+tocEntrySuffixIndex
; /* suffix starts here */
1243 fprintf(stderr
, " tocEntryName = %s\n", tocEntryName
.data());
1244 fprintf(stderr
, " tocEntryPath = %s\n", tocEntryName
.data());
1248 path
= COMMON_DATA_NAME
; /* "icudt26e" */
1251 /************************ Begin loop looking for ind. files ***************/
1253 fprintf(stderr
, "IND: inBasename = %s, pkg=%s\n", "(n/a)", packageNameFromPath(path
));
1256 /* End of dealing with a null basename */
1257 dataPath
= u_getDataDirectory();
1259 /**** Time zone individual files override */
1260 if (isTimeZoneFile(name
, type
) && isICUData
) {
1261 const char *tzFilesDir
= u_getTimeZoneFilesDirectory(pErrorCode
);
1262 if (tzFilesDir
[0] != 0) {
1264 fprintf(stderr
, "Trying Time Zone Files directory = %s\n", tzFilesDir
);
1266 #ifdef UDATA_TZFILES_DEBUG
1267 fprintf(stderr
, "# dOC U_TIMEZONE_FILES_DIR: %s\n", U_TIMEZONE_FILES_DIR
);
1270 #if defined(U_TIMEZONE_PACKAGE)
1271 // make tztocEntryName, like tocEntryName but with our package name
1272 UErrorCode tzpkgErrorCode
= U_ZERO_ERROR
;
1273 CharString tztocPkgPath
;
1274 tztocPkgPath
.append(tzFilesDir
, tzpkgErrorCode
);
1275 tztocPkgPath
.append(U_FILE_SEP_CHAR
, tzpkgErrorCode
).append(U_TIMEZONE_PACKAGE
, tzpkgErrorCode
);
1276 CharString tztocEntryName
;
1277 tztocEntryName
.append(U_TIMEZONE_PACKAGE
, tzpkgErrorCode
);
1278 if(!treeName
.isEmpty()) {
1279 tztocEntryName
.append(U_TREE_ENTRY_SEP_CHAR
, tzpkgErrorCode
).append(treeName
, tzpkgErrorCode
);
1281 tztocEntryName
.append(U_TREE_ENTRY_SEP_CHAR
, tzpkgErrorCode
).append(name
, tzpkgErrorCode
);
1282 if(type
!=NULL
&& *type
!=0) {
1283 tztocEntryName
.append(".", tzpkgErrorCode
).append(type
, tzpkgErrorCode
);
1285 #ifdef UDATA_TZFILES_DEBUG
1286 fprintf(stderr
, "# dOC tz pkg, doLoadFromCommonData start; U_TIMEZONE_PACKAGE: %s, tztocPkgPath.data(): %s, tztocEntryName.data(): %s, name: %s\n",
1287 U_TIMEZONE_PACKAGE
, tztocPkgPath
.data(), tztocEntryName
.data(), name
);
1289 retVal
= doLoadFromCommonData(FALSE
, "" /*ignored*/, "" /*ignored*/, "" /*ignored*/,
1290 tztocEntryName
.data(), // tocEntryName, like icutz44/zoneinfo64.res
1291 tztocPkgPath
.data(), // path = path to pkg, like /usr/share/icu/icutz44l
1292 type
, name
, isAcceptable
, context
, &subErrorCode
, &tzpkgErrorCode
);
1293 #ifdef UDATA_TZFILES_DEBUG
1294 fprintf(stderr
, "# dOC tz pkg, doLoadFromCommonData end; status %d, retVal %p\n", tzpkgErrorCode
, retVal
);
1296 if(U_SUCCESS(tzpkgErrorCode
) && retVal
!= NULL
) {
1299 #endif /* defined(U_TIMEZONE_PACKAGE) */
1300 // The following assumes any timezone resources in tzFilesDir are in individual .res files
1301 #ifdef UDATA_TZFILES_DEBUG
1302 fprintf(stderr
, "# dOC tz files, doLoadFromIndividualFiles start; tzFilesDir: %s, tocEntryPathSuffix: %s, name: %s\n",
1303 tzFilesDir
, tocEntryPathSuffix
, name
);
1305 retVal
= doLoadFromIndividualFiles(/* pkgName.data() */ "", tzFilesDir
, tocEntryPathSuffix
,
1306 /* path */ "", type
, name
, isAcceptable
, context
, &subErrorCode
, pErrorCode
);
1307 #ifdef UDATA_TZFILES_DEBUG
1308 fprintf(stderr
, "# dOC tz files, doLoadFromIndividualFiles end; status %d, retVal %p\n", *pErrorCode
, retVal
);
1310 if((retVal
!= NULL
) || U_FAILURE(*pErrorCode
)) {
1316 /**** COMMON PACKAGE - only if packages are first. */
1317 if(gDataFileAccess
== UDATA_PACKAGES_FIRST
) {
1319 fprintf(stderr
, "Trying packages (UDATA_PACKAGES_FIRST)\n");
1322 #ifdef UDATA_TZFILES_DEBUG
1323 if (isTimeZoneFile(name
, type
)) {
1324 fprintf(stderr
, "# dOC std common 1, doLoadFromCommonData start; U_TIMEZONE_PACKAGE: path: %s, tocEntryName.data(): %s, name: %s\n",
1325 path
, tocEntryName
.data(), name
);
1328 retVal
= doLoadFromCommonData(isICUData
,
1329 pkgName
.data(), dataPath
, tocEntryPathSuffix
, tocEntryName
.data(),
1330 path
, type
, name
, isAcceptable
, context
, &subErrorCode
, pErrorCode
);
1331 #ifdef UDATA_TZFILES_DEBUG
1332 if (isTimeZoneFile(name
, type
)) {
1333 fprintf(stderr
, "# dOC std common 1, doLoadFromCommonData end; status %d, retVal %p\n", *pErrorCode
, retVal
);
1336 if((retVal
!= NULL
) || U_FAILURE(*pErrorCode
)) {
1341 /**** INDIVIDUAL FILES */
1342 if((gDataFileAccess
==UDATA_PACKAGES_FIRST
) ||
1343 (gDataFileAccess
==UDATA_FILES_FIRST
)) {
1345 fprintf(stderr
, "Trying individual files\n");
1347 /* Check to make sure that there is a dataPath to iterate over */
1348 if ((dataPath
&& *dataPath
) || !isICUData
) {
1349 #ifdef UDATA_TZFILES_DEBUG
1350 if (isTimeZoneFile(name
, type
)) {
1351 fprintf(stderr
, "# dOC std indiv files, doLoadFromIndividualFiles start; dataPath: %s, tocEntryPathSuffix: %s, name: %s\n",
1352 dataPath
, tocEntryPathSuffix
, name
);
1355 retVal
= doLoadFromIndividualFiles(pkgName
.data(), dataPath
, tocEntryPathSuffix
,
1356 path
, type
, name
, isAcceptable
, context
, &subErrorCode
, pErrorCode
);
1357 #ifdef UDATA_TZFILES_DEBUG
1358 if (isTimeZoneFile(name
, type
)) {
1359 fprintf(stderr
, "# dOC std indiv files, doLoadFromIndividualFiles end; status %d, retVal %p\n", *pErrorCode
, retVal
);
1362 if((retVal
!= NULL
) || U_FAILURE(*pErrorCode
)) {
1368 /**** COMMON PACKAGE */
1369 if((gDataFileAccess
==UDATA_ONLY_PACKAGES
) ||
1370 (gDataFileAccess
==UDATA_FILES_FIRST
)) {
1372 fprintf(stderr
, "Trying packages (UDATA_ONLY_PACKAGES || UDATA_FILES_FIRST)\n");
1374 #ifdef UDATA_TZFILES_DEBUG
1375 if (isTimeZoneFile(name
, type
)) {
1376 fprintf(stderr
, "# dOC std common 2, doLoadFromCommonData start; U_TIMEZONE_PACKAGE: path: %s, tocEntryName.data(): %s, name: %s\n",
1377 path
, tocEntryName
.data(), name
);
1380 retVal
= doLoadFromCommonData(isICUData
,
1381 pkgName
.data(), dataPath
, tocEntryPathSuffix
, tocEntryName
.data(),
1382 path
, type
, name
, isAcceptable
, context
, &subErrorCode
, pErrorCode
);
1383 #ifdef UDATA_TZFILES_DEBUG
1384 if (isTimeZoneFile(name
, type
)) {
1385 fprintf(stderr
, "# dOC std common 2, doLoadFromCommonData end; status %d, retVal %p\n", *pErrorCode
, retVal
);
1388 if((retVal
!= NULL
) || U_FAILURE(*pErrorCode
)) {
1393 /* Load from DLL. If we haven't attempted package load, we also haven't had any chance to
1394 try a DLL (static or setCommonData/etc) load.
1395 If we ever have a "UDATA_ONLY_FILES", add it to the or list here. */
1396 if(gDataFileAccess
==UDATA_NO_FILES
) {
1398 fprintf(stderr
, "Trying common data (UDATA_NO_FILES)\n");
1400 retVal
= doLoadFromCommonData(isICUData
,
1401 pkgName
.data(), "", tocEntryPathSuffix
, tocEntryName
.data(),
1402 path
, type
, name
, isAcceptable
, context
, &subErrorCode
, pErrorCode
);
1403 if((retVal
!= NULL
) || U_FAILURE(*pErrorCode
)) {
1408 /* data not found */
1409 if(U_SUCCESS(*pErrorCode
)) {
1410 if(U_SUCCESS(subErrorCode
)) {
1411 /* file not found */
1412 *pErrorCode
=U_FILE_ACCESS_ERROR
;
1414 /* entry point not found or rejected */
1415 *pErrorCode
=subErrorCode
;
1423 /* API ---------------------------------------------------------------------- */
1425 U_CAPI UDataMemory
* U_EXPORT2
1426 udata_open(const char *path
, const char *type
, const char *name
,
1427 UErrorCode
*pErrorCode
) {
1429 fprintf(stderr
, "udata_open(): Opening: %s : %s . %s\n", (path
?path
:"NULL"), name
, type
);
1433 if(pErrorCode
==NULL
|| U_FAILURE(*pErrorCode
)) {
1435 } else if(name
==NULL
|| *name
==0) {
1436 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
1439 return doOpenChoice(path
, type
, name
, NULL
, NULL
, pErrorCode
);
1445 U_CAPI UDataMemory
* U_EXPORT2
1446 udata_openChoice(const char *path
, const char *type
, const char *name
,
1447 UDataMemoryIsAcceptable
*isAcceptable
, void *context
,
1448 UErrorCode
*pErrorCode
) {
1450 fprintf(stderr
, "udata_openChoice(): Opening: %s : %s . %s\n", (path
?path
:"NULL"), name
, type
);
1453 if(pErrorCode
==NULL
|| U_FAILURE(*pErrorCode
)) {
1455 } else if(name
==NULL
|| *name
==0 || isAcceptable
==NULL
) {
1456 *pErrorCode
=U_ILLEGAL_ARGUMENT_ERROR
;
1459 return doOpenChoice(path
, type
, name
, isAcceptable
, context
, pErrorCode
);
1465 U_CAPI
void U_EXPORT2
1466 udata_getInfo(UDataMemory
*pData
, UDataInfo
*pInfo
) {
1468 if(pData
!=NULL
&& pData
->pHeader
!=NULL
) {
1469 const UDataInfo
*info
=&pData
->pHeader
->info
;
1470 uint16_t dataInfoSize
=udata_getInfoSize(info
);
1471 if(pInfo
->size
>dataInfoSize
) {
1472 pInfo
->size
=dataInfoSize
;
1474 uprv_memcpy((uint16_t *)pInfo
+1, (const uint16_t *)info
+1, pInfo
->size
-2);
1475 if(info
->isBigEndian
!=U_IS_BIG_ENDIAN
) {
1476 /* opposite endianness */
1477 uint16_t x
=info
->reservedWord
;
1478 pInfo
->reservedWord
=(uint16_t)((x
<<8)|(x
>>8));
1487 U_CAPI
void U_EXPORT2
udata_setFileAccess(UDataFileAccess access
, UErrorCode
* /*status*/)
1489 // Note: this function is documented as not thread safe.
1490 gDataFileAccess
= access
;