Fix indentation and coding style. No code changes.
[reactos.git] / reactos / dll / win32 / 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 <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
31 VOID
32 InitCommandLines(VOID)
33 {
34 PRTL_USER_PROCESS_PARAMETERS Params;
35
36 /* FIXME - not thread-safe! */
37
38 // get command line
39 Params = NtCurrentPeb()->ProcessParameters;
40 RtlNormalizeProcessParams (Params);
41
42 // initialize command line buffers
43 CommandLineStringW.Length = Params->CommandLine.Length;
44 CommandLineStringW.MaximumLength = CommandLineStringW.Length + sizeof(WCHAR);
45 CommandLineStringW.Buffer = RtlAllocateHeap(GetProcessHeap(),
46 HEAP_GENERATE_EXCEPTIONS | HEAP_ZERO_MEMORY,
47 CommandLineStringW.MaximumLength);
48 if (CommandLineStringW.Buffer == NULL)
49 {
50 return;
51 }
52
53 RtlInitAnsiString(&CommandLineStringA, NULL);
54
55 /* Copy command line */
56 RtlCopyUnicodeString(&CommandLineStringW,
57 &(Params->CommandLine));
58 CommandLineStringW.Buffer[CommandLineStringW.Length / sizeof(WCHAR)] = 0;
59
60 /* convert unicode string to ansi (or oem) */
61 if (bIsFileApiAnsi)
62 RtlUnicodeStringToAnsiString(&CommandLineStringA,
63 &CommandLineStringW,
64 TRUE);
65 else
66 RtlUnicodeStringToOemString(&CommandLineStringA,
67 &CommandLineStringW,
68 TRUE);
69
70 CommandLineStringA.Buffer[CommandLineStringA.Length] = 0;
71
72 bCommandLineInitialized = TRUE;
73 }
74
75
76 /*
77 * @implemented
78 */
79 LPSTR
80 WINAPI
81 GetCommandLineA(VOID)
82 {
83 if (bCommandLineInitialized == FALSE)
84 {
85 InitCommandLines();
86 }
87
88 DPRINT("CommandLine \'%s\'\n", CommandLineStringA.Buffer);
89
90 return CommandLineStringA.Buffer;
91 }
92
93
94 /*
95 * @implemented
96 */
97 LPWSTR
98 WINAPI
99 GetCommandLineW(VOID)
100 {
101 if (bCommandLineInitialized == FALSE)
102 {
103 InitCommandLines();
104 }
105
106 DPRINT("CommandLine \'%S\'\n", CommandLineStringW.Buffer);
107
108 return CommandLineStringW.Buffer;
109 }
110
111 /* EOF */