From c0fa1d09702113a29f38622d520f8098fdcaa31b Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Sun, 22 Nov 2015 13:33:43 -0600 Subject: [PATCH] hexed: Remove write-only variable --- system/hexed/include/bfile.h | 6 ------ system/hexed/src/bfile.c | 35 +++-------------------------------- system/hexed/src/hexcopy.c | 7 +------ system/hexed/src/hexdump.c | 1 - system/hexed/src/hexed.c | 6 ++---- system/hexed/src/hexenter.c | 4 ---- system/hexed/src/hexhelp.c | 1 - system/hexed/src/hexinsert.c | 4 ---- system/hexed/src/hexmove.c | 7 +------ system/hexed/src/hexremove.c | 4 ---- system/hexed/src/hexword.c | 4 ---- 11 files changed, 7 insertions(+), 72 deletions(-) diff --git a/system/hexed/include/bfile.h b/system/hexed/include/bfile.h index 16ebc5749..65c7241ab 100644 --- a/system/hexed/include/bfile.h +++ b/system/hexed/include/bfile.h @@ -71,12 +71,6 @@ struct bfile_s FAR char *buf; }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - -extern int g_last_error; - /**************************************************************************** * Public Function Prototypes ****************************************************************************/ diff --git a/system/hexed/src/bfile.c b/system/hexed/src/bfile.c index 83032b413..1adaed84c 100644 --- a/system/hexed/src/bfile.c +++ b/system/hexed/src/bfile.c @@ -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; } diff --git a/system/hexed/src/hexcopy.c b/system/hexed/src/hexcopy.c index 71ad9cae6..b735dda88 100644 --- a/system/hexed/src/hexcopy.c +++ b/system/hexed/src/hexcopy.c @@ -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; } diff --git a/system/hexed/src/hexdump.c b/system/hexed/src/hexdump.c index fbcabc3f2..c4e0dea2a 100644 --- a/system/hexed/src/hexdump.c +++ b/system/hexed/src/hexdump.c @@ -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; } diff --git a/system/hexed/src/hexed.c b/system/hexed/src/hexed.c index bd8e65150..ef2137349 100644 --- a/system/hexed/src/hexed.c +++ b/system/hexed/src/hexed.c @@ -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; } diff --git a/system/hexed/src/hexenter.c b/system/hexed/src/hexenter.c index 17f53aa37..3fec1c302 100644 --- a/system/hexed/src/hexenter.c +++ b/system/hexed/src/hexenter.c @@ -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; } diff --git a/system/hexed/src/hexhelp.c b/system/hexed/src/hexhelp.c index 59d8a5cf0..6622ed2d7 100644 --- a/system/hexed/src/hexhelp.c +++ b/system/hexed/src/hexhelp.c @@ -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; } diff --git a/system/hexed/src/hexinsert.c b/system/hexed/src/hexinsert.c index 9d63b39a9..e0c1e3711 100644 --- a/system/hexed/src/hexinsert.c +++ b/system/hexed/src/hexinsert.c @@ -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; } diff --git a/system/hexed/src/hexmove.c b/system/hexed/src/hexmove.c index 6a450c5ac..b659bea7f 100644 --- a/system/hexed/src/hexmove.c +++ b/system/hexed/src/hexmove.c @@ -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; } diff --git a/system/hexed/src/hexremove.c b/system/hexed/src/hexremove.c index d66b9b0b4..69f9e52a3 100644 --- a/system/hexed/src/hexremove.c +++ b/system/hexed/src/hexremove.c @@ -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; } diff --git a/system/hexed/src/hexword.c b/system/hexed/src/hexword.c index ddb8950e8..660e0baa8 100644 --- a/system/hexed/src/hexword.c +++ b/system/hexed/src/hexword.c @@ -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; }