X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fhelper%2Fioutil.c;h=55319004b87bd5a554f7ddf46dece9230a9954a2;hb=e03eb89cfb7ee7a952bf8536ae1a4e7f2087d766;hp=4e9d6878eae396b72b3c533ac80b630aaffbcc20;hpb=8b00e56e6433cff3ff818835953b27765aaabab0;p=openocd.git diff --git a/src/helper/ioutil.c b/src/helper/ioutil.c index 4e9d6878ea..55319004b8 100644 --- a/src/helper/ioutil.c +++ b/src/helper/ioutil.c @@ -14,7 +14,7 @@ * You should have received a copy of the GNU General Public License * * along with this program; if not, write to the * * Free Software Foundation, Inc., * - * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ /* this file contains various functionality useful to standalone systems */ @@ -48,14 +48,12 @@ #include #endif #ifdef HAVE_MALLOC_H -#if !BUILD_ECOSBOARD #include #endif -#endif /* loads a file and returns a pointer to it in memory. The file contains * a 0 byte(sentinel) after len bytes - the length of the file. */ -int loadFile(const char *fileName, void **data, size_t *len) +static int loadFile(const char *fileName, char **data, size_t *len) { /* ensure returned length is always sane */ *len = 0; @@ -100,8 +98,7 @@ int loadFile(const char *fileName, void **data, size_t *len) fclose(pFile); /* 0-byte after buffer (not included in *len) serves as a sentinel */ - char *buf = (char *)*data; - buf[*len] = 0; + (*data)[*len] = 0; return ERROR_OK; } @@ -113,12 +110,12 @@ COMMAND_HANDLER(handle_cat_command) /* NOTE!!! we only have line printing capability so we print the entire file as a single * line. */ - void *data; + char *data; size_t len; int retval = loadFile(CMD_ARGV[0], &data, &len); if (retval == ERROR_OK) { - command_print(CMD_CTX, "%s", (char *)data); + command_print(CMD_CTX, "%s", data); free(data); } else command_print(CMD_CTX, "%s not found", CMD_ARGV[0]); @@ -139,6 +136,7 @@ COMMAND_HANDLER(handle_trunc_command) return ERROR_OK; } +#ifdef HAVE_MALLOC_H COMMAND_HANDLER(handle_meminfo_command) { static int prev; @@ -157,7 +155,7 @@ COMMAND_HANDLER(handle_meminfo_command) return ERROR_OK; } - +#endif COMMAND_HANDLER(handle_append_command) { @@ -197,7 +195,7 @@ COMMAND_HANDLER(handle_cp_command) /* NOTE!!! we only have line printing capability so we print the entire file as a single * line. */ - void *data; + char *data; size_t len; int retval = loadFile(CMD_ARGV[0], &data, &len); @@ -215,7 +213,7 @@ COMMAND_HANDLER(handle_cp_command) if (chunk > maxChunk) chunk = maxChunk; - if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk)) + if ((retval == ERROR_OK) && (fwrite(data + pos, 1, chunk, f) != chunk)) retval = ERROR_COMMAND_SYNTAX_ERROR; if (retval != ERROR_OK) @@ -379,7 +377,7 @@ static int ioutil_Jim_Command_ls(Jim_Interp *interp, return JIM_ERR; } - char *name = (char *) Jim_GetString(argv[1], NULL); + const char *name = Jim_GetString(argv[1], NULL); DIR *dirp = NULL; dirp = opendir(name); @@ -489,6 +487,8 @@ static int ioutil_Jim_Command_ip(Jim_Interp *interp, int argc, return JIM_OK; } +#ifdef HAVE_SYS_IOCTL_H +#ifdef SIOCGIFHWADDR /* not so pretty code to fish out eth0 mac address */ static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc, Jim_Obj *const *argv) @@ -547,6 +547,8 @@ static int ioutil_Jim_Command_mac(Jim_Interp *interp, int argc, return JIM_ERR; } +#endif +#endif static const struct command_registration ioutil_command_handlers[] = { { @@ -577,12 +579,14 @@ static const struct command_registration ioutil_command_handlers[] = { .help = "append a variable number of strings to a file", .usage = "file_name [, [, ...]]", }, +#ifdef HAVE_MALLOC_H { .name = "meminfo", .handler = handle_meminfo_command, .mode = COMMAND_ANY, .help = "display free heap space", }, +#endif { .name = "rm", .mode = COMMAND_ANY, @@ -618,12 +622,16 @@ static const struct command_registration ioutil_command_handlers[] = { .help = "show a listing of files", .usage = "dirname", }, +#ifdef HAVE_SYS_IOCTL_H +#ifdef SIOCGIFHWADDR { .name = "mac", .mode = COMMAND_ANY, .jim_handler = ioutil_Jim_Command_mac, .help = "show MAC address", }, +#endif +#endif { .name = "ip", .jim_handler = ioutil_Jim_Command_ip,