diff options
author | Julien Chaffraix <julien.chaffraix@gmail.com> | 2011-04-24 08:37:35 -0700 |
---|---|---|
committer | Michael Meeks <michael.meeks@novell.com> | 2011-04-26 15:13:59 +0100 |
commit | ab692f0f53d14e0d030ac34ac44bb05862f18280 (patch) | |
tree | 373ad9f885f83f15e1f2b38230d4bca018d388eb | |
parent | 71a8ef19e9d2006875bf939e19cb472923404d78 (diff) |
Migrated oslDoCopyFile to using the read/write helpers.
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 20 | ||||
-rw-r--r-- | sal/osl/unx/readwrite_helper.h | 9 |
2 files changed, 19 insertions, 10 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index eb7b94a3c..51691d5ae 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -39,6 +39,7 @@ #include "file_path_helper.hxx" #include "file_url.h" #include "uunxapi.hxx" +#include "readwrite_helper.h" #include <sys/types.h> #include <errno.h> @@ -1010,7 +1011,6 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD return nRet; } - size_t nWritten = 0; size_t nRemains = nSourceSize; if ( nRemains ) @@ -1021,18 +1021,18 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD do { - nRead = 0; - nWritten = 0; - size_t nToRead = std::min( sizeof(pBuffer), nRemains ); - nRead = read( SourceFileFD, pBuffer, nToRead ); - if ( (size_t)-1 != nRead ) - nWritten = write( DestFileFD, pBuffer, nRead ); + sal_Bool succeeded = safeRead( SourceFileFD, pBuffer, nToRead ); + if ( !succeeded ) + break; + + succeeded = safeWrite( DestFileFD, pBuffer, nToRead ); + if ( !succeeded ) + break; - if ( (size_t)-1 != nWritten ) - nRemains -= nWritten; + nRemains -= nToRead; } - while( nRemains && (size_t)-1 != nRead && nRead == nWritten ); + while( nRemains ); } if ( nRemains ) diff --git a/sal/osl/unx/readwrite_helper.h b/sal/osl/unx/readwrite_helper.h index 494c8861e..c96c4e3bf 100644 --- a/sal/osl/unx/readwrite_helper.h +++ b/sal/osl/unx/readwrite_helper.h @@ -29,9 +29,18 @@ #include <sal/types.h> +#ifdef __cplusplus +extern "C" +{ +#endif + sal_Bool safeWrite( int fd, void* data, sal_uInt32 dataSize ); // This function *will* read |count| bytes from |fd|, busy looping // if needed. Don't use it when you don't know if you can request enough // data. It will return sal_False for any partial transfer or error. sal_Bool safeRead( int fd, void* buffer, sal_uInt32 count ); + +#ifdef __cplusplus +} +#endif |