Commits

Anonymous committed 6d0a1ae

CWS-TOOLING: integrate CWS mhu20
2009-09-01 15:18:43 +0200 mhu r275662 : #i32526# Fixed missing includes, and a wrong cast
2009-08-28 13:30:05 +0200 mhu r275530 : #i32526# Fixed missing includes and remaining merge conflicts.
2009-08-28 13:28:45 +0200 mhu r275529 : #i32526# osl_readLine() now implemented in sal/osl/<platform>/file.cxx
2009-08-26 19:47:53 +0200 mhu r275445 : CWS-TOOLING: rebase CWS mhu20 to trunk@275331 (milestone: DEV300:m56)
2009-08-25 15:47:00 +0200 mhu r275365 : #i32526# Also maintain phys. file offset.
2009-08-25 15:24:56 +0200 mhu r275364 : #i32526# Added buffered file I/O; refactored file.cxx into multiple files.
2009-08-24 10:38:15 +0200 mhu r275294 : #i32526# Correct OpenFlags for osl_openFile().
2009-05-25 11:07:34 +0200 mhu r272225 : #i32526# Added support for non-seekable file handles (pipe et al.).
2009-05-25 11:01:50 +0200 mhu r272223 : #i32526# Add osl_readLine() test, cleanup obsolete tests.
2009-05-25 10:56:14 +0200 mhu r272221 : #i32526# Add missing include
2009-05-25 10:48:51 +0200 mhu r272220 : #i32526# Accept OpenJDK (IcedTea6) 1.6.0_0 version string
2009-05-15 19:18:20 +0200 mhu r271965 : #i32526# Initial osl/unx buffered file I/O implementation.
2009-05-15 17:41:57 +0200 mhu r271959 : CWS-TOOLING: rebase CWS mhu20 to trunk@271830 (milestone: DEV300:m48)
2009-03-26 17:28:53 +0100 mhu r270091 : CWS-TOOLING: rebase CWS mhu20 to trunk@270033 (milestone: DEV300:m45)

Comments (0)

Files changed (28)

jvmfwk/plugins/sunmajor/pluginlib/sunversion.cxx

                 {
                     //1.4.1_01-, 1.4.1_01a, the numerical part may only be 2 chars.
                     int len = pCur - pLast;
-                    if (len != 2)
+                    if (len > 2)
                         return false;
                     //we've got the update: 01, 02 etc
                     strncpy(buf, pLast, len);

jvmfwk/plugins/sunmajor/pluginlib/util.cxx

     {
         if (m_nIndex == m_nSize)
         {
-            sal_uInt64 nRead;
+            sal_uInt64 nRead = 0;
             switch (osl_readFile(
-                        m_aGuard.getHandle(), m_aBuffer, BUFFER_SIZE, &nRead))
+                        m_aGuard.getHandle(), m_aBuffer, sizeof(m_aBuffer), &nRead))
             {
             case osl_File_E_PIPE: //HACK! for windows
                 nRead = 0;
                 m_nIndex = 0;
                 m_nSize = static_cast< int >(nRead);
                 break;
-		case osl_File_E_INTR:
-			continue;
+            case osl_File_E_INTR:
+                continue;
 
             default:
                 return RESULT_ERROR;
  */
 rtl::OUString decodeOutput(const rtl::OString& s)
 {
-    OUString sEncoded = OStringToOUString(s, RTL_TEXTENCODING_ASCII_US);
     OUStringBuffer buff(512);
     sal_Int32 nIndex = 0;
     do
     {
-        OUString aToken = sEncoded.getToken( 0, ' ', nIndex );
+        OString aToken = s.getToken( 0, ' ', nIndex );
         if (aToken.getLength())
         {
-            sal_Unicode value = (sal_Unicode) aToken.toInt32();
+            sal_Unicode value = (sal_Unicode)(aToken.toInt32());
             buff.append(value);
         }
     } while (nIndex >= 0);
-   return buff.makeStringAndClear();
+
+    OUString sDecoded(buff.makeStringAndClear());
+    JFW_TRACE2(sDecoded);
+    return sDecoded;
 }
 
 

sal/osl/all/makefile.mk

 
 SLOFILES=	\
 			$(SLO)$/utility.obj\
-			$(SLO)$/readline.obj\
 			$(SLO)$/filepath.obj\
 			$(SLO)$/debugbase.obj\
             $(SLO)$/loadmodulerelative.obj
 
+#			$(SLO)$/readline.obj\
+
 #.IF "$(UPDATER)"=="YES"
 OBJFILES=	\
 			$(OBJ)$/utility.obj\
-			$(OBJ)$/readline.obj\
 			$(OBJ)$/filepath.obj\
 			$(OBJ)$/debugbase.obj\
             $(OBJ)$/loadmodulerelative.obj
+
+#			$(OBJ)$/readline.obj\
 #.ENDIF
 
 # --- Targets ------------------------------------------------------

sal/osl/all/readline.c

-/*************************************************************************
- *
- * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
- * Copyright 2008 by Sun Microsystems, Inc.
- *
- * OpenOffice.org - a multi-platform office productivity suite
- *
- * $RCSfile: readline.c,v $
- * $Revision: 1.9 $
- *
- * This file is part of OpenOffice.org.
- *
- * OpenOffice.org is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Lesser General Public License version 3
- * only, as published by the Free Software Foundation.
- *
- * OpenOffice.org is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Lesser General Public License version 3 for more details
- * (a copy is included in the LICENSE file that accompanied this code).
- *
- * You should have received a copy of the GNU Lesser General Public License
- * version 3 along with OpenOffice.org.  If not, see
- * <http://www.openoffice.org/license.html>
- * for a copy of the LGPLv3 License.
- *
- ************************************************************************/
-
-#include <osl/diagnose.h>
-#include <osl/file.h>
-#include <rtl/byteseq.h>
-#include <rtl/alloc.h>
-
-
-/* Test cases:
-
-	1.	A file without line ends
-	2.	A file with lines longer than the initial buffer size
-	3.	An empty file
-	4.	
-*/
-
-/** Some defines     
-*/
-#define CR 0x0D
-#define LF 0x0A
-
-#define INITIAL_BUFF_SIZE  80
-#define BUFFER_GROW_FACTOR 2 
-#define READ_BLOCK_SIZE (INITIAL_BUFF_SIZE - 1)
-
-/** Helper data and function
-*/    
-
-struct _Buffer
-{
-    sal_Char*	m_pMem;
-    sal_uInt64  m_Capacity;           /* elements possible in buffer */
-    sal_uInt64  m_Size;               /* elements actually in buffer */
-    sal_uInt64  m_ActiveSectionStart; /* buffer was lastly filled from here to
-                                         (m_Size - 1) */
-};
-
-typedef struct _Buffer Buffer;
-
-
-/** Allocate the memory of the buffer
-	@Returns	sal_True on succes
-*/
-static sal_Bool AllocateBuffer(Buffer* pBuffer, sal_uInt64 Capacity)
-{
-    sal_Bool rc = sal_False;
-    
-    OSL_ASSERT(pBuffer);
-        
-    pBuffer->m_pMem = (sal_Char*)rtl_allocateZeroMemory((sal_uInt32)Capacity);
-    if (pBuffer->m_pMem)
-    {
-        pBuffer->m_Capacity = Capacity;
-        pBuffer->m_Size = 0;
-        pBuffer->m_ActiveSectionStart = 0;
-        rc = sal_True;
-    }    
-    
-    return rc;
-}
-
-/** Release the memory occupied by the buffer 
-*/
-static void FreeBuffer(Buffer* pBuffer)
-{
-    OSL_ASSERT(pBuffer);
-    
-    rtl_freeMemory(pBuffer->m_pMem);
-    pBuffer->m_pMem  = 0;
-    pBuffer->m_Capacity = 0;
-    pBuffer->m_Size   = 0;
-    pBuffer->m_ActiveSectionStart = 0;
-}
-
-/** Grow the buffer by the specified factor (usually doubling
-	the buffer size)
-	In case of failure, growing the buffer, the original buffer
-	stays untouched
-
-	@Returns	sal_True on success	
-*/
-static sal_Bool GrowBuffer(Buffer* pBuffer, size_t factor)
-{
-    sal_Bool rc = sal_False;
-    void*	 p;
-    
-    OSL_ASSERT(pBuffer);
-    
-    p = rtl_reallocateMemory(
-        pBuffer->m_pMem, (sal_uInt32)(pBuffer->m_Capacity * factor));
-    if (p)
-    {
-        pBuffer->m_pMem		 = (sal_Char*)p;
-        pBuffer->m_Capacity *= factor;
-        rc					 = sal_True;
-    }
-    
-    return rc;
-}
-
-/** Read n bytes from file into buffer, 
-	grow the buffer if necessary
-
-	@Returns osl_File_E_None on success else
-	an error code
-*/
-static oslFileError ReadFromFile(oslFileHandle hFile, Buffer* pBuffer, sal_uInt64 Requested, sal_uInt64* pRead)
-{
-    oslFileError rc;
-    
-    OSL_ASSERT(pBuffer);
-    OSL_ASSERT(hFile);
-    OSL_ASSERT(pRead);
-    
-    if (((pBuffer->m_Size + Requested) > pBuffer->m_Capacity) &&
-        !GrowBuffer(pBuffer, BUFFER_GROW_FACTOR))
-        return osl_File_E_NOMEM;
-    
-    pBuffer->m_ActiveSectionStart = pBuffer->m_Size;
-
-    rc = osl_readFile(
-		hFile, 
-		pBuffer->m_pMem + pBuffer->m_ActiveSectionStart, 
-		Requested, 
-		pRead);
-    
-    if (osl_File_E_None == rc)
-        pBuffer->m_Size += *pRead;
-    
-    return rc; 
-}
-
-/** Makes a sequence from the given buffer and release the memory
-    occupied by the buffer
-*/
-static void MakeSequenceFreeBuffer(sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Length)
-{
-    OSL_ASSERT(ppSequence);
-    OSL_ASSERT(pBuffer);
-    OSL_ASSERT(Length <= pBuffer->m_Capacity);
-    
-    rtl_byte_sequence_constructFromArray(ppSequence, (sal_Int8*)pBuffer->m_pMem, (sal_Int32)Length);           
-    FreeBuffer(pBuffer);
-}
-
-/** Handle occurence of LF character:
-    construct a sequence from buffer
-    correct file pointer (maybe we have read more than necessary)
-
-	@Returns osl_File_E_None on success else
-	an error code
-*/
-static oslFileError HandleLFFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos)
-{    
-    sal_Int64    offset = 0;
-    oslFileError rc     = osl_File_E_None;
-    
-    OSL_ASSERT(hFile);
-    OSL_ASSERT(pBuffer);
-    OSL_ASSERT(LF == pBuffer->m_pMem[Pos]);
-  
-    /* correct file pointer pos in case we have read to far */
-    offset = pBuffer->m_Size - (Pos + 1);
-    rc = osl_setFilePos(hFile, osl_Pos_Current, -offset);
-    
-	if (osl_File_E_None == rc)
-		MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos);
-    else
-		FreeBuffer(pBuffer);
-
-    return rc;
-}
-
-/** Handle occurence of CR character
-    construct a sequence from buffer
-    correct file pointer (maybe we have read more than necessary)
-
-	@Returns osl_File_E_None on success else
-	an error code
-*/
-static oslFileError HandleCRFreeBuffer(oslFileHandle hFile, sal_Sequence** ppSequence, Buffer* pBuffer, sal_uInt64 Pos)
-{
-    sal_Int64    offset = 0;    
-    sal_uInt64   nread  = 0;
-    oslFileError rc     = osl_File_E_None;
-
-    OSL_ASSERT(hFile);
-    OSL_ASSERT(pBuffer);
-    OSL_ASSERT(CR == pBuffer->m_pMem[Pos]);
-    
-    if (Pos == (pBuffer->m_Size - 1))
-    {
-		/*	only need to check if the next byte is a LF 
-			that's why reading only one byte from file */
-        rc = ReadFromFile(hFile, pBuffer, 1, &nread);
-        
-        if (osl_File_E_None != rc)
-        {
-            FreeBuffer(pBuffer);
-            return rc;
-        }
-        else if (0 == nread)
-        {       
-            MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos);            
-            return osl_File_E_None;
-        }
-    }
-
-    if (LF == pBuffer->m_pMem[Pos + 1])                
-        Pos++;
-    
-    /* correct the file pointer */
-    offset = pBuffer->m_Size - (Pos + 1);    
-    rc = osl_setFilePos(hFile, osl_Pos_Current, -offset);
-
-	if (osl_File_E_None == rc)
-		MakeSequenceFreeBuffer(ppSequence, pBuffer, Pos - 1);
-	else
-		FreeBuffer(pBuffer);
-    
-    return rc;
-}
-
-/***************************************************************************
-    osl_readLine (platform independent)                                     
-    Reads a line from given file. The new line delimiter(s) are NOT returned!
-    Valid line ends: \n, \r\n or \r
-
-	@param	Handle [in] Handle to an open file.
-	@param	ppSequence [in/out] a pointer to a valid sequence. 
-    
-	@return osl_File_E_None on success otherwise one of the following errorcodes:<p> 
-
-	osl_File_E_INVAL		the format of the parameters was not valid<br>
-    osl_File_E_NOMEM        the necessary memory could not be allocated
-****************************************************************************/
-
-oslFileError SAL_CALL osl_readLine(oslFileHandle Handle, sal_Sequence** ppSeq)
-{
-    oslFileError rc;    
-    sal_uInt64   nread = 0;
-    Buffer       line_buffer;
-    sal_uInt64       pos;
-    
-    OSL_PRECOND(Handle, "invalid handle");
-    OSL_PRECOND(ppSeq,  "invalid parameter detected");
-
-    if (!AllocateBuffer(&line_buffer, INITIAL_BUFF_SIZE))
-        return osl_File_E_NOMEM;
-
-    for(;;)
-    {                       
-        rc = ReadFromFile(Handle, &line_buffer, READ_BLOCK_SIZE, &nread);
-
-        if (osl_File_E_None != rc)
-        {
-            FreeBuffer(&line_buffer);
-            return rc;
-        }
-        else if (0 == nread)
-        {
-			/* EOF */
-			nread = line_buffer.m_Size;
-			MakeSequenceFreeBuffer(ppSeq, &line_buffer, nread);
-			if (0 < nread)
-				return osl_File_E_None;
-			else
-				return osl_File_E_AGAIN;
-        }
-         
-        /* scan buffer for line end */
-        for (pos = line_buffer.m_ActiveSectionStart; pos < line_buffer.m_Size; pos++)
-        {
-			switch(line_buffer.m_pMem[pos])
-			{
-			case LF:
-				return HandleLFFreeBuffer(Handle, ppSeq, &line_buffer, pos);
-			case CR:
-				return HandleCRFreeBuffer(Handle, ppSeq, &line_buffer, pos);
-			}            
-        }
-    } /* end for */
-}   

