ReactOS 0.4.15-dev-7942-gd23573b
path.c File Reference
#include "precomp.h"
Include dependency graph for path.c:

Go to the source code of this file.

Macros

#define ENV_BUFFER_SIZE   1024
 

Functions

INT cmd_path (LPTSTR param)
 

Macro Definition Documentation

◆ ENV_BUFFER_SIZE

#define ENV_BUFFER_SIZE   1024

Definition at line 33 of file path.c.

Function Documentation

◆ cmd_path()

INT cmd_path ( LPTSTR  param)

Definition at line 36 of file path.c.

37{
38 INT retval = 0;
39
40 if (!_tcsncmp(param, _T("/?"), 2))
41 {
43 return 0;
44 }
45
46 /* If param is empty, display the PATH environment variable */
47 if (!param || !*param)
48 {
49 DWORD dwBuffer;
50 LPTSTR pszBuffer;
51
52 pszBuffer = (LPTSTR)cmd_alloc(ENV_BUFFER_SIZE * sizeof(TCHAR));
53 if (!pszBuffer)
54 {
55 WARN("Cannot allocate memory for pszBuffer!\n");
57 retval = 1;
58 goto Quit;
59 }
60
61 dwBuffer = GetEnvironmentVariable(_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
62 if (dwBuffer == 0)
63 {
64 cmd_free(pszBuffer);
66 retval = 0;
67 goto Quit;
68 }
69 else if (dwBuffer > ENV_BUFFER_SIZE)
70 {
71 LPTSTR pszOldBuffer = pszBuffer;
72 pszBuffer = (LPTSTR)cmd_realloc(pszBuffer, dwBuffer * sizeof (TCHAR));
73 if (!pszBuffer)
74 {
75 WARN("Cannot reallocate memory for pszBuffer!\n");
77 cmd_free(pszOldBuffer);
78 retval = 1;
79 goto Quit;
80 }
81 GetEnvironmentVariable(_T("PATH"), pszBuffer, dwBuffer);
82 }
83
84 ConOutPrintf(_T("PATH=%s\n"), pszBuffer);
85 cmd_free(pszBuffer);
86
87 retval = 0;
88 goto Quit;
89 }
90
91 /* Skip leading '=' */
92 if (*param == _T('='))
93 param++;
94
95 /* Set PATH environment variable */
96 if (!SetEnvironmentVariable(_T("PATH"), param))
97 {
98 retval = 1;
99 }
100
101Quit:
102 if (BatType != CMD_TYPE)
103 {
104 if (retval != 0)
105 nErrorLevel = retval;
106 }
107 else
108 {
109 nErrorLevel = retval;
110 }
111
112 return retval;
113}
BATCH_TYPE BatType
Definition: batch.c:66
INT nErrorLevel
Definition: cmd.c:158
VOID error_out_of_memory(VOID)
Definition: error.c:138
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define ConOutPrintf(szStr,...)
Definition: console.h:41
#define ConErrResPrintf(uID,...)
Definition: console.h:50
#define ENV_BUFFER_SIZE
Definition: path.c:33
#define STRING_SET_ENV_ERROR
Definition: resource.h:55
#define STRING_PATH_HELP1
Definition: resource.h:151
@ CMD_TYPE
Definition: batch.h:19
#define WARN(fmt,...)
Definition: debug.h:112
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define TRUE
Definition: types.h:120
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat param
Definition: glext.h:5796
#define _tcsncmp
Definition: tchar.h:1428
int32_t INT
Definition: typedefs.h:58
#define _T(x)
Definition: vfdio.h:22
#define GetEnvironmentVariable
Definition: winbase.h:3814
#define SetEnvironmentVariable
Definition: winbase.h:3908
char TCHAR
Definition: xmlstorage.h:189
CHAR * LPTSTR
Definition: xmlstorage.h:192

Referenced by RunShell().