diff options
author | Michael Meeks <michael.meeks@suse.com> | 2013-02-26 15:25:22 +0000 |
---|---|---|
committer | Michael Meeks <michael.meeks@suse.com> | 2013-02-27 09:09:02 +0000 |
commit | a82f7b20539e60f1cf599afcceaf865bef297a66 (patch) | |
tree | 4a5689872006e66834be0644e32943dfdc81242d /tools | |
parent | c607d6436566c23c0dc814f6b86949ad5bfeb808 (diff) |
port horrible tools temp directory abstraction to sal.
Change-Id: I3688c8babf7719091404317b13014283a8ce9492
Diffstat (limited to 'tools')
-rw-r--r-- | tools/source/fsys/dirent.cxx | 10 | ||||
-rw-r--r-- | tools/source/fsys/tempfile.cxx | 34 | ||||
-rw-r--r-- | tools/source/fsys/unx.cxx | 22 | ||||
-rw-r--r-- | tools/source/fsys/unx.hxx | 2 | ||||
-rw-r--r-- | tools/source/fsys/wntmsc.cxx | 11 | ||||
-rw-r--r-- | tools/source/fsys/wntmsc.hxx | 2 |
6 files changed, 21 insertions, 60 deletions
diff --git a/tools/source/fsys/dirent.cxx b/tools/source/fsys/dirent.cxx index 1e9000b9c2c4..c4ae7a98dc27 100644 --- a/tools/source/fsys/dirent.cxx +++ b/tools/source/fsys/dirent.cxx @@ -57,7 +57,7 @@ using namespace osl; using ::rtl::OUString; -int ApiRet2ToSolarError_Impl( int nApiRet ); +extern rtl::OUString GetSystemTempDirPath_Impl(); int Sys2SolarError_Impl( int nSysErr ) { @@ -1304,9 +1304,13 @@ DirEntry DirEntry::TempName( DirEntryKind eKind ) const } dir = aDirName.getStr(); - char sBuf[_MAX_PATH]; + OString sTempRoot; if ( eFlag == FSYS_FLAG_CURRENT || ( !pParent && pWild ) ) - dir = TempDirImpl(sBuf); + { + rtl::OUString aPath = GetSystemTempDirPath_Impl(); + sTempRoot = OUStringToOString( aPath, osl_getThreadTextEncoding() ); + dir = sTempRoot.getStr(); + } DirEntry aRet(FSYS_FLAG_INVALID); i = strlen(dir); diff --git a/tools/source/fsys/tempfile.cxx b/tools/source/fsys/tempfile.cxx index ae4db9683e5e..1a1da1ed3e38 100644 --- a/tools/source/fsys/tempfile.cxx +++ b/tools/source/fsys/tempfile.cxx @@ -43,26 +43,21 @@ struct TempFile_Impl sal_Bool bIsDirectory; }; -String GetSystemTempDir_Impl() +extern rtl::OUString GetSystemTempDirPath_Impl(); + +rtl::OUString GetSystemTempDirPath_Impl() { - char sBuf[_MAX_PATH]; - const char *pDir = TempDirImpl(sBuf); - - ::rtl::OString aTmpA( pDir ); - ::rtl::OUString aTmp = ::rtl::OStringToOUString( aTmpA, osl_getThreadTextEncoding() ); - rtl::OUString aRet; - FileBase::getFileURLFromSystemPath( aTmp, aRet ); - String aName = aRet; - if( aName.GetChar(aName.Len()-1) != '/' ) - aName += '/'; - return aName; + rtl::OUString aTmpURL, aPath; + osl::FileBase::getTempDirURL( aTmpURL ); + osl::FileBase::getSystemPathFromFileURL( aTmpURL, aPath ); + return aPath; } #define TMPNAME_SIZE ( 1 + 5 + 5 + 4 + 1 ) -String ConstructTempDir_Impl( const String* pParent ) +OUString ConstructTempDir_Impl( const String* pParent ) { - String aName; + OUString aName; if ( pParent && pParent->Len() ) { rtl::OUString aRet; @@ -79,19 +74,18 @@ String ConstructTempDir_Impl( const String* pParent ) } } - if ( !aName.Len() ) + if ( aName.isEmpty() ) { // if no parent or invalid parent : use system directory - ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); + ::rtl::OUString& rTempNameBase_Impl = TempNameBase_Impl::get(); if ( rTempNameBase_Impl.isEmpty() ) - rTempNameBase_Impl = GetSystemTempDir_Impl(); + rTempNameBase_Impl = GetSystemTempDirPath_Impl(); aName = rTempNameBase_Impl; } // Make sure that directory ends with a separator - xub_StrLen i = aName.Len(); - if( i>0 && aName.GetChar(i-1) != '/' ) - aName += '/'; + if( !aName.endsWith( "/" ) ) + aName += "/"; return aName; } diff --git a/tools/source/fsys/unx.cxx b/tools/source/fsys/unx.cxx index 59ca419a63df..f26882cd0d5e 100644 --- a/tools/source/fsys/unx.cxx +++ b/tools/source/fsys/unx.cxx @@ -363,26 +363,4 @@ sal_Bool FileStat::Update( const DirEntry& rDirEntry, SAL_UNUSED_PARAMETER sal_B return sal_True; } -const char *TempDirImpl( char *pBuf ) -{ -#ifdef MACOSX - // P_tmpdir is /var/tmp on Mac OS X, and it is not cleaned up on system - // startup - strcpy( pBuf, "/tmp" ); -#else - const char *pValue = getenv( "TEMP" ); - if ( !pValue ) - pValue = getenv( "TMP" ); - if ( pValue ) - strcpy( pBuf, pValue ); - else - // P_tempdir exists in Solaris and Linux - strcpy( pBuf, P_tmpdir ); - // don't use "/tmp" as hard coded directory - //strcpy( pBuf, "/tmp" ); -#endif /* MACOSX */ - - return pBuf; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/unx.hxx b/tools/source/fsys/unx.hxx index cf399cc6ea9c..9728d71f4d19 100644 --- a/tools/source/fsys/unx.hxx +++ b/tools/source/fsys/unx.hxx @@ -71,8 +71,6 @@ inline void Unx2DateAndTime( time_t nDate, Time& rTime, Date& rDate ) rDate = Date( pTime->tm_mday, pTime->tm_mon + 1, pTime->tm_year + 1900 ); } -const char* TempDirImpl( char *pBuf ); - #define FSysFailOnErrorImpl() #endif diff --git a/tools/source/fsys/wntmsc.cxx b/tools/source/fsys/wntmsc.cxx index 8a82ae8cea0c..7c74ed459bf0 100644 --- a/tools/source/fsys/wntmsc.cxx +++ b/tools/source/fsys/wntmsc.cxx @@ -776,15 +776,4 @@ sal_Bool IsRedirectable_Impl( const rtl::OString& rPath ) return sal_False; } -/// get name of the directory for temporary files -const char* TempDirImpl( char *pBuf ) -{ - if ( !GetTempPath( MAX_PATH, pBuf ) && - !GetWindowsDirectory( pBuf, MAX_PATH ) && - !GetEnvironmentVariable( "HOMEPATH", pBuf, MAX_PATH ) ) - return 0; - - return pBuf; -} - /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/tools/source/fsys/wntmsc.hxx b/tools/source/fsys/wntmsc.hxx index acbb8085f3ff..bb1dbac93793 100644 --- a/tools/source/fsys/wntmsc.hxx +++ b/tools/source/fsys/wntmsc.hxx @@ -63,8 +63,6 @@ inline sal_Bool DRIVE_EXISTS(char c) return GetDriveType( aDriveRoot.getStr() ) > 1; } -const char* TempDirImpl( char *pBuf ); - #define FSysFailOnErrorImpl() #endif |