sal/osl/unx/file.cxx

 // MARKER(update_precomp.py): autogen include statement, do not remove
 #include "precompiled_sal.hxx"
 
+#include "osl/file.hxx"
 
-/************************************************************************
- *   ToDo
- *
- *   Fix osl_getCanonicalName
- *
- *   - Fix: check for corresponding struct sizes in exported functions
- *   - check size/use of oslDirectory
- *   - check size/use of oslDirectoryItem
- *   - check size/use of oslFileStatus
- *   - check size/use of oslVolumeDeviceHandle
- *   - check size/use of oslVolumeInfo
- *   - check size/use of oslFileHandle
- ***********************************************************************/
+#include "osl/diagnose.h"
+#include "rtl/alloc.h"
+
+#include "system.h"
+#include "file_error_transl.h"
+#include "file_url.h"
 
 #include <algorithm>
 #include <limits>
-#include "system.h"
-#include <rtl/alloc.h>
 
-#include "osl/file.hxx"
-
-
-#include <sal/types.h>
-#include <osl/thread.h>
-#include <osl/diagnose.h>
-#include "file_error_transl.h"
-#include <osl/time.h>
-
-#ifndef _FILE_URL_H_
-#include "file_url.h"
-#endif
-
-#include "file_path_helper.hxx"
-#include "uunxapi.hxx"
-
-
+#include <string.h>
 #include <sys/mman.h>
 
-#ifdef HAVE_STATFS_H
-#undef HAVE_STATFS_H
-#endif
-
-#ifndef	_STRING_H
-#include <string.h>
-#endif
-
-#if defined(SOLARIS)
-#include <sys/mnttab.h>
-#include <sys/statvfs.h>
-#define  HAVE_STATFS_H
-#include <sys/fs/ufs_quota.h>
-static const sal_Char* MOUNTTAB="/etc/mnttab";
-
-#elif defined(LINUX)
-#include <mntent.h>
-#include <sys/vfs.h>
-#define  HAVE_STATFS_H
-#include <sys/quota.h>
-#include <ctype.h>
-static const sal_Char* MOUNTTAB="/etc/mtab";
-
-#elif defined(NETBSD) || defined(FREEBSD)
-#include <sys/param.h>
-#include <sys/ucred.h>
-#include <sys/mount.h>
-#include <ufs/ufs/quota.h>
-#include <ctype.h>
-#define  HAVE_STATFS_H
-/* No mounting table on *BSD
- * This information is stored only in the kernel. */
-/* static const sal_Char* MOUNTTAB="/etc/mtab"; */
-
-#elif defined(IRIX)
-#include <mntent.h>
-#include <sys/mount.h>
-#include <sys/statvfs.h>
-#define  HAVE_STATFS_H
-#include <sys/quota.h>
-#include <ctype.h>
-static const sal_Char* MOUNTTAB="/etc/mtab";
-
-#elif defined(MACOSX)
-#include <ufs/ufs/quota.h>
-#include <ctype.h>
-// static const sal_Char* MOUNTTAB="/etc/mtab";
+#if defined(MACOSX)
 
 #include <sys/param.h>
 #include <sys/mount.h>
-#define HAVE_STATFS_H
 #define HAVE_O_EXLOCK
 
 // add MACOSX Time Value
-
 #define TimeValue CFTimeValue
 #include <CoreFoundation/CoreFoundation.h>
 #undef TimeValue
 
