4949
5050#ifndef CONFIG_DISABLE_ENVIRON
5151static const char g_pwd [] = "PWD" ;
52- #ifndef CONFIG_NSH_DISABLE_CD
52+ # ifndef CONFIG_NSH_DISABLE_CD
5353static const char g_oldpwd [] = "OLDPWD" ;
54+ # endif
5455#endif
56+
57+ #if !defined(CONFIG_NSH_DISABLE_CD ) || !defined(CONFIG_DISABLE_ENVIRON )
5558static const char g_home [] = CONFIG_LIBC_HOMEDIR ;
5659#endif
5760
@@ -169,12 +172,14 @@ static int nsh_dumpvar(FAR struct nsh_vtbl_s *vtbl, FAR void *arg,
169172 * Name: nsh_getwd
170173 ****************************************************************************/
171174
172- #ifndef CONFIG_DISABLE_ENVIRON
173- FAR const char * nsh_getcwd (void )
175+ FAR const char * nsh_getcwd (FAR struct nsh_vtbl_s * vtbl )
174176{
177+ #ifndef CONFIG_DISABLE_ENVIRON
175178 return nsh_getwd (g_pwd );
176- }
179+ #else
180+ return vtbl -> cwd ;
177181#endif
182+ }
178183
179184/****************************************************************************
180185 * Name: nsh_getfullpath
@@ -201,7 +206,7 @@ FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl,
201206
202207 /* Get the path to the current working directory */
203208
204- wd = nsh_getcwd ();
209+ wd = nsh_getcwd (vtbl );
205210
206211 /* Fake the '.' directory */
207212
@@ -214,27 +219,24 @@ FAR char *nsh_getfullpath(FAR struct nsh_vtbl_s *vtbl,
214219
215220 return nsh_getdirpath (vtbl , wd , relpath );
216221}
217- #endif
218222
219223/****************************************************************************
220224 * Name: nsh_freefullpath
221225 ****************************************************************************/
222226
223- #ifndef CONFIG_DISABLE_ENVIRON
224227void nsh_freefullpath (FAR char * fullpath )
225228{
226229 if (fullpath )
227230 {
228231 free (fullpath );
229232 }
230233}
231- #endif
234+ #endif /* CONFIG_DISABLE_ENVIRON */
232235
233236/****************************************************************************
234237 * Name: cmd_cd
235238 ****************************************************************************/
236239
237- #ifndef CONFIG_DISABLE_ENVIRON
238240#ifndef CONFIG_NSH_DISABLE_CD
239241int cmd_cd (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
240242{
@@ -249,14 +251,16 @@ int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
249251 {
250252 path = g_home ;
251253 }
254+ #ifndef CONFIG_DISABLE_ENVIRON
252255 else if (strcmp (path , "- ") == 0 )
253256 {
254257 alloc = strdup (nsh_getwd (g_oldpwd ));
255258 path = alloc ;
256259 }
260+ #endif
257261 else if (strcmp (path , "..") == 0 )
258262 {
259- alloc = strdup (nsh_getcwd ());
263+ alloc = strdup (nsh_getcwd (vtbl ));
260264 path = dirname (alloc );
261265 }
262266 else
@@ -273,6 +277,12 @@ int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
273277 nsh_error (vtbl , g_fmtcmdfailed , argv [0 ], "chdir ", NSH_ERRNO );
274278 ret = ERROR ;
275279 }
280+ #ifdef CONFIG_DISABLE_ENVIRON
281+ else
282+ {
283+ strlcpy (vtbl -> cwd , path , sizeof (vtbl -> cwd ));
284+ }
285+ #endif
276286
277287 /* Free any memory that was allocated */
278288
@@ -289,7 +299,6 @@ int cmd_cd(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
289299 return ret ;
290300}
291301#endif
292- #endif
293302
294303/****************************************************************************
295304 * Name: cmd_echo
@@ -394,18 +403,16 @@ int cmd_env(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
394403 * Name: cmd_pwd
395404 ****************************************************************************/
396405
397- #ifndef CONFIG_DISABLE_ENVIRON
398406#ifndef CONFIG_NSH_DISABLE_PWD
399407int cmd_pwd (FAR struct nsh_vtbl_s * vtbl , int argc , FAR char * * argv )
400408{
401409 UNUSED (argc );
402410 UNUSED (argv );
403411
404- nsh_output (vtbl , "%s\n" , nsh_getcwd ());
412+ nsh_output (vtbl , "%s\n" , nsh_getcwd (vtbl ));
405413 return OK ;
406414}
407415#endif
408- #endif
409416
410417/****************************************************************************
411418 * Name: cmd_set
0 commit comments