1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "precompiled_tools.hxx"
25 #include "sal/config.h"
26 
27 #include <cstddef>
28 
29 #include "osl/diagnose.h"
30 #include "osl/file.hxx"
31 #include "osl/process.h"
32 #include "rtl/bootstrap.hxx"
33 #include "rtl/ustring.h"
34 #include "rtl/ustring.hxx"
35 #include "tools/getprocessworkingdir.hxx"
36 
37 namespace tools {
38 
getProcessWorkingDir(rtl::OUString * url)39 bool getProcessWorkingDir(rtl::OUString * url) {
40     OSL_ASSERT(url != NULL);
41     rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("$OOO_CWD"));
42     rtl::Bootstrap::expandMacros(s);
43     if (s.getLength() == 0) {
44         if (osl_getProcessWorkingDir(&url->pData) == osl_Process_E_None) {
45             return true;
46         }
47     } else if (s[0] == '1') {
48         *url = s.copy(1);
49         return true;
50     } else if (s[0] == '2' &&
51                (osl::FileBase::getFileURLFromSystemPath(s.copy(1), *url) ==
52                 osl::FileBase::E_None))
53     {
54         return true;
55     }
56     *url = rtl::OUString();
57     return false;
58 }
59 
60 }
61