-#endif
-
-#ifdef _DIRENT_HAVE_D_TYPE
-#include "file_impl.hxx"
-	oslDirectoryItemImpl* oslDirectoryItemImpl_CreateNew( rtl_uString* _ustrFilePath, bool _bHasDType, unsigned char _DType )
-	{
-		oslDirectoryItemImpl *pItemObject = (oslDirectoryItemImpl*) malloc( sizeof( oslDirectoryItemImpl ) );
-		pItemObject->RefCount = 1;
-		pItemObject->bHasType = _bHasDType;
-		pItemObject->DType = _DType;
-		pItemObject->ustrFilePath = _ustrFilePath;
-
-		return pItemObject;
-	}
-
-	void oslDirectoryItemImpl_Destroy( oslDirectoryItemImpl* pItem )
-	{
-		if( pItem->ustrFilePath ) {
-			rtl_uString_release( pItem->ustrFilePath );
-			pItem->ustrFilePath = NULL;
-		}
-		free( pItem );
-	}
-
-	void oslDirectoryItemImpl_acquire( oslDirectoryItemImpl* pItem )
-	{
-		pItem->RefCount ++;
-	}
-
-	void oslDirectoryItemImpl_release( oslDirectoryItemImpl* pItem )
-	{
-		pItem->RefCount --;
-
-		if( pItem->RefCount <= 0 )
-			oslDirectoryItemImpl_Destroy( pItem );
-	}
-#endif
-
-#if OSL_DEBUG_LEVEL > 1
-
-	extern void debug_ustring(rtl_uString*);
-
-#endif
-
+#endif /* MACOSX */
 
 #ifdef DEBUG_OSL_FILE
+#   define OSL_FILE_TRACE 0 ? (void)(0) : osl_trace
 #	define PERROR( a, b ) perror( a ); fprintf( stderr, b )
 #else
+#   define OSL_FILE_TRACE 1 ? (void)(0) : osl_trace
 #	define PERROR( a, b )
 #endif
 
-extern "C" oslFileHandle osl_createFileHandleFromFD( int fd );
+/*******************************************************************
+ *
+ * FileHandle_Impl interface
+ *
+ ******************************************************************/
+struct FileHandle_Impl
+{
+    rtl_String * m_strFilePath; /* holds native file path */
+    int          m_fd;
 
-/******************************************************************************
- *
- *                  Data Type Definition
- *
- ******************************************************************************/
+    /** State
+     */
+    enum StateBits
+    {
+        STATE_SEEKABLE  = 1, /* default */
+        STATE_READABLE  = 2, /* default */
+        STATE_WRITEABLE = 4, /* open() sets, write() requires, else osl_File_E_BADF */
+        STATE_MODIFIED  = 8  /* write() sets, flush() resets  */
+    };
+    int          m_state;
 
-#if 0
-/* FIXME: reintroducing this may save some extra bytes per Item */
-typedef struct
-{
-    rtl_uString* ustrFileName;       /* holds native file name */
-    rtl_uString* ustrDirPath;        /* holds native dir path */
-    sal_uInt32   RefCount;
-} oslDirectoryItemImpl;
-#endif
+    sal_uInt64   m_size;    /* file size */
+	off_t        m_offset;  /* physical offset from begin of file */
+    off_t        m_fileptr; /* logical offset from begin of file */
 
-typedef struct
-{
-    rtl_uString* ustrPath;           /* holds native directory path */
-    DIR*         pDirStruct;
-} oslDirectoryImpl;
+    off_t        m_bufptr;  /* buffer offset from begin of file */
+    size_t       m_buflen;  /* buffer filled [0, m_bufsiz - 1] */
 
+    size_t       m_bufsiz;
+    sal_uInt8 *  m_buffer;
 
-typedef struct
-{
-    rtl_uString* ustrFilePath;      /* holds native file path */
-    int fd;
-    sal_Bool bLocked;
-} oslFileHandleImpl;
+    explicit FileHandle_Impl (int fd, char const * path = "<anon>");
+    ~FileHandle_Impl();
 
+    static void* operator new (size_t n);
+    static void  operator delete (void * p, size_t);
 
-typedef struct _oslVolumeDeviceHandleImpl
-{
-    sal_Char pszMountPoint[PATH_MAX];
-    sal_Char pszFilePath[PATH_MAX];
-    sal_Char pszDevice[PATH_MAX];
-    sal_Char ident[4];
-    sal_uInt32   RefCount;
-} oslVolumeDeviceHandleImpl;
+    static size_t getpagesize();
 
+    sal_uInt64   getPos() const;
+    oslFileError setPos (sal_uInt64 uPos);
 
-/******************************************************************************
- *
- *                  static members
- *
- *****************************************************************************/
+    sal_uInt64   getSize() const;
 
-static const char * pFileLockEnvVar = (char *) -1;
+    oslFileError readAt (
+        off_t        nOffset,
+        void *       pBuffer,
+        size_t       nBytesRequested,
+        sal_uInt64 * pBytesRead);
 
+    oslFileError writeAt (
+        off_t        nOffset,
+        void const * pBuffer,
+        size_t       nBytesToWrite,
+        sal_uInt64 * pBytesWritten);
 
-/******************************************************************************
- *
- *                  C-String Function Declarations
- *
- *****************************************************************************/
+    oslFileError readFileAt (
+        off_t        nOffset,
+        void *       pBuffer,
+        size_t       nBytesRequested,
+        sal_uInt64 * pBytesRead);
 
-static oslFileError osl_psz_getVolumeInformation(const sal_Char* , oslVolumeInfo* pInfo, sal_uInt32 uFieldMask);
-static oslFileError osl_psz_removeFile(const sal_Char* pszPath);
-static oslFileError osl_psz_createDirectory(const sal_Char* pszPath);
-static oslFileError osl_psz_removeDirectory(const sal_Char* pszPath);
-static oslFileError osl_psz_copyFile(const sal_Char* pszPath, const sal_Char* pszDestPath);
-static oslFileError osl_psz_moveFile(const sal_Char* pszPath, const sal_Char* pszDestPath);
-static oslFileError osl_psz_setFileAttributes(const sal_Char* pszFilePath, sal_uInt64 uAttributes);
-static oslFileError osl_psz_setFileTime(const sal_Char* strFilePath, const TimeValue* pCreationTime, const TimeValue* pLastAccessTime, const TimeValue* pLastWriteTime);
+    oslFileError writeFileAt (
+        off_t        nOffset,
+        void const * pBuffer,
+        size_t       nBytesToWrite,
+        sal_uInt64 * pBytesWritten);
 
+    oslFileError readLineAt (
+        off_t           nOffset,
+        sal_Sequence ** ppSequence,
+        sal_uInt64 *    pBytesRead);
 
-/******************************************************************************
- *
- *                  Static Module Utility Function Declarations
- *
- *****************************************************************************/
+    oslFileError writeSequence_Impl (
+        sal_Sequence ** ppSequence,
+        size_t *        pnOffset,
+        const void *    pBuffer,
+        size_t          nBytes);
 
-static oslFileError  oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists);
-static oslFileError  oslChangeFileModes(const sal_Char* pszFileName, mode_t nMode, time_t nAcTime, time_t nModTime, uid_t nUID, gid_t nGID);
-static int           oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName);
-static int           oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode);
-static oslFileError  oslDoMoveFile(const sal_Char* pszPath, const sal_Char* pszDestPath);
-static rtl_uString*  oslMakeUStrFromPsz(const sal_Char* pszStr,rtl_uString** uStr);
+    oslFileError syncFile();
 
-/******************************************************************************
- *
- *                  Non-Static Utility Function Declarations
- *
- *****************************************************************************/
+    /** Buffer cache / allocator.
+     */
+    class Allocator
+    {
+        rtl_cache_type * m_cache;
+        size_t           m_bufsiz;
 
-extern "C" int UnicodeToText( char *, size_t, const sal_Unicode *, sal_Int32 );
-extern "C" int TextToUnicode(
-    const char* text, size_t text_buffer_size,	sal_Unicode* unic_text, sal_Int32 unic_text_buffer_size);
+        Allocator (Allocator const &);
+        Allocator & operator= (Allocator const &);
 
-/******************************************************************************
- *
- *                  'removeable device' aka floppy functions
- *
- *****************************************************************************/
+    public:
+        static Allocator & get();
 
-static oslVolumeDeviceHandle  osl_isFloppyDrive(const sal_Char* pszPath);
-static oslFileError   osl_mountFloppy(oslVolumeDeviceHandle hFloppy);
-static oslFileError   osl_unmountFloppy(oslVolumeDeviceHandle hFloppy);
+        void allocate (sal_uInt8 ** ppBuffer, size_t * pnSize);
+        void deallocate (sal_uInt8 * pBuffer);
 
-
-#if defined(SOLARIS)
-static sal_Bool       osl_isFloppyMounted(sal_Char* pszPath, sal_Char* pszMountPath);
-static sal_Bool       osl_getFloppyMountEntry(const sal_Char* pszPath, sal_Char* pBuffer);
-static sal_Bool       osl_checkFloppyPath(sal_Char* pszPath, sal_Char* pszFilePath, sal_Char* pszDevicePath);
-#endif
-
-#if defined(LINUX)
-static sal_Bool       osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice);
-static sal_Bool       osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem);
-#endif
-
-
-#if defined(IRIX)
-static sal_Bool       osl_isFloppyMounted(oslVolumeDeviceHandleImpl* pDevice);
-static sal_Bool       osl_getFloppyMountEntry(const sal_Char* pszPath, oslVolumeDeviceHandleImpl* pItem);
-#endif
-
-#ifdef DEBUG_OSL_FILE
-static void           osl_printFloppyHandle(oslVolumeDeviceHandleImpl* hFloppy);
-#endif
-
-#ifdef MACOSX
+    protected:
+        Allocator();
+        ~Allocator();
+    };
+};
 
 /*******************************************************************
- *	adjustLockFlags
+ *
+ * FileHandle_Impl implementation
+ *
  ******************************************************************/
 
