mirror of
https://github.com/apache/nuttx.git
synced 2026-05-31 23:40:19 +08:00
libc/chdir:"PWD" should save absolute path
Signed-off-by: anjiahao <anjiahao@xiaomi.com>
This commit is contained in:
@@ -100,6 +100,7 @@ int chdir(FAR const char *path)
|
|||||||
struct stat buf;
|
struct stat buf;
|
||||||
char *oldpwd;
|
char *oldpwd;
|
||||||
char *alloc;
|
char *alloc;
|
||||||
|
char *abspath;
|
||||||
int errcode;
|
int errcode;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@@ -151,7 +152,15 @@ int chdir(FAR const char *path)
|
|||||||
|
|
||||||
/* Set the cwd to the input 'path' */
|
/* Set the cwd to the input 'path' */
|
||||||
|
|
||||||
setenv("PWD", path, TRUE);
|
abspath = realpath(path, NULL);
|
||||||
|
if (abspath == NULL)
|
||||||
|
{
|
||||||
|
errcode = ENOENT;
|
||||||
|
goto errout;
|
||||||
|
}
|
||||||
|
|
||||||
|
setenv("PWD", abspath, TRUE);
|
||||||
|
lib_free(abspath);
|
||||||
sched_unlock();
|
sched_unlock();
|
||||||
return OK;
|
return OK;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user