diff options
author | Tor Lillqvist <tlillqvist@suse.com> | 2012-01-17 12:45:45 +0200 |
---|---|---|
committer | Tor Lillqvist <tlillqvist@suse.com> | 2012-01-18 23:15:42 +0200 |
commit | a64db11b6ca1c0c99937cd99129758dbbe575ac2 (patch) | |
tree | 0132ea0e43c6311a8163daa757e10b906ec117fa /sal/osl/unx/file.cxx | |
parent | 800806ba850c7fd03e37acb011fa993e08cb8fc8 (diff) |
Add some non-public API to be used by SvFileStream
Having SvFileStream call the file opening etc functions here, instead
of calling open() directly itself, means we won't have to duplicate
the Android .apk hooks there, too.
Diffstat (limited to 'sal/osl/unx/file.cxx')
-rw-r--r-- | sal/osl/unx/file.cxx | 77 |
1 files changed, 56 insertions, 21 deletions
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index 4bb30cfb6eab..64ce977d960e 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -28,6 +28,7 @@ #include "osl/file.hxx" +#include "osl/detail/file.h" #include "osl/diagnose.h" #include "rtl/alloc.h" @@ -885,40 +886,27 @@ SAL_CALL osl_openMemoryAsFile( void *address, size_t size, oslFileHandle *pHandl ***************************************************************************/ #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_RDWR | O_EXLOCK | O_NONBLOCK ) #else #define OPEN_WRITE_FLAGS ( O_RDWR ) -#define OPEN_CREATE_FLAGS ( O_CREAT | O_EXCL | O_RDWR ) +#define OPEN_CREATE_FLAGS ( O_CREAT | O_RDWR ) #endif oslFileError -SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags ) +SAL_CALL osl_openFilePath( const char *cpFilePath, oslFileHandle* pHandle, sal_uInt32 uFlags ) { oslFileError eRet; - if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0)) - return osl_File_E_INVAL; - - /* convert file URL to system path */ - 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 */ - #ifdef ANDROID /* Opening a file from /assets read-only means * we should mmap it from the .apk file */ if (!(uFlags & osl_File_OpenFlag_Write) && - strncmp (buffer, "/assets/", sizeof ("/assets/") - 1) == 0) + strncmp (cpFilePath, "/assets/", sizeof ("/assets/") - 1) == 0) { void *address; size_t size; - address = lo_apkentry(buffer, &size); + address = lo_apkentry(cpFilePath, &size); return osl_openMemoryAsFile(address, size, pHandle); } #endif @@ -936,6 +924,13 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn mode |= S_IWUSR | S_IWGRP | S_IWOTH; flags = OPEN_CREATE_FLAGS; } + + /* Check for flags passed in from SvFileStream::Open() */ + if (uFlags & osl_File_OpenFlag_Trunc) + flags |= O_TRUNC; + if (!(uFlags & osl_File_OpenFlag_NoExcl)) + flags |= O_EXCL; + if (uFlags & osl_File_OpenFlag_NoLock) { #ifdef HAVE_O_EXLOCK @@ -944,11 +939,11 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn } else { - flags = osl_file_adjustLockFlags (buffer, flags); + flags = osl_file_adjustLockFlags (cpFilePath, flags); } /* open the file */ - int fd = open( buffer, flags, mode ); + int fd = open( cpFilePath, flags, mode ); if (-1 == fd) return oslTranslateFileError (OSL_FET_ERROR, errno); @@ -1018,7 +1013,7 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn } /* allocate memory for impl structure */ - FileHandle_Impl * pImpl = new FileHandle_Impl (fd, FileHandle_Impl::KIND_FD, buffer); + FileHandle_Impl * pImpl = new FileHandle_Impl (fd, FileHandle_Impl::KIND_FD, cpFilePath); if (!pImpl) { eRet = oslTranslateFileError (OSL_FET_ERROR, ENOMEM); @@ -1037,6 +1032,28 @@ SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uIn return osl_File_E_None; } +oslFileError +SAL_CALL osl_openFile( rtl_uString* ustrFileURL, oslFileHandle* pHandle, sal_uInt32 uFlags ) +{ + oslFileError eRet; + + if ((ustrFileURL == 0) || (ustrFileURL->length == 0) || (pHandle == 0)) + return osl_File_E_INVAL; + + /* convert file URL to system path */ + 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 */ + + return osl_openFilePath (buffer, pHandle, uFlags); +} + /****************************************************************************/ /* osl_closeFile */ /****************************************************************************/ @@ -1104,6 +1121,24 @@ SAL_CALL osl_syncFile(oslFileHandle Handle) return osl_File_E_None; } +/************************************************ + * osl_fileGetOSHandle + ***********************************************/ +oslFileError +SAL_CALL osl_getFileOSHandle( + oslFileHandle Handle, + sal_IntPtr *piFileHandle ) +{ + FileHandle_Impl* pImpl = static_cast<FileHandle_Impl*>(Handle); + + if (0 == pImpl || pImpl->m_kind != FileHandle_Impl::KIND_FD || -1 == pImpl->m_fd) + return osl_File_E_INVAL; + + *piFileHandle = pImpl->m_fd; + + return osl_File_E_None; +} + /******************************************* osl_mapFile ********************************************/ |