fix toolbar import
[ooovba.git] / tools / source / misc / getprocessworkingdir.cxx
blob93bfb2f1fa1f3265d18d24e1ee5d1c323efcc41e
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: getprocessworkingdir.cxx,v $
10 * $Revision: 1.2 $
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 <cstddef>
36 #include "osl/diagnose.h"
37 #include "osl/file.hxx"
38 #include "osl/process.h"
39 #include "rtl/bootstrap.hxx"
40 #include "rtl/ustring.h"
41 #include "rtl/ustring.hxx"
42 #include "tools/getprocessworkingdir.hxx"
44 namespace tools {
46 bool getProcessWorkingDir(rtl::OUString * url) {
47 OSL_ASSERT(url != NULL);
48 rtl::OUString s(RTL_CONSTASCII_USTRINGPARAM("$OOO_CWD"));
49 rtl::Bootstrap::expandMacros(s);
50 if (s.getLength() == 0) {
51 if (osl_getProcessWorkingDir(&url->pData) == osl_Process_E_None) {
52 return true;
54 } else if (s[0] == '1') {
55 *url = s.copy(1);
56 return true;
57 } else if (s[0] == '2' &&
58 (osl::FileBase::getFileURLFromSystemPath(s.copy(1), *url) ==
59 osl::FileBase::E_None))
61 return true;
63 *url = rtl::OUString();
64 return false;