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/process.h>
22 #include <rtl/ustring.hxx>
26 rtl_uString
** g_ppCommandArgs
= 0;
27 sal_uInt32 g_nCommandArgCount
= 0;
34 ArgHolder::~ArgHolder()
36 while (g_nCommandArgCount
> 0)
37 rtl_uString_release (g_ppCommandArgs
[--g_nCommandArgCount
]);
39 rtl_freeMemory (g_ppCommandArgs
);
43 // The destructor of this static ArgHolder is "activated" by the assignments to
44 // g_ppCommandArgs and g_nCommandArgCount in init():
49 osl::MutexGuard
guard( osl::Mutex::getGlobalMutex() );
52 sal_Int32 i
, n
= osl_getCommandArgCount();
55 (rtl_uString
**)rtl_allocateZeroMemory (n
* sizeof(rtl_uString
*));
56 for (i
= 0; i
< n
; i
++)
58 rtl_uString
* pArg
= 0;
59 osl_getCommandArg (i
, &pArg
);
60 if (('-' == pArg
->buffer
[0] || '/' == pArg
->buffer
[0]) &&
61 'e' == pArg
->buffer
[1] &&
62 'n' == pArg
->buffer
[2] &&
63 'v' == pArg
->buffer
[3] &&
64 ':' == pArg
->buffer
[4] &&
65 rtl_ustr_indexOfChar (&(pArg
->buffer
[5]), '=') >= 0 )
68 rtl_uString_release (pArg
);
73 g_ppCommandArgs
[g_nCommandArgCount
++] = pArg
;
81 oslProcessError SAL_CALL
rtl_getAppCommandArg (
82 sal_uInt32 nArg
, rtl_uString
**ppCommandArg
)
85 oslProcessError result
= osl_Process_E_NotFound
;
86 if( nArg
< g_nCommandArgCount
)
88 rtl_uString_assign( ppCommandArg
, g_ppCommandArgs
[nArg
] );
89 result
= osl_Process_E_None
;
94 sal_uInt32 SAL_CALL
rtl_getAppCommandArgCount()
97 return g_nCommandArgCount
;
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */