hexed: Remove write-only variable

This commit is contained in:
Gregory Nutt 2015-11-22 13:33:43 -06:00
parent 37401b9889
commit c0fa1d0970
11 changed files with 7 additions and 72 deletions

View File

@ -71,12 +71,6 @@ struct bfile_s
FAR char *buf;
};
/****************************************************************************
* Public Data
****************************************************************************/
extern int g_last_error;
/****************************************************************************
* Public Function Prototypes
****************************************************************************/

View File

@ -43,12 +43,6 @@
#include "bfile.h"
/****************************************************************************
* Public Data
****************************************************************************/
int g_last_error;
/****************************************************************************
* Private Functions
****************************************************************************/
@ -59,7 +53,6 @@ static FAR void *bfallocbuf(FAR struct bfile_s *bf, long sz)
{
if (bf == NULL)
{
g_last_error = EBADF;
return NULL;
}
@ -68,7 +61,6 @@ static FAR void *bfallocbuf(FAR struct bfile_s *bf, long sz)
sz = BFILE_BUF_ALIGN(sz);
if ((bf->buf = realloc(bf->buf, sz)) == NULL)
{
g_last_error = ENOMEM;
return NULL;
}
@ -89,7 +81,6 @@ static int bffree(FAR struct bfile_s *bf)
{
if (bf == NULL)
{
g_last_error = EBADF;
return -EBADF;
}
@ -123,7 +114,6 @@ long fsize(FILE * fp)
if (fp == NULL)
{
g_last_error = EBADF;
return 0;
}
@ -140,7 +130,6 @@ long bftruncate(FAR struct bfile_s *bf, long sz)
{
if (bf == NULL)
{
g_last_error = EBADF;
return -EBADF;
}
@ -159,7 +148,6 @@ int bfflush(FAR struct bfile_s *bf)
if (bf == NULL)
{
g_last_error = EBADF;
return -EBADF;
}
@ -176,14 +164,13 @@ int bfflush(FAR struct bfile_s *bf)
nread = fwrite(bf->buf, 1, bf->size, bf->fp);
if (nread < 0)
{
g_last_error = errno;
fprintf(stderr, "ERROR: Write to file failed: %d\n", g_last_error);
ret = -g_last_error;
int errcode = errno;
fprintf(stderr, "ERROR: Write to file failed: %d\n", errcode);
ret = -errcode;
}
else if (fwrite(bf->buf, 1, bf->size, bf->fp) == bf->size)
{
fprintf(stderr, "ERROR: Bad write size\n");
g_last_error = EIO;
ret = -EIO;
}
else
@ -206,7 +193,6 @@ FAR struct bfile_s *bfopen(char *name, char *mode)
if (name == NULL)
{
g_last_error = EINVAL;
return NULL;
}
@ -214,7 +200,6 @@ FAR struct bfile_s *bfopen(char *name, char *mode)
if ((bf = malloc(sizeof(struct bfile_s))) == NULL)
{
g_last_error = ENOMEM;
return NULL;
}
@ -225,7 +210,6 @@ FAR struct bfile_s *bfopen(char *name, char *mode)
if ((bf->name = malloc(strlen(name) + 1)) == NULL)
{
bffree(bf);
g_last_error = ENOMEM;
return NULL;
}
@ -235,7 +219,6 @@ FAR struct bfile_s *bfopen(char *name, char *mode)
if ((bf->fp = fopen(bf->name, mode)) == NULL)
{
g_last_error = errno;
bffree(bf);
return NULL;
}
@ -260,7 +243,6 @@ int bfclose(FAR struct bfile_s *bf)
if (bf == NULL)
{
g_last_error = EBADF;
return -EBADF;
}
@ -285,7 +267,6 @@ long bfclip(FAR struct bfile_s *bf, long off, long sz)
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}
@ -293,7 +274,6 @@ long bfclip(FAR struct bfile_s *bf, long off, long sz)
if (off < 0 || sz <= 0)
{
g_last_error = ERANGE;
return EOF;
}
@ -301,7 +281,6 @@ long bfclip(FAR struct bfile_s *bf, long off, long sz)
if (off > bf->size)
{
g_last_error = ENFILE;
return EOF;
}
@ -336,7 +315,6 @@ long bfinsert(FAR struct bfile_s *bf, long off, void *mem, long sz)
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}
@ -344,7 +322,6 @@ long bfinsert(FAR struct bfile_s *bf, long off, void *mem, long sz)
if (off < 0 || sz <= 0)
{
g_last_error = ERANGE;
return EOF;
}
@ -383,7 +360,6 @@ long bfcopy(FAR struct bfile_s *bf, long off, long src, long sz)
{
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}
@ -391,7 +367,6 @@ long bfcopy(FAR struct bfile_s *bf, long off, long src, long sz)
if (src > bf->size)
{
g_last_error = ENFILE;
return EOF;
}
@ -431,7 +406,6 @@ long bfmove(FAR struct bfile_s *bf, long off, long src, long sz)
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}
@ -439,7 +413,6 @@ long bfmove(FAR struct bfile_s *bf, long off, long src, long sz)
if (src > bf->size)
{
g_last_error = ENFILE;
return EOF;
}
@ -496,7 +469,6 @@ long bfread(FAR struct bfile_s *bf)
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}
@ -531,7 +503,6 @@ long bfwrite(FAR struct bfile_s *bf, long off, void *mem, long sz)
{
if (bf == NULL)
{
g_last_error = EBADF;
return EOF;
}

View File

@ -81,7 +81,6 @@ static int runcopy(FAR struct command_s *cmd)
if (cmd->opts.src > g_hexfile->size)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -94,7 +93,7 @@ static int runcopy(FAR struct command_s *cmd)
return copyover(cmd);
default:
return -1;
return -EINVAL;
}
}
@ -116,7 +115,6 @@ static int setcopy(FAR struct command_s *cmd, int optc, char *opt)
if (opt == NULL)
{
g_last_error = EFAULT;
return -EFAULT;
}
@ -126,7 +124,6 @@ static int setcopy(FAR struct command_s *cmd, int optc, char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -159,7 +156,6 @@ static int setcopy(FAR struct command_s *cmd, int optc, char *opt)
default:
/* Too many options specified */
g_last_error = E2BIG;
return -E2BIG;
}
@ -178,7 +174,6 @@ int hexcopy(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || (cmd->id != CMD_COPY && cmd->id != CMD_COPY_OVER))
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -242,7 +242,6 @@ int hexdump(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_DUMP)
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -120,8 +120,8 @@ int loadfile(FAR char *name)
if (g_hexfile == NULL)
{
fprintf(stderr, "ERROR: Failed to open %s: %d\n", name, g_last_error);
return -g_last_error;
fprintf(stderr, "ERROR: Failed to open %s\n", name);
return -ENOENT;
}
bfread(g_hexfile);
@ -192,7 +192,6 @@ int hexcmd(FAR struct command_s *cmd, int optc, FAR char *opt)
break;
default:
g_last_error = EINVAL;
return -EINVAL;
}
@ -341,7 +340,6 @@ int runargs(void)
if (g_hexfile == NULL)
{
fprintf(stderr, "ERROR: Missing filename\n");
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -77,7 +77,6 @@ static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
if (opt == NULL)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -87,7 +86,6 @@ static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -135,7 +133,6 @@ static int setenter(FAR struct command_s *cmd, int optc, FAR char *opt)
else
{
fprintf(stderr, "ERROR: too many values set\n");
g_last_error = E2BIG;
return -E2BIG;
}
@ -154,7 +151,6 @@ int hexenter(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_ENTER)
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -119,7 +119,6 @@ int hexhelp(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_HELP)
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -91,7 +91,6 @@ static int setinsert(FAR struct command_s *cmd, int optc, char *opt)
if (opt == NULL)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -101,7 +100,6 @@ static int setinsert(FAR struct command_s *cmd, int optc, char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -158,7 +156,6 @@ static int setinsert(FAR struct command_s *cmd, int optc, char *opt)
else
{
fprintf(stderr, "ERROR: Too many values set\n");
g_last_error = E2BIG;
return -E2BIG;
}
}
@ -178,7 +175,6 @@ int hexinsert(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_INSERT)
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -112,7 +112,6 @@ static int runmove(FAR struct command_s *cmd)
if (cmd->opts.src > g_hexfile->size)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -129,7 +128,7 @@ static int runmove(FAR struct command_s *cmd)
}
}
/* set the move command */
/* Set the move command */
static int setmove(FAR struct command_s *cmd, int optc, char *opt)
{
@ -147,7 +146,6 @@ static int setmove(FAR struct command_s *cmd, int optc, char *opt)
if (opt == NULL)
{
g_last_error = EFAULT;
return -EFAULT;
}
@ -157,7 +155,6 @@ static int setmove(FAR struct command_s *cmd, int optc, char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -191,7 +188,6 @@ static int setmove(FAR struct command_s *cmd, int optc, char *opt)
default:
/* Too many options specified */
g_last_error = E2BIG;
return -E2BIG;
}
@ -210,7 +206,6 @@ int hexmove(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || (cmd->id != CMD_MOVE && cmd->id != CMD_MOVE_OVER))
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -75,7 +75,6 @@ static int setremove(FAR struct command_s *cmd, int optc, char *opt)
if (opt == NULL)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -85,7 +84,6 @@ static int setremove(FAR struct command_s *cmd, int optc, char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -111,7 +109,6 @@ static int setremove(FAR struct command_s *cmd, int optc, char *opt)
default:
/* Too many options specified */
g_last_error = E2BIG;
return -E2BIG;
}
@ -130,7 +127,6 @@ int hexremove(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_REMOVE)
{
g_last_error = EINVAL;
return -EINVAL;
}

View File

@ -65,7 +65,6 @@ static int setword(FAR struct command_s *cmd, int optc, char *opt)
if (opt == NULL)
{
g_last_error = EFAULT;
return -EFAULT;
}
@ -75,7 +74,6 @@ static int setword(FAR struct command_s *cmd, int optc, char *opt)
if (s == opt)
{
g_last_error = EINVAL;
return -EINVAL;
}
@ -106,7 +104,6 @@ static int setword(FAR struct command_s *cmd, int optc, char *opt)
{
/* Too many options specified */
g_last_error = E2BIG;
return -E2BIG;
}
@ -125,7 +122,6 @@ int hexword(FAR struct command_s *cmd, int optc, char *opt)
if (cmd == NULL || cmd->id != CMD_WORD)
{
g_last_error = EINVAL;
return -EINVAL;
}