-/* The AFP implementation of MacOS X 10.4 treats O_EXLOCK in a way 
- * that makes it impossible for OOo to create a backup copy of the
- * file it keeps opened. OTOH O_SHLOCK for AFP behaves as desired by
- * the OOo file handling, so we need to check the path of the file
- * for the filesystem name.
- */
- 
-static int adjustLockFlags(const char * path, int flags)
+FileHandle_Impl::Allocator &
+FileHandle_Impl::Allocator::get()
 {
+    static Allocator g_aBufferAllocator;
+    return g_aBufferAllocator;
+}
+
+FileHandle_Impl::Allocator::Allocator()
+    : m_cache  (0),
+      m_bufsiz (0)
+{
+    size_t const pagesize = FileHandle_Impl::getpagesize();
+    if (size_t(-1) != pagesize)
+    {
+        m_cache  = rtl_cache_create (
+            "osl_file_buffer_cache", pagesize, 0, 0, 0, 0, 0, 0, 0);
+        if (0 != m_cache)
+            m_bufsiz = pagesize;
+    }
+}
+FileHandle_Impl::Allocator::~Allocator()
+{
+    rtl_cache_destroy (m_cache), m_cache = 0;
+}
+
+void FileHandle_Impl::Allocator::allocate (sal_uInt8 ** ppBuffer, size_t * pnSize)
+{
+    OSL_PRECOND((0 != ppBuffer) && (0 != pnSize), "FileHandle_Impl::Allocator::allocate(): contract violation");
+    *ppBuffer = static_cast< sal_uInt8* >(rtl_cache_alloc(m_cache)), *pnSize = m_bufsiz;
+}
+void FileHandle_Impl::Allocator::deallocate (sal_uInt8 * pBuffer)
+{
+    if (0 != pBuffer)
+        rtl_cache_free (m_cache, pBuffer);
+}
+
+FileHandle_Impl::FileHandle_Impl (int fd, char const * path)
+    : m_strFilePath (0),
+      m_fd      (fd),
+      m_state   (STATE_SEEKABLE | STATE_READABLE),
+      m_size    (0),
+	  m_offset  (0),
+      m_fileptr (0),
+      m_bufptr  (-1),
+      m_buflen  (0),
+      m_bufsiz  (0),
+      m_buffer  (0)
+{
+    rtl_string_newFromStr (&m_strFilePath, path);
+    Allocator::get().allocate (&m_buffer, &m_bufsiz);
+    if (0 != m_buffer)
+        memset (m_buffer, 0, m_bufsiz);
+}
+FileHandle_Impl::~FileHandle_Impl()
+{
+    Allocator::get().deallocate (m_buffer), m_buffer = 0;
+    rtl_string_release (m_strFilePath), m_strFilePath = 0;
+}
+
+void* FileHandle_Impl::operator new (size_t n)
+{
+    return rtl_allocateMemory(n);
+}
+void FileHandle_Impl::operator delete (void * p, size_t)
+{
+    rtl_freeMemory(p);
+}
+
+size_t FileHandle_Impl::getpagesize()
+{
+#if defined(FREEBSD) || defined(NETBSD) || defined(MACOSX)
+    return sal::static_int_cast< size_t >(::getpagesize());
+#else /* POSIX */
+    return sal::static_int_cast< size_t >(::sysconf(_SC_PAGESIZE));
+#endif /* xBSD || POSIX */
+}
+
+sal_uInt64 FileHandle_Impl::getPos() const
+{
+    return sal::static_int_cast< sal_uInt64 >(m_fileptr);
+}
+
+oslFileError FileHandle_Impl::setPos (sal_uInt64 uPos)
+{
+    OSL_FILE_TRACE("FileHandle_Impl::setPos(%d, %lld) => %lld", m_fd, getPos(), uPos);
+    m_fileptr = sal::static_int_cast< off_t >(uPos);
+    return osl_File_E_None;
+}
+
+sal_uInt64 FileHandle_Impl::getSize() const
+{
+    off_t const bufend = std::max((off_t)(0), m_bufptr) + m_buflen;
+    return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend));
+}
+
+oslFileError FileHandle_Impl::readAt (
+    off_t        nOffset,
+    void *       pBuffer,
+    size_t       nBytesRequested,
+    sal_uInt64 * pBytesRead)
+{
+    OSL_PRECOND((m_state & STATE_SEEKABLE), "FileHandle_Impl::readAt(): not seekable");
+    if (!(m_state & STATE_SEEKABLE))
+        return osl_File_E_SPIPE;
+
+    OSL_PRECOND((m_state & STATE_READABLE), "FileHandle_Impl::readAt(): not readable");
+    if (!(m_state & STATE_READABLE))
+        return osl_File_E_BADF;
+
+#if defined(LINUX) || defined(SOLARIS)
+
+    ssize_t nBytes = ::pread (m_fd, pBuffer, nBytesRequested, nOffset);
+    if ((-1 == nBytes) && (EOVERFLOW == errno))
+    {
+        /* Some 'pread()'s fail with EOVERFLOW when reading at (or past)
+         * end-of-file, different from 'lseek() + read()' behaviour.
+         * Returning '0 bytes read' and 'osl_File_E_None' instead.
+         */
+        nBytes = 0;
+    }
+    if (-1 == nBytes)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+
+#else /* !(LINUX || SOLARIS) */
+
+    if (nOffset != m_offset)
+	{
+		if (-1 == ::lseek (m_fd, nOffset, SEEK_SET))
+			return oslTranslateFileError (OSL_FET_ERROR, errno);
+		m_offset = nOffset;
+	}
+
+    ssize_t nBytes = ::read (m_fd, pBuffer, nBytesRequested);
+    if (-1 == nBytes)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+	m_offset += nBytes;
+
+#endif /* !(LINUX || SOLARIS) */
+
+    OSL_FILE_TRACE("FileHandle_Impl::readAt(%d, %lld, %ld)", m_fd, nOffset, nBytes);
+    *pBytesRead = nBytes;
+    return osl_File_E_None;
+}
+
+oslFileError FileHandle_Impl::writeAt (
+    off_t        nOffset,
+    void const * pBuffer,
+    size_t       nBytesToWrite,
+    sal_uInt64 * pBytesWritten)
+{
+    OSL_PRECOND((m_state & STATE_SEEKABLE), "FileHandle_Impl::writeAt(): not seekable");
+    if (!(m_state & STATE_SEEKABLE))
+        return osl_File_E_SPIPE;
+
+    OSL_PRECOND((m_state & STATE_WRITEABLE), "FileHandle_Impl::writeAt(): not writeable");
+    if (!(m_state & STATE_WRITEABLE))
+        return osl_File_E_BADF;
+
+#if defined(LINUX) || defined(SOLARIS)
+
+    ssize_t nBytes = ::pwrite (m_fd, pBuffer, nBytesToWrite, nOffset);
+    if (-1 == nBytes)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+
+#else /* !(LINUX || SOLARIS) */
+
+    if (nOffset != m_offset)
+	{
+		if (-1 == ::lseek (m_fd, nOffset, SEEK_SET))
+			return oslTranslateFileError (OSL_FET_ERROR, errno);
+		m_offset = nOffset;
+	}
+
+    ssize_t nBytes = ::write (m_fd, pBuffer, nBytesToWrite);
+    if (-1 == nBytes)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+	m_offset += nBytes;
+
+#endif /* !(LINUX || SOLARIS) */
+
+    OSL_FILE_TRACE("FileHandle_Impl::writeAt(%d, %lld, %ld)", m_fd, nOffset, nBytes);
+    m_size = std::max (m_size, sal::static_int_cast< sal_uInt64 >(nOffset + nBytes));
+
+    *pBytesWritten = nBytes;
+    return osl_File_E_None;
+}
+
+oslFileError FileHandle_Impl::readFileAt (
+    off_t        nOffset,
+    void *       pBuffer,
+    size_t       nBytesRequested,
+    sal_uInt64 * pBytesRead)
+{
+    if (0 == (m_state & STATE_SEEKABLE))
+    {
+        // not seekable (pipe)
+        ssize_t nBytes = ::read (m_fd, pBuffer, nBytesRequested);
+        if (-1 == nBytes)
+            return oslTranslateFileError (OSL_FET_ERROR, errno);
+        *pBytesRead = nBytes;
+        return osl_File_E_None;
+    }
+    else if (0 == m_buffer)
+    {
+        // not buffered
+        return readAt (nOffset, pBuffer, nBytesRequested, pBytesRead);
+    }
+    else
+    {
+        sal_uInt8 * buffer = static_cast<sal_uInt8*>(pBuffer);
+        for (*pBytesRead = 0; nBytesRequested > 0; )
+        {
+            off_t  const bufptr = (nOffset / m_bufsiz) * m_bufsiz;
+            size_t const bufpos = (nOffset % m_bufsiz);
+
+            if (bufptr != m_bufptr)
+            {
+                // flush current buffer
+                oslFileError result = syncFile();
+                if (result != osl_File_E_None)
+                    return (result);
+
+                if (nBytesRequested >= m_bufsiz)
+                {
+                    // buffer too small, read through from file
+                    sal_uInt64 uDone = 0;
+                    result = readAt (nOffset, &(buffer[*pBytesRead]), nBytesRequested, &uDone);
+                    if (result != osl_File_E_None)
+                        return (result);
+
+                    nBytesRequested -= uDone, *pBytesRead += uDone;
+                    return osl_File_E_None;
+                }
+
+                // update buffer (pointer)
+                sal_uInt64 uDone = 0;
+                result = readAt (bufptr, m_buffer, m_bufsiz, &uDone);
+                if (result != osl_File_E_None)
+                    return (result);
+                m_bufptr = bufptr, m_buflen = uDone;
+            }
+            if (bufpos >= m_buflen)
+            {
+                // end of file
+                return osl_File_E_None;
+            }
+
+            size_t const bytes = std::min (m_buflen - bufpos, nBytesRequested);
+            OSL_FILE_TRACE("FileHandle_Impl::readFileAt(%d, %lld, %ld)", m_fd, nOffset, bytes);
+
+            memcpy (&(buffer[*pBytesRead]), &(m_buffer[bufpos]), bytes);
+            nBytesRequested -= bytes, *pBytesRead += bytes, nOffset += bytes;
+        }
+        return osl_File_E_None;
+    }
+}
+
+oslFileError FileHandle_Impl::writeFileAt (
+    off_t        nOffset,
+    void const * pBuffer,
+    size_t       nBytesToWrite,
+    sal_uInt64 * pBytesWritten)
+{
+    if (0 == (m_state & STATE_SEEKABLE))
+    {
+        // not seekable (pipe)
+        ssize_t nBytes = ::write (m_fd, pBuffer, nBytesToWrite);
+        if (-1 == nBytes)
+            return oslTranslateFileError (OSL_FET_ERROR, errno);
+        *pBytesWritten = nBytes;
+        return osl_File_E_None;
+    }
+    else if (0 == m_buffer)
+    {
+        // not buffered
+        return writeAt (nOffset, pBuffer, nBytesToWrite, pBytesWritten);
+    }
+    else
+    {
+        sal_uInt8 const * buffer = static_cast<sal_uInt8 const *>(pBuffer);
+        for (*pBytesWritten = 0; nBytesToWrite > 0; )
+        {
+            off_t  const bufptr = (nOffset / m_bufsiz) * m_bufsiz;
+            size_t const bufpos = (nOffset % m_bufsiz);
+            if (bufptr != m_bufptr)
+            {
+                // flush current buffer
+                oslFileError result = syncFile();
+                if (result != osl_File_E_None)
+                    return (result);
+
+                if (nBytesToWrite >= m_bufsiz)
+                {
+                    // buffer to small, write through to file
+                    sal_uInt64 uDone = 0;
+                    result = writeAt (nOffset, &(buffer[*pBytesWritten]), nBytesToWrite, &uDone);
+                    if (result != osl_File_E_None)
+                        return (result);
+                    if (uDone != nBytesToWrite)
+                        return osl_File_E_IO;
+
+                    nBytesToWrite -= uDone, *pBytesWritten += uDone;
+                    return osl_File_E_None;
+                }
+
+                // update buffer (pointer)
+                sal_uInt64 uDone = 0;
+                result = readAt (bufptr, m_buffer, m_bufsiz, &uDone);
+                if (result != osl_File_E_None)
+                    return (result);
+                m_bufptr = bufptr, m_buflen = uDone;
+            }
+
+            size_t const bytes = std::min (m_bufsiz - bufpos, nBytesToWrite);
+            OSL_FILE_TRACE("FileHandle_Impl::writeFileAt(%d, %lld, %ld)", m_fd, nOffset, bytes);
+
+            memcpy (&(m_buffer[bufpos]), &(buffer[*pBytesWritten]), bytes);
+            nBytesToWrite -= bytes, *pBytesWritten += bytes, nOffset += bytes;
+
+            m_buflen = std::max(m_buflen, bufpos + bytes);
+            m_state |= STATE_MODIFIED;
+        }
+        return osl_File_E_None;
+    }
+}
+
+oslFileError FileHandle_Impl::readLineAt (
+    off_t           nOffset,
+    sal_Sequence ** ppSequence,
+    sal_uInt64 *    pBytesRead)
+{
+    oslFileError result = osl_File_E_None;
+
+    off_t bufptr = nOffset / m_bufsiz * m_bufsiz;
+    if (bufptr != m_bufptr)
+    {
+        /* flush current buffer */
+        result = syncFile();
+        if (result != osl_File_E_None)
+            return (result);
+
+        /* update buffer (pointer) */
+        sal_uInt64 uDone = 0;
+        result = readAt (bufptr, m_buffer, m_bufsiz, &uDone);
+        if (result != osl_File_E_None)
+            return (result);
+
+        m_bufptr = bufptr, m_buflen = uDone;
+    }
+
+    static int const LINE_STATE_BEGIN = 0;
+    static int const LINE_STATE_CR    = 1;
+    static int const LINE_STATE_LF    = 2;
+
+    size_t bufpos = nOffset - m_bufptr, curpos = bufpos, dstpos = 0;
+    int    state  = (bufpos >= m_buflen) ? LINE_STATE_LF : LINE_STATE_BEGIN;
+
+    for ( ; state != LINE_STATE_LF; )
+    {
+        if (curpos >= m_buflen)
+        {
+            /* buffer examined */
+            if (0 < (curpos - bufpos))
+            {
+                /* flush buffer to sequence */
+                result = writeSequence_Impl (
+                    ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos);
+                if (result != osl_File_E_None)
+                    return (result);
+                *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos;
+            }
+
+            bufptr = nOffset / m_bufsiz * m_bufsiz;
+            if (bufptr != m_bufptr)
+            {
+                /* update buffer (pointer) */
+                sal_uInt64 uDone = 0;
+                result = readAt (bufptr, m_buffer, m_bufsiz, &uDone);
+                if (result != osl_File_E_None)
+                    return (result);
+                m_bufptr = bufptr, m_buflen = uDone;
+            }
+
+            bufpos = nOffset - m_bufptr, curpos = bufpos;
+            if (bufpos >= m_buflen)
+                break;
+        }
+        switch (state)
+        {
+        case LINE_STATE_CR:
+            state = LINE_STATE_LF;
+            switch (m_buffer[curpos])
+            {
+            case 0x0A: /* CRLF */
+                /* eat current char */
+                curpos++;
+                break;
+            default: /* single CR */
+                /* keep current char */
+                break;
+            }
+            break;
+        default:
+            /* determine next state */
+            switch (m_buffer[curpos])
+            {
+            case 0x0A: /* single LF */
+                state = LINE_STATE_LF;
+                break;
+            case 0x0D: /* CR */
+                state = LINE_STATE_CR;
+                break;
+            default: /* advance to next char */
+                curpos++;
+                break;
+            }
+            if (state != LINE_STATE_BEGIN)
+            {
+                /* store (and eat) the newline char */
+                m_buffer[curpos] = 0x0A, curpos++;
+
+                /* flush buffer to sequence */
+                result = writeSequence_Impl (
+                    ppSequence, &dstpos, &(m_buffer[bufpos]), curpos - bufpos - 1);
+                if (result != osl_File_E_None)
+                    return (result);
+                *pBytesRead += curpos - bufpos, nOffset += curpos - bufpos;
+            }
+            break;
+        }
+    }
+
+    result = writeSequence_Impl (ppSequence, &dstpos, 0, 0);
+    if (result != osl_File_E_None)
+        return (result);
+    if (0 < dstpos)
+        return osl_File_E_None;
+    if (bufpos >= m_buflen)
+        return osl_File_E_AGAIN;
+    return osl_File_E_None;
+}
+
+oslFileError FileHandle_Impl::writeSequence_Impl (
+    sal_Sequence ** ppSequence,
+    size_t *        pnOffset,
+    const void *    pBuffer,
+    size_t          nBytes)
+{
+    sal_Int32 nElements = *pnOffset + nBytes;
+    if (!*ppSequence)
+    {
+        /* construct sequence */
+        rtl_byte_sequence_constructNoDefault(ppSequence, nElements);
+    }
+    else if (nElements != (*ppSequence)->nElements)
+    {
+        /* resize sequence */
+        rtl_byte_sequence_realloc(ppSequence, nElements);
+    }
+    if (*ppSequence != 0)
+    {
+        /* fill sequence */
+        memcpy(&((*ppSequence)->elements[*pnOffset]), pBuffer, nBytes), *pnOffset += nBytes;
+    }
+    return (*ppSequence != 0) ? osl_File_E_None : osl_File_E_NOMEM;
+}
+
+oslFileError FileHandle_Impl::syncFile()
+{
+    oslFileError result = osl_File_E_None;
+    if (m_state & STATE_MODIFIED)
+    {
+        sal_uInt64 uDone = 0;
+        result = writeAt (m_bufptr, m_buffer, m_buflen, &uDone);
+        if (result != osl_File_E_None)
+            return (result);
+        if (uDone != m_buflen)
+            return osl_File_E_IO;
+        m_state &= ~STATE_MODIFIED;
+    }
+    return (result);
+}
+
+/****************************************************************************
+ *	osl_createFileHandleFromFD
+ ***************************************************************************/
+extern "C" oslFileHandle osl_createFileHandleFromFD( int fd )
+{
+    if (-1 == fd)
+        return 0; // EINVAL
+
+    struct stat aFileStat;
+    if (-1 == fstat (fd, &aFileStat))
+        return 0; // EBADF
+
+	FileHandle_Impl * pImpl = new FileHandle_Impl (fd);
+    if (0 == pImpl)
+        return 0; // ENOMEM
+
+    // assume writeable
+    pImpl->m_state |= FileHandle_Impl::STATE_WRITEABLE;
+    if (!S_ISREG(aFileStat.st_mode))
+    {
+        /* not a regular file, mark not seekable */
+        pImpl->m_state &= ~FileHandle_Impl::STATE_SEEKABLE;
+    }
+    else
+    {
+        /* regular file, init current size */
+        pImpl->m_size = sal::static_int_cast< sal_uInt64 >(aFileStat.st_size);
+    }
+
+    OSL_FILE_TRACE("osl_createFileHandleFromFD(%d, writeable) => %s",
+                   pImpl->m_fd, rtl_string_getStr(pImpl->m_strFilePath));
+	return (oslFileHandle)(pImpl);
+}
+
+/*******************************************************************
+ * osl_file_adjustLockFlags
+ ******************************************************************/
+static int osl_file_adjustLockFlags (const char * path, int flags)
+{
+#ifdef MACOSX
+    /*
+     * The AFP implementation of MacOS X 10.4 treats O_EXLOCK in a way 
+     * that makes it impossible for OOo to create a backup copy of the
+     * file it keeps opened. OTOH O_SHLOCK for AFP behaves as desired by
+     * the OOo file handling, so we need to check the path of the file
+     * for the filesystem name.
+     */
     struct statfs s;
-  
     if( 0 <= statfs( path, &s ) )
     {
         if( 0 == strncmp("afpfs", s.f_fstypename, 5) )
         {
             flags &= ~O_EXLOCK;
-            flags |= O_SHLOCK;
+            flags |=  O_SHLOCK;
         }    
-        else
-        {
-            /* Needed flags to allow opening a webdav file */
-            flags &= ~( O_EXLOCK | O_SHLOCK );
-		}
+        else
+        {
+            /* Needed flags to allow opening a webdav file */
+            flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK);
+		}
     }
