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