1999-11-22 19:43:01 +00:00
|
|
|
/*
|
2001-03-21 20:44:20 +00:00
|
|
|
******************************************************************************
|
2000-01-13 23:54:23 +00:00
|
|
|
*
|
2001-03-21 20:44:20 +00:00
|
|
|
* Copyright (C) 1999-2001, 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
|
|
|
******************************************************************************
|
1999-11-22 19:43:01 +00:00
|
|
|
* file name: udata.c
|
|
|
|
* encoding: US-ASCII
|
|
|
|
* tab size: 8 (not used)
|
|
|
|
* indentation:4
|
|
|
|
*
|
|
|
|
* created on: 1999oct25
|
|
|
|
* created by: Markus W. Scherer
|
|
|
|
*/
|
|
|
|
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/utypes.h"
|
|
|
|
#include "unicode/putil.h"
|
1999-11-22 19:43:01 +00:00
|
|
|
#include "umutex.h"
|
|
|
|
#include "cmemory.h"
|
|
|
|
#include "cstring.h"
|
1999-12-28 23:39:02 +00:00
|
|
|
#include "unicode/udata.h"
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2001-03-09 23:30:31 +00:00
|
|
|
#ifdef OS390
|
2001-03-09 23:03:12 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#endif
|
|
|
|
|
2001-03-21 20:44:20 +00:00
|
|
|
/* configuration ---------------------------------------------------------- */
|
2000-05-03 23:11:04 +00:00
|
|
|
|
1999-12-04 02:31:40 +00:00
|
|
|
#if !defined(HAVE_DLOPEN)
|
|
|
|
# define HAVE_DLOPEN 0
|
|
|
|
#endif
|
|
|
|
|
1999-11-22 19:43:01 +00:00
|
|
|
#if !defined(UDATA_DLL) && !defined(UDATA_MAP)
|
|
|
|
# define UDATA_DLL
|
|
|
|
#endif
|
|
|
|
|
2000-11-22 01:24:40 +00:00
|
|
|
#define COMMON_DATA_NAME U_ICUDATA_NAME
|
|
|
|
#define COMMON_DATA_NAME_LENGTH 8
|
|
|
|
/* Tests must verify that it remains 8 characters. */
|
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
#ifdef OS390
|
2001-02-06 23:27:07 +00:00
|
|
|
#define COMMON_DATA1_NAME U_ICUDATA_NAME"_390"
|
|
|
|
#define COMMON_DATA1_NAME_LENGTH (COMMON_DATA_NAME_LENGTH + 4)
|
2000-12-05 02:28:32 +00:00
|
|
|
static UBool s390dll = TRUE;
|
|
|
|
#endif
|
|
|
|
|
1999-11-22 19:43:01 +00:00
|
|
|
#define DATA_TYPE "dat"
|
|
|
|
|
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
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* DLL/shared library base functions ---------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
# include <windows.h>
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef HINSTANCE Library;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define LIB_SUFFIX ".dll"
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_LIBRARY NULL
|
|
|
|
# define IS_LIBRARY(lib) ((lib)!=NULL)
|
|
|
|
# define LOAD_LIBRARY(path, basename) LoadLibrary(path)
|
|
|
|
# define UNLOAD_LIBRARY(lib) FreeLibrary(lib)
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define GET_LIBRARY_ENTRY(lib, entryName) GetProcAddress(lib, entryName)
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-11 23:23:49 +00:00
|
|
|
#elif HAVE_DLOPEN /* POSIX-y shared library environment. dlopen() or equivalent.. */
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifndef UDATA_SO_SUFFIX
|
|
|
|
# error Please define UDATA_SO_SUFFIX to the shlib suffix (i.e. '.so' )
|
|
|
|
# endif
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define LIB_PREFIX "lib"
|
|
|
|
# define LIB_PREFIX_LENGTH 3
|
|
|
|
# define LIB_SUFFIX UDATA_SO_SUFFIX
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-11 23:23:49 +00:00
|
|
|
# ifdef ICU_USE_SHL_LOAD /* Some sort of compatibility stub:
|
|
|
|
* HPUX shl_load
|
|
|
|
* OS390 dllload */
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define RTLD_LAZY 0
|
|
|
|
# define RTLD_GLOBAL 0
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef OS390
|
|
|
|
# include <dll.h>
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define RTLD_LAZY 0
|
|
|
|
# define RTLD_GLOBAL 0
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
void *dlopen(const char *filename, int flag) {
|
|
|
|
dllhandle *handle;
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "dllload: %s ", filename);
|
|
|
|
# endif
|
|
|
|
handle=dllload(filename);
|
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, " -> %08X\n", handle );
|
|
|
|
# endif
|
|
|
|
return handle;
|
|
|
|
}
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
void *dlsym(void *h, const char *symbol) {
|
|
|
|
void *val=0;
|
|
|
|
val=dllqueryvar((dllhandle*)h,symbol);
|
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "dllqueryvar(%08X, %s) -> %08X\n", h, symbol, val);
|
|
|
|
# endif
|
|
|
|
return val;
|
|
|
|
}
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
int dlclose(void *handle) {
|
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "dllfree: %08X\n", handle);
|
|
|
|
# endif
|
|
|
|
return dllfree((dllhandle*)handle);
|
|
|
|
}
|
2000-05-11 23:23:49 +00:00
|
|
|
# else /* not OS390: HPUX shl_load */
|
2000-05-03 23:11:04 +00:00
|
|
|
# include <dl.h>
|
|
|
|
|
|
|
|
void *dlopen (const char *filename, int flag) {
|
2000-12-05 02:28:32 +00:00
|
|
|
void *handle; /* real type: 'shl_t' */
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "shl_load: %s ", filename);
|
2000-05-03 23:11:04 +00:00
|
|
|
# endif
|
2000-12-05 02:28:32 +00:00
|
|
|
handle=shl_load(filename, BIND_NONFATAL | BIND_DEFERRED | DYNAMIC_PATH, 0L);
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, " -> %08X\n", handle );
|
2000-05-03 23:11:04 +00:00
|
|
|
# endif
|
2000-12-05 02:28:32 +00:00
|
|
|
return handle;
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
void *dlsym(void *h, char *symbol) {
|
2000-12-05 02:28:32 +00:00
|
|
|
void *val=0;
|
|
|
|
int rv;
|
|
|
|
shl_t mysh;
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
mysh=(shl_t)h; /* real type */
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
rv=shl_findsym(&mysh, symbol, TYPE_DATA, (void*)&val);
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "shl_findsym(%08X, %s) -> %08X [%d]\n", h, symbol, val, rv);
|
2000-05-03 23:11:04 +00:00
|
|
|
# endif
|
2000-12-05 02:28:32 +00:00
|
|
|
return val;
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
int dlclose (void *handle) {
|
2000-05-30 19:30:55 +00:00
|
|
|
# ifndef HPUX
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "shl_unload: %08X\n", handle);
|
2000-05-03 23:11:04 +00:00
|
|
|
# endif
|
2000-12-05 02:28:32 +00:00
|
|
|
return shl_unload((shl_t)handle);
|
2000-05-30 19:30:55 +00:00
|
|
|
# else
|
2000-12-05 02:28:32 +00:00
|
|
|
/* "shl_unload .. always unloads the library.. no refcount is kept on PA32"
|
|
|
|
-- HPUX man pages [v. 11]
|
2000-05-30 19:30:55 +00:00
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
Fine, we'll leak! [for now.. Jitterbug 414 has been filed ]
|
|
|
|
*/
|
|
|
|
return 0;
|
2000-05-30 19:30:55 +00:00
|
|
|
# endif /* HPUX */
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
2000-05-11 23:23:49 +00:00
|
|
|
# endif /* HPUX shl_load */
|
2000-05-03 23:11:04 +00:00
|
|
|
# else /* not ICU_USE_SHL_LOAD */
|
|
|
|
/* 'de facto standard' dlopen etc. */
|
2000-10-13 22:13:35 +00:00
|
|
|
# include <dlfcn.h>
|
2000-06-28 22:20:08 +00:00
|
|
|
#ifndef RTLD_GLOBAL
|
|
|
|
#define RTLD_GLOBAL 0
|
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
# endif
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-04 22:41:23 +00:00
|
|
|
typedef void *Library;
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_LIBRARY NULL
|
|
|
|
# define IS_LIBRARY(lib) ((lib)!=NULL)
|
2000-11-04 02:16:12 +00:00
|
|
|
|
|
|
|
|
|
|
|
#ifndef UDATA_DEBUG
|
2000-05-03 23:11:04 +00:00
|
|
|
# define LOAD_LIBRARY(path, basename) dlopen(path, RTLD_LAZY|RTLD_GLOBAL)
|
|
|
|
# define UNLOAD_LIBRARY(lib) dlclose(lib)
|
|
|
|
# define GET_LIBRARY_ENTRY(lib, entryName) dlsym(lib, entryName)
|
2000-11-04 02:16:12 +00:00
|
|
|
#else
|
|
|
|
void *LOAD_LIBRARY(const char *path, const char *basename)
|
|
|
|
{
|
|
|
|
void *rc;
|
|
|
|
rc = dlopen(path, RTLD_LAZY|RTLD_GLOBAL);
|
|
|
|
fprintf(stderr, "Load [%s|%s] -> %p\n", path, basename, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
void UNLOAD_LIBRARY(void *lib)
|
|
|
|
{
|
|
|
|
dlclose(lib);
|
|
|
|
fprintf(stderr, "Unload [%p]\n", lib);
|
|
|
|
}
|
|
|
|
void * GET_LIBRARY_ENTRY(void *lib, const char *entryName)
|
|
|
|
{
|
|
|
|
void *rc;
|
|
|
|
rc = dlsym(lib, entryName);
|
|
|
|
fprintf(stderr, "Get[%p] %s->%p\n", lib, entryName, rc);
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
#endif
|
2000-05-11 23:23:49 +00:00
|
|
|
/* End of dlopen or compatible functions */
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#else /* unknown platform, no DLL implementation */
|
|
|
|
# ifndef UDATA_NO_DLL
|
|
|
|
# define UDATA_NO_DLL 1
|
|
|
|
# endif
|
|
|
|
typedef const void *Library;
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_LIBRARY NULL
|
|
|
|
# define IS_LIBRARY(lib) ((lib)!=NULL)
|
|
|
|
# define LOAD_LIBRARY(path, basename) NULL
|
|
|
|
# define UNLOAD_LIBRARY(lib) ;
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define GET_LIBRARY_ENTRY(lib, entryName) NULL
|
2000-03-10 01:52:03 +00:00
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* memory-mapping base definitions ------------------------------------------ */
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* we need these definitions before the common ones because
|
|
|
|
MemoryMap is a field of UDataMemory;
|
|
|
|
however, the mapping functions use UDataMemory,
|
|
|
|
therefore they are defined later
|
|
|
|
*/
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#define MAP_WIN32 1
|
|
|
|
#define MAP_POSIX 2
|
|
|
|
#define MAP_FILE_STREAM 3
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
typedef HANDLE MemoryMap;
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_MAP NULL
|
|
|
|
# define IS_MAP(map) ((map)!=NULL)
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define MAP_IMPLEMENTATION MAP_WIN32
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-18 17:37:33 +00:00
|
|
|
/* ### Todo: auto detect mmap(). Until then, just add your platform here. */
|
2000-09-22 19:02:20 +00:00
|
|
|
#elif HAVE_MMAP || defined(U_LINUX) || defined(POSIX) || defined(U_SOLARIS) || defined(AIX) || defined(HPUX) || defined(OS390) || defined(PTX)
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef size_t MemoryMap;
|
2000-03-10 01:52:03 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_MAP 0
|
|
|
|
# define IS_MAP(map) ((map)!=0)
|
2000-01-19 07:23:50 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# include <unistd.h>
|
|
|
|
# include <sys/mman.h>
|
|
|
|
# include <sys/stat.h>
|
|
|
|
# include <fcntl.h>
|
1999-12-13 21:36:13 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifndef MAP_FAILED
|
|
|
|
# define MAP_FAILED ((void*)-1)
|
|
|
|
# endif
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define MAP_IMPLEMENTATION MAP_POSIX
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#else /* unknown platform, no memory map implementation: use FileStream/uprv_malloc() instead */
|
2000-01-14 23:30:55 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# include "filestrm.h"
|
2000-01-14 23:30:55 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef void *MemoryMap;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define NO_MAP NULL
|
|
|
|
# define IS_MAP(map) ((map)!=NULL)
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# define MAP_IMPLEMENTATION MAP_FILE_STREAM
|
1999-12-04 02:31:40 +00:00
|
|
|
|
|
|
|
#endif
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* common definitions ------------------------------------------------------- */
|
1999-12-14 01:07:43 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* constants for UDataMemory flags: type of data memory */
|
|
|
|
enum {
|
|
|
|
NO_DATA_MEMORY,
|
|
|
|
FLAT_DATA_MEMORY,
|
|
|
|
DLL_DATA_MEMORY
|
1999-11-22 19:43:01 +00:00
|
|
|
};
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* constants for UDataMemory flags: type of TOC */
|
|
|
|
enum {
|
|
|
|
NO_TOC,
|
|
|
|
OFFSET_TOC,
|
|
|
|
POINTER_TOC,
|
|
|
|
DLL_INTRINSIC_TOC
|
|
|
|
};
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* constants for UDataMemory flags: type of TOC */
|
|
|
|
#define DATA_MEMORY_TYPE_MASK 0xf
|
|
|
|
#define TOC_TYPE_SHIFT 4
|
|
|
|
#define TOC_TYPE_MASK 0xf
|
|
|
|
#define SET_DATA_POINTER_SHIFT 30
|
|
|
|
#define DYNAMIC_DATA_MEMORY_SHIFT 31
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef struct {
|
|
|
|
uint16_t headerSize;
|
|
|
|
uint8_t magic1, magic2;
|
|
|
|
} MappedData;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef struct {
|
|
|
|
MappedData dataHeader;
|
|
|
|
UDataInfo info;
|
|
|
|
} DataHeader;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef const DataHeader *
|
|
|
|
LookupFn(const UDataMemory *pData,
|
|
|
|
const char *tocEntryName,
|
|
|
|
const char *dllEntryName,
|
|
|
|
UErrorCode *pErrorCode);
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
struct UDataMemory {
|
|
|
|
UDataMemory *parent;
|
|
|
|
Library lib;
|
|
|
|
MemoryMap map;
|
|
|
|
LookupFn *lookupFn;
|
|
|
|
const void *toc;
|
|
|
|
const DataHeader *pHeader;
|
|
|
|
uint32_t flags;
|
|
|
|
int32_t refCount;
|
|
|
|
};
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#define IS_DATA_MEMORY_LOADED(pData) ((pData)->flags!=0)
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
typedef struct {
|
|
|
|
const char *entryName;
|
|
|
|
const DataHeader *pHeader;
|
|
|
|
} PointerTOCEntry;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* memory-mapping base functions -------------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#if MAP_IMPLEMENTATION==MAP_WIN32
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_mapFile(UDataMemory *pData, const char *path, const char *basename) {
|
2000-11-22 01:24:40 +00:00
|
|
|
char buffer[200];
|
2000-05-03 23:11:04 +00:00
|
|
|
HANDLE map;
|
2000-12-05 02:28:32 +00:00
|
|
|
char *p;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* set up the mapping name and the filename */
|
2000-11-22 01:24:40 +00:00
|
|
|
uprv_strcpy(buffer, "icu" U_ICU_VERSION " ");
|
|
|
|
uprv_strcat(buffer, path);
|
2000-12-05 02:28:32 +00:00
|
|
|
|
|
|
|
/* replace in buffer \ with / */
|
|
|
|
for(p=buffer; *p; p++) {
|
|
|
|
if (*p == '\\') {
|
|
|
|
*p = '/';
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* open the mapping */
|
|
|
|
map=OpenFileMapping(FILE_MAP_READ, FALSE, buffer);
|
|
|
|
if(map==NULL) {
|
|
|
|
/* the mapping has not been created */
|
|
|
|
HANDLE file;
|
|
|
|
|
|
|
|
/* open the input file */
|
|
|
|
file=CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL,
|
|
|
|
OPEN_EXISTING,
|
|
|
|
FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS, NULL);
|
|
|
|
if(file==INVALID_HANDLE_VALUE) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* create the mapping */
|
|
|
|
map=CreateFileMapping(file, NULL, PAGE_READONLY, 0, 0, buffer);
|
|
|
|
CloseHandle(file);
|
|
|
|
if(map==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* get a view of the mapping */
|
|
|
|
pData->pHeader=(const DataHeader *)MapViewOfFile(map, FILE_MAP_READ, 0, 0, 0);
|
|
|
|
if(pData->pHeader==NULL) {
|
|
|
|
CloseHandle(map);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
pData->map=map;
|
|
|
|
pData->flags=FLAT_DATA_MEMORY;
|
|
|
|
return TRUE;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(UDataMemory *pData) {
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData!=NULL && pData->map!=NULL) {
|
|
|
|
UnmapViewOfFile(pData->pHeader);
|
|
|
|
CloseHandle(pData->map);
|
|
|
|
pData->pHeader=NULL;
|
|
|
|
pData->map=NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#elif MAP_IMPLEMENTATION==MAP_POSIX
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_mapFile(UDataMemory *pData, const char *path, const char *basename) {
|
2000-05-03 23:11:04 +00:00
|
|
|
int fd;
|
|
|
|
int length;
|
|
|
|
struct stat mystat;
|
|
|
|
const void *data;
|
|
|
|
|
|
|
|
/* determine the length of the file */
|
|
|
|
if(stat(path, &mystat)!=0 || mystat.st_size<=0) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
length=mystat.st_size;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* open the file */
|
|
|
|
fd=open(path, O_RDONLY);
|
|
|
|
if(fd==-1) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* get a view of the mapping */
|
2000-05-30 21:47:19 +00:00
|
|
|
#ifndef HPUX
|
|
|
|
data=mmap(0, length, PROT_READ, MAP_SHARED, fd, 0);
|
|
|
|
#else
|
|
|
|
data=mmap(0, length, PROT_READ, MAP_PRIVATE, fd, 0);
|
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
close(fd); /* no longer needed */
|
|
|
|
if(data==MAP_FAILED) {
|
2000-05-11 23:23:49 +00:00
|
|
|
|
|
|
|
# ifdef UDATA_DEBUG
|
2000-05-30 21:47:19 +00:00
|
|
|
perror("mmap");
|
2000-05-11 23:23:49 +00:00
|
|
|
# endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "mmap of %s [%d bytes] succeeded, -> 0x%X\n", path, length, data);
|
|
|
|
fflush(stderr);
|
|
|
|
# endif
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
pData->map=length;
|
|
|
|
pData->pHeader=(const DataHeader *)data;
|
|
|
|
pData->flags=FLAT_DATA_MEMORY;
|
|
|
|
return TRUE;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(UDataMemory *pData) {
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData!=NULL && pData->map>0) {
|
2000-05-04 22:41:23 +00:00
|
|
|
if(munmap((void *)pData->pHeader, pData->map)==-1) {
|
2000-08-30 17:27:08 +00:00
|
|
|
# ifdef UDATA_DEBUG
|
|
|
|
perror("munmap");
|
|
|
|
# endif
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
pData->pHeader=NULL;
|
|
|
|
pData->map=0;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#elif MAP_IMPLEMENTATION==MAP_FILE_STREAM
|
2000-05-18 22:08:39 +00:00
|
|
|
static UBool
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_mapFile(UDataMemory *pData, const char *path, const char *basename) {
|
2000-05-03 23:11:04 +00:00
|
|
|
FileStream *file;
|
|
|
|
int32_t fileLength;
|
|
|
|
void *p;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* open the input file */
|
|
|
|
file=T_FileStream_open(path, "rb");
|
|
|
|
if(file==NULL) {
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* get the file length */
|
|
|
|
fileLength=T_FileStream_size(file);
|
|
|
|
if(T_FileStream_error(file) || fileLength<=20) {
|
|
|
|
T_FileStream_close(file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* allocate the data structure */
|
|
|
|
p=uprv_malloc(fileLength);
|
|
|
|
if(p==NULL) {
|
|
|
|
T_FileStream_close(file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* read the file */
|
|
|
|
if(fileLength!=T_FileStream_read(file, p, fileLength)) {
|
|
|
|
uprv_free(p);
|
|
|
|
T_FileStream_close(file);
|
|
|
|
return FALSE;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
T_FileStream_close(file);
|
|
|
|
pData->map=p;
|
|
|
|
pData->pHeader=(const DataHeader *)p;
|
|
|
|
pData->flags=FLAT_DATA_MEMORY;
|
|
|
|
return TRUE;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(UDataMemory *pData) {
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData!=NULL && pData->map!=NULL) {
|
|
|
|
uprv_free(pData->map);
|
|
|
|
pData->map=NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
#else
|
|
|
|
# error MAP_IMPLEMENTATION is set incorrectly
|
|
|
|
#endif
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* entry point lookup implementations --------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static const DataHeader *
|
|
|
|
normalizeDataPointer(const DataHeader *p) {
|
|
|
|
/* allow the data to be optionally prepended with an alignment-forcing double value */
|
2000-10-12 18:34:26 +00:00
|
|
|
if(p==NULL || (p->dataHeader.magic1==0xda && p->dataHeader.magic2==0x27)) {
|
2000-05-03 23:11:04 +00:00
|
|
|
return p;
|
|
|
|
} else {
|
|
|
|
return (const DataHeader *)((const double *)p+1);
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static const DataHeader *
|
|
|
|
offsetTOCLookupFn(const UDataMemory *pData,
|
|
|
|
const char *tocEntryName,
|
|
|
|
const char *dllEntryName,
|
|
|
|
UErrorCode *pErrorCode) {
|
2000-12-05 02:28:32 +00:00
|
|
|
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "offsetTOC[%p] looking for %s/%s\n",
|
2000-12-05 02:28:32 +00:00
|
|
|
pData,
|
|
|
|
tocEntryName,dllEntryName);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData->toc!=NULL) {
|
|
|
|
const char *base=(const char *)pData->toc;
|
|
|
|
uint32_t *toc=(uint32_t *)pData->toc;
|
1999-11-22 19:43:01 +00:00
|
|
|
uint32_t start, limit, number;
|
|
|
|
|
|
|
|
/* perform a binary search for the data in the common data's table of contents */
|
|
|
|
start=0;
|
|
|
|
limit=*toc++; /* number of names in this table of contents */
|
|
|
|
while(start<limit-1) {
|
|
|
|
number=(start+limit)/2;
|
2000-05-03 23:11:04 +00:00
|
|
|
if(uprv_strcmp(tocEntryName, base+toc[2*number])<0) {
|
1999-11-22 19:43:01 +00:00
|
|
|
limit=number;
|
|
|
|
} else {
|
|
|
|
start=number;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(uprv_strcmp(tocEntryName, base+toc[2*start])==0) {
|
1999-11-22 19:43:01 +00:00
|
|
|
/* found it */
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "Found: %p\n",(base+toc[2*start+1]));
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
return (const DataHeader *)(base+toc[2*start+1]);
|
1999-11-22 19:43:01 +00:00
|
|
|
} else {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "Not found.\n");
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
1999-11-22 19:43:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
} else {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "returning header\n");
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
return pData->pHeader;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static const DataHeader *
|
|
|
|
pointerTOCLookupFn(const UDataMemory *pData,
|
|
|
|
const char *tocEntryName,
|
|
|
|
const char *dllEntryName,
|
|
|
|
UErrorCode *pErrorCode) {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "ptrTOC[%p] looking for %s/%s\n",
|
2000-12-05 02:28:32 +00:00
|
|
|
pData,
|
|
|
|
tocEntryName,dllEntryName);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData->toc!=NULL) {
|
|
|
|
const PointerTOCEntry *toc=(const PointerTOCEntry *)((const uint32_t *)pData->toc+2);
|
|
|
|
uint32_t start, limit, number;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* perform a binary search for the data in the common data's table of contents */
|
|
|
|
start=0;
|
|
|
|
limit=*(const uint32_t *)pData->toc; /* number of names in this table of contents */
|
2000-11-04 02:16:12 +00:00
|
|
|
|
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, " # of ents: %d\n", limit);
|
|
|
|
fflush(stderr);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
while(start<limit-1) {
|
|
|
|
number=(start+limit)/2;
|
|
|
|
if(uprv_strcmp(tocEntryName, toc[number].entryName)<0) {
|
|
|
|
limit=number;
|
|
|
|
} else {
|
|
|
|
start=number;
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(uprv_strcmp(tocEntryName, toc[start].entryName)==0) {
|
|
|
|
/* found it */
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "FOUND: %p\n",
|
|
|
|
normalizeDataPointer(toc[start].pHeader));
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
return normalizeDataPointer(toc[start].pHeader);
|
2000-05-03 23:11:04 +00:00
|
|
|
} else {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "NOT found\n");
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
} else {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "Returning header\n");
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-12-05 02:28:32 +00:00
|
|
|
return pData->pHeader;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static const DataHeader *
|
|
|
|
dllTOCLookupFn(const UDataMemory *pData,
|
|
|
|
const char *tocEntryName,
|
|
|
|
const char *dllEntryName,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
#ifndef UDATA_NO_DLL
|
|
|
|
if(pData->lib!=NULL) {
|
|
|
|
return normalizeDataPointer((const DataHeader *)GET_LIBRARY_ENTRY(pData->lib, dllEntryName));
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
#endif
|
|
|
|
return NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* common library functions ------------------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
static UDataMemory commonICUData={ NULL };
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
|
|
|
setCommonICUData(UDataMemory *pData) {
|
2000-05-18 22:08:39 +00:00
|
|
|
UBool setThisLib=FALSE;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* in the mutex block, set the common library for this process */
|
|
|
|
umtx_lock(NULL);
|
|
|
|
if(!IS_DATA_MEMORY_LOADED(&commonICUData)) {
|
|
|
|
uprv_memcpy(&commonICUData, pData, sizeof(UDataMemory));
|
2000-05-04 22:41:23 +00:00
|
|
|
commonICUData.flags&=~(1UL<<DYNAMIC_DATA_MEMORY_SHIFT);
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_memset(pData, 0, sizeof(UDataMemory));
|
|
|
|
setThisLib=TRUE;
|
|
|
|
}
|
|
|
|
umtx_unlock(NULL);
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* if a different thread set it first, then free the extra library instance */
|
|
|
|
if(!setThisLib) {
|
|
|
|
udata_close(pData);
|
1999-12-01 01:02:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static char *
|
|
|
|
strcpy_returnEnd(char *dest, const char *src) {
|
|
|
|
while((*dest=*src)!=0) {
|
|
|
|
++dest;
|
|
|
|
++src;
|
|
|
|
}
|
|
|
|
return dest;
|
|
|
|
}
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static char *
|
|
|
|
setPathGetBasename(const char *path, char *pathBuffer) {
|
|
|
|
/* set up the path in the pathBuffer and return a pointer behind its end,
|
|
|
|
to where the basename will go */
|
|
|
|
if(*pathBuffer!=0) {
|
|
|
|
/* the pathBuffer is already filled,
|
|
|
|
we just need to find the basename position;
|
|
|
|
assume that the last filling function removed the basename from the buffer */
|
|
|
|
return pathBuffer+uprv_strlen(pathBuffer);
|
|
|
|
} else if(path==NULL) {
|
|
|
|
/* copy the ICU_DATA path to the path buffer */
|
|
|
|
path=u_getDataDirectory();
|
|
|
|
if(path!=NULL && *path!=0) {
|
|
|
|
return strcpy_returnEnd(pathBuffer, path);
|
|
|
|
} else {
|
|
|
|
/* there is no path */
|
|
|
|
return pathBuffer;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* find the last file sepator in the input path */
|
|
|
|
char *basename=uprv_strrchr(path, U_FILE_SEP_CHAR);
|
|
|
|
if(basename==NULL) {
|
|
|
|
/* copy the ICU_DATA path to the path buffer */
|
|
|
|
path=u_getDataDirectory();
|
|
|
|
if(path!=NULL && *path!=0) {
|
|
|
|
return strcpy_returnEnd(pathBuffer, path);
|
|
|
|
} else {
|
|
|
|
/* there is no path */
|
|
|
|
return pathBuffer;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
/* copy the path to the path buffer */
|
|
|
|
++basename;
|
|
|
|
uprv_memcpy(pathBuffer, path, basename-path);
|
|
|
|
basename=pathBuffer+(basename-path);
|
|
|
|
*basename=0;
|
|
|
|
return basename;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-11-22 19:43:01 +00:00
|
|
|
static UDataMemory *
|
2000-05-03 23:11:04 +00:00
|
|
|
openCommonData(UDataMemory *pData,
|
2000-05-18 22:08:39 +00:00
|
|
|
const char *path, UBool isICUData,
|
2000-05-03 23:11:04 +00:00
|
|
|
char *pathBuffer,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
# if !UDATA_NO_DLL
|
|
|
|
Library lib;
|
|
|
|
# endif
|
|
|
|
const char *inBasename;
|
1999-11-22 19:43:01 +00:00
|
|
|
char *basename, *suffix;
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* "mini-cache" for common ICU data */
|
|
|
|
if(isICUData && IS_DATA_MEMORY_LOADED(&commonICUData)) {
|
|
|
|
return &commonICUData;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* ### we should have a real cache with a UHashTable and the path as the key */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* set up path and basename */
|
|
|
|
basename=setPathGetBasename(path, pathBuffer);
|
|
|
|
if(isICUData) {
|
2000-12-05 02:28:32 +00:00
|
|
|
#ifdef OS390
|
|
|
|
if (s390dll)
|
|
|
|
inBasename=COMMON_DATA1_NAME;
|
|
|
|
else
|
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
inBasename=COMMON_DATA_NAME;
|
|
|
|
} else {
|
|
|
|
inBasename=findBasename(path);
|
|
|
|
if(*inBasename==0) {
|
|
|
|
/* no basename, no common data */
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
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
|
|
|
/* try to load a common data DLL */
|
|
|
|
# if !UDATA_NO_DLL
|
|
|
|
/* set up the library name */
|
1999-11-22 19:43:01 +00:00
|
|
|
# ifndef LIB_PREFIX
|
2000-05-03 23:11:04 +00:00
|
|
|
suffix=strcpy_returnEnd(basename, inBasename);
|
1999-11-22 19:43:01 +00:00
|
|
|
# else
|
1999-12-28 23:39:02 +00:00
|
|
|
uprv_memcpy(basename, LIB_PREFIX, LIB_PREFIX_LENGTH);
|
2000-05-03 23:11:04 +00:00
|
|
|
suffix=strcpy_returnEnd(basename+LIB_PREFIX_LENGTH, inBasename);
|
1999-11-22 19:43:01 +00:00
|
|
|
# endif
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_strcpy(suffix, LIB_SUFFIX);
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try path/basename first */
|
2001-03-09 23:03:12 +00:00
|
|
|
# ifdef OS390
|
2001-03-15 00:31:08 +00:00
|
|
|
if (uprv_isOS390BatchMode()) {
|
2000-05-18 17:37:33 +00:00
|
|
|
/* ### hack: we still need to get u_getDataDirectory() fixed
|
2000-10-12 18:34:26 +00:00
|
|
|
for OS/390 (batch mode - always return "//"? )
|
2001-02-06 23:27:07 +00:00
|
|
|
and this here straightened out with LIB_PREFIX and LIB_SUFFIX (both empty?!)
|
|
|
|
This is probably due to the strange file system on OS/390. It's more like
|
|
|
|
a database with short entry names than a typical file system. */
|
2000-12-05 02:28:32 +00:00
|
|
|
if (s390dll) {
|
|
|
|
lib=LOAD_LIBRARY("//IXMICUD1", "//IXMICUD1");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
/* U_ICUDATA_NAME should always have the correct name */
|
2001-02-06 23:27:07 +00:00
|
|
|
/* 390port: BUT FOR BATCH MODE IT IS AN EXCEPTION ... */
|
|
|
|
/* 390port: THE NEXT LINE OF CODE WILL NOT WORK !!!!! */
|
|
|
|
/*lib=LOAD_LIBRARY("//" U_ICUDATA_NAME, "//" U_ICUDATA_NAME);*/
|
|
|
|
lib=LOAD_LIBRARY("//IXMICUDA", "//IXMICUDA"); /*390port*/
|
2000-12-05 02:28:32 +00:00
|
|
|
}
|
2001-03-09 23:03:12 +00:00
|
|
|
}
|
|
|
|
else
|
2000-05-18 17:37:33 +00:00
|
|
|
# endif
|
2001-03-09 23:03:12 +00:00
|
|
|
lib=LOAD_LIBRARY(pathBuffer, basename);
|
2000-05-18 17:37:33 +00:00
|
|
|
if(!IS_LIBRARY(lib) && basename!=pathBuffer) {
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try basename only next */
|
|
|
|
lib=LOAD_LIBRARY(basename, basename);
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(IS_LIBRARY(lib)) {
|
|
|
|
/* we have a data DLL - what kind of lookup do we need here? */
|
|
|
|
char entryName[100];
|
|
|
|
const DataHeader *pHeader;
|
|
|
|
*basename=0;
|
|
|
|
|
|
|
|
/* try to find the Table of Contents */
|
2000-12-06 03:02:21 +00:00
|
|
|
if(uprv_strcmp(inBasename, U_ICUDATA_NAME) == 0) {
|
|
|
|
uprv_strcpy(entryName, "icudata");
|
|
|
|
} else {
|
|
|
|
uprv_strcpy(entryName, inBasename);
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_strcat(entryName, "_" DATA_TYPE);
|
|
|
|
pHeader=normalizeDataPointer((const DataHeader *)GET_LIBRARY_ENTRY(lib, entryName));
|
|
|
|
if(pHeader==NULL) {
|
|
|
|
/* no TOC: assume DLL-intrinsic lookup */
|
|
|
|
pData->lib=lib;
|
|
|
|
pData->lookupFn=dllTOCLookupFn;
|
|
|
|
pData->flags=DLL_DATA_MEMORY|DLL_INTRINSIC_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
} else if(!(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pHeader->info.charsetFamily==U_CHARSET_FAMILY)
|
|
|
|
) {
|
|
|
|
/* header not valid */
|
|
|
|
UNLOAD_LIBRARY(lib);
|
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* which TOC type? */
|
|
|
|
} else if(pHeader->info.dataFormat[0]==0x43 &&
|
|
|
|
pHeader->info.dataFormat[1]==0x6d &&
|
|
|
|
pHeader->info.dataFormat[2]==0x6e &&
|
|
|
|
pHeader->info.dataFormat[3]==0x44 &&
|
|
|
|
pHeader->info.formatVersion[0]==1
|
|
|
|
) {
|
|
|
|
/* dataFormat="CmnD" */
|
|
|
|
pData->lib=lib;
|
|
|
|
pData->lookupFn=offsetTOCLookupFn;
|
|
|
|
pData->toc=(const char *)pHeader+pHeader->dataHeader.headerSize;
|
|
|
|
pData->flags=DLL_DATA_MEMORY|OFFSET_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
} else if(pHeader->info.dataFormat[0]==0x54 &&
|
|
|
|
pHeader->info.dataFormat[1]==0x6f &&
|
|
|
|
pHeader->info.dataFormat[2]==0x43 &&
|
|
|
|
pHeader->info.dataFormat[3]==0x50 &&
|
|
|
|
pHeader->info.formatVersion[0]==1
|
|
|
|
) {
|
|
|
|
/* dataFormat="ToCP" */
|
|
|
|
pData->lib=lib;
|
|
|
|
pData->lookupFn=pointerTOCLookupFn;
|
|
|
|
pData->toc=(const char *)pHeader+pHeader->dataHeader.headerSize;
|
|
|
|
pData->flags=DLL_DATA_MEMORY|POINTER_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
} else {
|
|
|
|
/* dataFormat not recognized */
|
|
|
|
UNLOAD_LIBRARY(lib);
|
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* we have common data from a DLL */
|
|
|
|
if(isICUData) {
|
|
|
|
setCommonICUData(pData);
|
|
|
|
return &commonICUData;
|
1999-11-22 19:43:01 +00:00
|
|
|
} else {
|
2000-05-03 23:11:04 +00:00
|
|
|
return pData;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
# endif
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try to map a common data file */
|
|
|
|
|
|
|
|
/* set up the file name */
|
|
|
|
suffix=strcpy_returnEnd(basename, inBasename);
|
|
|
|
uprv_strcpy(suffix, "." DATA_TYPE);
|
|
|
|
|
|
|
|
/* try path/basename first, then basename only */
|
2000-05-18 17:37:33 +00:00
|
|
|
if( uprv_mapFile(pData, pathBuffer, basename) ||
|
2000-10-12 18:34:26 +00:00
|
|
|
(basename!=pathBuffer && uprv_mapFile(pData, basename, basename))
|
2000-05-18 17:37:33 +00:00
|
|
|
) {
|
2000-05-03 23:11:04 +00:00
|
|
|
const DataHeader *pHeader;
|
|
|
|
*basename=0;
|
|
|
|
|
|
|
|
/* we have mapped a file, check its header */
|
|
|
|
pHeader=pData->pHeader;
|
|
|
|
if(!(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pHeader->info.charsetFamily==U_CHARSET_FAMILY &&
|
|
|
|
pHeader->info.dataFormat[0]==0x43 &&
|
|
|
|
pHeader->info.dataFormat[1]==0x6d &&
|
|
|
|
pHeader->info.dataFormat[2]==0x6e &&
|
|
|
|
pHeader->info.dataFormat[3]==0x44 &&
|
|
|
|
pHeader->info.formatVersion[0]==1)
|
|
|
|
) {
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(pData);
|
2000-05-03 23:11:04 +00:00
|
|
|
pData->flags=0;
|
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
|
|
|
|
/* we have common data from a mapped file */
|
|
|
|
pData->lookupFn=offsetTOCLookupFn;
|
|
|
|
pData->toc=(const char *)pHeader+pHeader->dataHeader.headerSize;
|
|
|
|
pData->flags|=OFFSET_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
if(isICUData) {
|
|
|
|
setCommonICUData(pData);
|
|
|
|
return &commonICUData;
|
|
|
|
} else {
|
|
|
|
return pData;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* cleanup for the caller, to keep setPathGetBasename() consistent */
|
|
|
|
*basename=0;
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* no common data */
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
1999-12-01 01:02:06 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udata_setCommonData(const void *data, UErrorCode *pErrorCode) {
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* do we already have common ICU data set? */
|
|
|
|
if(IS_DATA_MEMORY_LOADED(&commonICUData)) {
|
|
|
|
*pErrorCode=U_USING_DEFAULT_ERROR;
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
/* normalize the data pointer and test for validity */
|
|
|
|
UDataMemory dataMemory={ NULL };
|
|
|
|
const DataHeader *pHeader=normalizeDataPointer((const DataHeader *)data);
|
|
|
|
if(!(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
pHeader->info.charsetFamily==U_CHARSET_FAMILY)
|
|
|
|
) {
|
|
|
|
/* header not valid */
|
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* which TOC type? */
|
|
|
|
} else if(pHeader->info.dataFormat[0]==0x43 &&
|
|
|
|
pHeader->info.dataFormat[1]==0x6d &&
|
|
|
|
pHeader->info.dataFormat[2]==0x6e &&
|
|
|
|
pHeader->info.dataFormat[3]==0x44 &&
|
|
|
|
pHeader->info.formatVersion[0]==1
|
|
|
|
) {
|
|
|
|
/* dataFormat="CmnD" */
|
|
|
|
dataMemory.lookupFn=offsetTOCLookupFn;
|
|
|
|
dataMemory.toc=(const char *)pHeader+pHeader->dataHeader.headerSize;
|
|
|
|
dataMemory.flags=DLL_DATA_MEMORY|OFFSET_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
} else if(pHeader->info.dataFormat[0]==0x54 &&
|
|
|
|
pHeader->info.dataFormat[1]==0x6f &&
|
|
|
|
pHeader->info.dataFormat[2]==0x43 &&
|
|
|
|
pHeader->info.dataFormat[3]==0x50 &&
|
|
|
|
pHeader->info.formatVersion[0]==1
|
|
|
|
) {
|
|
|
|
/* dataFormat="ToCP" */
|
|
|
|
dataMemory.lookupFn=pointerTOCLookupFn;
|
|
|
|
dataMemory.toc=(const char *)pHeader+pHeader->dataHeader.headerSize;
|
|
|
|
dataMemory.flags=DLL_DATA_MEMORY|POINTER_TOC<<TOC_TYPE_SHIFT;
|
|
|
|
} else {
|
|
|
|
/* dataFormat not recognized */
|
|
|
|
*pErrorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
return;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* we have common data */
|
2000-05-04 22:41:23 +00:00
|
|
|
dataMemory.flags|=1UL<<SET_DATA_POINTER_SHIFT;
|
2000-05-03 23:11:04 +00:00
|
|
|
setCommonICUData(&dataMemory);
|
|
|
|
if(dataMemory.flags!=0) {
|
|
|
|
/* some thread passed us */
|
|
|
|
*pErrorCode=U_USING_DEFAULT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* main data loading function ----------------------------------------------- */
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
|
|
|
setEntryNames(const char *type, const char *name,
|
|
|
|
char *tocEntryName, char *dllEntryName) {
|
|
|
|
while(*name!=0) {
|
|
|
|
*tocEntryName=*name;
|
|
|
|
if(*name=='.' || *name=='-') {
|
|
|
|
*dllEntryName='_';
|
|
|
|
} else {
|
|
|
|
*dllEntryName=*name;
|
|
|
|
}
|
|
|
|
++tocEntryName;
|
|
|
|
++dllEntryName;
|
|
|
|
++name;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(type!=NULL && *type!=0) {
|
|
|
|
*tocEntryName++='.';
|
|
|
|
*dllEntryName++='_';
|
|
|
|
do {
|
|
|
|
*tocEntryName++=*dllEntryName++=*type++;
|
|
|
|
} while(*type!=0);
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
*tocEntryName=*dllEntryName=0;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static UDataMemory *
|
|
|
|
doOpenChoice(const char *path, const char *type, const char *name,
|
|
|
|
UDataMemoryIsAcceptable *isAcceptable, void *context,
|
|
|
|
UErrorCode *pErrorCode) {
|
|
|
|
char pathBuffer[1024];
|
|
|
|
char tocEntryName[100], dllEntryName[100];
|
|
|
|
UDataMemory dataMemory;
|
|
|
|
UDataMemory *pCommonData, *pEntryData;
|
|
|
|
const DataHeader *pHeader;
|
|
|
|
const char *inBasename;
|
|
|
|
char *basename, *suffix;
|
|
|
|
UErrorCode errorCode=U_ZERO_ERROR;
|
2000-08-10 01:59:18 +00:00
|
|
|
UBool isICUData= (UBool)(path==NULL);
|
2000-05-03 23:11:04 +00:00
|
|
|
|
|
|
|
/* set up the ToC names for DLL and offset-ToC lookups */
|
|
|
|
setEntryNames(type, name, tocEntryName, dllEntryName);
|
|
|
|
|
2000-12-05 02:28:32 +00:00
|
|
|
#ifdef OS390
|
|
|
|
if(s390dll == TRUE)
|
|
|
|
{
|
|
|
|
/* try to get high frequency S390 common data first */
|
|
|
|
uprv_memset(&dataMemory, 0, sizeof(UDataMemory));
|
|
|
|
pathBuffer[0]=0;
|
|
|
|
pCommonData=openCommonData(&dataMemory, path, isICUData, pathBuffer, &errorCode);
|
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* look up the data piece in the common data */
|
|
|
|
pHeader=pCommonData->lookupFn(pCommonData, tocEntryName, dllEntryName, &errorCode);
|
|
|
|
if(pHeader!=NULL) {
|
|
|
|
/* data found in the common data, test it */
|
|
|
|
if(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
(isAcceptable==NULL || isAcceptable(context, type, name, &pHeader->info))
|
|
|
|
) {
|
|
|
|
/* acceptable - allocate parent, too, if necessary */
|
|
|
|
if(pCommonData==&dataMemory) {
|
|
|
|
/* trick: do one malloc for both the common and the entry */
|
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(2*sizeof(UDataMemory));
|
|
|
|
if(pEntryData!=NULL) {
|
|
|
|
pCommonData=pEntryData+1;
|
|
|
|
uprv_memcpy(pCommonData, &dataMemory, sizeof(UDataMemory));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(sizeof(UDataMemory));
|
|
|
|
}
|
|
|
|
if(pEntryData==NULL) {
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
uprv_memset(pEntryData, 0, sizeof(UDataMemory));
|
|
|
|
pEntryData->parent=pCommonData;
|
|
|
|
pEntryData->pHeader=pHeader;
|
|
|
|
pEntryData->flags=pCommonData->flags&DATA_MEMORY_TYPE_MASK|1UL<<DYNAMIC_DATA_MEMORY_SHIFT;
|
|
|
|
return pEntryData;
|
|
|
|
} else {
|
|
|
|
/* the data is not acceptable, look further */
|
|
|
|
errorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* the data is not in the common data, close that and look further */
|
|
|
|
s390dll=FALSE;
|
|
|
|
if(pCommonData==&dataMemory) {
|
|
|
|
udata_close(&dataMemory);
|
|
|
|
/* commonICUData = { NULL }; */
|
|
|
|
(&commonICUData)->flags = 0;
|
|
|
|
/* clear out the 'mini cache' used in openCommonData */
|
|
|
|
/* This is not thread safe!!!!!!! */
|
|
|
|
}
|
|
|
|
}
|
|
|
|
s390dll=FALSE;
|
|
|
|
(&commonICUData)->flags = 0 ;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try to get common data */
|
|
|
|
uprv_memset(&dataMemory, 0, sizeof(UDataMemory));
|
|
|
|
pathBuffer[0]=0;
|
|
|
|
pCommonData=openCommonData(&dataMemory, path, isICUData, pathBuffer, &errorCode);
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "commonData;%p\n", pCommonData);
|
|
|
|
fflush(stderr);
|
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* look up the data piece in the common data */
|
|
|
|
pHeader=pCommonData->lookupFn(pCommonData, tocEntryName, dllEntryName, &errorCode);
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "Common found: %p\n", pHeader);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pHeader!=NULL) {
|
|
|
|
/* data found in the common data, test it */
|
|
|
|
if(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
(isAcceptable==NULL || isAcceptable(context, type, name, &pHeader->info))
|
|
|
|
) {
|
|
|
|
/* acceptable - allocate parent, too, if necessary */
|
|
|
|
if(pCommonData==&dataMemory) {
|
|
|
|
/* trick: do one malloc for both the common and the entry */
|
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(2*sizeof(UDataMemory));
|
|
|
|
if(pEntryData!=NULL) {
|
|
|
|
pCommonData=pEntryData+1;
|
|
|
|
uprv_memcpy(pCommonData, &dataMemory, sizeof(UDataMemory));
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
} else {
|
2000-05-03 23:11:04 +00:00
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(sizeof(UDataMemory));
|
|
|
|
}
|
|
|
|
if(pEntryData==NULL) {
|
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_memset(pEntryData, 0, sizeof(UDataMemory));
|
|
|
|
pEntryData->parent=pCommonData;
|
|
|
|
pEntryData->pHeader=pHeader;
|
2000-10-12 18:34:26 +00:00
|
|
|
pEntryData->flags=(pCommonData->flags&DATA_MEMORY_TYPE_MASK)|1UL<<DYNAMIC_DATA_MEMORY_SHIFT;
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, " made data @%p\n", pEntryData);
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
return pEntryData;
|
|
|
|
} else {
|
|
|
|
/* the data is not acceptable, look further */
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "Not acceptable\n");
|
2000-11-04 02:16:12 +00:00
|
|
|
#endif
|
2000-05-03 23:11:04 +00:00
|
|
|
errorCode=U_INVALID_FORMAT_ERROR;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* the data is not in the common data, close that and look further */
|
|
|
|
if(pCommonData==&dataMemory) {
|
|
|
|
udata_close(&dataMemory);
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try to get an individual data file */
|
|
|
|
basename=setPathGetBasename(path, pathBuffer);
|
|
|
|
if(isICUData) {
|
|
|
|
inBasename=COMMON_DATA_NAME;
|
|
|
|
} else {
|
|
|
|
inBasename=findBasename(path);
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "looking for ind. file\n");
|
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try path+basename+"_"+entryName first */
|
2000-06-05 17:24:34 +00:00
|
|
|
if(*inBasename!=0) {
|
2000-05-03 23:11:04 +00:00
|
|
|
suffix=strcpy_returnEnd(basename, inBasename);
|
|
|
|
*suffix++='_';
|
|
|
|
uprv_strcpy(suffix, tocEntryName);
|
|
|
|
|
2000-05-18 17:37:33 +00:00
|
|
|
if( uprv_mapFile(&dataMemory, pathBuffer, basename) ||
|
2000-10-12 18:34:26 +00:00
|
|
|
(basename!=pathBuffer && uprv_mapFile(&dataMemory, basename, basename))
|
2000-05-18 17:37:33 +00:00
|
|
|
) {
|
2000-05-03 23:11:04 +00:00
|
|
|
pHeader=dataMemory.pHeader;
|
|
|
|
if(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
(isAcceptable==NULL || isAcceptable(context, type, name, &pHeader->info))
|
|
|
|
) {
|
|
|
|
/* acceptable */
|
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(sizeof(UDataMemory));
|
|
|
|
if(pEntryData==NULL) {
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(&dataMemory);
|
2000-05-03 23:11:04 +00:00
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-04 22:41:23 +00:00
|
|
|
dataMemory.flags|=1UL<<DYNAMIC_DATA_MEMORY_SHIFT;
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_memcpy(pEntryData, &dataMemory, sizeof(UDataMemory));
|
|
|
|
return pEntryData;
|
|
|
|
} else {
|
|
|
|
/* the data is not acceptable, look further */
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(&dataMemory);
|
2000-05-03 23:11:04 +00:00
|
|
|
errorCode=U_INVALID_FORMAT_ERROR;
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
/* try path+entryName next */
|
|
|
|
uprv_strcpy(basename, tocEntryName);
|
2000-05-18 17:37:33 +00:00
|
|
|
if( uprv_mapFile(&dataMemory, pathBuffer, basename) ||
|
2000-10-12 18:34:26 +00:00
|
|
|
(basename!=pathBuffer && uprv_mapFile(&dataMemory, basename, basename))
|
2000-05-18 17:37:33 +00:00
|
|
|
) {
|
2000-05-03 23:11:04 +00:00
|
|
|
pHeader=dataMemory.pHeader;
|
|
|
|
if(pHeader->dataHeader.magic1==0xda && pHeader->dataHeader.magic2==0x27 &&
|
|
|
|
pHeader->info.isBigEndian==U_IS_BIG_ENDIAN &&
|
|
|
|
(isAcceptable==NULL || isAcceptable(context, type, name, &pHeader->info))
|
|
|
|
) {
|
|
|
|
/* acceptable */
|
|
|
|
pEntryData=(UDataMemory *)uprv_malloc(sizeof(UDataMemory));
|
|
|
|
if(pEntryData==NULL) {
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(&dataMemory);
|
1999-11-22 19:43:01 +00:00
|
|
|
*pErrorCode=U_MEMORY_ALLOCATION_ERROR;
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-05-04 22:41:23 +00:00
|
|
|
dataMemory.flags|=1UL<<DYNAMIC_DATA_MEMORY_SHIFT;
|
2000-05-03 23:11:04 +00:00
|
|
|
uprv_memcpy(pEntryData, &dataMemory, sizeof(UDataMemory));
|
|
|
|
return pEntryData;
|
|
|
|
} else {
|
|
|
|
/* the data is not acceptable, look further */
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(&dataMemory);
|
2000-05-03 23:11:04 +00:00
|
|
|
errorCode=U_INVALID_FORMAT_ERROR;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* data not found */
|
|
|
|
if(U_SUCCESS(*pErrorCode)) {
|
1999-11-22 19:53:19 +00:00
|
|
|
if(U_SUCCESS(errorCode)) {
|
|
|
|
/* file not found */
|
|
|
|
*pErrorCode=U_FILE_ACCESS_ERROR;
|
|
|
|
} else {
|
|
|
|
/* entry point not found or rejected */
|
|
|
|
*pErrorCode=errorCode;
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
static void
|
|
|
|
unloadDataMemory(UDataMemory *pData) {
|
2000-05-04 22:41:23 +00:00
|
|
|
if(!(pData->flags&(1UL<<SET_DATA_POINTER_SHIFT))) {
|
2000-05-03 23:11:04 +00:00
|
|
|
switch(pData->flags&DATA_MEMORY_TYPE_MASK) {
|
|
|
|
case FLAT_DATA_MEMORY:
|
|
|
|
if(IS_MAP(pData->map)) {
|
2000-05-04 00:34:46 +00:00
|
|
|
uprv_unmapFile(pData);
|
2000-05-03 23:11:04 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case DLL_DATA_MEMORY:
|
|
|
|
if(IS_LIBRARY(pData->lib)) {
|
|
|
|
UNLOAD_LIBRARY(pData->lib);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* 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
|
2000-12-05 02:28:32 +00:00
|
|
|
fprintf(stderr, "udata_open(): Opening: %s . %s\n", name, type);
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
fprintf(stderr, "udata_openChoice(): Opening: %s . %s\n", name, type);fflush(stderr);
|
|
|
|
#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
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI void U_EXPORT2
|
|
|
|
udata_close(UDataMemory *pData) {
|
2000-11-04 02:16:12 +00:00
|
|
|
#ifdef UDATA_DEBUG
|
|
|
|
fprintf(stderr, "udata_close()\n");fflush(stderr);
|
|
|
|
#endif
|
|
|
|
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData!=NULL && IS_DATA_MEMORY_LOADED(pData)) {
|
|
|
|
unloadDataMemory(pData);
|
2000-05-04 22:41:23 +00:00
|
|
|
if(pData->flags&(1UL<<DYNAMIC_DATA_MEMORY_SHIFT)) {
|
2000-05-03 23:11:04 +00:00
|
|
|
if(pData->parent==pData+1) {
|
|
|
|
/* this data entry was allocated together with its parent */
|
|
|
|
unloadDataMemory(pData+1);
|
|
|
|
}
|
|
|
|
uprv_free(pData);
|
|
|
|
} else {
|
|
|
|
pData->flags=0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
U_CAPI const void * U_EXPORT2
|
|
|
|
udata_getMemory(UDataMemory *pData) {
|
|
|
|
if(pData!=NULL && pData->pHeader!=NULL) {
|
|
|
|
return (char *)(pData->pHeader)+pData->pHeader->dataHeader.headerSize;
|
|
|
|
} else {
|
1999-11-22 19:43:01 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
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;
|
2001-05-25 21:50:10 +00:00
|
|
|
if(pInfo->size>info->size) {
|
2000-05-03 23:11:04 +00:00
|
|
|
pInfo->size=info->size;
|
|
|
|
}
|
2001-05-25 21:50:10 +00:00
|
|
|
uprv_memcpy((uint16_t *)pInfo+1, (uint16_t *)info+1, pInfo->size-2);
|
2000-05-03 23:11:04 +00:00
|
|
|
} else {
|
|
|
|
pInfo->size=0;
|
|
|
|
}
|
|
|
|
}
|
1999-11-22 19:43:01 +00:00
|
|
|
}
|