ReactOS  0.4.14-dev-376-gaedba84
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  if (!_tcsncmp (param, _T("/?"), 2))
39  {
41  return 0;
42  }
43 
44  nErrorLevel = 0;
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");
56  return 1;
57  }
58 
59  dwBuffer = GetEnvironmentVariable (_T("PATH"), pszBuffer, ENV_BUFFER_SIZE);
60  if (dwBuffer == 0)
61  {
62  cmd_free(pszBuffer);
64  return 0;
65  }
66  else if (dwBuffer > ENV_BUFFER_SIZE)
67  {
68  LPTSTR pszOldBuffer = pszBuffer;
69  pszBuffer = (LPTSTR)cmd_realloc (pszBuffer, dwBuffer * sizeof (TCHAR));
70  if (!pszBuffer)
71  {
72  WARN("Cannot reallocate memory for pszBuffer!\n");
73  cmd_free(pszOldBuffer);
74  return 1;
75  }
76  GetEnvironmentVariable (_T("PATH"), pszBuffer, dwBuffer);
77  }
78 
79  ConOutPrintf(_T("PATH=%s\n"), pszBuffer);
80  cmd_free (pszBuffer);
81 
82  return 0;
83  }
84 
85  /* skip leading '=' */
86  if (*param == _T('='))
87  param++;
88 
89  /* set PATH environment variable */
90  if (!SetEnvironmentVariable (_T("PATH"), param))
91  {
92  nErrorLevel = 1;
93  return 1;
94  }
95 
96  return 0;
97 }
INT nErrorLevel
Definition: cmd.c:157
#define TRUE
Definition: types.h:120
#define WARN(fmt,...)
Definition: debug.h:111
#define ConOutPrintf(szStr,...)
Definition: console.h:42
VOID ConOutResPaging(BOOL StartPaging, UINT resID)
Definition: console.c:182
#define STRING_VOL_HELP2
Definition: resource.h:201
CHAR * LPTSTR
Definition: xmlstorage.h:192
char TCHAR
Definition: xmlstorage.h:189
#define _T(x)
Definition: vfdio.h:22
GLfloat param
Definition: glext.h:5796
#define ConOutResPrintf(uID,...)
Definition: console.h:48
unsigned long DWORD
Definition: ntddk_ex.h:95
#define cmd_realloc(ptr, size)
Definition: cmddbg.h:30
#define SetEnvironmentVariable
Definition: winbase.h:3732
#define cmd_alloc(size)
Definition: cmddbg.h:29
#define cmd_free(ptr)
Definition: cmddbg.h:31
#define GetEnvironmentVariable
Definition: winbase.h:3638
#define ENV_BUFFER_SIZE
Definition: path.c:33
#define STRING_PATH_HELP1
Definition: resource.h:151
int _tcsncmp(const _TCHAR *s1, const _TCHAR *s2, size_t n)
Definition: tcsncmp.h:9

Referenced by RunShell().