Merge 14551:14980 from trunk
[reactos.git] / reactos / subsys / system / cmd / path.c
1 /*
2 * PATH.C - path internal command.
3 *
4 *
5 * History:
6 *
7 * 17 Jul 1998 (John P Price)
8 * Separated commands into individual files.
9 *
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
12 *
13 * 09-Dec-1998 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
14 * Added help text ("/?").
15 *
16 * 18-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
17 * Unicode ready!
18 *
19 * 18-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
20 * Redirection safe!
21 *
22 * 24-Jan-1999 (Eric Kohl <ekohl@abo.rhein-zeitung.de>)
23 * Fixed Win32 environment handling.
24 *
25 * 30-Apr-2005 (Magnus Olsen) <magnus@greatlord.com>)
26 * Remove all hardcode string to En.rc
27 */
28 #include "precomp.h"
29 #include "resource.h"
30
31 #ifdef INCLUDE_CMD_PATH
32
33 /* size of environment variable buffer */
34 #define ENV_BUFFER_SIZE 1024
35
36
37 INT cmd_path (LPTSTR cmd, LPTSTR param)
38 {
39 TCHAR szMsg[RC_STRING_MAX_SIZE];
40
41 if (!_tcsncmp (param, _T("/?"), 2))
42 {
43 LoadString(GetModuleHandle(NULL), STRING_PATH_HELP1, szMsg, RC_STRING_MAX_SIZE);
44 ConOutPuts(szMsg);
45 return 0;
46 }
47
48 /* if param is empty, display the PATH environment variable */
49 if (!param || !*param)
50 {
51 DWORD dwBuffer;
52 LPTSTR pszBuffer;
53
54 pszBuffer = (LPTSTR)malloc (ENV_BUFFER_SIZE * sizeof(TCHAR));
55 dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
56 if (dwBuffer == 0)
57 {
58 LoadString(GetModuleHandle(NULL), STRING_PATH_ERROR, szMsg, RC_STRING_MAX_SIZE);
59 ConErrPrintf(szMsg);
60 return 0;
61 }
62 else if (dwBuffer > ENV_BUFFER_SIZE)
63 {
64 pszBuffer = (LPTSTR)realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
65 GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
66 }
67
68 ConOutPrintf (_T("PATH=%s\n"), pszBuffer);
69 free (pszBuffer);
70
71 return 0;
72 }
73
74 /* skip leading '=' */
75 if (*param == _T('='))
76 param++;
77
78 /* set PATH environment variable */
79 if (!SetEnvironmentVariable (_T("PATH"), param))
80 return 1;
81
82 return 0;
83 }
84
85 #endif
86
87 /* EOF */