This is an automated email from the ASF dual-hosted git repository. jerpelea pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
The following commit(s) were added to refs/heads/master by this push: new ce3c604 libc/chdir:"PWD" should save absolute path ce3c604 is described below commit ce3c604f48c8217fefdccf649da314bbc5901ee6 Author: anjiahao <anjia...@xiaomi.com> AuthorDate: Fri Feb 11 16:15:01 2022 +0800 libc/chdir:"PWD" should save absolute path Signed-off-by: anjiahao <anjia...@xiaomi.com> --- libs/libc/unistd/lib_chdir.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/libs/libc/unistd/lib_chdir.c b/libs/libc/unistd/lib_chdir.c index 20111b6..020027e 100644 --- a/libs/libc/unistd/lib_chdir.c +++ b/libs/libc/unistd/lib_chdir.c @@ -100,6 +100,7 @@ int chdir(FAR const char *path) struct stat buf; char *oldpwd; char *alloc; + char *abspath; int errcode; int ret; @@ -151,7 +152,15 @@ int chdir(FAR const char *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(); return OK;