From 9252dea9088b3a9ffabdae7a14428dfc19f118b9 Mon Sep 17 00:00:00 2001 From: Jon Szymaniak Date: Sun, 1 Sep 2013 02:39:29 -0400 Subject: [PATCH] bladeRF-cli: Fixed struct field initializers and removed use of unistd.h --- host/common/include/host_config.h.in | 14 +++++++------- host/utilities/bladeRF-cli/src/cmd/load.c | 2 +- host/utilities/bladeRF-cli/src/cmd/printset.c | 10 ++++++++-- host/utilities/bladeRF-cli/src/cmd/rxtx.c | 11 ++++------- host/utilities/bladeRF-cli/src/common.c | 8 +++----- 5 files changed, 23 insertions(+), 22 deletions(-) diff --git a/host/common/include/host_config.h.in b/host/common/include/host_config.h.in index e3078f4f..5022bf2b 100644 --- a/host/common/include/host_config.h.in +++ b/host/common/include/host_config.h.in @@ -89,13 +89,13 @@ /* Rename a few functions and types */ #include -#define strtok_r strtok_s -#define strtoull _strtoui64 -//#define snprintf _snprintf -//#define vsnprintf _vsnprintf -#define strcasecmp _stricmp -#define strncasecmp _strnicmp -#define usleep Sleep +#define strtok_r strtok_s +#define strtoull _strtoui64 +#define snprintf _snprintf_s +#define vsnprintf _vsnprintf_s +#define strcasecmp _stricmp +#define strncasecmp _strnicmp +#define usleep Sleep /* ssize_t lives elsewhere */ #include diff --git a/host/utilities/bladeRF-cli/src/cmd/load.c b/host/utilities/bladeRF-cli/src/cmd/load.c index e273d84b..69ea1fe3 100644 --- a/host/utilities/bladeRF-cli/src/cmd/load.c +++ b/host/utilities/bladeRF-cli/src/cmd/load.c @@ -39,7 +39,7 @@ static int load_fx3(struct cli_state *s, char *file) int lib_status; if ((expanded_path = interactive_expand_path(file)) == NULL) { - cli_err(s, "Unable to expand firmware file path: \%s\"", file); + cli_err(s, "Unable to expand firmware file path: \"%s\"", file); cmd_status = CMD_RET_INVPARAM; } else { printf("Flashing firmware from %s...\n", expanded_path); diff --git a/host/utilities/bladeRF-cli/src/cmd/printset.c b/host/utilities/bladeRF-cli/src/cmd/printset.c index 354e5ffe..f53d0286 100644 --- a/host/utilities/bladeRF-cli/src/cmd/printset.c +++ b/host/utilities/bladeRF-cli/src/cmd/printset.c @@ -5,7 +5,11 @@ #include "conversions.h" #define PRINTSET_DECL(x) int print_##x(struct cli_state *, int, char **); int set_##x(struct cli_state *, int, char **); -#define PRINTSET_ENTRY(x) { .print = print_##x, .set = set_##x, .name = #x } +#define PRINTSET_ENTRY(x) { \ + FIELD_INIT(.print, print_##x), \ + FIELD_INIT(.set, set_##x), \ + FIELD_INIT(.name, #x) \ +} /* An entry in the printset table */ struct printset_entry { @@ -56,7 +60,9 @@ struct printset_entry printset_table[] = { PRINTSET_ENTRY(trimdac), PRINTSET_ENTRY(txvga1), PRINTSET_ENTRY(txvga2), - { .print = NULL, .set = NULL, .name = "" } + + /* End of table marked by entry with NULL/empty fields */ + { FIELD_INIT(.print, NULL), FIELD_INIT(.set, NULL), FIELD_INIT(.name, "") } }; bladerf_module get_module( char *mod, bool *ok ) diff --git a/host/utilities/bladeRF-cli/src/cmd/rxtx.c b/host/utilities/bladeRF-cli/src/cmd/rxtx.c index 9e0f88ba..7f05b3f2 100644 --- a/host/utilities/bladeRF-cli/src/cmd/rxtx.c +++ b/host/utilities/bladeRF-cli/src/cmd/rxtx.c @@ -16,7 +16,6 @@ #include #include #include -#include #include "cmd.h" #include "conversions.h" #include "minmax.h" @@ -345,9 +344,8 @@ static int rx_write_csv_c16(struct cli_state *s, size_t n_samples) size_t i; struct rx_cfg *rx = &s->rxtx_data->rx; struct common_cfg *common = &rx->common; - const size_t line_sz = 32; const size_t to_write = n_samples * 2; - char line[line_sz]; + char line[32] = { 0 }; /* We assume we have pairs... */ assert((common->buff_size & 1) == 0); @@ -355,7 +353,7 @@ static int rx_write_csv_c16(struct cli_state *s, size_t n_samples) rx_sc16q12_sample_fixup(common->buff, common->buff_size/2); for (i = 0; i < to_write; i += 2) { - snprintf(line, line_sz, "%d, %d" EOL, + snprintf(line, sizeof(line), "%d, %d" EOL, common->buff[i], common->buff[i + 1]); if (fputs(line, common->file) < 0) { @@ -461,8 +459,7 @@ static ssize_t tx_read_bin_c16(struct cli_state *s, unsigned int *repeats_left) static int tx_csv_to_sc16q12(struct cli_state *s) { const char delim[] = " \r\n\t,.:"; - const size_t buff_size = 81; - char buff[buff_size]; + char buff[81] = { 0 }; enum rxtx_fmt fmt = RXTX_FMT_BIN_SC16Q12; struct tx_cfg *tx = &s->rxtx_data->tx; char *token, *saveptr; @@ -486,7 +483,7 @@ static int tx_csv_to_sc16q12(struct cli_state *s) return CMD_RET_FILEOP; } - while (fgets(buff, buff_size, tx->common.file)) + while (fgets(buff, sizeof(buff), tx->common.file)) { /* I */ token = strtok_r(buff, delim, &saveptr); diff --git a/host/utilities/bladeRF-cli/src/common.c b/host/utilities/bladeRF-cli/src/common.c index 5156b576..ef1b13ba 100644 --- a/host/utilities/bladeRF-cli/src/common.c +++ b/host/utilities/bladeRF-cli/src/common.c @@ -1,7 +1,6 @@ #include #include #include -#include #include #include #include @@ -58,15 +57,14 @@ bool cli_device_in_use(struct cli_state *s) void cli_err(struct cli_state *s, const char *pfx, const char *format, ...) { va_list arg_list; - const size_t lbuf_sz = 32; - char lbuf[lbuf_sz]; + char lbuf[32]; char *err; - memset(lbuf, 0, lbuf_sz); + memset(lbuf, 0, sizeof(lbuf)); /* If we're in a script, we can provide line number info */ if (s->script) { - snprintf(lbuf, lbuf_sz, " (line %d)", s->lineno); + snprintf(lbuf, sizeof(lbuf), " (line %d)", s->lineno); } /* +6 --> 3 newlines, 2 chars padding, NUL terminator */