diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2019-08-29 11:16:43 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2019-08-29 13:23:01 +0200 |
commit | 554f27d22b94941e7b5f777dd10f0108923d6aac (patch) | |
tree | f6969072620b78c233d77263abc26daef581578d /sal | |
parent | df2b4a9daa643e66b705a7b39d8988a3d97d731e (diff) |
Make oslDirectoryImpl a bit more C++y
Change-Id: Iff5e26369889345d1f907e52d86eff6b89c63e20
Reviewed-on: https://gerrit.libreoffice.org/78260
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/osl/unx/file_misc.cxx | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx index 31641593e781..436cf07b271f 100644 --- a/sal/osl/unx/file_misc.cxx +++ b/sal/osl/unx/file_misc.cxx @@ -48,6 +48,7 @@ #include <algorithm> #include <cassert> +#include <new> #ifdef ANDROID #include <osl/detail/android-bootstrap.h> @@ -61,9 +62,11 @@ * - check size/use of oslDirectoryItem ***********************************************************************/ -typedef struct +namespace { + +struct DirectoryImpl { - rtl_uString* ustrPath; /* holds native directory path */ + OUString ustrPath; /* holds native directory path */ DIR* pDirStruct; #ifdef ANDROID enum Kind @@ -74,7 +77,9 @@ typedef struct int eKind; lo_apk_dir* pApkDirStruct; #endif -} oslDirectoryImpl; +}; + +} DirectoryItem_Impl::DirectoryItem_Impl( rtl_uString * ustrFilePath, unsigned char DType) @@ -171,13 +176,13 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect if( pdir ) { - oslDirectoryImpl* pDirImpl = (oslDirectoryImpl*) malloc( sizeof(oslDirectoryImpl) ); + DirectoryImpl* pDirImpl = new(std::nothrow) DirectoryImpl; if( pDirImpl ) { - pDirImpl->eKind = oslDirectoryImpl::KIND_ASSETS; + pDirImpl->eKind = DirectoryImpl::KIND_ASSETS; pDirImpl->pApkDirStruct = pdir; - pDirImpl->ustrPath = ustrSystemPath; + pDirImpl->ustrPath = OUString::unacquired(&ustrSystemPath); *pDirectory = (oslDirectory) pDirImpl; return osl_File_E_None; @@ -200,14 +205,14 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect SAL_INFO("sal.file", "opendir(" << path << ") => " << pdir); /* create and initialize impl structure */ - oslDirectoryImpl* pDirImpl = static_cast<oslDirectoryImpl*>(malloc( sizeof(oslDirectoryImpl) )); + DirectoryImpl* pDirImpl = new(std::nothrow) DirectoryImpl; if( pDirImpl ) { pDirImpl->pDirStruct = pdir; - pDirImpl->ustrPath = ustrSystemPath; + pDirImpl->ustrPath = OUString::unacquired(&ustrSystemPath); #ifdef ANDROID - pDirImpl->eKind = oslDirectoryImpl::KIND_DIRENT; + pDirImpl->eKind = DirectoryImpl::KIND_DIRENT; #endif *pDirectory = static_cast<oslDirectory>(pDirImpl); return osl_File_E_None; @@ -233,14 +238,14 @@ oslFileError SAL_CALL osl_openDirectory(rtl_uString* ustrDirectoryURL, oslDirect oslFileError SAL_CALL osl_closeDirectory(oslDirectory pDirectory) { SAL_WARN_IF(!pDirectory, "sal.file", "pDirectory is nullptr"); - oslDirectoryImpl* pDirImpl = static_cast<oslDirectoryImpl*>(pDirectory); + DirectoryImpl* pDirImpl = static_cast<DirectoryImpl*>(pDirectory); oslFileError err = osl_File_E_None; if (!pDirImpl) return osl_File_E_INVAL; #ifdef ANDROID - if (pDirImpl->eKind == oslDirectoryImpl::KIND_ASSETS) + if (pDirImpl->eKind == DirectoryImpl::KIND_ASSETS) { if (lo_apk_closedir(pDirImpl->pApkDirStruct)) err = osl_File_E_IO; @@ -258,10 +263,7 @@ oslFileError SAL_CALL osl_closeDirectory(oslDirectory pDirectory) SAL_INFO("sal.file", "closedir(" << pDirImpl->pDirStruct << "): OK"); } - /* cleanup members */ - rtl_uString_release(pDirImpl->ustrPath); - - free(pDirImpl); + delete pDirImpl; return err; } @@ -293,7 +295,7 @@ oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory pDirectory, SAL_WARN_IF(!pDirectory, "sal.file", "pDirectory is nullptr"); SAL_WARN_IF(!pItem, "sal.file", "pItem is nullptr"); - oslDirectoryImpl* pDirImpl = static_cast<oslDirectoryImpl*>(pDirectory); + DirectoryImpl* pDirImpl = static_cast<DirectoryImpl*>(pDirectory); rtl_uString* ustrFileName = nullptr; rtl_uString* ustrFilePath = nullptr; struct dirent* pEntry; @@ -302,7 +304,7 @@ oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory pDirectory, return osl_File_E_INVAL; #ifdef ANDROID - if(pDirImpl->eKind == oslDirectoryImpl::KIND_ASSETS) + if(pDirImpl->eKind == DirectoryImpl::KIND_ASSETS) { pEntry = lo_apk_readdir(pDirImpl->pApkDirStruct); } @@ -335,7 +337,7 @@ oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory pDirectory, #endif - osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &ustrFilePath); + osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath.pData, ustrFileName, &ustrFilePath); rtl_uString_release(ustrFileName); DirectoryItem_Impl* pImpl = static_cast< DirectoryItem_Impl* >(*pItem); |