b94226c4cce2fde961bf22813d87c37c7b1d4dea
[reactos.git] / reactos / lib / kernel32 / process / cmdline.c
1 /* $Id$
2 *
3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS system libraries
5 * FILE: lib/kernel32/proc/proc.c
6 * PURPOSE: Process functions
7 * PROGRAMMER: Ariadne ( ariadne@xs4all.nl)
8 * UPDATE HISTORY:
9 * Created 01/11/98
10 */
11
12 /* INCLUDES ****************************************************************/
13
14 #include <k32.h>
15
16 #define NDEBUG
17 #include "../include/debug.h"
18
19
20 /* GLOBALS ******************************************************************/
21
22 static UNICODE_STRING CommandLineStringW;
23 static ANSI_STRING CommandLineStringA;
24
25 static BOOL bCommandLineInitialized = FALSE;
26
27
28 /* FUNCTIONS ****************************************************************/
29
30 static VOID
31 InitCommandLines (VOID)
32 {
33 PRTL_USER_PROCESS_PARAMETERS Params;
34
35 // get command line
36 Params = NtCurrentPeb()->ProcessParameters;
37 RtlNormalizeProcessParams (Params);
38
39 // initialize command line buffers
40 CommandLineStringW.Length = Params->CommandLine.Length;
41 CommandLineStringW.MaximumLength = CommandLineStringW.Length + sizeof(WCHAR);
42 CommandLineStringW.Buffer = RtlAllocateHeap(GetProcessHeap(),
43 HEAP_GENERATE_EXCEPTIONS|HEAP_ZERO_MEMORY,
44 CommandLineStringW.MaximumLength);
45
46 RtlInitAnsiString(&CommandLineStringA, NULL);
47
48 // copy command line
49 RtlCopyUnicodeString (&CommandLineStringW,
50 &(Params->CommandLine));
51 CommandLineStringW.Buffer[CommandLineStringW.Length / sizeof(WCHAR)] = 0;
52
53 /* convert unicode string to ansi (or oem) */
54 if (bIsFileApiAnsi)
55 RtlUnicodeStringToAnsiString (&CommandLineStringA,
56 &CommandLineStringW,
57 TRUE);
58 else
59 RtlUnicodeStringToOemString (&CommandLineStringA,
60 &CommandLineStringW,
61 TRUE);
62
63 CommandLineStringA.Buffer[CommandLineStringA.Length] = 0;
64
65 bCommandLineInitialized = TRUE;
66 }
67
68
69 /*
70 * @implemented
71 */
72 LPSTR STDCALL GetCommandLineA(VOID)
73 {
74 if (bCommandLineInitialized == FALSE)
75 {
76 InitCommandLines ();
77 }
78
79 DPRINT ("CommandLine \'%s\'\n", CommandLineStringA.Buffer);
80
81 return(CommandLineStringA.Buffer);
82 }
83
84
85 /*
86 * @implemented
87 */
88 LPWSTR STDCALL GetCommandLineW (VOID)
89 {
90 if (bCommandLineInitialized == FALSE)
91 {
92 InitCommandLines ();
93 }
94
95 DPRINT ("CommandLine \'%S\'\n", CommandLineStringW.Buffer);
96
97 return(CommandLineStringW.Buffer);
98 }
99
100 /* EOF */