fb412538bf6cdc5d5ffb69b2d01dcd01820dc490
[reactos.git] / 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 <kernel32/kernel32.h>
18
19
20 /* GLOBALS ******************************************************************/
21
22 static UNICODE_STRING CommandLineStringW;
23 static ANSI_STRING CommandLineStringA;
24
25 static WINBOOL 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 LPSTR STDCALL GetCommandLineA(VOID)
70 {
71         if (bCommandLineInitialized == FALSE)
72         {
73                 InitCommandLines ();
74         }
75
76         DPRINT ("CommandLine \'%s\'\n", CommandLineStringA.Buffer);
77
78         return(CommandLineStringA.Buffer);
79 }
80
81 LPWSTR STDCALL GetCommandLineW (VOID)
82 {
83         if (bCommandLineInitialized == FALSE)
84         {
85                 InitCommandLines ();
86         }
87
88         DPRINT ("CommandLine \'%S\'\n", CommandLineStringW.Buffer);
89
90         return(CommandLineStringW.Buffer);
91 }
92
93 /* EOF */