[ooo-build-commit] Branch 'ooo/master' - sal/osl

Jan Holesovsky kendy at kemper.freedesktop.org
Fri Sep 25 22:05:46 PDT 2009


 sal/osl/unx/file.cxx |   97 +++++++++++++++++++++++----------------------------
 sal/osl/w32/file.cxx |   33 ++++++++++-------
 2 files changed, 64 insertions(+), 66 deletions(-)

New commits:
commit 9cead29bf5cdfd06f2251adfc240817ea5175eb5
Author: Release Engineers <releng at openoffice.org>
Date:   Fri Sep 25 13:28:16 2009 +0000

    CWS-TOOLING: integrate CWS fwk117
    2009-09-17 11:48:50 +0200 mav  r276234 : #i105082# fix setFileSize implementation, the patch from MHU

diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 28cc358..b8627b8 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -110,6 +110,7 @@ struct FileHandle_Impl
     oslFileError setPos (sal_uInt64 uPos);
 
     sal_uInt64   getSize() const;
+    oslFileError setSize (sal_uInt64 uSize);
 
     oslFileError readAt (
         off_t        nOffset,
@@ -271,6 +272,47 @@ sal_uInt64 FileHandle_Impl::getSize() const
     return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend));
 }
 
+oslFileError FileHandle_Impl::setSize (sal_uInt64 uSize)
+{
+    off_t const nSize = sal::static_int_cast< off_t >(uSize);
+    if (-1 == ftruncate (m_fd, nSize))
+    {
+        /* Failure. Save original result. Try fallback algorithm */
+        oslFileError result = oslTranslateFileError (OSL_FET_ERROR, errno);
+
+        /* Check against current size. Fail upon 'shrink' */
+        if (uSize <= getSize())
+        {
+            /* Failure upon 'shrink'. Return original result */
+            return (result);
+        }
+
+        /* Save current position */
+        off_t const nCurPos = (off_t)lseek (m_fd, (off_t)0, SEEK_CUR);
+        if (nCurPos == (off_t)(-1))
+            return (result);
+
+        /* Try 'expand' via 'lseek()' and 'write()' */
+        if (-1 == lseek (m_fd, (off_t)(nSize - 1), SEEK_SET))
+            return (result);
+
+        if (-1 == write (m_fd, (char*)"", (size_t)1))
+        {
+            /* Failure. Restore saved position */
+            (void) lseek (m_fd, (off_t)(nCurPos), SEEK_SET);
+            return (result);
+        }
+
+        /* Success. Restore saved position */
+        if (-1 == lseek (m_fd, (off_t)nCurPos, SEEK_SET))
+            return (result);
+    }
+
+    OSL_FILE_TRACE("osl_setFileSize(%d, %lld) => %ld", m_fd, getSize(), nSize);
+    m_size = sal::static_int_cast< sal_uInt64 >(nSize);
+    return osl_File_E_None;
+}
+
 oslFileError FileHandle_Impl::readAt (
     off_t        nOffset,
     void *       pBuffer,
@@ -1282,62 +1324,11 @@ SAL_CALL osl_setFileSize( oslFileHandle Handle, sal_uInt64 uSize )
     static sal_uInt64 const g_limit_off_t = std::numeric_limits< off_t >::max();
     if (g_limit_off_t < uSize)
         return osl_File_E_OVERFLOW;
-    off_t const nSize = sal::static_int_cast< off_t >(uSize);
 
     oslFileError result = pImpl->syncFile();
     if (result != osl_File_E_None)
         return (result);
+    pImpl->m_bufptr = -1, pImpl->m_buflen = 0;
 
-    if (-1 == ftruncate (pImpl->m_fd, nSize))
-    {
-        /* Failure. Try fallback algorithm */
-        off_t nCurPos;
-
-        /* Save original result */
-        result = oslTranslateFileError (OSL_FET_ERROR, errno);
-        PERROR("ftruncate", "Try osl_setFileSize [fallback]\n");
-
-        /* Check against current size. Fail upon 'shrink' */
-        if (uSize <= pImpl->getSize())
-        {
-            /* Failure upon 'shrink'. Return original result */
-            return (result);
-        }
-
-        /* Save current position *//* @@@ pImpl->m_offset @@@ */
-        nCurPos = (off_t)lseek (pImpl->m_fd, (off_t)0, SEEK_CUR);
-        if (nCurPos == (off_t)(-1))
-        {
-            PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n");
-            return (result);
-        }
-
-        /* Try 'expand' via 'lseek()' and 'write()' */
-        if (lseek (pImpl->m_fd, (off_t)(nSize - 1), SEEK_SET) < 0)
-        {
-            PERROR("ftruncate: lseek", "Out osl_setFileSize [error]\n");
-            return (result);
-        }
-        if (write (pImpl->m_fd, (char*)"", (size_t)1) < 0)
-        {
-            /* Failure. Restore saved position */
-            PERROR("ftruncate: write", "Out osl_setFileSize [error]\n");
-            if (lseek (pImpl->m_fd, (off_t)nCurPos, SEEK_SET) < 0)
-            {
-                PERROR("ftruncate: lseek", "ignoring");
-            }
-            return (result);
-        }
-
-        /* Success. Restore saved position */
-        if (lseek (pImpl->m_fd, (off_t)nCurPos, SEEK_SET) < 0)
-        {
-            PERROR("ftruncate: lseek", "Out osl_setFileSize [error]");
-            return (result);
-        }
-    }
-
-    OSL_FILE_TRACE("osl_setFileSize(%d, %lld) => %ld", pImpl->m_fd, pImpl->getSize(), nSize);
-    pImpl->m_size = sal::static_int_cast< sal_uInt64 >(nSize);
-    return osl_File_E_None;
+    return pImpl->setSize (uSize);
 }
