diff options
author | Tor Lillqvist <tlillqvist@suse.com> | 2012-01-04 00:03:18 +0200 |
---|---|---|
committer | Tor Lillqvist <tlillqvist@suse.com> | 2012-01-04 00:17:25 +0200 |
commit | 90b141496018201ee9df721b382cd2b177a3a92f (patch) | |
tree | 1a0fc73adbf51c618b10661cc396f5ec11ee491a | |
parent | 2717fe35ae7fd35b787b53d291919449d307ea01 (diff) |
Use the lo_apk_* functions for files under /assets
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 104 | ||||
-rw-r--r-- | sal/osl/unx/uunxapi.cxx | 32 |
2 files changed, 112 insertions, 24 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index e1da32a0aa25..7c84086b42ff 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -53,6 +53,10 @@ #include <algorithm> +#ifdef ANDROID +#include <lo-bootstrap.h> +#endif + /************************************************************************ * ToDo * @@ -70,6 +74,15 @@ typedef struct { rtl_uString* ustrPath; /* holds native directory path */ DIR* pDirStruct; +#ifdef ANDROID + enum Kind + { + KIND_DIRENT = 1, + KIND_ASSETS = 2 + }; + int eKind; + lo_apk_dir* pApkDirStruct; +#endif } oslDirectoryImpl; DirectoryItem_Impl::DirectoryItem_Impl( @@ -169,33 +182,64 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect #endif /* MACOSX */ ) { - /* open directory */ - DIR *pdir = opendir( path ); - - if( pdir ) +#ifdef ANDROID + if( strncmp( path, "/assets/", sizeof( "/assets/" ) - 1) == 0 ) { - /* create and initialize impl structure */ - oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) ); - - if( pDirImpl ) - { - pDirImpl->pDirStruct = pdir; - pDirImpl->ustrPath = ustrSystemPath; + lo_apk_dir *pdir = lo_apk_opendir( path ); - *pDirectory = (oslDirectory) pDirImpl; - return osl_File_E_None; - } - else + if( pdir ) { - errno = ENOMEM; - closedir( pdir ); + oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) ); + + if( pDirImpl ) + { + pDirImpl->eKind = oslDirectoryImpl::KIND_ASSETS; + pDirImpl->pApkDirStruct = pdir; + pDirImpl->ustrPath = ustrSystemPath; + + *pDirectory = (oslDirectory) pDirImpl; + return osl_File_E_None; + } + else + { + errno = ENOMEM; + lo_apk_closedir( pdir ); + } } } else +#endif { + /* open directory */ + DIR *pdir = opendir( path ); + + if( pdir ) + { + /* create and initialize impl structure */ + oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) rtl_allocateMemory( sizeof(oslDirectoryImpl) ); + + if( pDirImpl ) + { + pDirImpl->pDirStruct = pdir; + pDirImpl->ustrPath = ustrSystemPath; +#ifdef ANDROID + pDirImpl->eKind = oslDirectoryImpl::KIND_DIRENT; +#endif + *pDirectory = (oslDirectory) pDirImpl; + return osl_File_E_None; + } + else + { + errno = ENOMEM; + closedir( pdir ); + } + } + else + { #ifdef DEBUG_OSL_FILE - perror ("osl_openDirectory"); fprintf (stderr, path); + perror ("osl_openDirectory"); fprintf (stderr, path); #endif + } } } @@ -218,10 +262,17 @@ oslFileError SAL_CALL osl_closeDirectory( oslDirectory Directory ) if( NULL == pDirImpl ) return osl_File_E_INVAL; - /* close directory */ - if( closedir( pDirImpl->pDirStruct ) ) +#ifdef ANDROID + if( pDirImpl->eKind == oslDirectoryImpl::KIND_ASSETS ) + { + if (lo_apk_closedir( pDirImpl->pApkDirStruct )) + err = osl_File_E_IO; + } + else +#endif { - err = oslTranslateFileError(OSL_FET_ERROR, errno); + if( closedir( pDirImpl->pDirStruct ) ) + err = oslTranslateFileError(OSL_FET_ERROR, errno); } /* cleanup members */ @@ -272,7 +323,16 @@ oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirect if ((NULL == Directory) || (NULL == pItem)) return osl_File_E_INVAL; - pEntry = osl_readdir_impl_(pDirImpl->pDirStruct, sal_True); +#ifdef ANDROID + if( pDirImpl->eKind == oslDirectoryImpl::KIND_ASSETS ) + { + pEntry = lo_apk_readdir(pDirImpl->pApkDirStruct); + } + else +#endif + { + pEntry = osl_readdir_impl_(pDirImpl->pDirStruct, sal_True); + } if (NULL == pEntry) return osl_File_E_NOENT; diff --git a/sal/osl/unx/uunxapi.cxx b/sal/osl/unx/uunxapi.cxx index ee3cdeb928d8..3c2067bb318d 100644 --- a/sal/osl/unx/uunxapi.cxx +++ b/sal/osl/unx/uunxapi.cxx @@ -47,6 +47,10 @@ #include <osl/thread.h> #endif + #ifdef ANDROID + #include <lo-bootstrap.h> + #endif + //########################### inline rtl::OString OUStringToOString(const rtl_uString* s) { @@ -80,7 +84,24 @@ int access_u(const rtl_uString* pustrPath, int mode) { #ifndef MACOSX // not MACOSX - return access(OUStringToOString(pustrPath).getStr(), mode); + const char *path = OUStringToOString(pustrPath).getStr(); +#ifdef ANDROID + if (strncmp(path, "/assets", sizeof("/assets")-1) == 0 && + (path[sizeof("/assets")-1] == '\0' || + path[sizeof("/assets")-1] == '/')) + { + struct stat stat; + if (lo_apk_lstat(path, &stat) == -1) + return -1; + if (mode & W_OK) + { + errno = EACCES; + return -1; + } + return 0; + } +#endif + return access(path, mode); #else return access(macxp_resolveAliasAndConvert(pustrPath).getStr(), mode); #endif @@ -114,7 +135,14 @@ int lstat_u(const rtl_uString* pustrPath, struct stat* buf) { #ifndef MACOSX // not MACOSX - return lstat(OUStringToOString(pustrPath).getStr(), buf); + const char *path = OUStringToOString(pustrPath).getStr(); +#ifdef ANDROID + if (strncmp(path, "/assets", sizeof("/assets")-1) == 0 && + (path[sizeof("/assets")-1] == '\0' || + path[sizeof("/assets")-1] == '/')) + return lo_apk_lstat(path, buf); +#endif + return lstat(path, buf); #else return lstat(macxp_resolveAliasAndConvert(pustrPath).getStr(), buf); #endif |