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 | |
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')
-rw-r--r-- | sal/osl/unx/file.cxx | 77 | ||||
-rw-r--r-- | sal/osl/unx/file_stat.cxx | 23 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.cxx | 34 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.h | 6 |
4 files changed, 112 insertions, 28 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 ********************************************/ diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx index ffeb885c37a3..9cbb39af0edc 100644 --- a/sal/osl/unx/file_stat.cxx +++ b/sal/osl/unx/file_stat.cxx @@ -28,6 +28,7 @@ #include "osl/file.h" +#include "osl/detail/file.h" #include "system.h" #include <sys/types.h> @@ -447,4 +448,26 @@ oslFileError SAL_CALL osl_setFileTime ( return osl_psz_setFileTime( path, pCreationTime, pLastAccessTime, pLastWriteTime ); } +oslFileError +SAL_CALL osl_statFilePath( const char *cpFilePath, struct stat *statb ) +{ + int rc = stat_c( cpFilePath, statb ); + + if (rc == -1) + return oslTranslateFileError(OSL_FET_ERROR, errno); + else + return osl_File_E_None; +} + +oslFileError +SAL_CALL osl_lstatFilePath( const char *cpFilePath, struct stat *statb ) +{ + int rc = lstat_c( cpFilePath, statb ); + + if (rc == -1) + return oslTranslateFileError(OSL_FET_ERROR, errno); + else + return osl_File_E_None; +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx index 86e86e2bb32d..8abe57f3b2f7 100644 --- a/sal/osl/unx/uunxapi.cxx +++ b/sal/osl/unx/uunxapi.cxx @@ -145,18 +145,38 @@ } //######################### + //stat_c + int stat_c(const char* cpPath, struct stat* buf) + { +#ifdef ANDROID + if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 && + (cpPath[sizeof("/assets")-1] == '\0' || + cpPath[sizeof("/assets")-1] == '/')) + return lo_apk_lstat(cpPath, buf); +#endif + return stat(cpPath, buf); + } + + //######################### + //lstat_c + int lstat_c(const char* cpPath, struct stat* buf) + { +#ifdef ANDROID + if (strncmp(cpPath, "/assets", sizeof("/assets")-1) == 0 && + (cpPath[sizeof("/assets")-1] == '\0' || + cpPath[sizeof("/assets")-1] == '/')) + return lo_apk_lstat(cpPath, buf); +#endif + return lstat(cpPath, buf); + } + + //######################### //lstat_u int lstat_u(const rtl_uString* pustrPath, struct stat* buf) { #ifndef MACOSX // not MACOSX rtl::OString fn = OUStringToOString(pustrPath); -#ifdef ANDROID - if (strncmp(fn.getStr(), "/assets", sizeof("/assets")-1) == 0 && - (fn.getStr()[sizeof("/assets")-1] == '\0' || - fn.getStr()[sizeof("/assets")-1] == '/')) - return lo_apk_lstat(fn.getStr(), buf); -#endif - return lstat(fn.getStr(), buf); + return lstat_c(fn.getStr(), buf); #else return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf); #endif diff --git a/sal/osl/unx/uunxapi.h b/sal/osl/unx/uunxapi.h index 9ac7ddd7ebb5..3696ab49f327 100644 --- a/sal/osl/unx/uunxapi.h +++ b/sal/osl/unx/uunxapi.h @@ -72,6 +72,12 @@ const rtl_uString* pustrFileName, rtl_uString** ppustrResolvedName); + /* @see stat */ + int stat_c(const char *cpPath, struct stat* buf); + + /* @see lstat */ + int lstat_c(const char *cpPath, struct stat* buf); + /* @see lstat */ int lstat_u(const rtl_uString* pustrPath, struct stat* buf); |