+#endif /* MACOSX */
 
+    (void) path;
     return flags;
 }
 
-#endif
-
-
-/*******************************************************************
- *	osl_openDirectory
- ******************************************************************/
-
-oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirectory* pDirectory)
+/****************************************************************************
+ *	osl_file_queryLocking
+ ***************************************************************************/
+struct Locking_Impl
 {
-    rtl_uString* ustrSystemPath = NULL;
-    oslFileError eRet;
-
-    char path[PATH_MAX];
-
-    OSL_ASSERT(ustrDirectoryURL && (ustrDirectoryURL->length > 0));
-    OSL_ASSERT(pDirectory);
-
-    if (0 == ustrDirectoryURL->length )
-        return osl_File_E_INVAL;
-
-    /* convert file URL to system path */
-    eRet = osl_getSystemPathFromFileURL_Ex(ustrDirectoryURL, &ustrSystemPath, sal_False);
-
-	if( osl_File_E_None != eRet )
-        return eRet;
-
-	osl_systemPathRemoveSeparator(ustrSystemPath);
-
-    /* convert unicode path to text */
-    if ( UnicodeToText( path, PATH_MAX, ustrSystemPath->buffer, ustrSystemPath->length ) 
-#ifdef MACOSX 
-	 && macxp_resolveAlias( path, PATH_MAX ) == 0 
-#endif /* MACOSX */
-	 )
+    int m_enabled;
+    Locking_Impl() : m_enabled(0)
     {
-        /* open directory */
-        DIR *pdir = opendir( path );
-
-        if( pdir )
+#ifndef HAVE_O_EXLOCK
+        m_enabled = ((getenv("SAL_ENABLE_FILE_LOCKING") != 0) || (getenv("STAR_ENABLE_FILE_LOCKING") != 0));
+#endif /* HAVE_O_EXLOCK */
+    }
+};
+static int osl_file_queryLocking (sal_uInt32 uFlags)
+{
+    if (!(uFlags & osl_File_OpenFlag_NoLock))
+    {
+        if ((uFlags & osl_File_OpenFlag_Write) || (uFlags & osl_File_OpenFlag_Create))
         {
-            /* create and initialize impl structure */
-            oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) );
-
-            if( pDirImpl )
-            {
-                pDirImpl->pDirStruct = pdir;
-                pDirImpl->ustrPath = ustrSystemPath;
-
-                *pDirectory = (oslDirectory) pDirImpl;
-                return osl_File_E_None;
-            }
-            else
-            {
-                errno = ENOMEM;
-                closedir( pdir );
-            }
-        }
-        else
-        {
-            /* should be removed by optimizer in product version */
-            PERROR( "osl_openDirectory", path );
+            static Locking_Impl g_locking;
+            return (g_locking.m_enabled != 0);
         }
     }
