2 * PATH.C - path internal command.
7 * 17 Jul 1998 (John P Price)
8 * Separated commands into individual files.
10 * 27-Jul-1998 (John P Price <linux-guru@gcfl.net>)
11 * added config.h include
13 * 09-Dec-1998 (Eric Kohl)
14 * Added help text ("/?").
16 * 18-Jan-1999 (Eric Kohl)
19 * 18-Jan-1999 (Eric Kohl)
22 * 24-Jan-1999 (Eric Kohl)
23 * Fixed Win32 environment handling.
25 * 30-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
26 * Remove all hardcoded strings in En.rc
30 #ifdef INCLUDE_CMD_PATH
32 /* Size of environment variable buffer */
33 #define ENV_BUFFER_SIZE 1024
36 INT
cmd_path(LPTSTR param
)
40 if (!_tcsncmp(param
, _T("/?"), 2))
42 ConOutResPaging(TRUE
, STRING_PATH_HELP1
);
46 /* If param is empty, display the PATH environment variable */
47 if (!param
|| !*param
)
52 pszBuffer
= (LPTSTR
)cmd_alloc(ENV_BUFFER_SIZE
* sizeof(TCHAR
));
55 WARN("Cannot allocate memory for pszBuffer!\n");
56 error_out_of_memory();
61 dwBuffer
= GetEnvironmentVariable(_T("PATH"), pszBuffer
, ENV_BUFFER_SIZE
);
65 ConErrResPrintf(STRING_SET_ENV_ERROR
, _T("PATH"));
69 else if (dwBuffer
> ENV_BUFFER_SIZE
)
71 LPTSTR pszOldBuffer
= pszBuffer
;
72 pszBuffer
= (LPTSTR
)cmd_realloc(pszBuffer
, dwBuffer
* sizeof (TCHAR
));
75 WARN("Cannot reallocate memory for pszBuffer!\n");
76 error_out_of_memory();
77 cmd_free(pszOldBuffer
);
81 GetEnvironmentVariable(_T("PATH"), pszBuffer
, dwBuffer
);
84 ConOutPrintf(_T("PATH=%s\n"), pszBuffer
);
91 /* Skip leading '=' */
92 if (*param
== _T('='))
95 /* Set PATH environment variable */
96 if (!SetEnvironmentVariable(_T("PATH"), param
))
102 if (BatType
!= CMD_TYPE
)
105 nErrorLevel
= retval
;
109 nErrorLevel
= retval
;