xiaoxiang781216 commented on code in PR #3480:
URL: https://github.com/apache/nuttx-apps/pull/3480#discussion_r3238964607
##########
nshlib/nsh_fscmds.c:
##########
@@ -843,6 +843,150 @@ int cmd_cat(FAR struct nsh_vtbl_s *vtbl, int argc, FAR
char **argv)
}
#endif
+/****************************************************************************
+ * Name: cmd_chmod
+ *
+ * Description:
+ * chmod <octal-mode> <path>
+ *
+ * Only numeric (octal) modes are supported.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_CHMOD
+int cmd_chmod(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR char *fullpath;
+ FAR char *endptr;
+ long mode;
+ int ret = ERROR;
+
+ UNUSED(argc);
+
+ mode = strtol(argv[1], &endptr, 8);
+ if (endptr == argv[1] || *endptr != '\0' || mode < 0 || mode > 0777)
+ {
+ nsh_error(vtbl, g_fmtarginvalid, argv[0]);
+ return ERROR;
+ }
+
+ fullpath = nsh_getfullpath(vtbl, argv[2]);
+ if (fullpath != NULL)
+ {
+ ret = chmod(fullpath, (mode_t)mode);
+ if (ret < 0)
+ {
+ nsh_error(vtbl, g_fmtcmdfailed, argv[0], "chmod", NSH_ERRNO);
+ }
+
+ nsh_freefullpath(fullpath);
+ }
+
+ return ret;
+}
+#endif
+
+/****************************************************************************
+ * Name: cmd_chown
+ *
+ * Description:
+ * chown <uid>[:<gid>] <path>
+ * chown [<uid>]:<gid> <path>
+ *
+ * Only numeric uid/gid forms are supported. Empty uid or gid fields
+ * leave that side unchanged.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_NSH_DISABLE_CHOWN
+int cmd_chown(FAR struct nsh_vtbl_s *vtbl, int argc, FAR char **argv)
+{
+ FAR const char *spec = argv[1];
+ FAR const char *colon;
+ FAR const char *gidstr;
+ FAR char *endptr;
+ FAR char *fullpath;
+ long value;
+ uid_t uid = (uid_t)-1;
+ gid_t gid = (gid_t)-1;
+ int ret = ERROR;
+
+ UNUSED(argc);
+
+ colon = strchr(spec, ':');
Review Comment:
why need, let's check endptr after strtol
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]