-
-    rtl_uString_release( ustrSystemPath );
-
-    return oslTranslateFileError(OSL_FET_ERROR, errno);
+    return 0;
 }
 
-/****************************************************************************/
-/*	osl_closeDirectory */
-/****************************************************************************/
-
-oslFileError SAL_CALL osl_closeDirectory( oslDirectory Directory )
-{
-    oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) Directory;
-    oslFileError err = osl_File_E_None;
-
-    OSL_ASSERT( Directory );
-
-    if( NULL == pDirImpl )
-        return osl_File_E_INVAL;
-
-    /* close directory */
-    if( closedir( pDirImpl->pDirStruct ) )
-    {
-        err = oslTranslateFileError(OSL_FET_ERROR, errno);
-    }
-
-    /* cleanup members */
-    rtl_uString_release( pDirImpl->ustrPath );
-
-    rtl_freeMemory( pDirImpl );
-
-    return err;
-}
-
-/**********************************************
- * osl_readdir_impl_
- *
- * readdir wrapper, filters out "." and ".."
- * on request
- *********************************************/
-
-static struct dirent* osl_readdir_impl_(DIR* pdir, sal_Bool bFilterLocalAndParentDir)
-{
-	struct dirent* pdirent;
-
-	while ((pdirent = readdir(pdir)) != NULL)
-	{
-		if (bFilterLocalAndParentDir &&
-			((0 == strcmp(pdirent->d_name, ".")) || (0 == strcmp(pdirent->d_name, ".."))))
-			continue;
-		else
-			break;
-	}
-
-	return pdirent;
-}
-
-/****************************************************************************
- *	osl_getNextDirectoryItem
- ***************************************************************************/
-
-oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirectoryItem* pItem, sal_uInt32 /*uHint*/)
-{
-    oslDirectoryImpl* pDirImpl     = (oslDirectoryImpl*)Directory;
-    rtl_uString*      ustrFileName = NULL;
-    rtl_uString*      ustrFilePath = NULL;
-    struct dirent*    pEntry;
-
-    OSL_ASSERT(Directory);
-    OSL_ASSERT(pItem);
-
-    if ((NULL == Directory) || (NULL == pItem))
-        return osl_File_E_INVAL;
-
-    pEntry = osl_readdir_impl_(pDirImpl->pDirStruct, sal_True);
-
-    if (NULL == pEntry)
-        return osl_File_E_NOENT;
-
-
-#if defined(MACOSX)
-
-    // convert decomposed filename to precomposed unicode 
-    char composed_name[BUFSIZ];  
-    CFMutableStringRef strRef = CFStringCreateMutable (NULL, 0 );
-    CFStringAppendCString( strRef, pEntry->d_name, kCFStringEncodingUTF8 );  //UTF8 is default on Mac OSX
-    CFStringNormalize( strRef, kCFStringNormalizationFormC );
-    CFStringGetCString( strRef, composed_name, BUFSIZ, kCFStringEncodingUTF8 );
-    CFRelease( strRef );
-    rtl_string2UString( &ustrFileName, composed_name, strlen( composed_name),
-	osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS );
-
-#else  // not MACOSX
-    /* convert file name to unicode */
-    rtl_string2UString( &ustrFileName, pEntry->d_name, strlen( pEntry->d_name ),
-        osl_getThreadTextEncoding(), OSTRING_TO_OUSTRING_CVTFLAGS );
-    OSL_ASSERT(ustrFileName != 0);
-
-#endif
-
-	osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &ustrFilePath);
-    rtl_uString_release( ustrFileName );
-
-#ifdef _DIRENT_HAVE_D_TYPE
-    if(*pItem)
-        oslDirectoryItemImpl_release( ( oslDirectoryItemImpl* )( *pItem ) );
-
-     *pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrFilePath, true, pEntry->d_type );
-#else
-     /* use path as directory item */
-     *pItem = (oslDirectoryItem) ustrFilePath;
-#endif
-
-    return osl_File_E_None;
-}
-
-/****************************************************************************/
-/*	osl_getDirectoryItem */
-/****************************************************************************/
-
-oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirectoryItem* pItem )
-{
-    rtl_uString* ustrSystemPath = NULL;
-    oslFileError osl_error      = osl_File_E_INVAL;
-
-    OSL_ASSERT(ustrFileURL);
-    OSL_ASSERT(pItem);
-
-    if (0 == ustrFileURL->length || NULL == pItem)
-        return osl_File_E_INVAL;
-
-    osl_error = osl_getSystemPathFromFileURL_Ex(ustrFileURL, &ustrSystemPath, sal_False);
-
-    if (osl_File_E_None != osl_error)
-        return osl_error;
-
-	osl_systemPathRemoveSeparator(ustrSystemPath);
-
-	if (0 == access_u(ustrSystemPath, F_OK))
-	{
-#ifdef _DIRENT_HAVE_D_TYPE
-		*pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrSystemPath, false );
-#else
-		*pItem = (oslDirectoryItem)ustrSystemPath;
-#endif
-		osl_error = osl_File_E_None;
-	}
-	else
-	{
-		osl_error = oslTranslateFileError(OSL_FET_ERROR, errno);
-		rtl_uString_release(ustrSystemPath);
-	}
-	return osl_error;
-}
-
-
-/****************************************************************************/
-/*	osl_acquireDirectoryItem */
-/****************************************************************************/
-
-oslFileError osl_acquireDirectoryItem( oslDirectoryItem Item )
-{
-#ifdef _DIRENT_HAVE_D_TYPE
-	oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item;
-#else
-    rtl_uString* ustrFilePath = (rtl_uString *) Item;
-#endif
-
-    OSL_ASSERT( Item );
-
-#ifdef _DIRENT_HAVE_D_TYPE
-	if( pImpl )
-		oslDirectoryItemImpl_acquire( pImpl );
-#else
-    if( ustrFilePath )
-        rtl_uString_acquire( ustrFilePath );
-#endif
-
-    return osl_File_E_None;
-}
-
-/****************************************************************************/
-/*	osl_releaseDirectoryItem */
-/****************************************************************************/
-
-oslFileError osl_releaseDirectoryItem( oslDirectoryItem Item )
-{
-#ifdef _DIRENT_HAVE_D_TYPE
-	oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item;
-#else
-    rtl_uString* ustrFilePath = (rtl_uString *) Item;
-#endif
-
-    OSL_ASSERT( Item );
-
-#ifdef _DIRENT_HAVE_D_TYPE
-	if( pImpl )
-		oslDirectoryItemImpl_release( pImpl );
-#else
-    if( ustrFilePath )
-        rtl_uString_release( ustrFilePath );
-#endif
-
-    return osl_File_E_None;
-}
-
-/****************************************************************************
- *	osl_createFileHandleFromFD
- ***************************************************************************/
-
-oslFileHandle osl_createFileHandleFromFD( int fd )
-{
-	oslFileHandleImpl* pHandleImpl = NULL;
-
-	if ( fd >= 0 )
-	{
-		pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) );
-
-		if( pHandleImpl )
-		{
-			pHandleImpl->ustrFilePath = NULL;
-			rtl_uString_new( &pHandleImpl->ustrFilePath );
-			pHandleImpl->fd = fd;
-
-            /* FIXME: it should be detected whether the file has been locked */
-			pHandleImpl->bLocked = sal_True;
-		}
-	}
-
-	return (oslFileHandle)pHandleImpl;
-}
-
-
 /****************************************************************************
  *	osl_openFile
  ***************************************************************************/
