1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <osl/mutex.hxx>
21 #include <rtl/alloc.h>
22 #include <rtl/process.h>
23 #include <rtl/ustring.hxx>
27 rtl_uString
** g_ppCommandArgs
= nullptr;
28 sal_uInt32 g_nCommandArgCount
= 0;
35 ArgHolder::~ArgHolder()
37 while (g_nCommandArgCount
> 0)
38 rtl_uString_release (g_ppCommandArgs
[--g_nCommandArgCount
]);
40 free (g_ppCommandArgs
);
41 g_ppCommandArgs
= nullptr;
44 // The destructor of this static ArgHolder is "activated" by the assignments to
45 // g_ppCommandArgs and g_nCommandArgCount in init():
50 osl::MutexGuard
guard( osl::Mutex::getGlobalMutex() );
54 sal_Int32 i
, n
= osl_getCommandArgCount();
57 static_cast<rtl_uString
**>(rtl_allocateZeroMemory (n
* sizeof(rtl_uString
*)));
58 for (i
= 0; i
< n
; i
++)
60 rtl_uString
* pArg
= nullptr;
61 osl_getCommandArg (i
, &pArg
);
64 auto const & arg
= OUString::unacquired(&pArg
);
65 env
= (arg
.startsWith("-") || arg
.startsWith("/")) &&
66 arg
.match("env:", 1) &&
67 arg
.indexOf ('=') >= 0;
72 rtl_uString_release (pArg
);
77 g_ppCommandArgs
[g_nCommandArgCount
++] = pArg
;
84 oslProcessError SAL_CALL
rtl_getAppCommandArg (
85 sal_uInt32 nArg
, rtl_uString
**ppCommandArg
)
88 oslProcessError result
= osl_Process_E_NotFound
;
89 if( nArg
< g_nCommandArgCount
)
91 rtl_uString_assign( ppCommandArg
, g_ppCommandArgs
[nArg
] );
92 result
= osl_Process_E_None
;
97 sal_uInt32 SAL_CALL
rtl_getAppCommandArgCount()
100 return g_nCommandArgCount
;
103 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */