netutils/ftpd, examples/ftpd: code cleanup and nxstyle

Signed-off-by: Juha Niskanen <juha.niskanen@haltian.com>
This commit is contained in:
Juha Niskanen 2021-01-13 20:01:00 +02:00 committed by Xiang Xiao
parent 31f52a1971
commit eceaeb926a
4 changed files with 25 additions and 24 deletions

View File

@ -36,7 +36,7 @@
#define __APPS_EXAMPLES_FTPD_FTPD_H #define __APPS_EXAMPLES_FTPD_FTPD_H
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Included Files
****************************************************************************/ ****************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
@ -48,7 +48,9 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* Configuration ************************************************************/ /* Configuration ************************************************************/
/* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon. /* CONFIG_EXAMPLES_FTPD_PRIO - Priority of the FTP daemon.
* Default: SCHED_PRIORITY_DEFAULT * Default: SCHED_PRIORITY_DEFAULT
* CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the * CONFIG_EXAMPLES_FTPD_STACKSIZE - Stack size allocated for the

View File

@ -1,5 +1,5 @@
/**************************************************************************** /****************************************************************************
* examples/telnetd/shell.c * examples/ftpd/ftpd_main.c
* *
* Copyright (C) 2012 Gregory Nutt. All rights reserved. * Copyright (C) 2012 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
@ -90,6 +90,7 @@ struct ftpd_globals_s g_ftpdglob;
/**************************************************************************** /****************************************************************************
* Private Functions * Private Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: fptd_netinit * Name: fptd_netinit
****************************************************************************/ ****************************************************************************/
@ -153,7 +154,7 @@ static void ftpd_accounts(FTPD_SESSION handle)
account = &g_ftpdaccounts[i]; account = &g_ftpdaccounts[i];
printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i + 1, printf("%d. %s account: USER=%s PASSWORD=%s HOME=%s\n", i + 1,
(account->flags & FTPD_ACCOUNTFLAG_SYSTEM) != 0 ? "Root" : "User", (account->flags & FTPD_ACCOUNTFLAG_SYSTEM) ? "Root" : "User",
(!account->user) ? "(none)" : account->user, (!account->user) ? "(none)" : account->user,
(!account->password) ? "(none)" : account->password, (!account->password) ? "(none)" : account->password,
(!account->home) ? "(none)" : account->home); (!account->home) ? "(none)" : account->home);
@ -214,7 +215,8 @@ int ftpd_daemon(int s_argc, char **s_argv)
if (ret != -ETIMEDOUT) if (ret != -ETIMEDOUT)
{ {
printf("FTP daemon [%d] ftpd_session returned %d\n", g_ftpdglob.pid, ret); printf("FTP daemon [%d] ftpd_session returned %d\n",
g_ftpdglob.pid, ret);
} }
} }
@ -232,6 +234,7 @@ int ftpd_daemon(int s_argc, char **s_argv)
/**************************************************************************** /****************************************************************************
* Public Functions * Public Functions
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Name: ftpd_main * Name: ftpd_main
****************************************************************************/ ****************************************************************************/
@ -242,7 +245,6 @@ int main(int argc, FAR char *argv[])
if (!g_ftpdglob.initialized) if (!g_ftpdglob.initialized)
{ {
/* Bring up the network */ /* Bring up the network */
printf("Initializing the network\n"); printf("Initializing the network\n");
@ -263,6 +265,7 @@ int main(int argc, FAR char *argv[])
printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid); printf("Waiting for FTP daemon [%d] to stop\n", g_ftpdglob.pid);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!g_ftpdglob.running) if (!g_ftpdglob.running)
{ {
printf("Starting the FTP daemon\n"); printf("Starting the FTP daemon\n");

View File

@ -35,8 +35,6 @@
include $(APPDIR)/Make.defs include $(APPDIR)/Make.defs
# Telnet daemon
ifeq ($(CONFIG_NET_TCP),y) ifeq ($(CONFIG_NET_TCP),y)
CSRCS = ftpd.c CSRCS = ftpd.c
endif endif

View File

@ -1910,9 +1910,7 @@ static int ftpd_stream(FAR struct ftpd_session_s *session, int cmdtype)
if (cmdtype == 0) if (cmdtype == 0)
{ {
/* Read from the file. /* Read from the file. */
* Read returns the error condition via errno.
*/
rdbytes = read(session->fd, session->data.buffer, wantsize); rdbytes = read(session->fd, session->data.buffer, wantsize);
if (rdbytes < 0) if (rdbytes < 0)
@ -2384,7 +2382,7 @@ static int fptd_listscan(FAR struct ftpd_session_s *session, FAR char *path,
if (!dir) if (!dir)
{ {
int errval = errno; int errval = errno;
nerr("ERROR: dir() failed: %d\n", errval); nerr("ERROR: opendir() failed: %d\n", errval);
return -errval; return -errval;
} }
@ -3557,10 +3555,10 @@ static int ftpd_command_size(FAR struct ftpd_session_s *session)
} }
else if (!S_ISREG(st.st_mode)) else if (!S_ISREG(st.st_mode))
{ {
ret = ftpd_response(session->cmd.sd, session->txtimeout, ret = -EPERM;
ftpd_response(session->cmd.sd, session->txtimeout,
g_respfmt2, 550, ' ', session->param, g_respfmt2, 550, ' ', session->param,
": not a regular file."); ": not a regular file.");
ret = -EPERM;
goto errout_with_abspath; goto errout_with_abspath;
} }
@ -3673,9 +3671,9 @@ static int ftpd_command_rnto(FAR struct ftpd_session_s *session)
if (!session->renamefrom) if (!session->renamefrom)
{ {
return ftpd_response(session->cmd.sd, session->txtimeout, ftpd_response(session->cmd.sd, session->txtimeout,
g_respfmt1, 550, ' ', "RNTO error !"); g_respfmt1, 550, ' ', "RNTO error !");
return ret; return -EINVAL;
} }
ret = ftpd_getpath(session, session->param, &abspath, NULL); ret = ftpd_getpath(session, session->param, &abspath, NULL);