mirror of
https://github.com/apache/nuttx-apps.git
synced 2025-10-17 15:32:21 +08:00
nsh: Decouple with CONFIG_FILE_STREAM
Replace all fwrite/fread/fgets/... to write/read/... Before: ``` text data bss dec hex filename 109827 601 6608 117036 1c92c nuttx/nuttx ``` After: ``` text data bss dec hex filename 108053 601 6608 115262 1c23e nuttx/nuttx ``` After with CONFIG_FILE_STREAM disabled: ``` text data bss dec hex filename 105667 601 6608 112876 1b8ec nuttx/nuttx ``` Signed-off-by: Huang Qi <huangqi3@xiaomi.com>
This commit is contained in:
@@ -166,13 +166,12 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
||||
/* Ask for the login username */
|
||||
|
||||
username[0] = '\0';
|
||||
fputs(g_userprompt, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_userprompt, strlen(g_userprompt));
|
||||
|
||||
/* readline() returns EOF on failure */
|
||||
|
||||
ret = readline(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INSTREAM(pstate), OUTSTREAM(pstate));
|
||||
ret = readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INFD(pstate), OUTFD(pstate));
|
||||
if (ret != EOF)
|
||||
{
|
||||
/* Parse out the username */
|
||||
@@ -188,18 +187,16 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
||||
|
||||
#ifdef CONFIG_NSH_PLATFORM_CHALLENGE
|
||||
platform_challenge(challenge, sizeof(challenge));
|
||||
fputs(challenge, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), challenge, strlen(challenge));
|
||||
#endif
|
||||
|
||||
/* Ask for the login password */
|
||||
|
||||
fputs(g_passwordprompt, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_passwordprompt, strlen(g_passwordprompt));
|
||||
|
||||
password[0] = '\0';
|
||||
if (fgets(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INSTREAM(pstate)) != NULL)
|
||||
if (readline_fd(pstate->cn_line, CONFIG_NSH_LINELEN,
|
||||
INFD(pstate), -1) > 0)
|
||||
{
|
||||
/* Parse out the password */
|
||||
|
||||
@@ -226,14 +223,13 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
||||
# error No user verification method selected
|
||||
#endif
|
||||
{
|
||||
fputs(g_loginsuccess, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_loginsuccess, strlen(g_loginsuccess));
|
||||
return OK;
|
||||
}
|
||||
else
|
||||
{
|
||||
fputs(g_badcredentials, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_badcredentials,
|
||||
strlen(g_badcredentials));
|
||||
#if CONFIG_NSH_LOGIN_FAILDELAY > 0
|
||||
usleep(CONFIG_NSH_LOGIN_FAILDELAY * 1000L);
|
||||
#endif
|
||||
@@ -243,8 +239,7 @@ int nsh_login(FAR struct console_stdio_s *pstate)
|
||||
|
||||
/* Too many failed login attempts */
|
||||
|
||||
fputs(g_loginfailure, pstate->cn_outstream);
|
||||
fflush(pstate->cn_outstream);
|
||||
write(OUTFD(pstate), g_loginfailure, strlen(g_loginsuccess));
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user