| File: | sal/osl/unx/process_impl.cxx |
| Location: | line 318, column 13 |
| Description: | Dereference of null pointer (loaded from variable 'ppustrValue') |
| 1 | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ | |||||
| 2 | /************************************************************************* | |||||
| 3 | * | |||||
| 4 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |||||
| 5 | * | |||||
| 6 | * Copyright 2000, 2010 Oracle and/or its affiliates. | |||||
| 7 | * | |||||
| 8 | * OpenOffice.org - a multi-platform office productivity suite | |||||
| 9 | * | |||||
| 10 | * This file is part of OpenOffice.org. | |||||
| 11 | * | |||||
| 12 | * OpenOffice.org is free software: you can redistribute it and/or modify | |||||
| 13 | * it under the terms of the GNU Lesser General Public License version 3 | |||||
| 14 | * only, as published by the Free Software Foundation. | |||||
| 15 | * | |||||
| 16 | * OpenOffice.org is distributed in the hope that it will be useful, | |||||
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |||||
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||||
| 19 | * GNU Lesser General Public License version 3 for more details | |||||
| 20 | * (a copy is included in the LICENSE file that accompanied this code). | |||||
| 21 | * | |||||
| 22 | * You should have received a copy of the GNU Lesser General Public License | |||||
| 23 | * version 3 along with OpenOffice.org. If not, see | |||||
| 24 | * <http://www.openoffice.org/license.html> | |||||
| 25 | * for a copy of the LGPLv3 License. | |||||
| 26 | * | |||||
| 27 | ************************************************************************/ | |||||
| 28 | ||||||
| 29 | #include "osl/process.h" | |||||
| 30 | ||||||
| 31 | #include <limits.h> | |||||
| 32 | #include <pthread.h> | |||||
| 33 | #include <stdlib.h> | |||||
| 34 | #include <string.h> | |||||
| 35 | ||||||
| 36 | #include "osl/diagnose.h" | |||||
| 37 | #include "osl/file.h" | |||||
| 38 | #include "osl/module.h" | |||||
| 39 | #include "osl/thread.h" | |||||
| 40 | #include "rtl/ustring.hxx" | |||||
| 41 | #include "rtl/strbuf.h" | |||||
| 42 | ||||||
| 43 | #include "file_path_helper.h" | |||||
| 44 | ||||||
| 45 | #include "uunxapi.h" | |||||
| 46 | ||||||
| 47 | #ifdef ANDROID | |||||
| 48 | #include <osl/detail/android-bootstrap.h> | |||||
| 49 | #endif | |||||
| 50 | ||||||
| 51 | /*************************************** | |||||
| 52 | osl_bootstrap_getExecutableFile_Impl(). | |||||
| 53 | ||||||
| 54 | @internal | |||||
| 55 | @see rtl_bootstrap | |||||
| 56 | @see #i37371# | |||||
| 57 | ||||||
| 58 | **************************************/ | |||||
| 59 | ||||||
| 60 | extern "C" oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( | |||||
| 61 | rtl_uString ** ppFileURL | |||||
| 62 | ) SAL_THROW_EXTERN_C()throw (); | |||||
| 63 | ||||||
| 64 | ||||||
| 65 | #if defined(MACOSX) || defined(IOS) | |||||
| 66 | #include <mach-o/dyld.h> | |||||
| 67 | ||||||
| 68 | oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( | |||||
| 69 | rtl_uString ** ppFileURL | |||||
| 70 | ) SAL_THROW_EXTERN_C()throw () | |||||
| 71 | { | |||||
| 72 | oslProcessError result = osl_Process_E_NotFound; | |||||
| 73 | ||||||
| 74 | char buffer[PATH_MAX4096]; | |||||
| 75 | size_t buflen = sizeof(buffer); | |||||
| 76 | ||||||
| 77 | if (_NSGetExecutablePath (buffer, (uint32_t*)&buflen) == 0) | |||||
| 78 | { | |||||
| 79 | /* Determine absolute path. */ | |||||
| 80 | char abspath[PATH_MAX4096]; | |||||
| 81 | if (realpath (buffer, abspath) != 0) | |||||
| 82 | { | |||||
| 83 | /* Convert from utf8 to unicode. */ | |||||
| 84 | rtl_uString * pAbsPath = 0; | |||||
| 85 | rtl_string2UString ( | |||||
| 86 | &(pAbsPath), | |||||
| 87 | abspath, rtl_str_getLength (abspath), | |||||
| 88 | RTL_TEXTENCODING_UTF8(((rtl_TextEncoding) 76)), | |||||
| 89 | OSTRING_TO_OUSTRING_CVTFLAGS(((sal_uInt32)0x0003) | ((sal_uInt32)0x0030) | ((sal_uInt32)0x0300 ))); | |||||
| 90 | ||||||
| 91 | if (pAbsPath) | |||||
| 92 | { | |||||
| 93 | /* Convert from path to url. */ | |||||
| 94 | if (osl_getFileURLFromSystemPath (pAbsPath, ppFileURL) == osl_File_E_None) | |||||
| 95 | { | |||||
| 96 | /* Success. */ | |||||
| 97 | result = osl_Process_E_None; | |||||
| 98 | } | |||||
| 99 | rtl_uString_release (pAbsPath); | |||||
| 100 | } | |||||
| 101 | } | |||||
| 102 | } | |||||
| 103 | ||||||
| 104 | return (result); | |||||
| 105 | } | |||||
| 106 | ||||||
| 107 | #else | |||||
| 108 | #include <dlfcn.h> | |||||
| 109 | ||||||
| 110 | oslProcessError SAL_CALL osl_bootstrap_getExecutableFile_Impl ( | |||||
| 111 | rtl_uString ** ppFileURL | |||||
| 112 | ) SAL_THROW_EXTERN_C()throw () | |||||
| 113 | { | |||||
| 114 | oslProcessError result = osl_Process_E_NotFound; | |||||
| 115 | ||||||
| 116 | #ifdef ANDROID | |||||
| 117 | /* On Android we in theory want the address of the "lo_main()" | |||||
| 118 | * function, as that is what corresponds to "main()" in | |||||
| 119 | * LibreOffice programs on normal desktop OSes. | |||||
| 120 | * | |||||
| 121 | * But that is true only for apps with a "native activity", using | |||||
| 122 | * <sal/main.h> and the org.libreoffice.android.Bootstrap | |||||
| 123 | * mechanism. For more normal (?) Android apps that just use | |||||
| 124 | * LibreOffice libraries (components) where the main program is in | |||||
| 125 | * Java, that just use LibreOffice libraries, there is no | |||||
| 126 | * lo_main(). (Note that we don't know for sure yet how | |||||
| 127 | * complicated it might be to write such Android apps...) | |||||
| 128 | * | |||||
| 129 | * Maybe best to just pick some function in liblo-bootstrap.so | |||||
| 130 | * which also such Java apps *must* load as the very first | |||||
| 131 | * LibreOffice native library. We store all LibreOffice native | |||||
| 132 | * shared libraries an app uses in the same folder anyway, so it | |||||
| 133 | * doesn't really matter. | |||||
| 134 | */ | |||||
| 135 | void * addr = (void *) &lo_dlopen; | |||||
| 136 | #else | |||||
| 137 | /* Determine address of "main()" function. */ | |||||
| 138 | void * addr = dlsym (RTLD_DEFAULT((void *) 0), "main"); | |||||
| 139 | #endif | |||||
| 140 | if (addr != 0) | |||||
| 141 | { | |||||
| 142 | /* Determine module URL. */ | |||||
| 143 | if (osl_getModuleURLFromAddress (addr, ppFileURL)) | |||||
| 144 | { | |||||
| 145 | /* Success. */ | |||||
| 146 | result = osl_Process_E_None; | |||||
| 147 | } | |||||
| 148 | } | |||||
| 149 | ||||||
| 150 | /* Fallback to ordinary osl_getExecutableFile(). */ | |||||
| 151 | if (result == osl_Process_E_NotFound) | |||||
| 152 | result = osl_getExecutableFile (ppFileURL); | |||||
| 153 | ||||||
| 154 | return (result); | |||||
| 155 | } | |||||
| 156 | ||||||
| 157 | #endif | |||||
| 158 | ||||||
| 159 | /*************************************** | |||||
| 160 | CommandArgs_Impl. | |||||
| 161 | **************************************/ | |||||
| 162 | struct CommandArgs_Impl | |||||
| 163 | { | |||||
| 164 | pthread_mutex_t m_mutex; | |||||
| 165 | sal_uInt32 m_nCount; | |||||
| 166 | rtl_uString ** m_ppArgs; | |||||
| 167 | }; | |||||
| 168 | ||||||
| 169 | static struct CommandArgs_Impl g_command_args = | |||||
| 170 | { | |||||
| 171 | PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, { 0 } } }, | |||||
| 172 | 0, | |||||
| 173 | 0 | |||||
| 174 | }; | |||||
| 175 | ||||||
| 176 | /*************************************** | |||||
| 177 | osl_getExecutableFile(). | |||||
| 178 | **************************************/ | |||||
| 179 | oslProcessError SAL_CALL osl_getExecutableFile (rtl_uString ** ppustrFile) | |||||
| 180 | { | |||||
| 181 | oslProcessError result = osl_Process_E_NotFound; | |||||
| 182 | ||||||
| 183 | pthread_mutex_lock (&(g_command_args.m_mutex)); | |||||
| 184 | OSL_ASSERT(g_command_args.m_nCount > 0)do { if (true && (!(g_command_args.m_nCount > 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "184" ": "), "OSL_ASSERT: %s", "g_command_args.m_nCount > 0" ); } } while (false); | |||||
| 185 | if (g_command_args.m_nCount > 0) | |||||
| 186 | { | |||||
| 187 | /* CommandArgs set. Obtain argv[0]. */ | |||||
| 188 | rtl_uString_assign (ppustrFile, g_command_args.m_ppArgs[0]); | |||||
| 189 | result = osl_Process_E_None; | |||||
| 190 | } | |||||
| 191 | pthread_mutex_unlock (&(g_command_args.m_mutex)); | |||||
| 192 | ||||||
| 193 | return (result); | |||||
| 194 | } | |||||
| 195 | ||||||
| 196 | /*************************************** | |||||
| 197 | osl_getCommandArgCount(). | |||||
| 198 | **************************************/ | |||||
| 199 | sal_uInt32 SAL_CALL osl_getCommandArgCount (void) | |||||
| 200 | { | |||||
| 201 | sal_uInt32 result = 0; | |||||
| 202 | ||||||
| 203 | pthread_mutex_lock (&(g_command_args.m_mutex)); | |||||
| 204 | if (g_command_args.m_nCount == 0) { | |||||
| 205 | OSL_TRACE(do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "207" ": "), "/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "206" ": " "osl_getCommandArgCount w/o prior call to osl_setCommandArgs" ); } } while (false) | |||||
| 206 | OSL_LOG_PREFIXdo { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "207" ": "), "/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "206" ": " "osl_getCommandArgCount w/o prior call to osl_setCommandArgs" ); } } while (false) | |||||
| 207 | "osl_getCommandArgCount w/o prior call to osl_setCommandArgs")do { if (true && (1 > 0)) { sal_detail_logFormat(( SAL_DETAIL_LOG_LEVEL_INFO), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "207" ": "), "/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "206" ": " "osl_getCommandArgCount w/o prior call to osl_setCommandArgs" ); } } while (false); | |||||
| 208 | } | |||||
| 209 | if (g_command_args.m_nCount > 0) | |||||
| 210 | result = g_command_args.m_nCount - 1; | |||||
| 211 | pthread_mutex_unlock (&(g_command_args.m_mutex)); | |||||
| 212 | ||||||
| 213 | return (result); | |||||
| 214 | } | |||||
| 215 | ||||||
| 216 | /*************************************** | |||||
| 217 | osl_getCommandArg(). | |||||
| 218 | **************************************/ | |||||
| 219 | oslProcessError SAL_CALL osl_getCommandArg (sal_uInt32 nArg, rtl_uString ** strCommandArg) | |||||
| 220 | { | |||||
| 221 | oslProcessError result = osl_Process_E_NotFound; | |||||
| 222 | ||||||
| 223 | pthread_mutex_lock (&(g_command_args.m_mutex)); | |||||
| 224 | OSL_ASSERT(g_command_args.m_nCount > 0)do { if (true && (!(g_command_args.m_nCount > 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "224" ": "), "OSL_ASSERT: %s", "g_command_args.m_nCount > 0" ); } } while (false); | |||||
| 225 | if (g_command_args.m_nCount > (nArg + 1)) | |||||
| 226 | { | |||||
| 227 | rtl_uString_assign (strCommandArg, g_command_args.m_ppArgs[nArg + 1]); | |||||
| 228 | result = osl_Process_E_None; | |||||
| 229 | } | |||||
| 230 | pthread_mutex_unlock (&(g_command_args.m_mutex)); | |||||
| 231 | ||||||
| 232 | return (result); | |||||
| 233 | } | |||||
| 234 | ||||||
| 235 | /*************************************** | |||||
| 236 | osl_setCommandArgs(). | |||||
| 237 | **************************************/ | |||||
| 238 | void SAL_CALL osl_setCommandArgs (int argc, char ** argv) | |||||
| 239 | { | |||||
| 240 | OSL_ASSERT(argc > 0)do { if (true && (!(argc > 0))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "240" ": "), "OSL_ASSERT: %s", "argc > 0"); } } while (false); | |||||
| 241 | pthread_mutex_lock (&(g_command_args.m_mutex)); | |||||
| 242 | OSL_ENSURE (g_command_args.m_nCount == 0, "osl_setCommandArgs(): CommandArgs already set.")do { if (true && (!(g_command_args.m_nCount == 0))) { sal_detail_logFormat((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl" ), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "242" ": "), "%s", "osl_setCommandArgs(): CommandArgs already set." ); } } while (false); | |||||
| 243 | if (g_command_args.m_nCount == 0) | |||||
| 244 | { | |||||
| 245 | rtl_uString** ppArgs = (rtl_uString**)rtl_allocateZeroMemory (argc * sizeof(rtl_uString*)); | |||||
| 246 | if (ppArgs != 0) | |||||
| 247 | { | |||||
| 248 | rtl_TextEncoding encoding = osl_getThreadTextEncoding(); | |||||
| 249 | for (int i = 0; i < argc; i++) | |||||
| 250 | { | |||||
| 251 | rtl_string2UString ( | |||||
| 252 | &(ppArgs[i]), | |||||
| 253 | argv[i], rtl_str_getLength (argv[i]), encoding, | |||||
| 254 | OSTRING_TO_OUSTRING_CVTFLAGS(((sal_uInt32)0x0003) | ((sal_uInt32)0x0030) | ((sal_uInt32)0x0300 ))); | |||||
| 255 | } | |||||
| 256 | if (ppArgs[0] != 0) | |||||
| 257 | { | |||||
| 258 | #if !defined(ANDROID) && !defined(IOS) // No use searching PATH on Android or iOS | |||||
| 259 | /* see @ osl_getExecutableFile(). */ | |||||
| 260 | if (rtl_ustr_indexOfChar (rtl_uString_getStr(ppArgs[0]), sal_Unicode('/')) == -1) | |||||
| 261 | { | |||||
| 262 | const rtl::OUString PATH (RTL_CONSTASCII_USTRINGPARAM("PATH")(&("PATH")[0]), ((sal_Int32)((sizeof ("PATH") / sizeof (( "PATH")[0]))-1)), (((rtl_TextEncoding) 11))); | |||||
| 263 | ||||||
| 264 | rtl_uString * pSearchPath = 0; | |||||
| 265 | osl_getEnvironment (PATH.pData, &pSearchPath); | |||||
| 266 | if (pSearchPath) | |||||
| 267 | { | |||||
| 268 | rtl_uString * pSearchResult = 0; | |||||
| 269 | osl_searchPath (ppArgs[0], pSearchPath, &pSearchResult); | |||||
| 270 | if (pSearchResult) | |||||
| 271 | { | |||||
| 272 | rtl_uString_assign (&(ppArgs[0]), pSearchResult); | |||||
| 273 | rtl_uString_release (pSearchResult); | |||||
| 274 | } | |||||
| 275 | rtl_uString_release (pSearchPath); | |||||
| 276 | } | |||||
| 277 | } | |||||
| 278 | #endif | |||||
| 279 | rtl_uString * pArg0 = 0; | |||||
| 280 | if (realpath_u (ppArgs[0], &pArg0)) | |||||
| 281 | { | |||||
| 282 | osl_getFileURLFromSystemPath (pArg0, &(ppArgs[0])); | |||||
| 283 | rtl_uString_release (pArg0); | |||||
| 284 | } | |||||
| 285 | } | |||||
| 286 | g_command_args.m_nCount = argc; | |||||
| 287 | g_command_args.m_ppArgs = ppArgs; | |||||
| 288 | } | |||||
| 289 | } | |||||
| 290 | pthread_mutex_unlock (&(g_command_args.m_mutex)); | |||||
| 291 | } | |||||
| 292 | ||||||
| 293 | /*************************************** | |||||
| 294 | osl_getEnvironment(). | |||||
| 295 | **************************************/ | |||||
| 296 | oslProcessError SAL_CALL osl_getEnvironment(rtl_uString* pustrEnvVar, rtl_uString** ppustrValue) | |||||
| 297 | { | |||||
| 298 | oslProcessError result = osl_Process_E_NotFound; | |||||
| 299 | rtl_TextEncoding encoding = osl_getThreadTextEncoding(); | |||||
| 300 | rtl_String* pstr_env_var = 0; | |||||
| 301 | ||||||
| 302 | OSL_PRECOND(pustrEnvVar, "osl_getEnvironment(): Invalid parameter")do { if (true && (!(pustrEnvVar))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "302" ": "), "%s", "osl_getEnvironment(): Invalid parameter" ); } } while (false); | |||||
| 303 | OSL_PRECOND(ppustrValue, "osl_getEnvironment(): Invalid parameter")do { if (true && (!(ppustrValue))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "303" ": "), "%s", "osl_getEnvironment(): Invalid parameter" ); } } while (false); | |||||
| 304 | ||||||
| 305 | rtl_uString2String( | |||||
| 306 | &pstr_env_var, | |||||
| 307 | rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, | |||||
| 308 | OUSTRING_TO_OSTRING_CVTFLAGS(((sal_uInt32)0x0006) | ((sal_uInt32)0x0060) | ((sal_uInt32)0x0100 ) | ((sal_uInt32)0x0400) | ((sal_uInt32)0x4000))); | |||||
| 309 | if (pstr_env_var != 0) | |||||
| ||||||
| 310 | { | |||||
| 311 | const char* p_env_var = getenv (rtl_string_getStr (pstr_env_var)); | |||||
| 312 | if (p_env_var != 0) | |||||
| 313 | { | |||||
| 314 | rtl_string2UString( | |||||
| 315 | ppustrValue, | |||||
| 316 | p_env_var, strlen(p_env_var), encoding, | |||||
| 317 | OSTRING_TO_OUSTRING_CVTFLAGS(((sal_uInt32)0x0003) | ((sal_uInt32)0x0030) | ((sal_uInt32)0x0300 ))); | |||||
| 318 | OSL_ASSERT(*ppustrValue != NULL)do { if (true && (!(*ppustrValue != __null))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "318" ": "), "OSL_ASSERT: %s", "*ppustrValue != NULL"); } } while (false); | |||||
| ||||||
| 319 | ||||||
| 320 | result = osl_Process_E_None; | |||||
| 321 | } | |||||
| 322 | rtl_string_release(pstr_env_var); | |||||
| 323 | } | |||||
| 324 | ||||||
| 325 | return (result); | |||||
| 326 | } | |||||
| 327 | ||||||
| 328 | /*************************************** | |||||
| 329 | osl_setEnvironment(). | |||||
| 330 | **************************************/ | |||||
| 331 | oslProcessError SAL_CALL osl_setEnvironment(rtl_uString* pustrEnvVar, rtl_uString* pustrValue) | |||||
| 332 | { | |||||
| 333 | oslProcessError result = osl_Process_E_Unknown; | |||||
| 334 | rtl_TextEncoding encoding = osl_getThreadTextEncoding(); | |||||
| 335 | rtl_String* pstr_env_var = 0; | |||||
| 336 | rtl_String* pstr_val = 0; | |||||
| 337 | ||||||
| 338 | OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter")do { if (true && (!(pustrEnvVar))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "338" ": "), "%s", "osl_setEnvironment(): Invalid parameter" ); } } while (false); | |||||
| 339 | OSL_PRECOND(pustrValue, "osl_setEnvironment(): Invalid parameter")do { if (true && (!(pustrValue))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "339" ": "), "%s", "osl_setEnvironment(): Invalid parameter" ); } } while (false); | |||||
| 340 | ||||||
| 341 | rtl_uString2String( | |||||
| 342 | &pstr_env_var, | |||||
| 343 | rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, | |||||
| 344 | OUSTRING_TO_OSTRING_CVTFLAGS(((sal_uInt32)0x0006) | ((sal_uInt32)0x0060) | ((sal_uInt32)0x0100 ) | ((sal_uInt32)0x0400) | ((sal_uInt32)0x4000))); | |||||
| 345 | ||||||
| 346 | rtl_uString2String( | |||||
| 347 | &pstr_val, | |||||
| 348 | rtl_uString_getStr(pustrValue), rtl_uString_getLength(pustrValue), encoding, | |||||
| 349 | OUSTRING_TO_OSTRING_CVTFLAGS(((sal_uInt32)0x0006) | ((sal_uInt32)0x0060) | ((sal_uInt32)0x0100 ) | ((sal_uInt32)0x0400) | ((sal_uInt32)0x4000))); | |||||
| 350 | ||||||
| 351 | if (pstr_env_var != 0 && pstr_val != 0) | |||||
| 352 | { | |||||
| 353 | #if defined (SOLARIS) | |||||
| 354 | rtl_String * pBuffer = NULL__null; | |||||
| 355 | ||||||
| 356 | sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer, | |||||
| 357 | rtl_string_getLength(pstr_env_var) + rtl_string_getLength(pstr_val) + 1, | |||||
| 358 | pstr_env_var ); | |||||
| 359 | rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1); | |||||
| 360 | rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, | |||||
| 361 | rtl_string_getStr(pstr_val), rtl_string_getLength(pstr_val) ); | |||||
| 362 | ||||||
| 363 | rtl_string_acquire(pBuffer); // argument to putenv must leak on success | |||||
| 364 | ||||||
| 365 | if (putenv(rtl_string_getStr(pBuffer)) == 0) | |||||
| 366 | result = osl_Process_E_None; | |||||
| 367 | else | |||||
| 368 | rtl_string_release(pBuffer); | |||||
| 369 | #else | |||||
| 370 | if (setenv(rtl_string_getStr(pstr_env_var), rtl_string_getStr(pstr_val), 1) == 0) | |||||
| 371 | result = osl_Process_E_None; | |||||
| 372 | #endif | |||||
| 373 | } | |||||
| 374 | ||||||
| 375 | if (pstr_val) | |||||
| 376 | rtl_string_release(pstr_val); | |||||
| 377 | ||||||
| 378 | if (pstr_env_var != 0) | |||||
| 379 | rtl_string_release(pstr_env_var); | |||||
| 380 | ||||||
| 381 | return (result); | |||||
| 382 | } | |||||
| 383 | ||||||
| 384 | /*************************************** | |||||
| 385 | osl_clearEnvironment(). | |||||
| 386 | **************************************/ | |||||
| 387 | oslProcessError SAL_CALL osl_clearEnvironment(rtl_uString* pustrEnvVar) | |||||
| 388 | { | |||||
| 389 | oslProcessError result = osl_Process_E_Unknown; | |||||
| 390 | rtl_TextEncoding encoding = osl_getThreadTextEncoding(); | |||||
| 391 | rtl_String* pstr_env_var = 0; | |||||
| 392 | ||||||
| 393 | OSL_PRECOND(pustrEnvVar, "osl_setEnvironment(): Invalid parameter")do { if (true && (!(pustrEnvVar))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "393" ": "), "%s", "osl_setEnvironment(): Invalid parameter" ); } } while (false); | |||||
| 394 | ||||||
| 395 | rtl_uString2String( | |||||
| 396 | &pstr_env_var, | |||||
| 397 | rtl_uString_getStr(pustrEnvVar), rtl_uString_getLength(pustrEnvVar), encoding, | |||||
| 398 | OUSTRING_TO_OSTRING_CVTFLAGS(((sal_uInt32)0x0006) | ((sal_uInt32)0x0060) | ((sal_uInt32)0x0100 ) | ((sal_uInt32)0x0400) | ((sal_uInt32)0x4000))); | |||||
| 399 | ||||||
| 400 | if (pstr_env_var) | |||||
| 401 | { | |||||
| 402 | #if defined (SOLARIS) | |||||
| 403 | rtl_String * pBuffer = NULL__null; | |||||
| 404 | ||||||
| 405 | sal_Int32 nCapacity = rtl_stringbuffer_newFromStringBuffer( &pBuffer, | |||||
| 406 | rtl_string_getLength(pstr_env_var) + 1, pstr_env_var ); | |||||
| 407 | rtl_stringbuffer_insert( &pBuffer, &nCapacity, pBuffer->length, "=", 1); | |||||
| 408 | ||||||
| 409 | rtl_string_acquire(pBuffer); // argument to putenv must leak on success | |||||
| 410 | ||||||
| 411 | if (putenv(rtl_string_getStr(pBuffer)) == 0) | |||||
| 412 | result = osl_Process_E_None; | |||||
| 413 | else | |||||
| 414 | rtl_string_release(pBuffer); | |||||
| 415 | #elif (defined(MACOSX) || defined(NETBSD) || defined(FREEBSD)) | |||||
| 416 | //MacOSX baseline is 10.4, which has an old-school void return | |||||
| 417 | //for unsetenv. | |||||
| 418 | //See: http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/10.4/man3/unsetenv.3.html?useVersion=10.4 | |||||
| 419 | unsetenv(rtl_string_getStr(pstr_env_var)); | |||||
| 420 | result = osl_Process_E_None; | |||||
| 421 | #else | |||||
| 422 | if (unsetenv(rtl_string_getStr(pstr_env_var)) == 0) | |||||
| 423 | result = osl_Process_E_None; | |||||
| 424 | #endif | |||||
| 425 | rtl_string_release(pstr_env_var); | |||||
| 426 | } | |||||
| 427 | ||||||
| 428 | return (result); | |||||
| 429 | } | |||||
| 430 | ||||||
| 431 | ||||||
| 432 | /*************************************** | |||||
| 433 | osl_getProcessWorkingDir(). | |||||
| 434 | **************************************/ | |||||
| 435 | oslProcessError SAL_CALL osl_getProcessWorkingDir(rtl_uString **ppustrWorkingDir) | |||||
| 436 | { | |||||
| 437 | oslProcessError result = osl_Process_E_Unknown; | |||||
| 438 | char buffer[PATH_MAX4096]; | |||||
| 439 | ||||||
| 440 | OSL_PRECOND(ppustrWorkingDir, "osl_getProcessWorkingDir(): Invalid parameter")do { if (true && (!(ppustrWorkingDir))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "440" ": "), "%s", "osl_getProcessWorkingDir(): Invalid parameter" ); } } while (false); | |||||
| 441 | ||||||
| 442 | if (getcwd (buffer, sizeof(buffer)) != 0) | |||||
| 443 | { | |||||
| 444 | rtl_uString* ustrTmp = 0; | |||||
| 445 | ||||||
| 446 | rtl_string2UString( | |||||
| 447 | &ustrTmp, | |||||
| 448 | buffer, strlen(buffer), osl_getThreadTextEncoding(), | |||||
| 449 | OSTRING_TO_OUSTRING_CVTFLAGS(((sal_uInt32)0x0003) | ((sal_uInt32)0x0030) | ((sal_uInt32)0x0300 ))); | |||||
| 450 | if (ustrTmp != 0) | |||||
| 451 | { | |||||
| 452 | if (osl_getFileURLFromSystemPath (ustrTmp, ppustrWorkingDir) == osl_File_E_None) | |||||
| 453 | result = osl_Process_E_None; | |||||
| 454 | rtl_uString_release (ustrTmp); | |||||
| 455 | } | |||||
| 456 | } | |||||
| 457 | ||||||
| 458 | return (result); | |||||
| 459 | } | |||||
| 460 | ||||||
| 461 | /****************************************************************************** | |||||
| 462 | * | |||||
| 463 | * new functions to set/return the current process locale | |||||
| 464 | * | |||||
| 465 | *****************************************************************************/ | |||||
| 466 | ||||||
| 467 | struct ProcessLocale_Impl | |||||
| 468 | { | |||||
| 469 | pthread_mutex_t m_mutex; | |||||
| 470 | rtl_Locale * m_pLocale; | |||||
| 471 | }; | |||||
| 472 | ||||||
| 473 | static struct ProcessLocale_Impl g_process_locale = | |||||
| 474 | { | |||||
| 475 | PTHREAD_MUTEX_INITIALIZER{ { 0, 0, 0, 0, 0, { 0 } } }, | |||||
| 476 | 0 | |||||
| 477 | }; | |||||
| 478 | ||||||
| 479 | extern "C" void _imp_getProcessLocale( rtl_Locale ** ); | |||||
| 480 | extern "C" int _imp_setProcessLocale( rtl_Locale * ); | |||||
| 481 | ||||||
| 482 | /********************************************** | |||||
| 483 | osl_getProcessLocale(). | |||||
| 484 | *********************************************/ | |||||
| 485 | oslProcessError SAL_CALL osl_getProcessLocale( rtl_Locale ** ppLocale ) | |||||
| 486 | { | |||||
| 487 | oslProcessError result = osl_Process_E_Unknown; | |||||
| 488 | OSL_PRECOND(ppLocale, "osl_getProcessLocale(): Invalid parameter.")do { if (true && (!(ppLocale))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "488" ": "), "%s", "osl_getProcessLocale(): Invalid parameter." ); } } while (false); | |||||
| 489 | if (ppLocale) | |||||
| 490 | { | |||||
| 491 | pthread_mutex_lock(&(g_process_locale.m_mutex)); | |||||
| 492 | ||||||
| 493 | if (g_process_locale.m_pLocale == 0) | |||||
| 494 | _imp_getProcessLocale (&(g_process_locale.m_pLocale)); | |||||
| 495 | *ppLocale = g_process_locale.m_pLocale; | |||||
| 496 | result = osl_Process_E_None; | |||||
| 497 | ||||||
| 498 | pthread_mutex_unlock (&(g_process_locale.m_mutex)); | |||||
| 499 | } | |||||
| 500 | return (result); | |||||
| 501 | } | |||||
| 502 | ||||||
| 503 | /********************************************** | |||||
| 504 | osl_setProcessLocale(). | |||||
| 505 | *********************************************/ | |||||
| 506 | oslProcessError SAL_CALL osl_setProcessLocale( rtl_Locale * pLocale ) | |||||
| 507 | { | |||||
| 508 | oslProcessError result = osl_Process_E_Unknown; | |||||
| 509 | ||||||
| 510 | OSL_PRECOND(pLocale, "osl_setProcessLocale(): Invalid parameter.")do { if (true && (!(pLocale))) { sal_detail_logFormat ((SAL_DETAIL_LOG_LEVEL_WARN), ("legacy.osl"), ("/usr/local/src/libreoffice/sal/osl/unx/process_impl.cxx" ":" "510" ": "), "%s", "osl_setProcessLocale(): Invalid parameter." ); } } while (false); | |||||
| 511 | ||||||
| 512 | pthread_mutex_lock(&(g_process_locale.m_mutex)); | |||||
| 513 | if (_imp_setProcessLocale (pLocale) == 0) | |||||
| 514 | { | |||||
| 515 | g_process_locale.m_pLocale = pLocale; | |||||
| 516 | result = osl_Process_E_None; | |||||
| 517 | } | |||||
| 518 | pthread_mutex_unlock (&(g_process_locale.m_mutex)); | |||||
| 519 | ||||||
| 520 | return (result); | |||||
| 521 | } | |||||
| 522 | ||||||
| 523 | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |