Commit 792d2781 authored by Alessandro Rubini's avatar Alessandro Rubini

tools: some cleanup in error messages, remove a bogus printf

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent a9bf1e86
......@@ -43,22 +43,23 @@ int main(int argc, char **argv)
}
if (optind >= argc) {
fprintf(stderr, "Expected binary name after options.\n");
fprintf(stderr, "%s: Expected binary name after options.\n",
argv[0]);
exit(1);
}
card = spec_open(bus, dev_fn);
if(!card)
{
fprintf(stderr, "Can't detect a SPEC card under the given "
"adress. Make sure a SPEC card is present in your PC "
"and the driver is loaded.\n");
fprintf(stderr, "%s: Can't detect a SPEC card under the given "
"adress.\nMake sure a SPEC card is present in your PC "
"and the driver is loaded.\n", argv[0]);
exit(1);
}
if(spec_load_lm32(card, argv[optind], lm32_base) < 0)
{
fprintf(stderr, "Loader failure.\n");
fprintf(stderr, "%s: Loader failure.\n", argv[0]);
exit(1);
}
......
......@@ -167,41 +167,42 @@ static char *load_binary_file(const char *filename, size_t *size)
FILE *f;
f = fopen(filename, "r");
if (!f)
if (!f) {
fprintf(stderr, "%s: %s\n", filename, strerror(errno));
return NULL;
if (fstat(fileno(f), &stbuf))
{
}
if (fstat(fileno(f), &stbuf) < 0) {
fprintf(stderr, "%s: %s\n", filename, strerror(errno));
fclose(f);
return NULL;
}
if (!S_ISREG(stbuf.st_mode))
{
if (!S_ISREG(stbuf.st_mode)) {
fprintf(stderr, "%s: not a regular file\n", filename);
fclose(f);
return NULL;
}
buf = malloc(stbuf.st_size);
if (!buf)
{
if (!buf) {
fprintf(stderr, "loading %s: %s\n", filename, strerror(errno));
fclose(f);
return NULL;
}
i = fread(buf, 1, stbuf.st_size, f);
fclose(f);
if (i < 0) {
fclose(f);
fprintf(stderr, "reading %s: %s\n", filename, strerror(errno));
free(buf);
return NULL;
}
if (i != stbuf.st_size) {
fclose(f);
fprintf(stderr, "%s: short read\n", filename, strerror(errno));
free(buf);
return NULL;
}
fclose(f);
*size = stbuf.st_size;
return buf;
}
......
......@@ -91,7 +91,6 @@ int main(int argc, char **argv)
}
ptr = map_base + uarg[0];
printf("%p\n", ptr);
/* by default, operate quietly (only report read value) */
if (!do_write) {
uarg[1] = *ptr;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment