summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-12-13 11:06:14 +0100
committerMatthias Huetsch [mhu] <matthias.huetsch@oracle.com>2010-12-13 11:06:14 +0100
commitb480a8b31cfa6e4b24c111c32905b58e33a52138 (patch)
tree41cc052a715eb7df15cb846bfb26707fffec9f21 /sal/osl
parent340b22a09175abb796dc7df234962ef958b1ad6f (diff)
parente944bed1166d34170eaa6ff3dcabfc73a5d81edf (diff)
Update from master repository (DEV300_m95).
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/os2/process_impl.cxx92
-rw-r--r--sal/osl/os2/system.h3
-rw-r--r--sal/osl/unx/file_misc.cxx57
-rw-r--r--sal/osl/unx/nlsupport.c15
-rw-r--r--sal/osl/unx/process_impl.cxx107
-rw-r--r--sal/osl/w32/process.cxx19
-rw-r--r--sal/osl/w32/salinit.cxx20
-rw-r--r--sal/osl/w32/signal.cxx2
8 files changed, 260 insertions, 55 deletions
diff --git a/sal/osl/os2/process_impl.cxx b/sal/osl/os2/process_impl.cxx
index 27b12bbe0f6a..be6bb1898e65 100644
--- a/sal/osl/os2/process_impl.cxx
+++ b/sal/osl/os2/process_impl.cxx
@@ -282,6 +282,98 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uStrin
}
/***************************************
+ osl_setEnvironment().
+ **************************************/
+oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uString* pustrValue)
+{
+ oslProcessError result = osl_Process_E_Unknown;
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ rtl_String* pstr_env_var = 0;
+ rtl_String* pstr_val = 0;
+
+ OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter");
+ OSL_PRECOND(pustrValue, "osl_setEnvironment(): Invalid parameter");
+
+ rtl_uString2String(
+ &pstr_env_var,
+ rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ rtl_uString2String(
+ &pstr_val,
+ rtl_uString_getStr(pustrValue), rtl_uString_getLength(pustrValue), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ if (pstr_env_var != 0 && pstr_val != 0)
+ {
+ //Can't determine if OS/2 EMX has a working setenv or not, so use putenv,
+ //feel free to use setenv here if its available and works
+ rtl_String * pBuffer = NULL;
+
+ sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer,
+ rtl_string_getLength(pstr_env_var) + rtl_string_getLength(pstr_val) + 1,
+ pstr_env_var );
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1);
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length,
+ rtl_string_getStr(pstr_val), rtl_string_getLength(pstr_val) );
+
+ rtl_string_acquire(pBuffer); // argument to putenv must leak on success
+
+ if (putenv(rtl_string_getStr(pBuffer)) == 0)
+ result = osl_Process_E_None;
+ else
+ rtl_string_release(pBuffer);
+ }
+
+ if (pstr_val)
+ rtl_string_release(pstr_val);
+
+ if (pstr_env_var != 0)
+ rtl_string_release(pstr_env_var);
+
+ return (result);
+}
+
+/***************************************
+ osl_clearEnvironment().
+ **************************************/
+oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar)
+{
+ oslProcessError result = osl_Process_E_Unknown;
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ rtl_String* pstr_env_var = 0;
+
+ OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter");
+
+ rtl_uString2String(
+ &pstr_env_var,
+ rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ if (pstr_env_var)
+ {
+ //Can't determine if OS/2 EMX has a working unsetenv or not, so use putenv,
+ //feel free to use unsetenv here if its available and works
+ rtl_String * pBuffer = NULL;
+
+ sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer,
+ rtl_string_getLength(pstr_env_var) + 1, pstr_env_var );
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1);
+
+ rtl_string_acquire(pBuffer); // argument to putenv must leak on success
+
+ if (putenv(rtl_string_getStr(pBuffer)) == 0)
+ result = osl_Process_E_None;
+ else
+ rtl_string_release(pBuffer);
+
+ rtl_string_release(pstr_env_var);
+ }
+
+ return (result);
+}
+
+/***************************************
osl_getProcessWorkingDir().
**************************************/
oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir)
diff --git a/sal/osl/os2/system.h b/sal/osl/os2/system.h
index ac7e410c5a34..436ae0074a04 100644
--- a/sal/osl/os2/system.h
+++ b/sal/osl/os2/system.h
@@ -356,8 +356,7 @@ char *macxp_tempnam( const char *tmpdir, const char *prefix );
#if !defined(_WIN32) && !defined(_WIN16) && !defined(OS2) && \
!defined(LINUX) && !defined(NETBSD) && !defined(FREEBSD) && !defined(SCO) && \
!defined(AIX) && !defined(HPUX) && \
- !defined(SOLARIS) && !defined(MAC) && \
- !defined(MACOSX)
+ !defined(SOLARIS) && !defined(MACOSX)
# error "Target plattform not specified !"
#endif
diff --git a/sal/osl/unx/file_misc.cxx b/sal/osl/unx/file_misc.cxx
index 964a56336f8c..2ed57b01a2c4 100644
--- a/sal/osl/unx/file_misc.cxx
+++ b/sal/osl/unx/file_misc.cxx
@@ -1020,66 +1020,31 @@ static int oslDoCopyFile(const sal_Char* pszSourceFileName, const sal_Char* pszD
return nRet;
}
- /* HACK: because memory mapping fails on various
- platforms if the size of the source file is 0 byte */
- if (0 == nSourceSize)
- {
- close(SourceFileFD);
- close(DestFileFD);
- return 0;
- }
-
- // read and lseek are used to check the possibility to access the data
- // not a nice solution, but it allows to avoid a crash in case it is an opened samba file
- // generally, reading of one byte should not affect the performance
- char nCh;
- if ( 1 != read( SourceFileFD, &nCh, 1 )
- || -1 == lseek( SourceFileFD, 0, SEEK_SET ) )
- {
- nRet = errno;
- close( SourceFileFD );
- close( DestFileFD );
- return nRet;
- }
-
size_t nWritten = 0;
size_t nRemains = nSourceSize;
- /* mmap file -- open dest file -- write -- fsync it at the end */
- void* pSourceFile = mmap( 0, nSourceSize, PROT_READ, MAP_SHARED, SourceFileFD, 0 );
- if ( pSourceFile != MAP_FAILED )
- {
- nWritten = write( DestFileFD, pSourceFile, nSourceSize );
- nRemains -= nWritten;
- munmap( (char*)pSourceFile, nSourceSize );
- }
-
if ( nRemains )
{
/* mmap has problems, try the direct streaming */
- char pBuffer[32000];
+ char pBuffer[0x8000];
size_t nRead = 0;
nRemains = nSourceSize;
- if ( -1 != lseek( SourceFileFD, 0, SEEK_SET )
- && -1 != lseek( DestFileFD, 0, SEEK_SET ) )
+ do
{
- do
- {
- nRead = 0;
- nWritten = 0;
+ nRead = 0;
+ nWritten = 0;
- size_t nToRead = std::min( (size_t)32000, nRemains );
- nRead = read( SourceFileFD, pBuffer, nToRead );
- if ( (size_t)-1 != nRead )
- nWritten = write( DestFileFD, pBuffer, nRead );
+ size_t nToRead = std::min( (size_t)0x8000, nRemains );
+ nRead = read( SourceFileFD, pBuffer, nToRead );
+ if ( (size_t)-1 != nRead )
+ nWritten = write( DestFileFD, pBuffer, nRead );
- if ( (size_t)-1 != nWritten )
- nRemains -= nWritten;
- }
- while( nRemains && (size_t)-1 != nRead && nRead == nWritten );
+ if ( (size_t)-1 != nWritten )
+ nRemains -= nWritten;
}
+ while( nRemains && (size_t)-1 != nRead && nRead == nWritten );
}
if ( nRemains )
diff --git a/sal/osl/unx/nlsupport.c b/sal/osl/unx/nlsupport.c
index 0b09cf1ac2a4..c9f4fd18df21 100644
--- a/sal/osl/unx/nlsupport.c
+++ b/sal/osl/unx/nlsupport.c
@@ -105,7 +105,8 @@ _pair_search (const char *key, const _pair *base, unsigned int member )
static char * _compose_locale( rtl_Locale * pLocale, char * buffer, size_t n )
{
/* check if a valid locale is specified */
- if( pLocale && pLocale->Language && (pLocale->Language->length == 2) )
+ if( pLocale && pLocale->Language &&
+ (pLocale->Language->length == 2 || pLocale->Language->length == 3) )
{
size_t offset = 0;
@@ -193,16 +194,20 @@ static rtl_Locale * _parse_locale( const char * locale )
rtl_Locale * ret;
+ /* language is a two or three letter code */
+ if( (len > 3 && '_' == locale[3]) || (len == 3 && '_' != locale[2]) )
+ offset = 3;
+
/* convert language code to unicode */
- rtl_string2UString( &pLanguage, locale, 2, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
+ rtl_string2UString( &pLanguage, locale, offset, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
OSL_ASSERT(pLanguage != NULL);
/* convert country code to unicode */
- if( len >= 5 && '_' == locale[2] )
+ if( len >= offset+3 && '_' == locale[offset] )
{
- rtl_string2UString( &pCountry, locale + 3, 2, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
+ rtl_string2UString( &pCountry, locale + offset + 1, 2, RTL_TEXTENCODING_ASCII_US, OSTRING_TO_OUSTRING_CVTFLAGS );
OSL_ASSERT(pCountry != NULL);
- offset = 5;
+ offset += 3;
}
/* convert variant code to unicode - do not rely on "." as delimiter */
diff --git a/sal/osl/unx/process_impl.cxx b/sal/osl/unx/process_impl.cxx
index ee20c8552054..498778758ded 100644
--- a/sal/osl/unx/process_impl.cxx
+++ b/sal/osl/unx/process_impl.cxx
@@ -50,10 +50,11 @@
#define INCLUDED_STRING_H
#endif
#include "osl/diagnose.h"
-#include <osl/file.h>
+#include "osl/file.h"
#include "osl/module.h"
#include "osl/thread.h"
#include "rtl/ustring.hxx"
+#include "rtl/strbuf.h"
#ifndef _OSL_FILE_PATH_HELPER_H_
#include "file_path_helper.h"
@@ -324,6 +325,110 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uStrin
}
/***************************************
+ osl_setEnvironment().
+ **************************************/
+oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uString* pustrValue)
+{
+ oslProcessError result = osl_Process_E_Unknown;
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ rtl_String* pstr_env_var = 0;
+ rtl_String* pstr_val = 0;
+
+ OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter");
+ OSL_PRECOND(pustrValue, "osl_setEnvironment(): Invalid parameter");
+
+ rtl_uString2String(
+ &pstr_env_var,
+ rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ rtl_uString2String(
+ &pstr_val,
+ rtl_uString_getStr(pustrValue), rtl_uString_getLength(pustrValue), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ if (pstr_env_var != 0 && pstr_val != 0)
+ {
+#if defined (SOLARIS)
+ rtl_String * pBuffer = NULL;
+
+ sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer,
+ rtl_string_getLength(pstr_env_var) + rtl_string_getLength(pstr_val) + 1,
+ pstr_env_var );
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1);
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length,
+ rtl_string_getStr(pstr_val), rtl_string_getLength(pstr_val) );
+
+ rtl_string_acquire(pBuffer); // argument to putenv must leak on success
+
+ if (putenv(rtl_string_getStr(pBuffer)) == 0)
+ result = osl_Process_E_None;
+ else
+ rtl_string_release(pBuffer);
+#else
+ if (setenv(rtl_string_getStr(pstr_env_var), rtl_string_getStr(pstr_val), 1) == 0)
+ result = osl_Process_E_None;
+#endif
+ }
+
+ if (pstr_val)
+ rtl_string_release(pstr_val);
+
+ if (pstr_env_var != 0)
+ rtl_string_release(pstr_env_var);
+
+ return (result);
+}
+
+/***************************************
+ osl_clearEnvironment().
+ **************************************/
+oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar)
+{
+ oslProcessError result = osl_Process_E_Unknown;
+ rtl_TextEncoding encoding = osl_getThreadTextEncoding();
+ rtl_String* pstr_env_var = 0;
+
+ OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter");
+
+ rtl_uString2String(
+ &pstr_env_var,
+ rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding,
+ OUSTRING_TO_OSTRING_CVTFLAGS);
+
+ if (pstr_env_var)
+ {
+#if defined (SOLARIS)
+ rtl_String * pBuffer = NULL;
+
+ sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer,
+ rtl_string_getLength(pstr_env_var) + 1, pstr_env_var );
+ rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1);
+
+ rtl_string_acquire(pBuffer); // argument to putenv must leak on success
+
+ if (putenv(rtl_string_getStr(pBuffer)) == 0)
+ result = osl_Process_E_None;
+ else
+ rtl_string_release(pBuffer);
+#elif (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD))
+ //MacOSX baseline is 10.4, which has an old-school void return
+ //for unsetenv.
+ //See: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/10.4/man3/unsetenv.3.html?useVersion=10.4
+ unsetenv(rtl_string_getStr(pstr_env_var));
+ result = osl_Process_E_None;
+#else
+ if (unsetenv(rtl_string_getStr(pstr_env_var)) == 0)
+ result = osl_Process_E_None;
+#endif
+ rtl_string_release(pstr_env_var);
+ }
+
+ return (result);
+}
+
+
+/***************************************
osl_getProcessWorkingDir().
**************************************/
oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir)
diff --git a/sal/osl/w32/process.cxx b/sal/osl/w32/process.cxx
index 96187be7e203..521ac6f76ad4 100644
--- a/sal/osl/w32/process.cxx
+++ b/sal/osl/w32/process.cxx
@@ -413,6 +413,25 @@ oslProcessError SAL_CALL osl_getEnvironment(rtl_uString *ustrVar, rtl_uString **
return osl_Process_E_Unknown;
}
+oslProcessError SAL_CALL osl_setEnvironment(rtl_uString *ustrVar, rtl_uString *ustrValue)
+{
+ LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer);
+ LPCWSTR lpValue = reinterpret_cast<LPCWSTR>(ustrValue->buffer);
+ if (SetEnvironmentVariableW(lpName, lpValue))
+ return osl_Process_E_None;
+ return osl_Process_E_Unknown;
+}
+
+oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString *ustrVar)
+{
+ //If the second parameter is NULL, the variable is deleted from the current
+ //process's environment.
+ LPCWSTR lpName = reinterpret_cast<LPCWSTR>(ustrVar->buffer);
+ if (SetEnvironmentVariableW(lpName, NULL))
+ return osl_Process_E_None;
+ return osl_Process_E_Unknown;
+}
+
/***************************************************************************
* Current Working Directory.
***************************************************************************/
diff --git a/sal/osl/w32/salinit.cxx b/sal/osl/w32/salinit.cxx
index aea584f67970..ab124620a07c 100644
--- a/sal/osl/w32/salinit.cxx
+++ b/sal/osl/w32/salinit.cxx
@@ -40,6 +40,26 @@ extern "C" {
void SAL_CALL sal_detail_initialize(int argc, char ** argv)
{
+ // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
+ // SetDllDirectoryW(L"");
+ // SetSearchPathMode(
+ // BASE_SEARCH_PATH_ENABLE_SAFE_SEARCHMODE | BASE_SEARCH_PATH_PERMANENT);
+ HMODULE h = GetModuleHandleW(L"kernel32.dll");
+ if (h != 0) {
+ FARPROC p = GetProcAddress(h, "SetProcessDEPPolicy");
+ if (p != 0) {
+ reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x00000001);
+ }
+ p = GetProcAddress(h, "SetDllDirectoryW");
+ if (p != 0) {
+ reinterpret_cast< BOOL (WINAPI *)(LPCWSTR) >(p)(L"");
+ }
+ p = GetProcAddress(h, "SetSearchPathMode");
+ if (p != 0) {
+ reinterpret_cast< BOOL (WINAPI *)(DWORD) >(p)(0x8001);
+ }
+ }
+
WSADATA wsaData;
int error;
WORD wVersionRequested;
diff --git a/sal/osl/w32/signal.cxx b/sal/osl/w32/signal.cxx
index f893f7520d40..a74baaefc057 100644
--- a/sal/osl/w32/signal.cxx
+++ b/sal/osl/w32/signal.cxx
@@ -188,7 +188,7 @@ static BOOL ReportCrash( LPEXCEPTION_POINTERS lpEP )
sntprintf( szBuffer, elementsof(szBuffer),
_T("%s -p %u -excp 0x%p -t %u%s"),
- aPath,
+ static_cast<sal_Char*>( aPath ),
GetCurrentProcessId(),
lpEP,
GetCurrentThreadId(),