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() );
53 sal_Int32 i
, n
= osl_getCommandArgCount();
56 static_cast<rtl_uString
**>(rtl_allocateZeroMemory (n
* sizeof(rtl_uString
*)));
57 for (i
= 0; i
< n
; i
++)
59 rtl_uString
* pArg
= nullptr;
60 osl_getCommandArg (i
, &pArg
);
61 if ((pArg
->buffer
[0] == '-' || pArg
->buffer
[0] == '/') &&
62 pArg
->buffer
[1] == 'e' &&
63 pArg
->buffer
[2] == 'n' &&
64 pArg
->buffer
[3] == 'v' &&
65 pArg
->buffer
[4] == ':' &&
66 rtl_ustr_indexOfChar (&(pArg
->buffer
[5]), '=') >= 0 )
69 rtl_uString_release (pArg
);
74 g_ppCommandArgs
[g_nCommandArgCount
++] = pArg
;
82 oslProcessError SAL_CALL
rtl_getAppCommandArg (
83 sal_uInt32 nArg
, rtl_uString
**ppCommandArg
)
86 oslProcessError result
= osl_Process_E_NotFound
;
87 if( nArg
< g_nCommandArgCount
)
89 rtl_uString_assign( ppCommandArg
, g_ppCommandArgs
[nArg
] );
90 result
= osl_Process_E_None
;
95 sal_uInt32 SAL_CALL
rtl_getAppCommandArgCount()
98 return g_nCommandArgCount
;
101 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */