1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: extendapplicationenvironment.cxx,v $
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"
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
39 #include <sys/resource.h>
41 #include <sys/types.h>
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"
57 void extendApplicationEnvironment() {
59 // Try to set RLIMIT_NOFILE as large as possible (failure is harmless):
61 if (getrlimit(RLIMIT_NOFILE
, &l
) == 0) {
62 l
.rlim_cur
= l
.rlim_max
;
63 setrlimit(RLIMIT_NOFILE
, &l
);
67 // Make sure URE_BOOTSTRAP environment variable is set (failure is fatal):
68 rtl::OUStringBuffer env
;
69 env
.appendAscii(RTL_CONSTASCII_STRINGPARAM("URE_BOOTSTRAP="));
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
);
81 if (osl_getExecutableFile(&uri
.pData
) != osl_Process_E_None
) {
84 sal_Int32 i
= uri
.lastIndexOf('/');
86 uri
= uri
.copy(0, i
+ 1);
88 env
.append(rtl::Bootstrap::encode(uri
));
90 RTL_CONSTASCII_STRINGPARAM(SAL_CONFIGFILE("fundamental")));
93 if (!env
.makeStringAndClear().convertToString(
94 &s
, osl_getThreadTextEncoding(),
95 RTL_UNICODETOTEXT_FLAGS_UNDEFINED_ERROR
96 | RTL_UNICODETOTEXT_FLAGS_INVALID_ERROR
))
100 rtl_string_acquire(s
.pData
); // argument to putenv must leak
101 if (putenv(const_cast< char * >(s
.getStr())) != 0) {