summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Lillqvist <tlillqvist@suse.com>2012-01-24 20:51:02 +0200
committerTor Lillqvist <tlillqvist@suse.com>2012-01-24 21:35:03 +0200
commit52681e4405b303028340bfb63ddb6c14eb17caa2 (patch)
treee6820e8eb466f7efd238e0279ca1b48bb1189e8b
parente580fd501b67b9e0a56a712ffb24ec3c244a135b (diff)
Use own own <osl/file.h> API to read the source in osl_copyFile()
It seems that we call osl_copyFile() to copy from /assets on Android in some cases.
-rw-r--r--sal/inc/osl/detail/file.h5
-rw-r--r--sal/osl/unx/file.cxx5
-rw-r--r--sal/osl/unx/file_misc.cxx33
3 files changed, 32 insertions, 11 deletions
diff --git a/sal/inc/osl/detail/file.h b/sal/inc/osl/detail/file.h
index 8e2c910f258c..f9798da4768e 100644
--- a/sal/inc/osl/detail/file.h
+++ b/sal/inc/osl/detail/file.h
@@ -49,6 +49,11 @@ extern "C" {
#define osl_File_OpenFlag_Trunc 0x00000010L
#define osl_File_OpenFlag_NoExcl 0x00000020L
+SAL_DLLPUBLIC oslFileError SAL_CALL osl_openFilePath(
+ const char *cpFilePath,
+ oslFileHandle* pHandle,
+ sal_uInt32 uFlags );
+
/* Get the OS specific "handle" of an open file. */
SAL_DLLPUBLIC oslFileError SAL_CALL osl_getFileOSHandle(
oslFileHandle Handle,
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index aa6cc26b4908..63e9775fa25e 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -892,7 +892,7 @@ SAL_CALL osl_openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandl
#define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR )
#endif
-static oslFileError
+oslFileError
SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags )
{
oslFileError eRet;
@@ -908,7 +908,10 @@ SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_u
size_t size;
address = lo_apkentry(cpFilePath, &size);
if (address == NULL)
+ {
+ errno = ENOENT;
return osl_File_E_NOENT;
+ }
return osl_openMemoryAsFile(address, size, pHandle);
}
#endif
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index 52e73cb188c6..260b711ee1da 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -27,6 +27,7 @@
************************************************************************/
#include "osl/file.hxx"
+#include "osl/detail/file.h"
#include "osl/diagnose.h"
#include "osl/thread.h"
@@ -833,7 +834,7 @@ static oslFileError osl_psz_copyFile( const sal_Char* pszPath, const sal_Char* p
int DestFileExists=1;
/* mfe: does the source file really exists? */
- nRet = lstat(pszPath,&aFileStat);
+ nRet = lstat_c(pszPath,&aFileStat);
if ( nRet < 0 )
{
@@ -1050,13 +1051,23 @@ static int oslDoCopyLink(const sal_Char* pszSourceFileName, const sal_Char* pszD
static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszDestFileName, size_t nSourceSize, mode_t mode)
{
- int SourceFileFD=0;
+ oslFileHandle SourceFileFH=0;
int DestFileFD=0;
int nRet=0;
- SourceFileFD=open(pszSourceFileName,O_RDONLY);
- if ( SourceFileFD < 0 )
+#ifdef ANDROID
+ volatile int beenhere = 0;
+ if (!beenhere) {
+ beenhere++;
+ fprintf(stderr, "Sleeping NOW, start ndk-gdb!\n");
+ ::sleep(20);
+ }
+#endif
+ if (osl_openFilePath(pszSourceFileName,
+ &SourceFileFH,
+ osl_File_OpenFlag_Read|osl_File_OpenFlag_NoLock|osl_File_OpenFlag_NoExcl) != osl_File_E_None)
{
+ // Let's hope errno is still set relevantly after osl_openFilePath...
nRet=errno;
return nRet;
}
@@ -1066,7 +1077,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
if ( DestFileFD < 0 )
{
nRet=errno;
- close(SourceFileFD);
+ osl_closeFile(SourceFileFH);
return nRet;
}
@@ -1080,15 +1091,17 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
do
{
size_t nToRead = std::min( sizeof(pBuffer), nRemains );
- sal_Bool succeeded = safeRead( SourceFileFD, pBuffer, nToRead );
- if ( !succeeded )
+ sal_uInt64 nRead;
+ sal_Bool succeeded;
+ if ( osl_readFile( SourceFileFH, pBuffer, nToRead, &nRead ) != osl_File_E_None || nRead > nToRead || nRead == 0 )
break;
- succeeded = safeWrite( DestFileFD, pBuffer, nToRead );
+ succeeded = safeWrite( DestFileFD, pBuffer, nRead );
if ( !succeeded )
break;
- nRemains -= nToRead;
+ // We know nRead <= nToRead, so it must fit in a size_t
+ nRemains -= (size_t) nRead;
}
while( nRemains );
}
@@ -1101,7 +1114,7 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
nRet = ENOSPC;
}
- close( SourceFileFD );
+ osl_closeFile( SourceFileFH );
if ( close( DestFileFD ) == -1 && nRet == 0 )
nRet = errno;