-
 #ifdef HAVE_O_EXLOCK
 #define OPEN_WRITE_FLAGS ( O_RDWR | O_EXLOCK | O_NONBLOCK )
 #define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR | O_EXLOCK | O_NONBLOCK )
 #define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR )
 #endif
 
-oslFileError osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags )
+oslFileError
+SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags )
 {
-    oslFileHandleImpl* pHandleImpl = NULL;
     oslFileError eRet;
-    rtl_uString* ustrFilePath = NULL;
 
-    char buffer[PATH_MAX];
-    int  fd;
-    int  mode  = S_IRUSR | S_IRGRP | S_IROTH;
-    int  flags = O_RDONLY;
-
-    struct flock aflock;
-
-    /* locking the complete file */
-    aflock.l_type = 0;
-	aflock.l_whence = SEEK_SET;
-    aflock.l_start = 0;
-	aflock.l_len = 0;
-
-    OSL_ASSERT( ustrFileURL );
-    OSL_ASSERT( pHandle );
-
-    if( ( 0 == ustrFileURL->length ) )
+    if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0))
         return osl_File_E_INVAL;
 
     /* convert file URL to system path */
-    eRet = osl_getSystemPathFromFileURL( ustrFileURL, &ustrFilePath );
+    char buffer[PATH_MAX];
+    eRet = FileURLToPath (buffer, sizeof(buffer), ustrFileURL);
+    if (eRet != osl_File_E_None)
+        return eRet;
+#ifdef MACOSX 
+    if (macxp_resolveAlias (buffer, sizeof(buffer)) != 0)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+#endif /* MACOSX */
 
-    if( osl_File_E_None != eRet )
+    /* set mode and flags */
+    int mode  = S_IRUSR | S_IRGRP | S_IROTH;
+    int flags = O_RDONLY;
+    if (uFlags & osl_File_OpenFlag_Write)
+    {
+        mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+        flags = OPEN_WRITE_FLAGS;
+    }
+    if (uFlags & osl_File_OpenFlag_Create)
+    {
+        mode |= S_IWUSR | S_IWGRP | S_IWOTH;
+        flags = OPEN_CREATE_FLAGS;
+    }
+    if (uFlags & osl_File_OpenFlag_NoLock)
+    {
+#ifdef HAVE_O_EXLOCK
+        flags &= ~(O_EXLOCK | O_SHLOCK | O_NONBLOCK);
+#endif /* HAVE_O_EXLOCK */
+    }
+    else
+    {
+        flags = osl_file_adjustLockFlags (buffer, flags);
+    }
+
+    /* open the file */
+    int fd = open( buffer, flags, mode );
+    if (-1 == fd)
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+
+    /* reset O_NONBLOCK flag */
+    if (flags & O_NONBLOCK)
+    {
+        int f = fcntl (fd, F_GETFL, 0);
+        if (-1 == f)
+        {
+            eRet = oslTranslateFileError (OSL_FET_ERROR, errno);
+            (void) close(fd);
+            return eRet;
+        }
+        if (-1 == fcntl (fd, F_SETFL, (f & ~O_NONBLOCK)))
+        {
+            eRet = oslTranslateFileError (OSL_FET_ERROR, errno);
+            (void) close(fd);
+            return eRet;
+        }
+    }
+
+    /* get file status (mode, size) */
+    struct stat aFileStat;
+    if (-1 == fstat (fd, &aFileStat))
+    {
+        eRet = oslTranslateFileError (OSL_FET_ERROR, errno);
+        (void) close(fd);
         return eRet;
+    }
+    if (!S_ISREG(aFileStat.st_mode))
+    {
+        /* we only open regular files here */
+        (void) close(fd);
+        return osl_File_E_INVAL;
+    }
 
-	osl_systemPathRemoveSeparator(ustrFilePath);
-
-    /* convert unicode path to text */
-    if( UnicodeToText( buffer, PATH_MAX, ustrFilePath->buffer, ustrFilePath->length ) 
-#ifdef MACOSX 
-	 && macxp_resolveAlias( buffer, PATH_MAX ) == 0 
-#endif /* MACOSX */
-	 )
+    if (osl_file_queryLocking (uFlags))
     {
-        /* we do not open devices or such here */
-        if( !( uFlags & osl_File_OpenFlag_Create ) )
+#ifdef MACOSX
+        if (-1 == flock (fd, LOCK_EX | LOCK_NB))
         {
-            struct stat aFileStat;
-
-            if( 0 > stat( buffer, &aFileStat ) )
+            /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */
+            if ((errno != ENOTSUP) || ((-1 == flock (fd, LOCK_SH | LOCK_NB)) && (errno != ENOTSUP)))
             {
-                PERROR( "osl_openFile", buffer );
-                eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-            }
-
-            else if( !S_ISREG( aFileStat.st_mode ) )
-            {
-                eRet = osl_File_E_INVAL;
+                eRet = oslTranslateFileError (OSL_FET_ERROR, errno);
+                (void) close(fd);
+                return eRet;
             }
         }
+#else   /* F_SETLK */
+        {
+            struct flock aflock;
 
-        if( osl_File_E_None == eRet )
-        {
-            /*
-             * set flags and mode
-             */
+            aflock.l_type = F_WRLCK;
+            aflock.l_whence = SEEK_SET;
+            aflock.l_start = 0;
+            aflock.l_len = 0;
 
-            if ( uFlags & osl_File_OpenFlag_Write )
+            if (-1 == fcntl (fd, F_SETLK, &aflock))
             {
-                mode |= S_IWUSR | S_IWGRP | S_IWOTH;
-                flags = OPEN_WRITE_FLAGS;
-#ifdef MACOSX
-                flags = adjustLockFlags(buffer, flags);
-#endif
-                aflock.l_type = F_WRLCK;
+                eRet = oslTranslateFileError (OSL_FET_ERROR, errno);
+                (void) close(fd);
+                return eRet;
             }
+        }
+#endif  /* F_SETLK */
+    }
 
-            if ( uFlags & osl_File_OpenFlag_Create )
-            {
-                mode |= S_IWUSR | S_IWGRP | S_IWOTH;
-                flags = OPEN_CREATE_FLAGS;
-#ifdef MACOSX
-                flags = adjustLockFlags(buffer, flags);
-#endif
-            }
+    /* allocate memory for impl structure */
+    FileHandle_Impl * pImpl = new FileHandle_Impl (fd, buffer);
+    if (!pImpl)
+    {
+        eRet = oslTranslateFileError (OSL_FET_ERROR, ENOMEM);
+        (void) close(fd);
+        return eRet;
+    }
+    if (flags & O_RDWR)
+        pImpl->m_state |= FileHandle_Impl::STATE_WRITEABLE;
+    pImpl->m_size = sal::static_int_cast< sal_uInt64 >(aFileStat.st_size);
 
-            sal_Bool bNeedsLock = ( ( uFlags & osl_File_OpenFlag_NoLock ) == 0 );
-            if ( !bNeedsLock )
-            {
-#ifdef MACOSX
-                flags &= ~O_EXLOCK;
-                flags &= ~O_SHLOCK;
-#endif
-            }    
+    OSL_TRACE("osl_openFile(%d, %s) => %s", pImpl->m_fd,
+              flags & O_RDWR ? "writeable":"readonly",
+              rtl_string_getStr(pImpl->m_strFilePath));
 
-            /* open the file */
-            fd = open( buffer, flags, mode );
-            if ( fd >= 0 )
-            {
-                sal_Bool bLocked = sal_False;
-                if( bNeedsLock )
-                {
-#ifndef HAVE_O_EXLOCK
-                    /* check if file lock is enabled and clear l_type member of flock otherwise */
-                    if( (char *) -1 == pFileLockEnvVar )
-                    {
-                        /* FIXME: this is not MT safe */
-                        pFileLockEnvVar = getenv("SAL_ENABLE_FILE_LOCKING");
-
-                        if( NULL == pFileLockEnvVar)
-                            pFileLockEnvVar = getenv("STAR_ENABLE_FILE_LOCKING");
-                    }
-#else
-                    /* disable range based locking */
-                    pFileLockEnvVar = NULL;
-                    
-                    /* remove the NONBLOCK flag again */
-                    flags = fcntl(fd, F_GETFL, NULL);
-                    flags &= ~O_NONBLOCK;
-                    if( 0 > fcntl(fd, F_SETFL, flags) )
-                   {
-                        close(fd);
-                        return oslTranslateFileError(OSL_FET_ERROR, errno);
-                   }
-#endif
-                    if( NULL == pFileLockEnvVar )
-                        aflock.l_type = 0;
-
-                    /* lock the file if flock.l_type is set */
-#ifdef MACOSX
-                    bLocked = ( F_WRLCK != aflock.l_type );
-                    if (!bLocked) 
-					{
-                       /* Mac OSX returns ENOTSUP for webdav drives. We should try read lock */
-                       if ( 0 == flock( fd, LOCK_EX | LOCK_NB ) || errno == ENOTSUP )
-                          bLocked = ( errno != ENOTSUP ) || ( 0 == flock( fd, LOCK_SH | LOCK_NB ) || errno == ENOTSUP );
-                    }
-#else	/* MACOSX */
-                     bLocked = ( F_WRLCK != aflock.l_type || -1 != fcntl( fd, F_SETLK, &aflock ) );
-#endif	/* MACOSX */
-
-                }
-
-                if ( !bNeedsLock || bLocked )
-                {
-                    /* allocate memory for impl structure */
-                    pHandleImpl = (oslFileHandleImpl*) rtl_allocateMemory( sizeof(oslFileHandleImpl) );
-                    if( pHandleImpl )
-                    {
-                        pHandleImpl->ustrFilePath = ustrFilePath;
-                        pHandleImpl->fd = fd;
-			            pHandleImpl->bLocked = bLocked;
-
-                        *pHandle = (oslFileHandle) pHandleImpl;
-
-                        return osl_File_E_None;
-                    }
-                    else
-                    {
-                        errno = ENOMEM;
-                    }
-                }
-
-                close( fd );
-            }
-
-            PERROR( "osl_openFile", buffer );
-            eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-        }
-    }
-    else
-        eRet = osl_File_E_INVAL;
-
-    rtl_uString_release( ustrFilePath );
-    return eRet;
+    *pHandle = (oslFileHandle)(pImpl);
+    return osl_File_E_None;
 }
 
 /****************************************************************************/
 /*	osl_closeFile */
 /****************************************************************************/