diff --git a/sal/osl/w32/file.cxx b/sal/osl/w32/file.cxx
index b8d231a..763fddd 100644
--- a/sal/osl/w32/file.cxx
+++ b/sal/osl/w32/file.cxx
@@ -103,6 +103,7 @@ struct FileHandle_Impl
     oslFileError  setPos (sal_uInt64 uPos);
 
     sal_uInt64    getSize() const;
+    oslFileError  setSize (sal_uInt64 uPos);
 
     oslFileError readAt (
         LONGLONG     nOffset,
@@ -253,6 +254,23 @@ sal_uInt64 FileHandle_Impl::getSize() const
     return std::max(m_size, sal::static_int_cast< sal_uInt64 >(bufend));
 }
 
+oslFileError FileHandle_Impl::setSize (sal_uInt64 uSize)
+{
+    LARGE_INTEGER nDstPos; nDstPos.QuadPart = sal::static_int_cast< LONGLONG >(uSize);
+    if (!::SetFilePointerEx(m_hFile, nDstPos, 0, FILE_BEGIN))
+        return oslTranslateFileError( GetLastError() );
+
+    if (!::SetEndOfFile(m_hFile))
+        return oslTranslateFileError( GetLastError() );
+    m_size = uSize;
+
+    nDstPos.QuadPart = m_offset;
+    if (!::SetFilePointerEx(m_hFile, nDstPos, 0, FILE_BEGIN))
+        return oslTranslateFileError( GetLastError() );
+
+    return osl_File_E_None;
+}
+
 oslFileError FileHandle_Impl::readAt (
     LONGLONG     nOffset,
     void *       pBuffer,
@@ -1049,20 +1067,9 @@ SAL_CALL osl_setFileSize (oslFileHandle Handle, sal_uInt64 uSize)
     oslFileError result = pImpl->syncFile();
     if (result != osl_File_E_None)
         return (result);
+    pImpl->m_bufptr = -1, pImpl->m_buflen = 0;
 
-    LARGE_INTEGER nDstPos; nDstPos.QuadPart = sal::static_int_cast< LONGLONG >(uSize);
-    if (!::SetFilePointerEx(pImpl->m_hFile, nDstPos, 0, FILE_BEGIN))
-        return oslTranslateFileError( GetLastError() );
-
-    if (!::SetEndOfFile(pImpl->m_hFile))
-        return oslTranslateFileError( GetLastError() );
-    pImpl->m_size = uSize;
-
-    nDstPos.QuadPart = pImpl->m_offset;
-    if (!::SetFilePointerEx(pImpl->m_hFile, nDstPos, 0, FILE_BEGIN))
-        return oslTranslateFileError( GetLastError() );
-
-    return osl_File_E_None;
+    return pImpl->setSize (uSize);
 }
 
 //##################################################################


More information about the ooo-build-commit mailing list