Commits

Anonymous committed a8791bf

cmcfixes76: #i112656# osl_setEnvironment/osl_clearEnvironment, can't find out of os/2 has setenv/unsetenv, so use putenv which I can definitely see in the ancient emx headers

  • Participants
  • Parent commits 43feab6

Comments (0)

Files changed (1)

File sal/osl/os2/process_impl.cxx

 
 	if (pstr_env_var != 0 && pstr_val != 0)
 	{
-		if (setenv(rtl_string_getStr(pstr_env_var), rtl_string_getStr(pstr_val), 1) == 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 != 0)
+	if (pstr_val)
 		rtl_string_release(pstr_val);
 
 	if (pstr_env_var != 0)
 
 	if (pstr_env_var)
 	{
-		if (unsetenv(rtl_string_getStr(pstr_env_var)) == 0)
+		//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);
 	}