32f3298c3bc58854af5d87de0c299b6e8e823203
[reactos.git] / reactos / lib / kernel32 / process / cmdline.c
1 /* $Id: cmdline.c,v 1.12 2000/06/29 23:35:26 dwelch Exp $
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 <ddk/ntddk.h>
15 #include <windows.h>
16 #include <kernel32/proc.h>
17 #include <kernel32/thread.h>
18 #include <wchar.h>
19 #include <string.h>
20 #include <napi/teb.h>
21 #include <ntdll/rtl.h>
22
23 #define NDEBUG
24 #include <kernel32/kernel32.h>
25
26
27 /* GLOBALS ******************************************************************/
28
29 static UNICODE_STRING CommandLineStringW;
30 static ANSI_STRING CommandLineStringA;
31
32 static WCHAR CommandLineW[MAX_PATH];
33 static CHAR CommandLineA[MAX_PATH];
34
35 static WINBOOL bCommandLineInitialized = FALSE;
36
37
38 /* FUNCTIONS ****************************************************************/
39
40 static VOID
41 InitCommandLines (VOID)
42 {
43 PRTL_USER_PROCESS_PARAMETERS Params;
44 // initialize command line buffers
45 CommandLineW[0] = 0;
46 CommandLineStringW.Buffer = CommandLineW;
47 CommandLineStringW.Length = 0;
48 CommandLineStringW.MaximumLength = MAX_PATH * sizeof(WCHAR);
49
50 CommandLineA[0] = 0;
51 CommandLineStringA.Buffer = CommandLineA;
52 CommandLineStringA.Length = 0;
53 CommandLineStringA.MaximumLength = MAX_PATH;
54
55 // get command line
56 Params = NtCurrentPeb()->ProcessParameters;
57 RtlNormalizeProcessParams (Params);
58
59 RtlCopyUnicodeString (&CommandLineStringW,
60 &(Params->CommandLine));
61 RtlUnicodeStringToAnsiString (&CommandLineStringA,
62 &CommandLineStringW,
63 FALSE);
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", CommandLineA);
77
78 return(CommandLineA);
79 }
80
81 LPWSTR STDCALL GetCommandLineW (VOID)
82 {
83 if (bCommandLineInitialized == FALSE)
84 {
85 InitCommandLines ();
86 }
87
88 DPRINT ("CommandLine \'%S\'\n", CommandLineW);
89
90 return(CommandLineW);
91 }
92
93 /* EOF */