Change return value on error.
[fw/openocd] / src / helper / ioutil.c
index 60064abc4b7c28e8d041e71b6f3fa95e388435da..8dc70312afcd8876e78738e9b155245e23994e9d 100644 (file)
@@ -65,19 +65,19 @@ int loadFile(const char *fileName, void **data, size_t *len)
        pFile = fopen(fileName,"rb");
        if (pFile == NULL)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                return ERROR_FAIL;
        }
        if (fseek(pFile, 0, SEEK_END) != 0)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                fclose(pFile);
                return ERROR_FAIL;
        }
        long fsize = ftell(pFile);
        if (fsize == -1)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                fclose(pFile);
                return ERROR_FAIL;
        }
@@ -85,14 +85,14 @@ int loadFile(const char *fileName, void **data, size_t *len)
 
        if (fseek(pFile, 0, SEEK_SET) != 0)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                fclose(pFile);
                return ERROR_FAIL;
        }
        *data = malloc(*len + 1);
        if (*data == NULL)
        {
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                fclose(pFile);
                return ERROR_FAIL;
        }
@@ -101,7 +101,7 @@ int loadFile(const char *fileName, void **data, size_t *len)
        {
                fclose(pFile);
                free(*data);
-               LOG_ERROR("Can't open %s\n", fileName);
+               LOG_ERROR("Can't open %s", fileName);
                return ERROR_FAIL;
        }
        fclose(pFile);
@@ -117,8 +117,7 @@ COMMAND_HANDLER(handle_cat_command)
 {
        if (CMD_ARGC != 1)
        {
-               command_print(CMD_CTX, "cat <filename>");
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        // NOTE!!! we only have line printing capability so we print the entire file as a single line.
@@ -143,8 +142,7 @@ COMMAND_HANDLER(handle_trunc_command)
 {
        if (CMD_ARGC != 1)
        {
-               command_print(CMD_CTX, "trunc <filename>");
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        FILE *config_file = NULL;
@@ -162,8 +160,7 @@ COMMAND_HANDLER(handle_meminfo_command)
 
        if (CMD_ARGC != 0)
        {
-               command_print(CMD_CTX, "meminfo");
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        info = mallinfo();
@@ -184,9 +181,7 @@ COMMAND_HANDLER(handle_append_command)
 {
        if (CMD_ARGC < 1)
        {
-               command_print(CMD_CTX,
-                               "append <filename> [<string1>, [<string2>, ...]]");
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        int retval = ERROR_FAIL;
@@ -224,7 +219,7 @@ COMMAND_HANDLER(handle_cp_command)
 {
        if (CMD_ARGC != 2)
        {
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
        }
 
        // NOTE!!! we only have line printing capability so we print the entire file as a single line.
@@ -237,7 +232,7 @@ COMMAND_HANDLER(handle_cp_command)
 
        FILE *f = fopen(CMD_ARGV[1], "wb");
        if (f == NULL)
-               retval = ERROR_INVALID_ARGUMENTS;
+               retval = ERROR_COMMAND_SYNTAX_ERROR;
 
        size_t pos = 0;
        for (;;)
@@ -250,7 +245,7 @@ COMMAND_HANDLER(handle_cp_command)
                }
 
                if ((retval == ERROR_OK) && (fwrite(((char *)data) + pos, 1, chunk, f) != chunk))
-                       retval = ERROR_INVALID_ARGUMENTS;
+                       retval = ERROR_COMMAND_SYNTAX_ERROR;
 
                if (retval != ERROR_OK)
                {
@@ -405,7 +400,7 @@ void copydir(char *name, char *destdir)
 COMMAND_HANDLER(handle_rm_command)
 {
        if (CMD_ARGC != 1)
-               return ERROR_INVALID_ARGUMENTS;
+               return ERROR_COMMAND_SYNTAX_ERROR;
 
        bool del = false;
        if (rmdir(CMD_ARGV[0]) == 0)
@@ -644,7 +639,7 @@ static const struct command_registration ioutil_command_handlers[] = {
                .handler = handle_append_command,
                .mode = COMMAND_ANY,
                .help = "append a variable number of strings to a file",
-               .usage= "file_name [string ...]",
+               .usage = "file_name [<string1>, [<string2>, ...]]",
        },
        {
                .name = "meminfo",