Index: ext/libicpf/src/libicpf/buffer.h
===================================================================
diff -u
--- ext/libicpf/src/libicpf/buffer.h	(revision 0)
+++ ext/libicpf/src/libicpf/buffer.h	(revision 6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0)
@@ -0,0 +1,109 @@
+#ifndef __BUFFER_H__
+#define __BUFFER_H__
+
+#include "libicpf.h"
+#include "gen_types.h"
+
+BEGIN_ICPF_NAMESPACE
+
+template<class T>
+class buffer
+{
+public:
+/** \name Construction/destruction/operators */
+/**@{*/
+	buffer();
+	buffer(const T* pData, size_t stCount);
+	buffer(const buffer& rSrc);
+	~buffer();
+
+	buffer& operator=(const buffer& rSrc);
+	const T* operator T*() const; { return m_pData; };
+/**@}*/
+
+	size_t get_size() const { return m_stBufSize; };
+	void resize(size_t stNewSize);
+
+	size_t get_block_size() const { return m_stBlockSize; };
+	void set_block_size(size_t stBlockSize);
+
+	size_t get_max_unused() const { return m_stMaxUnused; };
+	size_t set_max_unused();
+
+protected:
+	T* m_pData;				///< Pointer to the data
+	size_t m_stBufSize;		///< Current buffer size
+	size_t m_stBlockSize;	///< Block size
+	size_t m_stMaxUnused;	///< Max count of unused items allowed
+};
+
+template<class T>
+buffer::buffer() :
+	m_pData(NULL),
+	m_stBufSize(0),
+	m_stBlockSize(1024),
+	m_stMaxUnused(1024)
+{
+}
+
+template<class T>
+buffer::buffer(const T* pData, size_t stCount) :
+	m_pData(NULL),
+	m_stBufSize(0),
+	m_stBlockSize(1024),
+	m_stMaxUnused(1024)
+{
+	resize(stCount);
+	memcpy(m_pData, pData, stCount*sizeof(T));
+}
+
+template<class T>
+buffer::buffer(const buffer& rSrc) :
+	m_pData((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL),
+	m_stBufSize(rSrc.m_stBufSize),
+	m_stBlockSize(rSrc.m_stBlockSize),
+	m_stMaxUnused(rSrc.m_stMaxUnused)
+{
+	assert(m_stBlockSize > 0);
+	if (m_pData)
+		memcpy(m_pData, pData, stCount*sizeof(T));
+}
+
+template<class T>
+buffer::~buffer()
+{
+	delete [] m_pData;
+}
+
+template<class T>
+buffer& buffer::operator=(const buffer& rSrc)
+{
+	if (this != &rSrc)
+	{
+		delete [] m_pData;
+
+		m_pData=((rSrc.m_stBufSize > 0) ? new T[rSrc.m_stBufSize] : NULL);
+		m_stBufSize=rSrc.m_stBufSize;
+		m_stBlockSize=rSrc.m_stBlockSize;
+		m_stMaxUnused=rSrc.m_stMaxUnused;
+
+	}
+
+	return *this;
+}
+
+template<class T>
+const T* operator T*() const; { return m_pData; };
+
+template<class T>
+void resize(size_t stNewSize);
+
+template<class T>
+void set_block_size(size_t stBlockSize);
+
+template<class T>
+size_t set_max_unused();
+
+END_ICPF_NAMESPACE
+
+#endif
Index: ext/libicpf/src/libicpf/cfg_xml.cpp
===================================================================
diff -u -r1f103531cd331900ca0d7cb189f9b36f6171f0b5 -r6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0
--- ext/libicpf/src/libicpf/cfg_xml.cpp	(.../cfg_xml.cpp)	(revision 1f103531cd331900ca0d7cb189f9b36f6171f0b5)
+++ ext/libicpf/src/libicpf/cfg_xml.cpp	(.../cfg_xml.cpp)	(revision 6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0)
@@ -10,6 +10,13 @@
 /// Buffer size for reading xml data from a file
 #define XML_BUFFER	65536
 
+// definition of line ending - system dependent
+#if defined(_WIN32) || defined(_WIN64)
+	#define ENDL _t("\r\n")
+#else
+	#define ENDL _t("\n")
+#endif
+
 // forward declaration
 class xml_node;
 
@@ -195,9 +202,32 @@
 	if (pFile == NULL)
 		THROW(icpf::exception::format(_t("Cannot open the file ") TSTRFMT _t(" for writing."), pszPath), 0, errno, 0);
 
-	// and write
-	save_node(pFile, m_pMainNode);
+	// put BOM into the file
+#if defined(_UNICODE) && (defined(_WIN32) || defined(_WIN64))
+	// utf-16le
+	uint_t uiBOM=0x0000feff;
+	uint_t uiCount=2;
+#else
+	// utf-8
+	uint_t uiBOM=0x00bfbbef;
+	uint_t uiCount=3;
+#endif
 
+	try
+	{
+		// write bom, check if it succeeded
+		if (fwrite(&uiBOM, 1, uiCount, pFile) != uiCount)
+			THROW(_t("Cannot write the BOM to the file '") TSTRFMT _t("'"), 0, errno, 0);
+
+		// and write
+		save_node(pFile, m_pMainNode);
+	}
+	catch(...)
+	{
+		fclose(pFile);
+		throw;
+	}
+
 	// close the file
 	fclose(pFile);
 }
