diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2017-03-03 13:52:45 +0100 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2017-03-04 17:36:22 +0000 |
commit | 4af9612f2be9e023e762831207cbdb1d5f25906f (patch) | |
tree | f945e83dfc005b9984cc527831b5edfe4ecbbf3c /sal | |
parent | d35c25ee8f2e3125ddcd48b4fae75359a5b0ab8f (diff) |
Change sal/osl/w32/*.c -> *.cxx
...and fix any ensuing errors/warnings, but no further C++'ification. Not sure
whether any parts of dllentry.c would need to be extern "C", so leaving that one
alone for now.
TODO: Put definition of _CRT_RAND_S into bin/update_pch, so it doesn't get
removed again from sal/inc/pch/precompiled_sal.hxx. (For the surrounding #ifndef
see 244d22a3d27b303d44f59296a19dc4cb31fd429d "Work around -Werror,-Wunused-macros
with clang-cl".)
Change-Id: I2ada3717845eb0be0c559465d68e00e3a7720156
Reviewed-on: https://gerrit.libreoffice.org/34860
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'sal')
-rw-r--r-- | sal/Library_sal.mk | 22 | ||||
-rw-r--r-- | sal/inc/pch/precompiled_sal.hxx | 4 | ||||
-rw-r--r-- | sal/osl/w32/conditn.cxx (renamed from sal/osl/w32/conditn.c) | 20 | ||||
-rw-r--r-- | sal/osl/w32/dllentry.c | 6 | ||||
-rw-r--r-- | sal/osl/w32/file_error.cxx (renamed from sal/osl/w32/file_error.c) | 0 | ||||
-rw-r--r-- | sal/osl/w32/gmutex.h | 39 | ||||
-rw-r--r-- | sal/osl/w32/interlck.cxx (renamed from sal/osl/w32/interlck.c) | 0 | ||||
-rw-r--r-- | sal/osl/w32/memory.cxx (renamed from sal/osl/w32/memory.c) | 0 | ||||
-rw-r--r-- | sal/osl/w32/mutex.cxx (renamed from sal/osl/w32/mutex.c) | 21 | ||||
-rw-r--r-- | sal/osl/w32/nlsupport.cxx (renamed from sal/osl/w32/nlsupport.c) | 6 | ||||
-rw-r--r-- | sal/osl/w32/pipe.cxx (renamed from sal/osl/w32/pipe.c) | 70 | ||||
-rw-r--r-- | sal/osl/w32/random.cxx (renamed from sal/osl/w32/random.c) | 8 | ||||
-rw-r--r-- | sal/osl/w32/security.cxx (renamed from sal/osl/w32/security.c) | 276 | ||||
-rw-r--r-- | sal/osl/w32/thread.cxx (renamed from sal/osl/w32/thread.c) | 100 | ||||
-rw-r--r-- | sal/osl/w32/thread.h | 2 | ||||
-rw-r--r-- | sal/osl/w32/time.cxx (renamed from sal/osl/w32/time.c) | 30 |
16 files changed, 325 insertions, 279 deletions
diff --git a/sal/Library_sal.mk b/sal/Library_sal.mk index ac254d167751..e5585b9bca32 100644 --- a/sal/Library_sal.mk +++ b/sal/Library_sal.mk @@ -225,32 +225,32 @@ else # $(OS) == WNT $(eval $(call gb_Library_add_exception_objects,sal,\ sal/osl/w32/backtrace \ + sal/osl/w32/conditn \ sal/osl/w32/file \ sal/osl/w32/file_dirvol \ + sal/osl/w32/file_error \ sal/osl/w32/file_url \ + sal/osl/w32/interlck \ + sal/osl/w32/memory \ sal/osl/w32/module \ + sal/osl/w32/mutex \ + sal/osl/w32/nlsupport \ sal/osl/w32/path_helper \ + sal/osl/w32/pipe \ sal/osl/w32/process \ sal/osl/w32/procimpl \ sal/osl/w32/profile \ + sal/osl/w32/random \ sal/osl/w32/salinit \ + sal/osl/w32/security \ sal/osl/w32/signal \ sal/osl/w32/socket \ sal/osl/w32/tempfile \ + sal/osl/w32/thread \ + sal/osl/w32/time \ )) $(eval $(call gb_Library_add_cobjects,sal,\ - sal/osl/w32/conditn \ sal/osl/w32/dllentry \ - sal/osl/w32/file_error \ - sal/osl/w32/interlck \ - sal/osl/w32/memory \ - sal/osl/w32/mutex \ - sal/osl/w32/nlsupport \ - sal/osl/w32/pipe \ - sal/osl/w32/random \ - sal/osl/w32/security \ - sal/osl/w32/thread \ - sal/osl/w32/time \ )) endif # ifneq ($(OS),WNT) diff --git a/sal/inc/pch/precompiled_sal.hxx b/sal/inc/pch/precompiled_sal.hxx index 5f94a26f429e..8699e20ce1e1 100644 --- a/sal/inc/pch/precompiled_sal.hxx +++ b/sal/inc/pch/precompiled_sal.hxx @@ -20,6 +20,10 @@ ./bin/update_pch_bisect ./sal/inc/pch/precompiled_sal.hxx "make sal.build" --find-conflicts */ +#if !defined _CRT_RAND_S +#define _CRT_RAND_S +#endif + #include <algorithm> #include <cassert> #include <cstddef> diff --git a/sal/osl/w32/conditn.c b/sal/osl/w32/conditn.cxx index 6f90e50672f0..a6a54961764a 100644 --- a/sal/osl/w32/conditn.c +++ b/sal/osl/w32/conditn.cxx @@ -35,10 +35,10 @@ oslCondition SAL_CALL osl_createCondition(void) { oslCondition Condition; - Condition= (oslCondition)CreateEvent(NULL, /* no security */ - sal_True, /* manual reset */ - sal_False, /* initial state not signaled */ - NULL); /* automatic name */ + Condition= reinterpret_cast<oslCondition>(CreateEvent(nullptr, /* no security */ + true, /* manual reset */ + false, /* initial state not signaled */ + nullptr)); /* automatic name */ return Condition; @@ -62,7 +62,7 @@ sal_Bool SAL_CALL osl_setCondition(oslCondition Condition) { OSL_ASSERT(Condition); - return (sal_Bool)(SetEvent((HANDLE)Condition) != FALSE); + return SetEvent(reinterpret_cast<HANDLE>(Condition)) != FALSE; } /*****************************************************************************/ @@ -72,7 +72,7 @@ sal_Bool SAL_CALL osl_resetCondition(oslCondition Condition) { OSL_ASSERT(Condition); - return (sal_Bool)(ResetEvent((HANDLE)Condition) != FALSE); + return ResetEvent(reinterpret_cast<HANDLE>(Condition)) != FALSE; } /*****************************************************************************/ @@ -93,10 +93,10 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, /* It's necessary to process SendMessage calls to the current thread to give other threads access to COM objects instantiated in this thread */ - while ( 1 ) + while ( true ) { /* 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, reinterpret_cast<HANDLE *>(&Condition), FALSE, timeout, QS_SENDMESSAGE ) ) { case WAIT_OBJECT_0 + 1: { @@ -105,7 +105,7 @@ oslConditionResult SAL_CALL osl_waitCondition(oslCondition Condition, /* We Must not dispatch the message. PM_NOREMOVE leaves the message queue untouched but dispatches SendMessage calls automatically */ - PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ); + PeekMessage( &msg, nullptr, 0, 0, PM_NOREMOVE ); } break; @@ -128,7 +128,7 @@ sal_Bool SAL_CALL osl_checkCondition(oslCondition Condition) { OSL_ASSERT(Condition); - return (sal_Bool)(WaitForSingleObject((HANDLE)Condition, 0) == WAIT_OBJECT_0); + return WaitForSingleObject(reinterpret_cast<HANDLE>(Condition), 0) == WAIT_OBJECT_0; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/w32/dllentry.c b/sal/osl/w32/dllentry.c index 670592b3a600..6cb8669a455f 100644 --- a/sal/osl/w32/dllentry.c +++ b/sal/osl/w32/dllentry.c @@ -38,15 +38,11 @@ #include <osl/thread.h> #include "file_url.h" +#include "gmutex.h" #include "rtllifecycle.h" #include <thread.h> -// externals - -extern CRITICAL_SECTION g_ThreadKeyListCS; -extern oslMutex g_Mutex; - /* This is needed because DllMain is called after static constructors. A DLL's startup and shutdown sequence looks like this: diff --git a/sal/osl/w32/file_error.c b/sal/osl/w32/file_error.cxx index cdb8571ab97d..cdb8571ab97d 100644 --- a/sal/osl/w32/file_error.c +++ b/sal/osl/w32/file_error.cxx diff --git a/sal/osl/w32/gmutex.h b/sal/osl/w32/gmutex.h new file mode 100644 index 000000000000..cb7e27e37258 --- /dev/null +++ b/sal/osl/w32/gmutex.h @@ -0,0 +1,39 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SAL_OSL_W32_GMUTEX_H +#define INCLUDED_SAL_OSL_W32_GMUTEX_H + +#include <sal/config.h> + +#include <osl/mutex.h> + +#if defined __cplusplus +extern "C" { +#endif + +extern oslMutex g_Mutex; + +#if defined __cplusplus +} +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sal/osl/w32/interlck.c b/sal/osl/w32/interlck.cxx index 68c9504763a1..68c9504763a1 100644 --- a/sal/osl/w32/interlck.c +++ b/sal/osl/w32/interlck.cxx diff --git a/sal/osl/w32/memory.c b/sal/osl/w32/memory.cxx index 1f1a5b516ff0..1f1a5b516ff0 100644 --- a/sal/osl/w32/memory.c +++ b/sal/osl/w32/memory.cxx diff --git a/sal/osl/w32/mutex.c b/sal/osl/w32/mutex.cxx index f9ce1c0e3a8a..b436f95972d9 100644 --- a/sal/osl/w32/mutex.c +++ b/sal/osl/w32/mutex.cxx @@ -17,6 +17,9 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <sal/config.h> + +#include "gmutex.h" #include "system.h" #include <osl/mutex.h> @@ -35,13 +38,13 @@ oslMutex SAL_CALL osl_createMutex(void) { CRITICAL_SECTION *pMutexImpl; - pMutexImpl = calloc(sizeof(CRITICAL_SECTION), 1); + pMutexImpl = static_cast<CRITICAL_SECTION *>(calloc(sizeof(CRITICAL_SECTION), 1)); OSL_ASSERT(pMutexImpl); /* alloc successful? */ InitializeCriticalSection(pMutexImpl); - return (oslMutex)pMutexImpl; + return reinterpret_cast<oslMutex>(pMutexImpl); } /*****************************************************************************/ @@ -49,7 +52,7 @@ oslMutex SAL_CALL osl_createMutex(void) /*****************************************************************************/ void SAL_CALL osl_destroyMutex(oslMutex Mutex) { - CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex; + CRITICAL_SECTION *pMutexImpl = reinterpret_cast<CRITICAL_SECTION *>(Mutex); if (pMutexImpl) { @@ -63,13 +66,13 @@ void SAL_CALL osl_destroyMutex(oslMutex Mutex) /*****************************************************************************/ sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex) { - CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex; + CRITICAL_SECTION *pMutexImpl = reinterpret_cast<CRITICAL_SECTION *>(Mutex); OSL_ASSERT(Mutex); EnterCriticalSection(pMutexImpl); - return sal_True; + return true; } /*****************************************************************************/ @@ -77,11 +80,11 @@ sal_Bool SAL_CALL osl_acquireMutex(oslMutex Mutex) /*****************************************************************************/ sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex) { - CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex; + CRITICAL_SECTION *pMutexImpl = reinterpret_cast<CRITICAL_SECTION *>(Mutex); OSL_ASSERT(Mutex); - return (sal_Bool)(TryEnterCriticalSection(pMutexImpl) != FALSE); + return TryEnterCriticalSection(pMutexImpl) != FALSE; } /*****************************************************************************/ @@ -89,13 +92,13 @@ sal_Bool SAL_CALL osl_tryToAcquireMutex(oslMutex Mutex) /*****************************************************************************/ sal_Bool SAL_CALL osl_releaseMutex(oslMutex Mutex) { - CRITICAL_SECTION *pMutexImpl = (CRITICAL_SECTION *)Mutex; + CRITICAL_SECTION *pMutexImpl = reinterpret_cast<CRITICAL_SECTION *>(Mutex); OSL_ASSERT(Mutex); LeaveCriticalSection(pMutexImpl); - return sal_True; + return true; } /*****************************************************************************/ diff --git a/sal/osl/w32/nlsupport.c b/sal/osl/w32/nlsupport.cxx index afee1593dd09..16328da54097 100644 --- a/sal/osl/w32/nlsupport.c +++ b/sal/osl/w32/nlsupport.cxx @@ -79,8 +79,8 @@ BOOL CALLBACK EnumLocalesProcA( LPSTR lpLocaleStringA ) localeId = strtol( lpLocaleStringA, &pszEndA, 16 ); /* check params received via TLS */ - params = (struct EnumLocalesParams *) TlsGetValue( g_dwTLSLocaleEncId ); - if( NULL == params || '\0' == params->Language[0] ) + params = static_cast<struct EnumLocalesParams *>(TlsGetValue( g_dwTLSLocaleEncId )); + if( nullptr == params || '\0' == params->Language[0] ) return FALSE; /* @@ -183,7 +183,7 @@ rtl_TextEncoding SAL_CALL osl_getTextEncodingFromLocale( rtl_Locale * pLocale ) } /* if pLocale is NULL, use process locale as default */ - if( NULL == pLocale ) + if( nullptr == pLocale ) osl_getProcessLocale( &pLocale ); /* copy in parameters to structure */ diff --git a/sal/osl/w32/pipe.c b/sal/osl/w32/pipe.cxx index 7693a25b6196..532e931e4f21 100644 --- a/sal/osl/w32/pipe.c +++ b/sal/osl/w32/pipe.cxx @@ -57,7 +57,7 @@ struct oslPipeImpl { HANDLE m_AcceptEvent; rtl_uString* m_Name; oslPipeError m_Error; - sal_Bool m_bClosed; + bool m_bClosed; }; /*****************************************************************************/ @@ -68,29 +68,29 @@ oslPipe osl_createPipeImpl(void) { oslPipe pPipe; - pPipe = (oslPipe) rtl_allocateZeroMemory(sizeof(struct oslPipeImpl)); + pPipe = static_cast<oslPipe>(rtl_allocateZeroMemory(sizeof(struct oslPipeImpl))); - pPipe->m_bClosed = sal_False; + pPipe->m_bClosed = false; pPipe->m_Reference = 0; - pPipe->m_Name = NULL; + pPipe->m_Name = nullptr; pPipe->m_File = INVALID_HANDLE_VALUE; pPipe->m_NamedObject = INVALID_HANDLE_VALUE; - pPipe->m_ReadEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - pPipe->m_WriteEvent = CreateEvent(NULL, TRUE, FALSE, NULL); - pPipe->m_AcceptEvent = CreateEvent(NULL, TRUE, FALSE, NULL); + pPipe->m_ReadEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); + pPipe->m_WriteEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); + pPipe->m_AcceptEvent = CreateEvent(nullptr, TRUE, FALSE, nullptr); return pPipe; } void osl_destroyPipeImpl(oslPipe pPipe) { - if (pPipe != NULL) + if (pPipe != nullptr) { - if ( pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != NULL ) + if ( pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != nullptr ) CloseHandle( pPipe->m_NamedObject ); - if (pPipe->m_Security != NULL) + if (pPipe->m_Security != nullptr) { rtl_freeMemory(pPipe->m_Security->lpSecurityDescriptor); rtl_freeMemory(pPipe->m_Security); @@ -113,20 +113,20 @@ void osl_destroyPipeImpl(oslPipe pPipe) oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options, oslSecurity Security) { - rtl_uString* name = NULL; - rtl_uString* path = NULL; - rtl_uString* temp = NULL; + rtl_uString* name = nullptr; + rtl_uString* path = nullptr; + rtl_uString* temp = nullptr; oslPipe pPipe; - PSECURITY_ATTRIBUTES pSecAttr = NULL; + PSECURITY_ATTRIBUTES pSecAttr = nullptr; rtl_uString_newFromAscii(&path, PIPESYSTEM); rtl_uString_newFromAscii(&name, PIPEPREFIX); if ( Security) { - rtl_uString *Ident = NULL; - rtl_uString *Delim = NULL; + rtl_uString *Ident = nullptr; + rtl_uString *Delim = nullptr; OSL_VERIFY(osl_getUserIdent(Security, &Ident)); rtl_uString_newFromAscii(&Delim, "_"); @@ -143,13 +143,13 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options { PSECURITY_DESCRIPTOR pSecDesc; - pSecDesc = (PSECURITY_DESCRIPTOR) rtl_allocateMemory(SECURITY_DESCRIPTOR_MIN_LENGTH); + pSecDesc = static_cast<PSECURITY_DESCRIPTOR>(rtl_allocateMemory(SECURITY_DESCRIPTOR_MIN_LENGTH)); /* add a NULL disc. ACL to the security descriptor */ OSL_VERIFY(InitializeSecurityDescriptor(pSecDesc, SECURITY_DESCRIPTOR_REVISION)); - OSL_VERIFY(SetSecurityDescriptorDacl(pSecDesc, TRUE, (PACL) NULL, FALSE)); + OSL_VERIFY(SetSecurityDescriptorDacl(pSecDesc, TRUE, nullptr, FALSE)); - pSecAttr = rtl_allocateMemory(sizeof(SECURITY_ATTRIBUTES)); + pSecAttr = static_cast<PSECURITY_ATTRIBUTES>(rtl_allocateMemory(sizeof(SECURITY_ATTRIBUTES))); pSecAttr->nLength = sizeof(SECURITY_ATTRIBUTES); pSecAttr->lpSecurityDescriptor = pSecDesc; pSecAttr->bInheritHandle = TRUE; @@ -167,15 +167,15 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options rtl_uString_assign(&temp, path); rtl_uString_newConcat(&path, temp, name); rtl_uString_release(temp); - temp = NULL; + temp = nullptr; if (Options & osl_Pipe_CREATE) { SetLastError( ERROR_SUCCESS ); - pPipe->m_NamedObject = CreateMutexW( NULL, FALSE, name->buffer ); + pPipe->m_NamedObject = CreateMutexW( nullptr, FALSE, name->buffer ); - if ( pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != NULL ) + if ( pPipe->m_NamedObject != INVALID_HANDLE_VALUE && pPipe->m_NamedObject != nullptr ) { if ( GetLastError() != ERROR_ALREADY_EXISTS ) { @@ -223,10 +223,10 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options path->buffer, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, - NULL, + nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED, - NULL); + nullptr); if ( pPipe->m_File != INVALID_HANDLE_VALUE ) { @@ -247,7 +247,7 @@ oslPipe SAL_CALL osl_createPipe(rtl_uString *strPipeName, oslPipeOptions Options /* if we reach here something went wrong */ osl_destroyPipeImpl(pPipe); - return NULL; + return nullptr; } void SAL_CALL osl_acquirePipe( oslPipe pPipe ) @@ -259,7 +259,7 @@ void SAL_CALL osl_releasePipe( oslPipe pPipe ) { // OSL_ASSERT( pPipe ); - if( NULL == pPipe ) + if( nullptr == pPipe ) return; if( 0 == osl_atomic_decrement( &(pPipe->m_Reference) ) ) @@ -275,7 +275,7 @@ void SAL_CALL osl_closePipe( oslPipe pPipe ) { if( pPipe && ! pPipe->m_bClosed ) { - pPipe->m_bClosed = sal_True; + pPipe->m_bClosed = true; /* if we have a system pipe close it */ if (pPipe->m_File != INVALID_HANDLE_VALUE) { @@ -291,13 +291,13 @@ void SAL_CALL osl_closePipe( oslPipe pPipe ) /*****************************************************************************/ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe) { - oslPipe pAcceptedPipe = NULL; + oslPipe pAcceptedPipe = nullptr; OVERLAPPED os; DWORD nBytesTransfered; - rtl_uString* path = NULL; - rtl_uString* temp = NULL; + rtl_uString* path = nullptr; + rtl_uString* temp = nullptr; OSL_ASSERT(pPipe); OSL_ASSERT(pPipe->m_File != INVALID_HANDLE_VALUE); @@ -331,12 +331,12 @@ oslPipe SAL_CALL osl_acceptPipe(oslPipe pPipe) break; // Everything's fine !!! default: // Something went wrong - return NULL; + return nullptr; } } break; default: // All other error say that somethings going wrong. - return NULL; + return nullptr; } } @@ -456,7 +456,7 @@ sal_Int32 SAL_CALL osl_writePipe( oslPipe pPipe, const void *pBuffer , sal_Int32 BytesToSend -= RetVal; BytesSend += RetVal; - pBuffer= (sal_Char*)pBuffer + RetVal; + pBuffer= static_cast<sal_Char const *>(pBuffer) + RetVal; } return BytesSend; @@ -482,7 +482,7 @@ sal_Int32 SAL_CALL osl_readPipe( oslPipe pPipe, void *pBuffer , sal_Int32 n ) BytesToRead -= RetVal; BytesRead += RetVal; - pBuffer= (sal_Char*)pBuffer + RetVal; + pBuffer= static_cast<sal_Char*>(pBuffer) + RetVal; } return BytesRead; } @@ -494,7 +494,7 @@ oslPipeError SAL_CALL osl_getLastPipeError(oslPipe pPipe) { oslPipeError Error; - if (pPipe != NULL) + if (pPipe != nullptr) { Error = pPipe->m_Error; pPipe->m_Error = osl_Pipe_E_None; diff --git a/sal/osl/w32/random.c b/sal/osl/w32/random.cxx index d394f19a03af..ce495a8e3dc4 100644 --- a/sal/osl/w32/random.c +++ b/sal/osl/w32/random.cxx @@ -14,14 +14,16 @@ #include <stdlib.h> #include <memory.h> +#include <oslrandom.h> + int osl_get_system_random_data(char* buffer, size_t desired_len) { unsigned int val; /* if unaligned fill to alignment */ - if((uintptr_t)buffer & 3) + if(reinterpret_cast<uintptr_t>(buffer) & 3) { - size_t len = 4 - ((size_t)(buffer) & 3); + size_t len = 4 - (reinterpret_cast<size_t>(buffer) & 3); if(len > desired_len) { @@ -38,7 +40,7 @@ int osl_get_system_random_data(char* buffer, size_t desired_len) /* fill directly into the buffer as long as we can */ while(desired_len >= 4) { - if(rand_s((unsigned int*)buffer)) + if(rand_s(reinterpret_cast<unsigned int*>(buffer))) { return 0; } diff --git a/sal/osl/w32/security.c b/sal/osl/w32/security.cxx index d4dad55ade84..4406bfb8da26 100644 --- a/sal/osl/w32/security.c +++ b/sal/osl/w32/security.cxx @@ -73,9 +73,9 @@ typedef BOOL (STDMETHODCALLTYPE FAR * LPFNGETUSERPROFILEDIR) ( /* Static Module Function Declarations */ /*****************************************************************************/ -static sal_Bool GetSpecialFolder(rtl_uString **strPath,int nFolder); +static bool GetSpecialFolder(rtl_uString **strPath,int nFolder); static BOOL Privilege(LPTSTR pszPrivilege, BOOL bEnable); -static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, sal_Bool bIncludeDomain); +static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, bool bIncludeDomain); /*****************************************************************************/ /* Exported Module Functions */ @@ -83,14 +83,14 @@ static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **str oslSecurity SAL_CALL osl_getCurrentSecurity(void) { - oslSecurityImpl* pSecImpl = malloc(sizeof(oslSecurityImpl)); + oslSecurityImpl* pSecImpl = static_cast<oslSecurityImpl *>(malloc(sizeof(oslSecurityImpl))); - pSecImpl->m_pNetResource = NULL; + pSecImpl->m_pNetResource = nullptr; pSecImpl->m_User[0] = '\0'; - pSecImpl->m_hToken = NULL; - pSecImpl->m_hProfile = NULL; + pSecImpl->m_hToken = nullptr; + pSecImpl->m_hProfile = nullptr; - return (oslSecurity)pSecImpl; + return pSecImpl; } oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString *strPasswd, oslSecurity *pSecurity ) @@ -102,30 +102,30 @@ oslSecurityError SAL_CALL osl_loginUser( rtl_uString *strUserName, rtl_uString * HANDLE hUserToken; LUID luid; - if (NULL != (strUser = wcschr(strDomain, L'/'))) + if (nullptr != (strUser = wcschr(strDomain, L'/'))) *strUser++ = L'\0'; else { strUser = strDomain; - strDomain = NULL; + strDomain = nullptr; } // this process must have the right: 'act as a part of operatingsystem' - OSL_ASSERT(LookupPrivilegeValue(NULL, SE_TCB_NAME, &luid)); + OSL_ASSERT(LookupPrivilegeValue(nullptr, SE_TCB_NAME, &luid)); (void) luid; if (LogonUserW(strUser, strDomain ? strDomain : L"", rtl_uString_getStr(strPasswd), LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, &hUserToken)) { - oslSecurityImpl* pSecImpl = malloc(sizeof(oslSecurityImpl)); + oslSecurityImpl* pSecImpl = static_cast<oslSecurityImpl *>(malloc(sizeof(oslSecurityImpl))); - pSecImpl->m_pNetResource = NULL; + pSecImpl->m_pNetResource = nullptr; pSecImpl->m_hToken = hUserToken; - pSecImpl->m_hProfile = NULL; + pSecImpl->m_hProfile = nullptr; wcscpy(pSecImpl->m_User, strUser); - *pSecurity = (oslSecurity)pSecImpl; + *pSecurity = pSecImpl; ret = osl_Security_E_None; } else @@ -150,8 +150,8 @@ oslSecurityError SAL_CALL osl_loginUserOnFileServer(rtl_uString *strUserName, sal_Unicode* remoteName; sal_Unicode* userName; - remoteName = malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 4) * sizeof(sal_Unicode)); - userName = malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 2) * sizeof(sal_Unicode)); + remoteName = static_cast<sal_Unicode *>(malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 4) * sizeof(sal_Unicode))); + userName = static_cast<sal_Unicode *>(malloc((rtl_uString_getLength(strFileServer) + rtl_uString_getLength(strUserName) + 2) * sizeof(sal_Unicode))); wcscpy(remoteName, L"\\\\"); wcscat(remoteName, rtl_uString_getStr(strFileServer)); @@ -166,25 +166,25 @@ oslSecurityError SAL_CALL osl_loginUserOnFileServer(rtl_uString *strUserName, netResource.dwType = RESOURCETYPE_DISK; netResource.dwDisplayType = RESOURCEDISPLAYTYPE_SHARE; netResource.dwUsage = RESOURCEUSAGE_CONNECTABLE; - netResource.lpLocalName = NULL; + netResource.lpLocalName = nullptr; netResource.lpRemoteName = remoteName; - netResource.lpComment = NULL; - netResource.lpProvider = NULL; + netResource.lpComment = nullptr; + netResource.lpProvider = nullptr; err = WNetAddConnection2W(&netResource, rtl_uString_getStr(strPasswd), userName, 0); if ((err == NO_ERROR) || (err == ERROR_ALREADY_ASSIGNED)) { - oslSecurityImpl* pSecImpl = malloc(sizeof(oslSecurityImpl)); + oslSecurityImpl* pSecImpl = static_cast<oslSecurityImpl *>(malloc(sizeof(oslSecurityImpl))); - pSecImpl->m_pNetResource = malloc(sizeof(NETRESOURCE)); + pSecImpl->m_pNetResource = static_cast<NETRESOURCEW *>(malloc(sizeof(NETRESOURCE))); *pSecImpl->m_pNetResource = netResource; - pSecImpl->m_hToken = NULL; - pSecImpl->m_hProfile = NULL; + pSecImpl->m_hToken = nullptr; + pSecImpl->m_hProfile = nullptr; wcscpy(pSecImpl->m_User, rtl_uString_getStr(strUserName)); - *pSecurity = (oslSecurity)pSecImpl; + *pSecurity = pSecImpl; ret = osl_Security_E_None; } @@ -201,8 +201,8 @@ static BOOL WINAPI CheckTokenMembership_Stub( HANDLE TokenHandle, PSID SidToChec { typedef BOOL (WINAPI *CheckTokenMembership_PROC)( HANDLE, PSID, PBOOL ); - static HMODULE hModule = NULL; - static CheckTokenMembership_PROC pCheckTokenMembership = NULL; + static HMODULE hModule = nullptr; + static CheckTokenMembership_PROC pCheckTokenMembership = nullptr; if ( !hModule ) { @@ -210,7 +210,7 @@ static BOOL WINAPI CheckTokenMembership_Stub( HANDLE TokenHandle, PSID SidToChec hModule = GetModuleHandleA( "ADVAPI32.DLL" ); - pCheckTokenMembership = (CheckTokenMembership_PROC)GetProcAddress( hModule, "CheckTokenMembership" ); + pCheckTokenMembership = reinterpret_cast<CheckTokenMembership_PROC>(GetProcAddress( hModule, "CheckTokenMembership" )); } if ( pCheckTokenMembership ) @@ -225,22 +225,22 @@ static BOOL WINAPI CheckTokenMembership_Stub( HANDLE TokenHandle, PSID SidToChec sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security) { - if (Security != NULL) + if (Security != nullptr) { - HANDLE hImpersonationToken = NULL; + HANDLE hImpersonationToken = nullptr; PSID psidAdministrators; SID_IDENTIFIER_AUTHORITY siaNtAuthority = { SECURITY_NT_AUTHORITY }; - sal_Bool bSuccess = sal_False; + bool bSuccess = false; /* If Security contains an access token we need to duplicate it to an impersonation access token. NULL works with CheckTokenMembership() as the current effective impersonation token */ - if ( ((oslSecurityImpl*)Security)->m_hToken ) + if ( static_cast<oslSecurityImpl*>(Security)->m_hToken ) { - if ( !DuplicateToken (((oslSecurityImpl*)Security)->m_hToken, SecurityImpersonation, &hImpersonationToken) ) - return sal_False; + if ( !DuplicateToken (static_cast<oslSecurityImpl*>(Security)->m_hToken, SecurityImpersonation, &hImpersonationToken) ) + return false; } /* CheckTokenMembership() can be used on W2K and higher (NT4 no longer supported by OOo) @@ -259,7 +259,7 @@ sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security) BOOL fSuccess = FALSE; if ( CheckTokenMembership_Stub( hImpersonationToken, psidAdministrators, &fSuccess ) && fSuccess ) - bSuccess = sal_True; + bSuccess = true; FreeSid(psidAdministrators); } @@ -270,18 +270,18 @@ sal_Bool SAL_CALL osl_isAdministrator(oslSecurity Security) return bSuccess; } else - return sal_False; + return false; } void SAL_CALL osl_freeSecurityHandle(oslSecurity Security) { if (Security) { - oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; + oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl*>(Security); - if (pSecImpl->m_pNetResource != NULL) + if (pSecImpl->m_pNetResource != nullptr) { - WNetCancelConnection2W(pSecImpl->m_pNetResource->lpRemoteName, 0, sal_True); + WNetCancelConnection2W(pSecImpl->m_pNetResource->lpRemoteName, 0, true); free(pSecImpl->m_pNetResource->lpRemoteName); free(pSecImpl->m_pNetResource); @@ -299,40 +299,40 @@ void SAL_CALL osl_freeSecurityHandle(oslSecurity Security) sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) { - if (Security != NULL) + if (Security != nullptr) { - oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; + oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl*>(Security); HANDLE hAccessToken = pSecImpl->m_hToken; - if (hAccessToken == NULL) + if (hAccessToken == nullptr) OpenProcessToken(GetCurrentProcess(), TOKEN_DUP_QUERY, &hAccessToken); if (hAccessToken) { sal_Char *Ident; DWORD nInfoBuffer = 512; - UCHAR* pInfoBuffer = malloc(nInfoBuffer); + UCHAR* pInfoBuffer = static_cast<UCHAR *>(malloc(nInfoBuffer)); while (!GetTokenInformation(hAccessToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); + pInfoBuffer = static_cast<UCHAR *>(realloc(pInfoBuffer, nInfoBuffer)); else { free(pInfoBuffer); - pInfoBuffer = NULL; + pInfoBuffer = nullptr; break; } } - if (pSecImpl->m_hToken == NULL) + if (pSecImpl->m_hToken == nullptr) CloseHandle(hAccessToken); if (pInfoBuffer) { - PSID pSid = ((PTOKEN_USER)pInfoBuffer)->User.Sid; + PSID pSid = reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid; PSID_IDENTIFIER_AUTHORITY psia; DWORD dwSubAuthorities; DWORD dwSidRev=SID_REVISION; @@ -348,7 +348,7 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) dwSubAuthorities = (*pSSACount < 5) ? *pSSACount : 5; /* buffer length: S-SID_REVISION- + identifierauthority- + subauthorities- + NULL */ - Ident=malloc(88*sizeof(sal_Char)); + Ident=static_cast<sal_Char *>(malloc(88*sizeof(sal_Char))); /* prepare S-SID_REVISION- */ dwSidSize=wsprintf(Ident, TEXT("S-%lu-"), dwSidRev); @@ -387,7 +387,7 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) free(pInfoBuffer); free(Ident); - return sal_True; + return true; } } else @@ -395,14 +395,14 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) DWORD needed=0; sal_Unicode *Ident; - WNetGetUserA(NULL, NULL, &needed); + WNetGetUserA(nullptr, nullptr, &needed); if (needed < 16) { needed = 16; } - Ident=malloc(needed*sizeof(sal_Unicode)); + Ident=static_cast<sal_Unicode *>(malloc(needed*sizeof(sal_Unicode))); - if (WNetGetUserW(NULL, Ident, &needed) != NO_ERROR) + if (WNetGetUserW(nullptr, Ident, &needed) != NO_ERROR) { wcscpy(Ident, L"unknown"); Ident[7] = L'\0'; @@ -412,42 +412,42 @@ sal_Bool SAL_CALL osl_getUserIdent(oslSecurity Security, rtl_uString **strIdent) free(Ident); - return sal_True; + return true; } } - return sal_False; + return false; } sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **strName) { - return getUserNameImpl(Security, strName, sal_True); + return getUserNameImpl(Security, strName, true); } sal_Bool SAL_CALL osl_getShortUserName(oslSecurity Security, rtl_uString **strName) { - return getUserNameImpl(Security, strName, sal_False); + return getUserNameImpl(Security, strName, false); } sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirectory) { - rtl_uString *ustrSysDir = NULL; - sal_Bool bSuccess = sal_False; + rtl_uString *ustrSysDir = nullptr; + bool bSuccess = false; - if (Security != NULL) + if (Security != nullptr) { - oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; + oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl*>(Security); - if (pSecImpl->m_pNetResource != NULL) + if (pSecImpl->m_pNetResource != nullptr) { rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); - bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory )); + bSuccess = osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory ); } else { - bSuccess = (sal_Bool)(GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && - (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory))); + bSuccess = GetSpecialFolder(&ustrSysDir, CSIDL_PERSONAL) && + (osl_File_E_None == osl_getFileURLFromSystemPath(ustrSysDir, pustrDirectory)); } } @@ -459,18 +459,18 @@ sal_Bool SAL_CALL osl_getHomeDir(oslSecurity Security, rtl_uString **pustrDirect sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDirectory) { - sal_Bool bSuccess = sal_False; + bool bSuccess = false; - if (Security != NULL) + if (Security != nullptr) { - oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; + oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl*>(Security); - if (pSecImpl->m_pNetResource != NULL) + if (pSecImpl->m_pNetResource != nullptr) { - rtl_uString *ustrSysDir = NULL; + rtl_uString *ustrSysDir = nullptr; rtl_uString_newFromStr( &ustrSysDir, pSecImpl->m_pNetResource->lpRemoteName); - bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory)); + bSuccess = osl_File_E_None == osl_getFileURLFromSystemPath( ustrSysDir, pustrDirectory); if ( ustrSysDir ) rtl_uString_release( ustrSysDir ); @@ -480,11 +480,11 @@ sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDire if (pSecImpl->m_hToken) { /* not implemented */ - OSL_ASSERT(sal_False); + OSL_ASSERT(false); } else { - rtl_uString *ustrFile = NULL; + rtl_uString *ustrFile = nullptr; sal_Unicode sFile[_MAX_PATH]; if ( !GetSpecialFolder( &ustrFile, CSIDL_APPDATA) ) @@ -494,7 +494,7 @@ sal_Bool SAL_CALL osl_getConfigDir(oslSecurity Security, rtl_uString **pustrDire rtl_uString_newFromStr( &ustrFile, sFile); } - bSuccess = (sal_Bool)(osl_File_E_None == osl_getFileURLFromSystemPath(ustrFile, pustrDirectory)); + bSuccess = osl_File_E_None == osl_getFileURLFromSystemPath(ustrFile, pustrDirectory); if ( ustrFile ) rtl_uString_release( ustrFile ); @@ -514,16 +514,16 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) It is your responsibility to load the user's registry hive into HKEY_USERS with the LoadUserProfile function before calling CreateProcessAsUser. */ - BOOL bOk = FALSE; + bool bOk = false; RegCloseKey(HKEY_CURRENT_USER); - if (Privilege(SE_RESTORE_NAME, TRUE)) + if (Privilege(const_cast<char *>(SE_RESTORE_NAME), TRUE)) { - HMODULE hUserEnvLib = NULL; - LPFNLOADUSERPROFILE fLoadUserProfile = NULL; - LPFNUNLOADUSERPROFILE fUnloadUserProfile = NULL; - HANDLE hAccessToken = ((oslSecurityImpl*)Security)->m_hToken; + HMODULE hUserEnvLib = nullptr; + LPFNLOADUSERPROFILE fLoadUserProfile = nullptr; + LPFNUNLOADUSERPROFILE fUnloadUserProfile = nullptr; + HANDLE hAccessToken = static_cast<oslSecurityImpl*>(Security)->m_hToken; /* try to create user profile */ if ( !hAccessToken ) @@ -532,7 +532,7 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) */ HANDLE hProcess = GetCurrentProcess(); - if (hProcess != NULL) + if (hProcess != nullptr) { OpenProcessToken(hProcess, TOKEN_IMPERSONATE, &hAccessToken); CloseHandle(hProcess); @@ -543,15 +543,15 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) if (hUserEnvLib) { - fLoadUserProfile = (LPFNLOADUSERPROFILE)GetProcAddress(hUserEnvLib, "LoadUserProfileW"); - fUnloadUserProfile = (LPFNUNLOADUSERPROFILE)GetProcAddress(hUserEnvLib, "UnloadUserProfile"); + fLoadUserProfile = reinterpret_cast<LPFNLOADUSERPROFILE>(GetProcAddress(hUserEnvLib, "LoadUserProfileW")); + fUnloadUserProfile = reinterpret_cast<LPFNUNLOADUSERPROFILE>(GetProcAddress(hUserEnvLib, "UnloadUserProfile")); if (fLoadUserProfile && fUnloadUserProfile) { - rtl_uString *buffer = NULL; + rtl_uString *buffer = nullptr; PROFILEINFOW pi; - getUserNameImpl(Security, &buffer, sal_False); + getUserNameImpl(Security, &buffer, false); ZeroMemory( &pi, sizeof(pi) ); pi.dwSize = sizeof(pi); @@ -562,7 +562,7 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) { fUnloadUserProfile(hAccessToken, pi.hProfile); - bOk = TRUE; + bOk = true; } rtl_uString_release(buffer); @@ -571,21 +571,21 @@ sal_Bool SAL_CALL osl_loadUserProfile(oslSecurity Security) FreeLibrary(hUserEnvLib); } - if (hAccessToken && (hAccessToken != ((oslSecurityImpl*)Security)->m_hToken)) + if (hAccessToken && (hAccessToken != static_cast<oslSecurityImpl*>(Security)->m_hToken)) CloseHandle(hAccessToken); } - return (sal_Bool)bOk; + return bOk; } void SAL_CALL osl_unloadUserProfile(oslSecurity Security) { - if ( ((oslSecurityImpl*)Security)->m_hProfile != NULL ) + if ( static_cast<oslSecurityImpl*>(Security)->m_hProfile != nullptr ) { - HMODULE hUserEnvLib = NULL; - LPFNLOADUSERPROFILE fLoadUserProfile = NULL; - LPFNUNLOADUSERPROFILE fUnloadUserProfile = NULL; - HANDLE hAccessToken = ((oslSecurityImpl*)Security)->m_hToken; + HMODULE hUserEnvLib = nullptr; + LPFNLOADUSERPROFILE fLoadUserProfile = nullptr; + LPFNUNLOADUSERPROFILE fUnloadUserProfile = nullptr; + HANDLE hAccessToken = static_cast<oslSecurityImpl*>(Security)->m_hToken; if ( !hAccessToken ) { @@ -593,7 +593,7 @@ void SAL_CALL osl_unloadUserProfile(oslSecurity Security) */ HANDLE hProcess = GetCurrentProcess(); - if (hProcess != NULL) + if (hProcess != nullptr) { OpenProcessToken(hProcess, TOKEN_IMPERSONATE, &hAccessToken); CloseHandle(hProcess); @@ -604,23 +604,23 @@ void SAL_CALL osl_unloadUserProfile(oslSecurity Security) if (hUserEnvLib) { - fLoadUserProfile = (LPFNLOADUSERPROFILE)GetProcAddress(hUserEnvLib, "LoadUserProfileA"); - fUnloadUserProfile = (LPFNUNLOADUSERPROFILE)GetProcAddress(hUserEnvLib, "UnloadUserProfile"); + fLoadUserProfile = reinterpret_cast<LPFNLOADUSERPROFILE>(GetProcAddress(hUserEnvLib, "LoadUserProfileA")); + fUnloadUserProfile = reinterpret_cast<LPFNUNLOADUSERPROFILE>(GetProcAddress(hUserEnvLib, "UnloadUserProfile")); if (fLoadUserProfile && fUnloadUserProfile) { /* unloading the user profile */ if (fLoadUserProfile && fUnloadUserProfile) - fUnloadUserProfile(hAccessToken, ((oslSecurityImpl*)Security)->m_hProfile); + fUnloadUserProfile(hAccessToken, static_cast<oslSecurityImpl*>(Security)->m_hProfile); if (hUserEnvLib) FreeLibrary(hUserEnvLib); } } - ((oslSecurityImpl*)Security)->m_hProfile = NULL; + static_cast<oslSecurityImpl*>(Security)->m_hProfile = nullptr; - if (hAccessToken && (hAccessToken != ((oslSecurityImpl*)Security)->m_hToken)) + if (hAccessToken && (hAccessToken != static_cast<oslSecurityImpl*>(Security)->m_hToken)) { CloseHandle(hAccessToken); } @@ -631,28 +631,28 @@ void SAL_CALL osl_unloadUserProfile(oslSecurity Security) /* Static Module Functions */ /*****************************************************************************/ -static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) +static bool GetSpecialFolder(rtl_uString **strPath, int nFolder) { - sal_Bool bRet = sal_False; + bool bRet = false; HINSTANCE hLibrary; sal_Char PathA[_MAX_PATH]; sal_Unicode PathW[_MAX_PATH]; - if ((hLibrary = LoadLibrary("shell32.dll")) != NULL) + if ((hLibrary = LoadLibrary("shell32.dll")) != nullptr) { BOOL (WINAPI *pSHGetSpecialFolderPathA)(HWND, LPSTR, int, BOOL); BOOL (WINAPI *pSHGetSpecialFolderPathW)(HWND, LPWSTR, int, BOOL); - pSHGetSpecialFolderPathA = (BOOL (WINAPI *)(HWND, LPSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathA"); - pSHGetSpecialFolderPathW = (BOOL (WINAPI *)(HWND, LPWSTR, int, BOOL))GetProcAddress(hLibrary, "SHGetSpecialFolderPathW"); + pSHGetSpecialFolderPathA = reinterpret_cast<BOOL (WINAPI *)(HWND, LPSTR, int, BOOL)>(GetProcAddress(hLibrary, "SHGetSpecialFolderPathA")); + pSHGetSpecialFolderPathW = reinterpret_cast<BOOL (WINAPI *)(HWND, LPWSTR, int, BOOL)>(GetProcAddress(hLibrary, "SHGetSpecialFolderPathW")); if (pSHGetSpecialFolderPathA) { if (pSHGetSpecialFolderPathA(GetActiveWindow(), PathA, nFolder, TRUE)) { rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); - OSL_ASSERT(*strPath != NULL); - bRet = sal_True; + OSL_ASSERT(*strPath != nullptr); + bRet = true; } } else if (pSHGetSpecialFolderPathW) @@ -660,15 +660,15 @@ static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) if (pSHGetSpecialFolderPathW(GetActiveWindow(), PathW, nFolder, TRUE)) { rtl_uString_newFromStr( strPath, PathW); - bRet = sal_True; + bRet = true; } } else { - HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *) = (HRESULT (WINAPI *)(HWND, int, LPITEMIDLIST *))GetProcAddress(hLibrary, "SHGetSpecialFolderLocation"); - BOOL (WINAPI *pSHGetPathFromIDListA)(LPCITEMIDLIST, LPSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListA"); - BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR) = (BOOL (WINAPI *)(LPCITEMIDLIST, LPWSTR))GetProcAddress(hLibrary, "SHGetPathFromIDListW"); - HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *) = (HRESULT (WINAPI *)(LPMALLOC *))GetProcAddress(hLibrary, "SHGetMalloc"); + HRESULT (WINAPI *pSHGetSpecialFolderLocation)(HWND, int, LPITEMIDLIST *) = reinterpret_cast<HRESULT (WINAPI *)(HWND, int, LPITEMIDLIST *)>(GetProcAddress(hLibrary, "SHGetSpecialFolderLocation")); + BOOL (WINAPI *pSHGetPathFromIDListA)(LPCITEMIDLIST, LPSTR) = reinterpret_cast<BOOL (WINAPI *)(LPCITEMIDLIST, LPSTR)>(GetProcAddress(hLibrary, "SHGetPathFromIDListA")); + BOOL (WINAPI *pSHGetPathFromIDListW)(LPCITEMIDLIST, LPWSTR) = reinterpret_cast<BOOL (WINAPI *)(LPCITEMIDLIST, LPWSTR)>(GetProcAddress(hLibrary, "SHGetPathFromIDListW")); + HRESULT (WINAPI *pSHGetMalloc)(LPMALLOC *) = reinterpret_cast<HRESULT (WINAPI *)(LPMALLOC *)>(GetProcAddress(hLibrary, "SHGetMalloc")); if (pSHGetSpecialFolderLocation && (pSHGetPathFromIDListA || pSHGetPathFromIDListW ) && pSHGetMalloc ) { @@ -695,11 +695,11 @@ static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) switch (nFolder) { case CSIDL_APPDATA: - lRet = RegQueryValueEx(hRegKey, "AppData", NULL, &Type, (LPBYTE)PathA, &lSize); + lRet = RegQueryValueEx(hRegKey, "AppData", nullptr, &Type, reinterpret_cast<LPBYTE>(PathA), &lSize); break; case CSIDL_PERSONAL: - lRet = RegQueryValueEx(hRegKey, "Personal", NULL, &Type, (LPBYTE)PathA, &lSize); + lRet = RegQueryValueEx(hRegKey, "Personal", nullptr, &Type, reinterpret_cast<LPBYTE>(PathA), &lSize); break; default: @@ -709,7 +709,7 @@ static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) if ((lRet == ERROR_SUCCESS) && (Type == REG_SZ)) { if (_access(PathA, 0) < 0) - CreateDirectory(PathA, NULL); + CreateDirectory(PathA, nullptr); hr = pSHGetSpecialFolderLocation(GetActiveWindow(), nFolder, &pidl); } @@ -724,27 +724,27 @@ static sal_Bool GetSpecialFolder(rtl_uString **strPath, int nFolder) { /* if directory does not exist, create it */ if (_waccess(PathW, 0) < 0) - CreateDirectoryW(PathW, NULL); + CreateDirectoryW(PathW, nullptr); rtl_uString_newFromStr( strPath, PathW); - bRet = sal_True; + bRet = true; } else if (pSHGetPathFromIDListA && pSHGetPathFromIDListA(pidl, PathA)) { /* if directory does not exist, create it */ if (_access(PathA, 0) < 0) - CreateDirectoryA(PathA, NULL); + CreateDirectoryA(PathA, nullptr); rtl_string2UString( strPath, PathA, (sal_Int32) strlen(PathA), osl_getThreadTextEncoding(), OUSTRING_TO_OSTRING_CVTFLAGS); - OSL_ASSERT(*strPath != NULL); - bRet = sal_True; + OSL_ASSERT(*strPath != nullptr); + bRet = true; } } if (SUCCEEDED(pSHGetMalloc(&pMalloc))) { - pMalloc->lpVtbl->Free(pMalloc, (void *) pidl); - pMalloc->lpVtbl->Release(pMalloc); + pMalloc->Free(pidl); + pMalloc->Release(); } } } @@ -769,7 +769,7 @@ static BOOL Privilege(LPTSTR strPrivilege, BOOL bEnable) /* get the luid */ - if (!LookupPrivilegeValue(NULL, strPrivilege, &tp.Privileges[0].Luid)) + if (!LookupPrivilegeValue(nullptr, strPrivilege, &tp.Privileges[0].Luid)) return FALSE; tp.PrivilegeCount = 1; @@ -782,7 +782,7 @@ static BOOL Privilege(LPTSTR strPrivilege, BOOL bEnable) /* enable or disable the privilege */ - if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, (PTOKEN_PRIVILEGES)NULL, NULL)) + if (!AdjustTokenPrivileges(hToken, FALSE, &tp, 0, nullptr, nullptr)) return FALSE; if (!CloseHandle(hToken)) @@ -791,36 +791,36 @@ static BOOL Privilege(LPTSTR strPrivilege, BOOL bEnable) return TRUE; } -static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, sal_Bool bIncludeDomain) +static bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **strName, bool bIncludeDomain) { - if (Security != NULL) + if (Security != nullptr) { - oslSecurityImpl *pSecImpl = (oslSecurityImpl*)Security; + oslSecurityImpl *pSecImpl = static_cast<oslSecurityImpl*>(Security); HANDLE hAccessToken = pSecImpl->m_hToken; - if (hAccessToken == NULL) + if (hAccessToken == nullptr) OpenProcessToken(GetCurrentProcess(), TOKEN_DUP_QUERY, &hAccessToken); if (hAccessToken) { DWORD nInfoBuffer = 512; - UCHAR* pInfoBuffer = malloc(nInfoBuffer); + UCHAR* pInfoBuffer = static_cast<UCHAR *>(malloc(nInfoBuffer)); while (!GetTokenInformation(hAccessToken, TokenUser, pInfoBuffer, nInfoBuffer, &nInfoBuffer)) { if (GetLastError() == ERROR_INSUFFICIENT_BUFFER) - pInfoBuffer = realloc(pInfoBuffer, nInfoBuffer); + pInfoBuffer = static_cast<UCHAR *>(realloc(pInfoBuffer, nInfoBuffer)); else { free(pInfoBuffer); - pInfoBuffer = NULL; + pInfoBuffer = nullptr; break; } } - if (pSecImpl->m_hToken == NULL) + if (pSecImpl->m_hToken == nullptr) CloseHandle(hAccessToken); if (pInfoBuffer) @@ -832,7 +832,7 @@ static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **str DWORD nDomainName = sizeof(DomainName); SID_NAME_USE sUse; - if (LookupAccountSidW(NULL, ((PTOKEN_USER)pInfoBuffer)->User.Sid, + if (LookupAccountSidW(nullptr, reinterpret_cast<PTOKEN_USER>(pInfoBuffer)->User.Sid, UserName, &nUserName, DomainName, &nDomainName, &sUse)) { @@ -851,24 +851,24 @@ static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **str free(pInfoBuffer); - return sal_True; + return true; } } else { DWORD needed=0; - sal_Unicode *pNameW=NULL; + sal_Unicode *pNameW=nullptr; - WNetGetUserW(NULL, NULL, &needed); - pNameW = malloc (needed*sizeof(sal_Unicode)); + WNetGetUserW(nullptr, nullptr, &needed); + pNameW = static_cast<sal_Unicode *>(malloc (needed*sizeof(sal_Unicode))); - if (WNetGetUserW(NULL, pNameW, &needed) == NO_ERROR) + if (WNetGetUserW(nullptr, pNameW, &needed) == NO_ERROR) { rtl_uString_newFromStr( strName, pNameW); if (pNameW) free(pNameW); - return sal_True; + return true; } else if (pSecImpl->m_User[0] != '\0') { @@ -877,7 +877,7 @@ static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **str if (pNameW) free(pNameW); - return sal_True; + return true; } if (pNameW) @@ -885,7 +885,7 @@ static sal_Bool SAL_CALL getUserNameImpl(oslSecurity Security, rtl_uString **str } } - return sal_False; + return false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sal/osl/w32/thread.c b/sal/osl/w32/thread.cxx index 02cd97ec9f83..b16e87246877 100644 --- a/sal/osl/w32/thread.c +++ b/sal/osl/w32/thread.cxx @@ -49,10 +49,10 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker, void* pThreadData, s /*****************************************************************************/ static unsigned __stdcall oslWorkerWrapperFunction(void* pData) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)pData; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(pData); /* Initialize COM - Multi Threaded Apartment (MTA) for all threads */ - CoInitializeEx(NULL, COINIT_MULTITHREADED); /* spawned by oslCreateThread */ + CoInitializeEx(nullptr, COINIT_MULTITHREADED); /* spawned by oslCreateThread */ /* call worker-function with data */ @@ -73,13 +73,13 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker, osl_TThreadImpl* pThreadImpl; /* alloc mem. for our internal data structure */ - pThreadImpl= malloc(sizeof(osl_TThreadImpl)); + pThreadImpl= static_cast<osl_TThreadImpl *>(malloc(sizeof(osl_TThreadImpl))); OSL_ASSERT(pThreadImpl); - if ( pThreadImpl == NULL ) + if ( pThreadImpl == nullptr ) { - return NULL; + return nullptr; } pThreadImpl->m_WorkerFunction= pWorker; @@ -87,14 +87,14 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker, pThreadImpl->m_nTerminationRequested= 0; pThreadImpl->m_hThread= - (HANDLE)_beginthreadex(NULL, /* no security */ + reinterpret_cast<HANDLE>(_beginthreadex(nullptr, /* no security */ 0, /* default stack-size */ oslWorkerWrapperFunction, /* worker-function */ pThreadImpl, /* provide worker-function with data */ nFlags, /* start thread immediately or suspended */ - &pThreadImpl->m_ThreadId); + &pThreadImpl->m_ThreadId)); - if(pThreadImpl->m_hThread == NULL) + if(pThreadImpl->m_hThread == nullptr) { switch (errno) { @@ -117,10 +117,10 @@ static oslThread oslCreateThread(oslWorkerFunction pWorker, /* create failed */ free(pThreadImpl); - return NULL; + return nullptr; } - return (oslThread)pThreadImpl; + return pThreadImpl; } /*****************************************************************************/ @@ -146,9 +146,9 @@ oslThread SAL_CALL osl_createSuspendedThread(oslWorkerFunction pWorker, /*****************************************************************************/ oslThreadIdentifier SAL_CALL osl_getThreadIdentifier(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); - if (pThreadImpl != NULL) + if (pThreadImpl != nullptr) return (oslThreadIdentifier)pThreadImpl->m_ThreadId; else return (oslThreadIdentifier)GetCurrentThreadId(); @@ -159,9 +159,9 @@ oslThreadIdentifier SAL_CALL osl_getThreadIdentifier(oslThread Thread) /*****************************************************************************/ void SAL_CALL osl_destroyThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); - if (Thread == NULL) /* valid ptr? */ + if (Thread == nullptr) /* valid ptr? */ { /* thread already destroyed or not created */ return; @@ -179,7 +179,7 @@ void SAL_CALL osl_destroyThread(oslThread Thread) /*****************************************************************************/ void SAL_CALL osl_resumeThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); OSL_ASSERT(pThreadImpl); /* valid ptr? */ @@ -191,7 +191,7 @@ void SAL_CALL osl_resumeThread(oslThread Thread) /*****************************************************************************/ void SAL_CALL osl_suspendThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); OSL_ASSERT(pThreadImpl); /* valid ptr? */ @@ -205,7 +205,7 @@ void SAL_CALL osl_setThreadPriority(oslThread Thread, oslThreadPriority Priority) { int winPriority; - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); OSL_ASSERT(pThreadImpl); /* valid ptr? */ @@ -260,10 +260,10 @@ oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread) int winPriority; oslThreadPriority Priority; - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); /* invalid arguments ?*/ - if(pThreadImpl==NULL || pThreadImpl->m_hThread==NULL) + if(pThreadImpl==nullptr || pThreadImpl->m_hThread==nullptr) { return osl_Thread_PriorityUnknown; } @@ -316,15 +316,15 @@ oslThreadPriority SAL_CALL osl_getThreadPriority(const oslThread Thread) /*****************************************************************************/ sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); /* invalid arguments ?*/ - if(pThreadImpl==NULL || pThreadImpl->m_hThread==NULL) + if(pThreadImpl==nullptr || pThreadImpl->m_hThread==nullptr) { - return sal_False; + return false; } - return (sal_Bool)(WaitForSingleObject(pThreadImpl->m_hThread, 0) != WAIT_OBJECT_0); + return WaitForSingleObject(pThreadImpl->m_hThread, 0) != WAIT_OBJECT_0; } /*****************************************************************************/ @@ -332,10 +332,10 @@ sal_Bool SAL_CALL osl_isThreadRunning(const oslThread Thread) /*****************************************************************************/ void SAL_CALL osl_joinWithThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); /* invalid arguments?*/ - if(pThreadImpl==NULL || pThreadImpl->m_hThread==NULL) + if(pThreadImpl==nullptr || pThreadImpl->m_hThread==nullptr) { /* assume thread is not running */ return; @@ -362,10 +362,10 @@ void SAL_CALL osl_waitThread(const TimeValue* pDelay) /*****************************************************************************/ void SAL_CALL osl_terminateThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); /* invalid arguments?*/ - if (pThreadImpl==NULL || pThreadImpl->m_hThread==NULL) + if (pThreadImpl==nullptr || pThreadImpl->m_hThread==nullptr) { /* assume thread is not running */ return; @@ -379,18 +379,18 @@ void SAL_CALL osl_terminateThread(oslThread Thread) /*****************************************************************************/ sal_Bool SAL_CALL osl_scheduleThread(oslThread Thread) { - osl_TThreadImpl* pThreadImpl= (osl_TThreadImpl*)Thread; + osl_TThreadImpl* pThreadImpl= static_cast<osl_TThreadImpl*>(Thread); osl_yieldThread(); /* invalid arguments?*/ - if (pThreadImpl==NULL || pThreadImpl->m_hThread==NULL) + if (pThreadImpl==nullptr || pThreadImpl->m_hThread==nullptr) { /* assume thread is not running */ - return sal_False; + return false; } - return (sal_Bool)(0 == pThreadImpl->m_nTerminationRequested); + return 0 == pThreadImpl->m_nTerminationRequested; } /*****************************************************************************/ @@ -419,7 +419,7 @@ void SAL_CALL osl_setThreadName(char const * name) { __try { RaiseException( 0x406D1388, 0, sizeof info / sizeof (ULONG_PTR), - (ULONG_PTR *) &info); + reinterpret_cast<ULONG_PTR *>(&info)); } __except (EXCEPTION_EXECUTE_HANDLER) {} #else (void) name; @@ -433,7 +433,7 @@ typedef struct TLS_ struct TLS_ *pNext, *pPrev; } TLS, *PTLS; -static PTLS g_pThreadKeyList = NULL; +static PTLS g_pThreadKeyList = nullptr; CRITICAL_SECTION g_ThreadKeyListCS; static void AddKeyToList( PTLS pTls ) @@ -443,7 +443,7 @@ static void AddKeyToList( PTLS pTls ) EnterCriticalSection( &g_ThreadKeyListCS ); pTls->pNext = g_pThreadKeyList; - pTls->pPrev = NULL; + pTls->pPrev = nullptr; if ( g_pThreadKeyList ) g_pThreadKeyList->pPrev = pTls; @@ -499,7 +499,7 @@ void SAL_CALL osl_callThreadKeyCallbackOnThreadDetach(void) /*****************************************************************************/ oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback) { - PTLS pTls = rtl_allocateMemory( sizeof(TLS) ); + PTLS pTls = static_cast<PTLS>(rtl_allocateMemory( sizeof(TLS) )); if ( pTls ) { @@ -507,13 +507,13 @@ oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback if ( (DWORD)-1 == (pTls->dwIndex = TlsAlloc()) ) { rtl_freeMemory( pTls ); - pTls = NULL; + pTls = nullptr; } else AddKeyToList( pTls ); } - return (oslThreadKey)pTls; + return pTls; } /*****************************************************************************/ @@ -521,9 +521,9 @@ oslThreadKey SAL_CALL osl_createThreadKey(oslThreadKeyCallbackFunction pCallback /*****************************************************************************/ void SAL_CALL osl_destroyThreadKey(oslThreadKey Key) { - if (Key != NULL) + if (Key != nullptr) { - PTLS pTls = (PTLS)Key; + PTLS pTls = static_cast<PTLS>(Key); RemoveKeyFromList( pTls ); TlsFree( pTls->dwIndex ); @@ -536,14 +536,14 @@ void SAL_CALL osl_destroyThreadKey(oslThreadKey Key) /*****************************************************************************/ void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key) { - if (Key != NULL) + if (Key != nullptr) { - PTLS pTls = (PTLS)Key; + PTLS pTls = static_cast<PTLS>(Key); return TlsGetValue( pTls->dwIndex ); } - return NULL; + return nullptr; } /*****************************************************************************/ @@ -551,10 +551,10 @@ void* SAL_CALL osl_getThreadKeyData(oslThreadKey Key) /*****************************************************************************/ sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData) { - if (Key != NULL) + if (Key != nullptr) { - PTLS pTls = (PTLS)Key; - void* pOldData = NULL; + PTLS pTls = static_cast<PTLS>(Key); + void* pOldData = nullptr; BOOL fSuccess; if ( pTls->pfnCallback ) @@ -565,10 +565,10 @@ sal_Bool SAL_CALL osl_setThreadKeyData(oslThreadKey Key, void *pData) if ( fSuccess && pTls->pfnCallback && pOldData ) pTls->pfnCallback( pOldData ); - return (sal_Bool)(fSuccess != FALSE); + return fSuccess != FALSE; } - return sal_False; + return false; } /*****************************************************************************/ @@ -586,14 +586,14 @@ rtl_TextEncoding SAL_CALL osl_getThreadTextEncoding(void) if ( (DWORD)-1 == g_dwTLSTextEncodingIndex ) g_dwTLSTextEncodingIndex = TlsAlloc(); - dwEncoding = (DWORD_PTR)TlsGetValue( g_dwTLSTextEncodingIndex ); + dwEncoding = reinterpret_cast<DWORD_PTR>(TlsGetValue( g_dwTLSTextEncodingIndex )); _encoding = LOWORD(dwEncoding); gotACP = HIWORD(dwEncoding); if ( !gotACP ) { _encoding = rtl_getTextEncodingFromWindowsCodePage( GetACP() ); - TlsSetValue( g_dwTLSTextEncodingIndex, (LPVOID)(DWORD_PTR)MAKELONG( _encoding, TRUE ) ); + TlsSetValue( g_dwTLSTextEncodingIndex, reinterpret_cast<LPVOID>((DWORD_PTR)MAKELONG( _encoding, TRUE )) ); } return _encoding; @@ -606,7 +606,7 @@ rtl_TextEncoding SAL_CALL osl_setThreadTextEncoding( rtl_TextEncoding Encoding ) { rtl_TextEncoding oldEncoding = osl_getThreadTextEncoding(); - TlsSetValue( g_dwTLSTextEncodingIndex, (LPVOID)(DWORD_PTR)MAKELONG( Encoding, TRUE) ); + TlsSetValue( g_dwTLSTextEncodingIndex, reinterpret_cast<LPVOID>((DWORD_PTR)MAKELONG( Encoding, TRUE)) ); return oldEncoding; } diff --git a/sal/osl/w32/thread.h b/sal/osl/w32/thread.h index fb896f531cc5..2c2b040dc885 100644 --- a/sal/osl/w32/thread.h +++ b/sal/osl/w32/thread.h @@ -22,6 +22,8 @@ void SAL_CALL osl_callThreadKeyCallbackOnThreadDetach(void); extern DWORD g_dwTLSTextEncodingIndex; +extern CRITICAL_SECTION g_ThreadKeyListCS; + #if defined __cplusplus } #endif diff --git a/sal/osl/w32/time.c b/sal/osl/w32/time.cxx index 5acb65a7d7eb..f3d90a4d9e2d 100644 --- a/sal/osl/w32/time.c +++ b/sal/osl/w32/time.cxx @@ -37,17 +37,17 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal) typedef VOID (WINAPI *GetSystemTimePreciseAsFileTime_PROC)(LPFILETIME); - static HMODULE hModule = NULL; - static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = NULL; + static HMODULE hModule = nullptr; + static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = nullptr; - OSL_ASSERT(pTimeVal != NULL); + OSL_ASSERT(pTimeVal != nullptr); if ( !hModule ) { hModule = GetModuleHandleA( "Kernel32.dll" ); if ( hModule ) - pGetSystemTimePreciseAsFileTime = (GetSystemTimePreciseAsFileTime_PROC) - GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime"); + pGetSystemTimePreciseAsFileTime = reinterpret_cast<GetSystemTimePreciseAsFileTime_PROC>( + GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime")); } // use ~1 microsecond resolution if available @@ -70,12 +70,12 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal) SystemTimeToFileTime(&SystemTime, &OffTime); - Value = *((__int64 *)&CurTime) - *((__int64 *)&OffTime); + Value = *reinterpret_cast<__int64 *>(&CurTime) - *reinterpret_cast<__int64 *>(&OffTime); pTimeVal->Seconds = (unsigned long) (Value / 10000000L); pTimeVal->Nanosec = (unsigned long)((Value % 10000000L) * 100); - return sal_True; + return true; } // osl_getDateTimeFromTimeValue @@ -99,11 +99,11 @@ sal_Bool SAL_CALL osl_getDateTimeFromTimeValue( const TimeValue* pTimeVal, oslDa pDateTime->Month = aSystemTime.wMonth; pDateTime->Year = aSystemTime.wYear; - return sal_True; + return true; } } - return sal_False; + return false; } // osl_getTimeValueFromDateTime @@ -127,11 +127,11 @@ sal_Bool SAL_CALL osl_getTimeValueFromDateTime( const oslDateTime* pDateTime, Ti if (FileTimeToTimeValue( &aFileTime, pTimeVal ) ) { pTimeVal->Nanosec = pDateTime->NanoSeconds; - return sal_True; + return true; } } - return sal_False; + return false; } // osl_getLocalTimeFromSystemTime @@ -156,11 +156,11 @@ sal_Bool SAL_CALL osl_getLocalTimeFromSystemTime( const TimeValue* pSystemTimeVa pLocalTimeVal->Seconds = (sal_uInt32) (pSystemTimeVal->Seconds - ( bias * 60) ); pLocalTimeVal->Nanosec = pSystemTimeVal->Nanosec; - return sal_True; + return true; } } - return sal_False; + return false; } // osl_getSystemTimeFromLocalTime @@ -185,11 +185,11 @@ sal_Bool SAL_CALL osl_getSystemTimeFromLocalTime( const TimeValue* pLocalTimeVal pSystemTimeVal->Seconds = (sal_uInt32) ( pLocalTimeVal->Seconds + ( bias * 60) ); pSystemTimeVal->Nanosec = pLocalTimeVal->Nanosec; - return sal_True; + return true; } } - return sal_False; + return false; } static struct _timeb startTime; |