X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/73c04bcfe1096173b00431f0cdc742894b15eef0..b25be06635768807f8f693286fa73bb2297bb06c:/icuSources/common/umapfile.c?ds=sidebyside diff --git a/icuSources/common/umapfile.c b/icuSources/common/umapfile.c index 356e55ac..f9f857e9 100644 --- a/icuSources/common/umapfile.c +++ b/icuSources/common/umapfile.c @@ -1,38 +1,28 @@ /* ****************************************************************************** * -* Copyright (C) 1999-2006, International Business Machines +* Copyright (C) 1999-2010, International Business Machines * Corporation and others. All Rights Reserved. * ******************************************************************************/ /*---------------------------------------------------------------------------- - * + * * Memory mapped file wrappers for use by the ICU Data Implementation * All of the platform-specific implementation for mapping data files * is here. The rest of the ICU Data implementation uses only the * wrapper functions. * *----------------------------------------------------------------------------*/ -#include "unicode/putil.h" - +#include "unicode/putil.h" #include "udatamem.h" #include "umapfile.h" /* memory-mapping base definitions ------------------------------------------ */ -/* MAP_NONE: no memory mapping, no file access at all */ -#define MAP_NONE 0 -#define MAP_WIN32 1 -#define MAP_POSIX 2 -#define MAP_STDIO 3 -#define MAP_390DLL 4 - -#if UCONFIG_NO_FILE_IO -# define MAP_IMPLEMENTATION MAP_NONE -#elif defined(U_WINDOWS) +#if MAP_IMPLEMENTATION==MAP_WIN32 # define WIN32_LEAN_AND_MEAN # define VC_EXTRALEAN # define NOUSER @@ -45,20 +35,11 @@ typedef HANDLE MemoryMap; # define IS_MAP(map) ((map)!=NULL) - -# define MAP_IMPLEMENTATION MAP_WIN32 - -/* ### Todo: properly auto detect mmap(). Until then, just add your platform here. */ -#elif U_HAVE_MMAP || defined(U_AIX) || defined(U_HPUX) || defined(OS390) +#elif MAP_IMPLEMENTATION==MAP_POSIX || MAP_IMPLEMENTATION==MAP_390DLL typedef size_t MemoryMap; # define IS_MAP(map) ((map)!=0) - /* Needed by OSF to get the correct mmap version */ -# ifndef _XOPEN_SOURCE_EXTENDED -# define _XOPEN_SOURCE_EXTENDED -# endif - # include # include # include @@ -68,7 +49,7 @@ # define MAP_FAILED ((void*)-1) # endif -# if defined(OS390) && defined (OS390_STUBDATA) +# if MAP_IMPLEMENTATION==MAP_390DLL /* No memory mapping for 390 batch mode. Fake it using dll loading. */ # include # include "cstring.h" @@ -76,30 +57,22 @@ # include "unicode/udata.h" # define LIB_PREFIX "lib" # define LIB_SUFFIX ".dll" -# define MAP_IMPLEMENTATION MAP_390DLL - -/* This is inconvienient until we figure out what to do with U_ICUDATA_NAME in utypes.h */ + /* This is inconvienient until we figure out what to do with U_ICUDATA_NAME in utypes.h */ # define U_ICUDATA_ENTRY_NAME "icudt" U_ICU_VERSION_SHORT U_LIB_SUFFIX_C_NAME_STRING "_dat" # else -# define MAP_IMPLEMENTATION MAP_POSIX +# if defined(U_DARWIN) +# include +# endif # endif - -#else /* unknown platform, no memory map implementation: use stdio.h and uprv_malloc() instead */ - +#elif MAP_IMPLEMENTATION==MAP_STDIO # include # include "cmemory.h" typedef void *MemoryMap; # define IS_MAP(map) ((map)!=NULL) - -# define MAP_IMPLEMENTATION MAP_STDIO - #endif - - - /*----------------------------------------------------------------------------* * * * Memory Mapped File support. Platform dependent implementation of * @@ -107,17 +80,17 @@ * * *----------------------------------------------------------------------------*/ #if MAP_IMPLEMENTATION==MAP_NONE - UBool + U_CFUNC UBool uprv_mapFile(UDataMemory *pData, const char *path) { UDataMemory_init(pData); /* Clear the output struct. */ return FALSE; /* no file access */ } - void uprv_unmapFile(UDataMemory *pData) { + U_CFUNC void uprv_unmapFile(UDataMemory *pData) { /* nothing to do */ } #elif MAP_IMPLEMENTATION==MAP_WIN32 - UBool + U_CFUNC UBool uprv_mapFile( UDataMemory *pData, /* Fill in with info on the result doing the mapping. */ /* Output only; any original contents are cleared. */ @@ -133,7 +106,7 @@ UDataMemory_init(pData); /* Clear the output struct. */ /* open the input file */ - file=CreateFile(path, GENERIC_READ, FILE_SHARE_READ, NULL, + file=CreateFileA(path, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL|FILE_FLAG_RANDOM_ACCESS, NULL); if(file==INVALID_HANDLE_VALUE) { @@ -173,8 +146,7 @@ return TRUE; } - - void + U_CFUNC void uprv_unmapFile(UDataMemory *pData) { if(pData!=NULL && pData->map!=NULL) { UnmapViewOfFile(pData->pHeader); @@ -187,7 +159,7 @@ #elif MAP_IMPLEMENTATION==MAP_POSIX - UBool + U_CFUNC UBool uprv_mapFile(UDataMemory *pData, const char *path) { int fd; int length; @@ -222,12 +194,13 @@ pData->map = (char *)data + length; pData->pHeader=(const DataHeader *)data; pData->mapAddr = data; +#if defined(U_DARWIN) && TARGET_OS_IPHONE + posix_madvise(data, length, POSIX_MADV_RANDOM); +#endif return TRUE; } - - - void + U_CFUNC void uprv_unmapFile(UDataMemory *pData) { if(pData!=NULL && pData->map!=NULL) { size_t dataLen = (char *)pData->map - (char *)pData->mapAddr; @@ -256,7 +229,7 @@ return size; } - UBool + U_CFUNC UBool uprv_mapFile(UDataMemory *pData, const char *path) { FILE *file; int32_t fileLength; @@ -297,7 +270,7 @@ return TRUE; } - void + U_CFUNC void uprv_unmapFile(UDataMemory *pData) { if(pData!=NULL && pData->map!=NULL) { uprv_free(pData->map); @@ -385,7 +358,7 @@ # define DATA_TYPE "dat" - UBool uprv_mapFile(UDataMemory *pData, const char *path) { + U_CFUNC UBool uprv_mapFile(UDataMemory *pData, const char *path) { const char *inBasename; char *basename; char pathBuffer[1024]; @@ -478,9 +451,7 @@ } } - - - void uprv_unmapFile(UDataMemory *pData) { + U_CFUNC void uprv_unmapFile(UDataMemory *pData) { if(pData!=NULL && pData->map!=NULL) { uprv_free(pData->map); pData->map = NULL;