summaryrefslogtreecommitdiff
path: root/utils/imxtools/misc.c
diff options
context:
space:
mode:
authorAmaury Pouly <amaury.pouly@gmail.com>2012-02-19 18:36:57 +0100
committerAmaury Pouly <amaury.pouly@gmail.com>2012-02-19 18:36:57 +0100
commitc483905b9244646e89bc36940da7ea5a65e37392 (patch)
tree4006357666d2a614bce1303df5eeabf4c51d8168 /utils/imxtools/misc.c
parent2d7a4e9dfaee0fc82561bc19c65647b05ad3e0d5 (diff)
downloadrockbox-c483905b9244646e89bc36940da7ea5a65e37392.zip
rockbox-c483905b9244646e89bc36940da7ea5a65e37392.tar.gz
rockbox-c483905b9244646e89bc36940da7ea5a65e37392.tar.bz2
rockbox-c483905b9244646e89bc36940da7ea5a65e37392.tar.xz
imxtools: remove most calls to bug/bugp from core library.
It should not exit() anymore on error except on malloc failure. Resource leaks on errors (especially I/O) are quite likely though. Change-Id: I6fcf72fb08fc683468b390d0b8745d31ca982b48
Diffstat (limited to 'utils/imxtools/misc.c')
-rw-r--r--utils/imxtools/misc.c28
1 files changed, 23 insertions, 5 deletions
diff --git a/utils/imxtools/misc.c b/utils/imxtools/misc.c
index abbffbd..a7cc096 100644
--- a/utils/imxtools/misc.c
+++ b/utils/imxtools/misc.c
@@ -157,18 +157,27 @@ void clear_keys()
g_key_array = NULL;
}
-void add_keys_from_file(const char *key_file)
+bool add_keys_from_file(const char *key_file)
{
int size;
FILE *fd = fopen(key_file, "r");
if(fd == NULL)
- bug("opening key file failed");
+ {
+ if(g_debug)
+ perror("cannot open key file");
+ return false;
+ }
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);
char *buf = xmalloc(size + 1);
if(fread(buf, 1, size, fd) != (size_t)size)
- bug("reading key file");
+ {
+ if(g_debug)
+ perror("Cannot read key file");
+ fclose(fd);
+ return false;
+ }
buf[size] = 0;
fclose(fd);
@@ -180,7 +189,11 @@ void add_keys_from_file(const char *key_file)
struct crypto_key_t k;
/* parse key */
if(!parse_key(&p, &k))
- bug("invalid key file");
+ {
+ if(g_debug)
+ printf("invalid key file\n");
+ return false;
+ }
if(g_debug)
{
printf("Add key: ");
@@ -189,7 +202,11 @@ void add_keys_from_file(const char *key_file)
add_keys(&k, 1);
/* request at least one space character before next key, or end of file */
if(*p != 0 && !isspace(*p))
- bug("invalid key file");
+ {
+ if(g_debug)
+ printf("invalid key file\n");
+ return false;
+ }
/* skip whitespace */
while(isspace(*p))
p++;
@@ -197,6 +214,7 @@ void add_keys_from_file(const char *key_file)
break;
}
free(buf);
+ return true;
}
void print_hex(byte *data, int len, bool newline)