+oslFileError
+SAL_CALL osl_closeFile( oslFileHandle Handle )
+{
+    FileHandle_Impl* pImpl = static_cast<FileHandle_Impl*>(Handle);
 
-oslFileError osl_closeFile( oslFileHandle Handle )
-{
-    oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle;
-    oslFileError eRet = osl_File_E_INVAL;
+    if ((pImpl == 0) || (pImpl->m_fd < 0))
+        return osl_File_E_INVAL;
 
-    OSL_ASSERT( Handle );
-
-    if( pHandleImpl )
+    /* close(2) implicitly (and unconditionally) unlocks */
+    OSL_TRACE("osl_closeFile(%d) => %s", pImpl->m_fd, rtl_string_getStr(pImpl->m_strFilePath));
+    oslFileError result = pImpl->syncFile();
+    if (result != osl_File_E_None)
     {
-        rtl_uString_release( pHandleImpl->ustrFilePath );
-
-        /* release file lock if locking is enabled */
-        if( pFileLockEnvVar )
-        {
-            struct flock aflock;
-
-            aflock.l_type = F_UNLCK;
-            aflock.l_whence = SEEK_SET;
-            aflock.l_start = 0;
-            aflock.l_len = 0;
-
-            if ( pHandleImpl->bLocked )
-            {
-                /* FIXME: check if file is really locked ?  */
-
-                /* release the file share lock on this file */
-#ifdef MACOSX
-                /* Mac OSX will return ENOTSUP for webdav drives. We should ignore the error */
-                if ( 0 != flock( pHandleImpl->fd, LOCK_UN | LOCK_NB ) && errno != ENOTSUP )
-#else	/* MACOSX */
-                if( -1 == fcntl( pHandleImpl->fd, F_SETLK, &aflock ) )
-#endif	/* MACOSX */
-                {
-                    PERROR( "osl_closeFile", "unlock failed" );
-                }
-            }
-        }
-
-        if( 0 > close( pHandleImpl->fd ) )
-        {
-            eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-        }
-        else
-            eRet = osl_File_E_None;
-
-        rtl_freeMemory( pHandleImpl );
+        /* close, ignoring double failure */
+        (void) close (pImpl->m_fd);
+    }
+    else if (-1 == close (pImpl->m_fd))
+    {
+        /* translate error code */
+        result = oslTranslateFileError (OSL_FET_ERROR, errno);
     }
 
-    return eRet;
+    delete pImpl;
+    return (result);
 }
 
-/****************************************************************************/
-/*	osl_isEndOfFile */
-/****************************************************************************/
+/************************************************
+ * osl_syncFile
+ ***********************************************/
+oslFileError
+SAL_CALL osl_syncFile(oslFileHandle Handle)
+{
+    FileHandle_Impl* pImpl = static_cast<FileHandle_Impl*>(Handle);
+    
+    if ((0 == pImpl) || (-1 == pImpl->m_fd))
+        return osl_File_E_INVAL;
 
-oslFileError SAL_CALL osl_isEndOfFile( oslFileHandle Handle, sal_Bool *pIsEOF )
-{
-    oslFileHandleImpl* pHandleImpl = (oslFileHandleImpl *) Handle;
-    oslFileError eRet = osl_File_E_INVAL;
-
-	if ( pHandleImpl)
-	{
-		long curPos = lseek( pHandleImpl->fd, 0, SEEK_CUR );
-
-		if ( curPos >= 0 )
-		{
-			long endPos = lseek( pHandleImpl->fd, 0, SEEK_END  );
-
-			if ( endPos >= 0 )
-			{
-				*pIsEOF = ( curPos == endPos );
-				curPos = lseek( pHandleImpl->fd, curPos, SEEK_SET );
-
-				if ( curPos >= 0 )
-					eRet = osl_File_E_None;
-				else
-					eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-			}
-			else
-				eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-		}
-		else
-			eRet = oslTranslateFileError(OSL_FET_ERROR, errno );
-	}
-
-	return eRet;
+    OSL_FILE_TRACE("osl_syncFile(%d)", pImpl->m_fd);
+    oslFileError result = pImpl->syncFile();
+    if (result != osl_File_E_None)
+        return (result);
+    if (-1 == fsync (pImpl->m_fd))
+        return oslTranslateFileError (OSL_FET_ERROR, errno);
+    
+    return osl_File_E_None;
 }
 
-
-/****************************************************************************/
-/*	osl_moveFile */
-/****************************************************************************/
-
-oslFileError osl_moveFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL )
-{
-    char srcPath[PATH_MAX];
-    char destPath[PATH_MAX];
-    oslFileError eRet;
-
-    OSL_ASSERT( ustrFileURL );
-    OSL_ASSERT( ustrDestURL );
-
-    /* convert source url to system path */
-    eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL );
-    if( eRet != osl_File_E_None )
-        return eRet;
-
-    /* convert destination url to system path */
-    eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL );
-    if( eRet != osl_File_E_None )
-        return eRet;
-
-#ifdef MACOSX
-    if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 )
-      return oslTranslateFileError( OSL_FET_ERROR, errno );
-#endif/* MACOSX */
-
-    return oslDoMoveFile( srcPath, destPath );
-}
-
-/****************************************************************************/
-/*	osl_copyFile */
-/****************************************************************************/
-
-oslFileError osl_copyFile( rtl_uString* ustrFileURL, rtl_uString* ustrDestURL )
-{
-    char srcPath[PATH_MAX];
-    char destPath[PATH_MAX];
-    oslFileError eRet;
-
-    OSL_ASSERT( ustrFileURL );
-    OSL_ASSERT( ustrDestURL );
-
-    /* convert source url to system path */
-    eRet = FileURLToPath( srcPath, PATH_MAX, ustrFileURL );
-    if( eRet != osl_File_E_None )
-        return eRet;
-
-    /* convert destination url to system path */
-    eRet = FileURLToPath( destPath, PATH_MAX, ustrDestURL );
-    if( eRet != osl_File_E_None )
-        return eRet;
-
-#ifdef MACOSX
-    if ( macxp_resolveAlias( srcPath, PATH_MAX ) != 0 || macxp_resolveAlias( destPath, PATH_MAX ) != 0 )
-      return oslTranslateFileError( OSL_FET_ERROR, errno );
-#endif/* MACOSX */
-
-    return osl_psz_copyFile( srcPath, destPath );
-}
-
-/****************************************************************************/
-/*	osl_removeFile */
-/****************************************************************************/
-
-oslFileError osl_removeFile( rtl_uString* ustrFileURL )
-{
-    char path[PATH_MAX];
-    oslFileError eRet;
-
-    OSL_ASSERT( ustrFileURL );
-