9
0
Fork 0

strerror() is big; don't use it unless requested

git-svn-id: https://nuttx.svn.sourceforge.net/svnroot/nuttx/trunk@717 7fd9a85b-ad96-42d3-883c-3090e2eb8679
This commit is contained in:
patacongo 2008-02-20 18:02:55 +00:00
parent 3313c6f1e7
commit 3cd8420d40
6 changed files with 34 additions and 18 deletions

View File

@ -50,8 +50,20 @@
* Definitions
****************************************************************************/
/* This is the maximum number of arguments that will be accepted for a command */
#define NSH_MAX_ARGUMENTS 6
/* strerror() produces much nicer output but is, however, quite large and
* will only be used if CONFIG_NSH_STRERROR is defined.
*/
#ifdef CONFIG_NSH_STRERROR
# define NSH_ERRNO strerror(errno)
#else
# define NSH_ERRNO errno
#endif
/****************************************************************************
* Public Types
****************************************************************************/

View File

@ -1,7 +1,7 @@
/****************************************************************************
* nsh_envcmds.c
*
* Copyright (C) 2007 Gregory Nutt. All rights reserved.
* Copyright (C) 2007, 2008 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <spudmonkey@racsa.co.cr>
*
* Redistribution and use in source and binary forms, with or without
@ -14,7 +14,7 @@
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name Gregory Nutt nor the names of its contributors may be
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
@ -118,7 +118,7 @@ void cmd_set(FAR void *handle, int argc, char **argv)
{
if (setenv(argv[1], argv[2], TRUE) < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "setenv", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "setenv", NSH_ERRNO);
}
}
#endif
@ -132,7 +132,7 @@ void cmd_unset(FAR void *handle, int argc, char **argv)
{
if (unsetenv(argv[1]) < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "unsetenv", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "unsetenv", NSH_ERRNO);
}
}
#endif

View File

@ -229,7 +229,7 @@ static int ls_handler(FAR void *handle, const char *dirpath, struct dirent *entr
free(fullpath);
if (ret != 0)
{
nsh_output(handle, g_fmtcmdfailed, "ls", "stat", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, "ls", "stat", NSH_ERRNO);
return OK;
}
@ -371,7 +371,7 @@ void cmd_cat(FAR void *handle, int argc, char **argv)
int fd = open(argv[1], O_RDONLY);
if (fd < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
return;
}
@ -389,7 +389,7 @@ void cmd_cat(FAR void *handle, int argc, char **argv)
if (errno != EINTR)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
break;
}
}
@ -409,7 +409,7 @@ void cmd_cat(FAR void *handle, int argc, char **argv)
if (errno != EINTR)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
break;
}
}
@ -452,7 +452,7 @@ void cmd_cp(FAR void *handle, int argc, char **argv)
rdfd = open(argv[1], O_RDONLY);
if (rdfd < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
return;
}
@ -494,7 +494,7 @@ void cmd_cp(FAR void *handle, int argc, char **argv)
wrfd = open(wrpath, oflags, 0666);
if (wrfd < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "open", NSH_ERRNO);
goto out_with_fullpath;
}
@ -518,7 +518,7 @@ void cmd_cp(FAR void *handle, int argc, char **argv)
{
/* Read error */
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "read", NSH_ERRNO);
goto out_with_wrfd;
}
}
@ -535,7 +535,7 @@ void cmd_cp(FAR void *handle, int argc, char **argv)
{
/* Read error */
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "write", NSH_ERRNO);
goto out_with_wrfd;
}
}
@ -628,7 +628,7 @@ void cmd_mkdir(FAR void *handle, int argc, char **argv)
int result = mkdir(argv[1], 0777);
if ( result < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "mkdir", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "mkdir", NSH_ERRNO);
}
}
#endif
@ -683,7 +683,7 @@ void cmd_mount(FAR void *handle, int argc, char **argv)
result = mount(argv[optind], argv[optind+1], filesystem, 0, NULL);
if ( result < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "mount", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "mount", NSH_ERRNO);
}
}
#endif
@ -698,7 +698,7 @@ void cmd_rm(FAR void *handle, int argc, char **argv)
{
if (unlink(argv[1]) < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "unlink", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "unlink", NSH_ERRNO);
}
}
#endif
@ -712,7 +712,7 @@ void cmd_rmdir(FAR void *handle, int argc, char **argv)
{
if (rmdir(argv[1]) < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "rmdir", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "rmdir", NSH_ERRNO);
}
}
#endif
@ -729,7 +729,7 @@ void cmd_umount(FAR void *handle, int argc, char **argv)
int result = umount(argv[1]);
if ( result < 0)
{
nsh_output(handle, g_fmtcmdfailed, argv[0], "umount", strerror(errno));
nsh_output(handle, g_fmtcmdfailed, argv[0], "umount", NSH_ERRNO);
}
}
#endif

View File

@ -132,7 +132,11 @@ const char g_fmtcmdnotfound[] = "nsh: %s: command not found\n";
const char g_fmtcmdnotimpl[] = "nsh: %s: command not implemented\n";
const char g_fmtnosuch[] = "nsh: %s: no such %s: %s\n";
const char g_fmttoomanyargs[] = "nsh: %s: too many arguments\n";
#ifdef CONFIG_NSH_STRERROR
const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %s\n";
#else
const char g_fmtcmdfailed[] = "nsh: %s: %s failed: %d\n";
#endif
const char g_fmtcmdoutofmemory[] = "nsh: %s: out of memory\n";
/****************************************************************************

View File

@ -209,6 +209,7 @@ int ifconfig_callback(FAR struct uip_driver_s *dev, void *arg)
nsh_output(arg, "DRaddr:%s ", inet_ntoa(addr));
addr.s_addr = dev->d_netmask;
nsh_output(arg, "Mask:%s\n\n", inet_ntoa(addr));
return OK;
}
/****************************************************************************

View File

@ -95,7 +95,6 @@ static const char *g_statenames[] =
static void ps_task(FAR _TCB *tcb, FAR void *arg)
{
boolean needcomma = FALSE;
int i;
/* Show task status */