diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2014-10-31 13:26:22 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2014-10-31 13:26:22 +0100 |
commit | 30c9034c87b6cbc93a5ff4cf7e3fc9bff59b9ac5 (patch) | |
tree | 4327c3f608bd09f8f9d1de05e9efee8ed789fa56 /sal | |
parent | 292256d2f24ce62d53c721539e7670b8c7d8d9f1 (diff) |
Simplify by using OString
Change-Id: Ia46417525e655a5a80f9e70f25f65e4916e4c8d8
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index 5386e4e31077..597349d5cb65 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -24,6 +24,7 @@ #include "osl/thread.h" #include <osl/signal.h> #include "rtl/alloc.h" +#include <rtl/string.hxx> #include "system.h" #include "file_impl.hxx" @@ -795,31 +796,16 @@ static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* p return tErr; } -#define TMP_DEST_FILE_EXTENSION ".osl-tmp" - static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, mode_t nMode, size_t nSourceSize, int DestFileExists) { int nRet=0; - sal_Char pszTmpDestFile[PATH_MAX]; - size_t size_tmp_dest_buff = sizeof(pszTmpDestFile); - - /* Quick fix for #106048, the whole copy file function seems - to be erroneous anyway and needs to be rewritten. - */ - memset(pszTmpDestFile, 0, size_tmp_dest_buff); + rtl::OString tmpDestFile; if ( DestFileExists ) { //TODO: better pick a temp file name instead of adding .osl-tmp: - - strncpy(pszTmpDestFile, pszDestFileName, size_tmp_dest_buff - 1); - - if ((strlen(pszTmpDestFile) + strlen(TMP_DEST_FILE_EXTENSION)) >= size_tmp_dest_buff) - return osl_File_E_NAMETOOLONG; - - strncat(pszTmpDestFile, TMP_DEST_FILE_EXTENSION, strlen(TMP_DEST_FILE_EXTENSION)); - - if (rename(pszDestFileName,pszTmpDestFile) != 0) + tmpDestFile = rtl::OString(pszSourceFileName) + ".osl-tmp"; + if (rename(pszDestFileName, tmpDestFile.getStr()) != 0) { if (errno == ENOENT) { @@ -830,7 +816,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* int e = errno; SAL_INFO( "sal.osl", - "rename(" << pszDestFileName << ", " << pszTmpDestFile + "rename(" << pszDestFileName << ", " << tmpDestFile << ") failed with errno " << e); return osl_File_E_BUSY; // for want of a better error code } @@ -857,7 +843,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* if ( nRet > 0 && DestFileExists == 1 ) { unlink(pszDestFileName); - rename(pszTmpDestFile,pszDestFileName); + rename(tmpDestFile.getStr(), pszDestFileName); } if ( nRet > 0 ) @@ -867,7 +853,7 @@ static oslFileError oslDoCopy(const sal_Char* pszSourceFileName, const sal_Char* if ( DestFileExists == 1 ) { - unlink(pszTmpDestFile); + unlink(tmpDestFile.getStr()); } return osl_File_E_None; |