fix toolbar import
[ooovba.git] / tools / source / misc / extendapplicationenvironment.cxx
blob507b37c0edcaac97f0e78e6aef97a2f68a66b6c7
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: extendapplicationenvironment.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_tools.hxx"
32 #include "sal/config.h"
34 #include <stdlib.h>
35 // not <cstdlib> as putenv is POSIX-only; setenv instead of putenv would be
36 // better but is not supported by Solaris 9 and earlier
38 #if defined UNX
39 #include <sys/resource.h>
40 #include <sys/time.h>
41 #include <sys/types.h>
42 #endif
44 #include "osl/process.h"
45 #include "osl/thread.h"
46 #include "rtl/bootstrap.hxx"
47 #include "rtl/string.hxx"
48 #include "rtl/textcvt.h"
49 #include "rtl/ustrbuf.hxx"
50 #include "rtl/ustring.h"
51 #include "rtl/ustring.hxx"
52 #include "sal/types.h"
53 #include "tools/extendapplicationenvironment.hxx"
55 namespace tools {
57 void extendApplicationEnvironment() {
58 #if defined UNX
59 // Try to set RLIMIT_NOFILE as large as possible (failure is harmless):
60 rlimit l;
61 if (getrlimit(RLIMIT_NOFILE, &l) == 0) {
62 l.rlim_cur = l.rlim_max;
63 setrlimit(RLIMIT_NOFILE, &l);
65 #endif
67 // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal):
68 rtl::OUStringBuffer env;
69 env.appendAscii(RTL_CONSTASCII_STRINGPARAM("URE_BOOTSTRAP="));
70 rtl::OUString uri;
71 if (rtl::Bootstrap::get(
72 rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URE_BOOTSTRAP")), uri))
74 if (!uri.matchIgnoreAsciiCaseAsciiL(
75 RTL_CONSTASCII_STRINGPARAM("vnd.sun.star.pathname:")))
77 uri = rtl::Bootstrap::encode(uri);
79 env.append(uri);
80 } else {
81 if (osl_getExecutableFile(&uri.pData) != osl_Process_E_None) {
82 abort();
84 sal_Int32 i = uri.lastIndexOf('/');
85 if (i >= 0) {
86 uri = uri.copy(0, i + 1);
88 env.append(rtl::Bootstrap::encode(uri));
89 env.appendAscii(
90 RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental")));
92 rtl::OString s;
93 if (!env.makeStringAndClear().convertToString(
94 &s, osl_getThreadTextEncoding(),
95 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
96 | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR))
98 abort();
100 rtl_string_acquire(s.pData); // argument to putenv must leak
101 if (putenv(const_cast< char * >(s.getStr())) != 0) {
102 abort();