@@ -209,21 +239,48 @@
 	// attributes first
 	for (attr_storage::iterator it=pNode->m_mAttr.begin();it != pNode->m_mAttr.end();it++)
 	{
-		_ftprintf(pFile, _t("<") TSTRFMT _t(" value=\"") TSTRFMT _t("\"/>\n"), (*it).first, (*it).second.c_str());
+		const tchar_t pszFmt[]=_t("<") TSTRFMT _t(" value=\"") TSTRFMT _t("\"/>") ENDL;
+
+		int_t iSize=_sctprintf(pszFmt, (*it).first.c_str(), (*it).second.c_str());
+
+		if (_ftprintf(pFile, pszFmt, (*it).first.c_str(), (*it).second.c_str()) < 0)
+			THROW(_t("Cannot write requested data to the file"), 0, errno, 0);
 	}
 
 	// sub-nodes
 	for (xml_storage::iterator it=pNode->m_mNodes.begin();it != pNode->m_mNodes.end();it++)
 	{
 		// tag opening
-		_ftprintf(pFile, _t("<") TSTRFMT _t(">\n"), (*it).first);
+		if (_ftprintf(pFile, _t("<") TSTRFMT _t(">") ENDL, (*it).first.c_str()) < 0)
+			THROW(_t("Cannot write requested data to the file"), 0, errno, 0);
 
 		save_node(pFile, &(*it).second);
 
-		_ftprintf(pFile, _t("</") TSTRFMT _t(">\n"), (*it).first);
+		if (_ftprintf(pFile, _t("</") TSTRFMT _t(">") ENDL, (*it).first.c_str()) < 0)
+			THROW(_t("Cannot write requested data to the file"), 0, errno, 0);
 	}
 }
 
+void xml_cfg::fprintf_utf8(FILE* pFile, const tchar_t* pszFmt, ...)
+{
+	va_list va;
+	va_start(va, pszFmt);
+
+	// get count of characters in the string
+	int_t iCount=_vsctprintf(pszFmt, va);
+	tchar_t* pszFormatted=new tchar_t[iCount+1];
+
+	// make a formatted string
+	va_start(va, pszFmt);
+	_vsntprintf(pszFormatted, iCount, pszFmt, va);
+
+
+	delete [] pszFormatted;
+
+	va_end(va);
+
+}
+
 /** Function starts a search operation. Given the name of the property
  *  to be searched for (ie. "ch/program/startup"), funtion searches for
  *  it and returns a handle that can be used by subsequent calls to the
Index: ext/libicpf/src/libicpf/cfg_xml.h
===================================================================
diff -u -r1f103531cd331900ca0d7cb189f9b36f6171f0b5 -r6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0
--- ext/libicpf/src/libicpf/cfg_xml.h	(.../cfg_xml.h)	(revision 1f103531cd331900ca0d7cb189f9b36f6171f0b5)
+++ ext/libicpf/src/libicpf/cfg_xml.h	(.../cfg_xml.h)	(revision 6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0)
@@ -55,11 +55,15 @@
 	/// Saves the specific node into the file
 	void save_node(FILE* pFile, ptr_t pNodePtr);
 
+	/// Stores the string to the file converted to utf8
+	void fprintf_utf8(FILE* pFile, const tchar_t* pszFmt, ...);
+
 	static void element_start(void *userData, const tchar_t *name, const tchar_t **attrs);
 	static void element_end(void *userData, const tchar_t* /*name*/);
 
 protected:
 	ptr_t m_hMainNode;		///< Handle to the internal xml storage
+	tchar_t* m_pszBuffer;	///< Internal buffer to use for formatting data
 };
 
 END_ICPF_NAMESPACE
Index: ext/libicpf/src/libicpf/libicpf.vc71.vcproj
===================================================================
diff -u -r00b3627ec93a423ee0bbf70197bfef4a81d4bab3 -r6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0
--- ext/libicpf/src/libicpf/libicpf.vc71.vcproj	(.../libicpf.vc71.vcproj)	(revision 00b3627ec93a423ee0bbf70197bfef4a81d4bab3)
+++ ext/libicpf/src/libicpf/libicpf.vc71.vcproj	(.../libicpf.vc71.vcproj)	(revision 6eab6a2aa6bb49edaf1fcbcb9c9d8bc2d7795bb0)
@@ -279,6 +279,9 @@
 			Filter="h;hpp;hxx;hm;inl;inc;xsd"
 			UniqueIdentifier="{93995380-89BD-4b04-88EB-625FBE52EBFB}">
 			<File
+				RelativePath=".\buffer.h">
+			</File>
+			<File
 				RelativePath=".\callback.h">
 			</File>
 			<File