diff options
-rw-r--r-- | sal/inc/systools/win32/snprintf.h | 4 | ||||
-rw-r--r-- | sal/osl/unx/file.cxx | 69 | ||||
-rw-r--r-- | sal/osl/unx/file_impl.hxx | 48 | ||||
-rw-r--r-- | sal/osl/unx/file_stat.cxx | 70 | ||||
-rw-r--r-- | sal/osl/unx/process.c | 12 | ||||
-rw-r--r-- | sal/osl/unx/security.c | 9 | ||||
-rw-r--r-- | sal/osl/w32/conditn.c | 3 | ||||
-rw-r--r-- | sal/osl/w32/diagnose.c | 4 |
8 files changed, 208 insertions, 11 deletions
diff --git a/sal/inc/systools/win32/snprintf.h b/sal/inc/systools/win32/snprintf.h index 254726e2f37b..79441f032fee 100644 --- a/sal/inc/systools/win32/snprintf.h +++ b/sal/inc/systools/win32/snprintf.h @@ -1,4 +1,4 @@ -#ifndef _SMPRINTF_H +#ifndef _SNPRINTF_H #define _SNPRINTF_H #if !defined(_WIN32) @@ -77,4 +77,4 @@ _SNPRINTF_DLLIMPORT int __cdecl vsnprintf( char *buffer, size_t count, const cha } #endif -#endif /* _SMPRINTF_H */ +#endif /* _SNPRINTF_H */ diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx index e28328368a96..bd5b54a6d8c3 100644 --- a/sal/osl/unx/file.cxx +++ b/sal/osl/unx/file.cxx @@ -131,6 +131,42 @@ static const sal_Char* MOUNTTAB="/etc/mtab"; #endif +#ifdef _DIRENT_HAVE_D_TYPE +#include "file_impl.hxx" + oslDirectoryItemImpl* oslDirectoryItemImpl_CreateNew( rtl_uString* _ustrFilePath, bool _bHasDType, unsigned char _DType ) + { + oslDirectoryItemImpl *pItemObject = (oslDirectoryItemImpl*) malloc( sizeof( oslDirectoryItemImpl ) ); + pItemObject->RefCount = 1; + pItemObject->bHasType = _bHasDType; + pItemObject->DType = _DType; + pItemObject->ustrFilePath = _ustrFilePath; + + return pItemObject; + } + + void oslDirectoryItemImpl_Destroy( oslDirectoryItemImpl* pItem ) + { + if( pItem->ustrFilePath ) { + rtl_uString_release( pItem->ustrFilePath ); + pItem->ustrFilePath = NULL; + } + free( pItem ); + } + + void oslDirectoryItemImpl_acquire( oslDirectoryItemImpl* pItem ) + { + pItem->RefCount ++; + } + + void oslDirectoryItemImpl_release( oslDirectoryItemImpl* pItem ) + { + pItem->RefCount --; + + if( pItem->RefCount <= 0 ) + oslDirectoryItemImpl_Destroy( pItem ); + } +#endif + #if OSL_DEBUG_LEVEL > 1 extern void debug_ustring(rtl_uString*); @@ -467,8 +503,15 @@ oslFileError SAL_CALL osl_getNextDirectoryItem(oslDirectory Directory, oslDirect osl_systemPathMakeAbsolutePath(pDirImpl->ustrPath, ustrFileName, &ustrFilePath); rtl_uString_release( ustrFileName ); - /* use path as directory item */ - *pItem = (oslDirectoryItem) ustrFilePath; +#ifdef _DIRENT_HAVE_D_TYPE + if(*pItem) + oslDirectoryItemImpl_release( ( oslDirectoryItemImpl* )( *pItem ) ); + + *pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrFilePath, true, pEntry->d_type ); +#else + /* use path as directory item */ + *pItem = (oslDirectoryItem) ustrFilePath; +#endif return osl_File_E_None; } @@ -497,7 +540,11 @@ oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirecto if (0 == access_u(ustrSystemPath, F_OK)) { +#ifdef _DIRENT_HAVE_D_TYPE + *pItem = (oslDirectoryItem) oslDirectoryItemImpl_CreateNew( ustrSystemPath, false ); +#else *pItem = (oslDirectoryItem)ustrSystemPath; +#endif osl_error = osl_File_E_None; } else @@ -515,12 +562,21 @@ oslFileError SAL_CALL osl_getDirectoryItem( rtl_uString* ustrFileURL, oslDirecto oslFileError osl_acquireDirectoryItem( oslDirectoryItem Item ) { +#ifdef _DIRENT_HAVE_D_TYPE + oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; +#else rtl_uString* ustrFilePath = (rtl_uString *) Item; +#endif OSL_ASSERT( Item ); +#ifdef _DIRENT_HAVE_D_TYPE + if( pImpl ) + oslDirectoryItemImpl_acquire( pImpl ); +#else if( ustrFilePath ) rtl_uString_acquire( ustrFilePath ); +#endif return osl_File_E_None; } @@ -531,12 +587,21 @@ oslFileError osl_acquireDirectoryItem( oslDirectoryItem Item ) oslFileError osl_releaseDirectoryItem( oslDirectoryItem Item ) { +#ifdef _DIRENT_HAVE_D_TYPE + oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; +#else rtl_uString* ustrFilePath = (rtl_uString *) Item; +#endif OSL_ASSERT( Item ); +#ifdef _DIRENT_HAVE_D_TYPE + if( pImpl ) + oslDirectoryItemImpl_release( pImpl ); +#else if( ustrFilePath ) rtl_uString_release( ustrFilePath ); +#endif return osl_File_E_None; } diff --git a/sal/osl/unx/file_impl.hxx b/sal/osl/unx/file_impl.hxx new file mode 100644 index 000000000000..ae9d56ca85f3 --- /dev/null +++ b/sal/osl/unx/file_impl.hxx @@ -0,0 +1,48 @@ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2008 by Sun Microsystems, Inc. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * $RCSfile: $ + * $Revision: $ + * + * This file is part of OpenOffice.org. + * + * OpenOffice.org is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License version 3 + * only, as published by the Free Software Foundation. + * + * OpenOffice.org is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License version 3 for more details + * (a copy is included in the LICENSE file that accompanied this code). + * + * You should have received a copy of the GNU Lesser General Public License + * version 3 along with OpenOffice.org. If not, see + * <http://www.openoffice.org/license.html> + * for a copy of the LGPLv3 License. + * + ************************************************************************/ + +#ifdef __cplusplus +extern "C" { +#endif +typedef struct +{ + rtl_uString* ustrFilePath; /* holds native file name */ + unsigned char DType; + bool bHasType; + sal_uInt32 RefCount; +} oslDirectoryItemImpl; + + oslDirectoryItemImpl* oslDirectoryItemImpl_CreateNew( rtl_uString* _ustrFilePath, bool _bHasDType, unsigned char _DType=0 ); + void oslDirectoryItemImpl_Destroy( oslDirectoryItemImpl* pItem ); + void oslDirectoryItemImpl_acquire( oslDirectoryItemImpl* pItem ); + void oslDirectoryItemImpl_release( oslDirectoryItemImpl* pItem ); +#ifdef __cplusplus +} /* extern "C" */ +#endif diff --git a/sal/osl/unx/file_stat.cxx b/sal/osl/unx/file_stat.cxx index ec8cead84620..3a710743a1b2 100644 --- a/sal/osl/unx/file_stat.cxx +++ b/sal/osl/unx/file_stat.cxx @@ -42,6 +42,11 @@ #ifndef _UNISTD_H #include <unistd.h> #endif + +#ifndef _DIRENT_H +#include <dirent.h> +#endif + #include <osl/file.h> #ifndef _ERRNO_H @@ -56,6 +61,9 @@ #include "file_path_helper.hxx" #include "file_error_transl.h" +#ifdef _DIRENT_HAVE_D_TYPE +#include "file_impl.hxx" +#endif namespace /* private */ { @@ -223,9 +231,19 @@ namespace /* private */ /* we only need to call stat or lstat if one of the following flags is set */ +#ifdef _DIRENT_HAVE_D_TYPE + inline bool is_stat_call_necessary(sal_uInt32 field_mask, oslDirectoryItemImpl *pImpl) +#else inline bool is_stat_call_necessary(sal_uInt32 field_mask) +#endif { - return ((field_mask & osl_FileStatus_Mask_Type) || + return ( +/* on linux the dirent might have d_type */ +#ifdef _DIRENT_HAVE_D_TYPE + ((field_mask & osl_FileStatus_Mask_Type) && (!pImpl->bHasType || pImpl->DType == DT_UNKNOWN)) || +#else + (field_mask & osl_FileStatus_Mask_Type) || +#endif (field_mask & osl_FileStatus_Mask_Attributes) || (field_mask & osl_FileStatus_Mask_CreationTime) || (field_mask & osl_FileStatus_Mask_AccessTime) || @@ -254,7 +272,11 @@ namespace /* private */ if ((NULL == Item) || (NULL == pStat)) return osl_File_E_INVAL; +#ifdef _DIRENT_HAVE_D_TYPE + file_path = rtl::OUString(reinterpret_cast<rtl_uString*>(((oslDirectoryItemImpl* ) Item)->ustrFilePath)); +#else file_path = rtl::OUString(reinterpret_cast<rtl_uString*>(Item)); +#endif OSL_ASSERT(file_path.getLength() > 0); @@ -285,10 +307,18 @@ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pS #else struct stat file_stat; #endif - if (is_stat_call_necessary(uFieldMask) && (0 != osl::lstat(file_path, file_stat))) + +#ifdef _DIRENT_HAVE_D_TYPE + oslDirectoryItemImpl* pImpl = (oslDirectoryItemImpl*) Item; + bool bStatNeeded = is_stat_call_necessary(uFieldMask, pImpl); +#else + bool bStatNeeded = is_stat_call_necessary(uFieldMask); +#endif + + if (bStatNeeded && (0 != osl::lstat(file_path, file_stat))) return oslTranslateFileError(OSL_FET_ERROR, errno); - if (is_stat_call_necessary(uFieldMask)) + if (bStatNeeded) { // we set all these attributes because it's cheap set_file_type(file_stat, pStat); @@ -305,6 +335,40 @@ oslFileError SAL_CALL osl_getFileStatus(oslDirectoryItem Item, oslFileStatus* pS return osl_error; } } +#ifdef _DIRENT_HAVE_D_TYPE + else if (uFieldMask & osl_FileStatus_Mask_Type) + { + OSL_ASSERT(pImpl->bHasType); + + switch(pImpl->DType) + { + case DT_LNK: + pStat->eType = osl_File_Type_Link; + break; + case DT_DIR: + pStat->eType = osl_File_Type_Directory; + break; + case DT_REG: + pStat->eType = osl_File_Type_Regular; + break; + case DT_FIFO: + pStat->eType = osl_File_Type_Fifo; + break; + case DT_SOCK: + pStat->eType = osl_File_Type_Socket; + break; + case DT_CHR: + case DT_BLK: + pStat->eType = osl_File_Type_Special; + break; + default: + OSL_ASSERT(0); + pStat->eType = osl_File_Type_Unknown; + } + + pStat->uValidFields |= osl_FileStatus_Mask_Type; + } +#endif if (uFieldMask & osl_FileStatus_Mask_FileURL) { diff --git a/sal/osl/unx/process.c b/sal/osl/unx/process.c index a163436031d2..e5faf46548a6 100644 --- a/sal/osl/unx/process.c +++ b/sal/osl/unx/process.c @@ -650,6 +650,18 @@ static void ChildStatusProc(void *pData) close( stdOutput[0] ); close( stdError[0] ); + //if pid > 0 then a process was created, even if it later failed + //e.g. bash searching for a command to execute, and we still + //need to clean it up to avoid "defunct" processes + if (pid > 0) + { + pid_t child_pid; + do + { + child_pid = waitpid(pid, &status, 0); + } while ( 0 > child_pid && EINTR == errno ); + } + /* notify (and unblock) parent thread */ osl_setCondition(pdata->m_started); } diff --git a/sal/osl/unx/security.c b/sal/osl/unx/security.c index 53dd452e220b..5b601ee138a9 100644 --- a/sal/osl/unx/security.c +++ b/sal/osl/unx/security.c @@ -801,7 +801,14 @@ sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDire static sal_Bool SAL_CALL osl_psz_getConfigDir(oslSecurity Security, sal_Char* pszDirectory, sal_uInt32 nMax) { - return (osl_psz_getHomeDir(Security, pszDirectory, nMax)); + sal_Char *pStr = getenv("XDG_CONFIG_HOME"); + + if ((pStr == NULL) || (strlen(pStr) == 0) || + (access(pStr, 0) != 0)) + return (osl_psz_getHomeDir(Security, pszDirectory, nMax)); + + strncpy(pszDirectory, pStr, nMax); + return sal_True; } #else diff --git a/sal/osl/w32/conditn.c b/sal/osl/w32/conditn.c index c87d161137b4..7af4398284be 100644 --- a/sal/osl/w32/conditn.c +++ b/sal/osl/w32/conditn.c @@ -107,8 +107,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, while ( 1 ) { /* Only wake up if a SendMessage call to the threads message loop is detected */ - - switch( MsgWaitForMultipleObjects( 1, &(HANDLE)Condition, FALSE, timeout, QS_SENDMESSAGE ) ) + switch( MsgWaitForMultipleObjects( 1, (HANDLE *)(&Condition), FALSE, timeout, QS_SENDMESSAGE ) ) { case WAIT_OBJECT_0 + 1: { diff --git a/sal/osl/w32/diagnose.c b/sal/osl/w32/diagnose.c index af1b67eff5ac..6a67c1aa5b0f 100644 --- a/sal/osl/w32/diagnose.c +++ b/sal/osl/w32/diagnose.c @@ -73,6 +73,7 @@ void SAL_CALL osl_breakDebug(void) void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...) { va_list args; + int written = 0; va_start(args, lpszFormat); @@ -90,7 +91,8 @@ void SAL_CALL osl_trace(const sal_Char* lpszFormat, ...) { sal_Char szMessage[512]; szMessage[sizeof(szMessage)-1] = 0; - _vsnprintf( szMessage, sizeof(szMessage) -1, lpszFormat, args ); + written = _vsnprintf( szMessage, sizeof(szMessage) - 2, lpszFormat, args ); + szMessage[ written == -1 ? sizeof(szMessage) - 2 : written ] = '\n'; OutputDebugString( szMessage ); } |