You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2022/04/17 16:40:41 UTC

[GitHub] [incubator-nuttx] xiaoxiang781216 commented on a diff in pull request #6087: libc: Don't duplicate string in chdir and lib_restoredir

xiaoxiang781216 commented on code in PR #6087:
URL: https://github.com/apache/incubator-nuttx/pull/6087#discussion_r851778615


##########
libs/libc/unistd/lib_chdir.c:
##########
@@ -98,42 +73,35 @@ static inline void _trimdir(char *path)
 int chdir(FAR const char *path)
 {
   struct stat buf;
-  char *oldpwd;
-  char *alloc;
-  char *abspath;
-  int errcode;
+  FAR char *oldpwd;
+  FAR char *abspath;
   int ret;
 
-  /* Verify the input parameters */
-
-  if (!path)
-    {
-      errcode = ENOENT;
-      goto errout;
-    }
-
   /* Verify that 'path' refers to a directory */
 
   ret = stat(path, &buf);
   if (ret < 0)
     {
-      errcode = ENOENT;
-      goto errout;
+      return ret;
     }
 
   /* Something exists here... is it a directory? */
 
   if (!S_ISDIR(buf.st_mode))
     {
-      errcode = ENOTDIR;
-      goto errout;
+      set_errno(ENOTDIR);
+      return ERROR;
     }
 
   /* Yes, it is a directory.
    * Remove any trailing '/' characters from the path
    */
 
-  _trimdir(path);
+  abspath = realpath(path, NULL);

Review Comment:
   Done.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org