diff --git a/icu4c/source/common/Makefile.in b/icu4c/source/common/Makefile.in
index a8efe46d8da..2499d3ff5c4 100644
--- a/icu4c/source/common/Makefile.in
+++ b/icu4c/source/common/Makefile.in
@@ -76,7 +76,7 @@ brkiter.o brkdict.o ubrk.o dbbi.o dbbi_tbl.o \
rbbi.o rbbidata.o rbbinode.o rbbirb.o rbbiscan.o rbbisetb.o rbbistbl.o rbbitblb.o \
serv.o servnotf.o servls.o servlk.o servlkf.o servrbf.o servslkf.o locutil.o \
uenum.o ustrenum.o uidna.o usprep.o punycode.o \
-cwchar.o filestrm.o util.o parsepos.o utrace.o locbased.o
+cwchar.o util.o parsepos.o utrace.o locbased.o
STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O))
diff --git a/icu4c/source/common/common.vcproj b/icu4c/source/common/common.vcproj
index 7b847a2f4d3..66159fdefef 100644
--- a/icu4c/source/common/common.vcproj
+++ b/icu4c/source/common/common.vcproj
@@ -499,12 +499,6 @@
Outputs="..\..\include\unicode\$(InputFileName)"/>
-
-
-
-
@@ -1760,14 +1754,16 @@
Name="Release|Win32">
diff --git a/icu4c/source/common/umapfile.c b/icu4c/source/common/umapfile.c
index 57fcc176222..d956e77211a 100644
--- a/icu4c/source/common/umapfile.c
+++ b/icu4c/source/common/umapfile.c
@@ -21,16 +21,44 @@
#include "udatamem.h"
#include "umapfile.h"
+#if U_ICU_VERSION_MAJOR_NUM>3 || (U_ICU_VERSION_MAJOR_NUM==3 && U_ICU_VERSION_MINOR_NUM>4)
+# error Time bomb: After ICU 3.4 move the definition of UCONFIG_NO_FILE_IO to uconfig.h. Use Jitterbug 4614.
+#endif
+
+/**
+ * \def UCONFIG_NO_FILE_IO
+ * This switch turns off all file access in the common library
+ * where file access is only used for data loading.
+ * ICU data must then be provided in the form of a data DLL (or with an
+ * equivalent way to link to the data residing in an executable,
+ * as in building a combined library with both the common library's code and
+ * the data), or via udata_setCommonData().
+ * Application data must be provided via udata_setAppData() or by using
+ * "open" functions that take pointers to data, for example ucol_openBinary().
+ *
+ * File access is not used at all in the i18n library.
+ *
+ * File access cannot be turned off for the icuio library or for the ICU
+ * test suites and ICU tools.
+ *
+ * @draft ICU 3.6
+ */
+#ifndef UCONFIG_NO_FILE_IO
+# define UCONFIG_NO_FILE_IO 0
+#endif
/* 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_FILE_STREAM 3
+#define MAP_STDIO 3
#define MAP_390DLL 4
-#ifdef U_WINDOWS
+#if UCONFIG_NO_FILE_IO
+# define MAP_IMPLEMENTATION MAP_NONE
+#elif defined(U_WINDOWS)
# define WIN32_LEAN_AND_MEAN
# define VC_EXTRALEAN
# define NOUSER
@@ -81,16 +109,16 @@
# define MAP_IMPLEMENTATION MAP_POSIX
# endif
-#else /* unknown platform, no memory map implementation: use FileStream/uprv_malloc() instead */
+#else /* unknown platform, no memory map implementation: use stdio.h and uprv_malloc() instead */
-# include "filestrm.h"
+# include
# include "cmemory.h"
typedef void *MemoryMap;
# define IS_MAP(map) ((map)!=NULL)
-# define MAP_IMPLEMENTATION MAP_FILE_STREAM
+# define MAP_IMPLEMENTATION MAP_STDIO
#endif
@@ -103,7 +131,17 @@
* functions used by the rest of the implementation.*
* *
*----------------------------------------------------------------------------*/
-#if MAP_IMPLEMENTATION==MAP_WIN32
+#if MAP_IMPLEMENTATION==MAP_NONE
+ 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) {
+ /* nothing to do */
+ }
+#elif MAP_IMPLEMENTATION==MAP_WIN32
UBool
uprv_mapFile(
UDataMemory *pData, /* Fill in with info on the result doing the mapping. */
@@ -209,42 +247,56 @@
-#elif MAP_IMPLEMENTATION==MAP_FILE_STREAM
+#elif MAP_IMPLEMENTATION==MAP_STDIO
+ /* copy of the filestrm.c/T_FileStream_size() implementation */
+ static int32_t
+ umap_fsize(FILE *f) {
+ int32_t savedPos = ftell(f);
+ int32_t size = 0;
+
+ /*Changes by Bertrand A. D. doesn't affect the current position
+ goes to the end of the file before ftell*/
+ fseek(f, 0, SEEK_END);
+ size = (int32_t)ftell(f);
+ fseek(f, savedPos, SEEK_SET);
+ return size;
+ }
+
UBool
uprv_mapFile(UDataMemory *pData, const char *path) {
- FileStream *file;
+ FILE *file;
int32_t fileLength;
void *p;
UDataMemory_init(pData); /* Clear the output struct. */
/* open the input file */
- file=T_FileStream_open(path, "rb");
+ file=fopen(path, "rb");
if(file==NULL) {
return FALSE;
}
/* get the file length */
- fileLength=T_FileStream_size(file);
- if(T_FileStream_error(file) || fileLength<=20) {
- T_FileStream_close(file);
+ fileLength=umap_fsize(file);
+ if(ferror(file) || fileLength<=20) {
+ fclose(file);
return FALSE;
}
/* allocate the memory to hold the file data */
p=uprv_malloc(fileLength);
if(p==NULL) {
- T_FileStream_close(file);
+ fclose(file);
return FALSE;
}
/* read the file */
- if(fileLength!=T_FileStream_read(file, p, fileLength)) {
+ if(fileLength!=fread(p, 1, fileLength, file)) {
uprv_free(p);
- T_FileStream_close(file);
+ fclose(file);
return FALSE;
}
- T_FileStream_close(file);
+ fclose(file);
pData->map=p;
pData->pHeader=(const DataHeader *)p;
pData->mapAddr=p;
@@ -446,5 +498,3 @@
#else
# error MAP_IMPLEMENTATION is set incorrectly
#endif
-
-
diff --git a/icu4c/source/tools/toolutil/Makefile.in b/icu4c/source/tools/toolutil/Makefile.in
index 9602768f224..208333fa632 100644
--- a/icu4c/source/tools/toolutil/Makefile.in
+++ b/icu4c/source/tools/toolutil/Makefile.in
@@ -42,7 +42,7 @@ CPPFLAGS += -I$(top_builddir)/common -I$(top_srcdir)/common -I$(top_srcdir)/i18n
DEFS += -DU_TOOLUTIL_IMPLEMENTATION
LIBS = $(LIBICUI18N) $(LIBICUUC) $(DEFAULT_LIBS)
-OBJECTS = propsvec.o toolutil.o unewdata.o ucm.o ucmstate.o uoptions.o uparse.o ucbuf.o xmlparser.o writesrc.o
+OBJECTS = filestrm.o propsvec.o toolutil.o unewdata.o ucm.o ucmstate.o uoptions.o uparse.o ucbuf.o xmlparser.o writesrc.o
STATIC_OBJECTS = $(OBJECTS:.o=.$(STATIC_O))
diff --git a/icu4c/source/common/filestrm.c b/icu4c/source/tools/toolutil/filestrm.c
similarity index 97%
rename from icu4c/source/common/filestrm.c
rename to icu4c/source/tools/toolutil/filestrm.c
index 8ab542cc797..bf646916f61 100644
--- a/icu4c/source/common/filestrm.c
+++ b/icu4c/source/tools/toolutil/filestrm.c
@@ -23,8 +23,6 @@
#include "filestrm.h"
-#if !defined(UCONFIG_NO_FILE_IO) || !UCONFIG_NO_FILE_IO
-
#include "cmemory.h"
#include
@@ -170,7 +168,7 @@ T_FileStream_size(FileStream* fileStream)
/*Changes by Bertrand A. D. doesn't affect the current position
goes to the end of the file before ftell*/
fseek((FILE*)fileStream, 0, SEEK_END);
- size = ftell((FILE*)fileStream);
+ size = (int32_t)ftell((FILE*)fileStream);
fseek((FILE*)fileStream, savedPos, SEEK_SET);
return size;
}
@@ -225,6 +223,3 @@ U_CAPI UBool U_EXPORT2
T_FileStream_remove(const char* fileName){
return (remove(fileName) == 0);
}
-
-#endif /* !UCONFIG_NO_FILE_IO */
-
diff --git a/icu4c/source/common/filestrm.h b/icu4c/source/tools/toolutil/filestrm.h
similarity index 96%
rename from icu4c/source/common/filestrm.h
rename to icu4c/source/tools/toolutil/filestrm.h
index cbcbec44665..0eeba98b661 100644
--- a/icu4c/source/common/filestrm.h
+++ b/icu4c/source/tools/toolutil/filestrm.h
@@ -27,8 +27,6 @@
#include "unicode/utypes.h"
-#if !defined(UCONFIG_NO_FILE_IO) || !UCONFIG_NO_FILE_IO
-
typedef struct _FileStream FileStream;
U_CAPI FileStream* U_EXPORT2
@@ -103,6 +101,4 @@ T_FileStream_stderr(void);
U_CAPI UBool U_EXPORT2
T_FileStream_remove(const char* fileName);
-#endif /* !UCONFIG_NO_FILE_IO */
#endif /* _FILESTRM*/
-
diff --git a/icu4c/source/tools/toolutil/toolutil.vcproj b/icu4c/source/tools/toolutil/toolutil.vcproj
index c7568a2a134..12d6b307cc9 100644
--- a/icu4c/source/tools/toolutil/toolutil.vcproj
+++ b/icu4c/source/tools/toolutil/toolutil.vcproj
@@ -145,6 +145,9 @@
+
+
@@ -179,6 +182,9 @@
+
+