summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-26 15:23:46 +0200
committerSascha Hauer <sha@octopus.labnet.pengutronix.de>2007-09-26 15:23:46 +0200
commit326e4bddc3d36a2afc2781e3018e2649d2be0680 (patch)
tree73d5eb3166f160af6a912ec8bed0616ed5ed050e
parent5efc6836b7318b2bb442b1584d9371d2ea2df6d9 (diff)
downloadbarebox-326e4bddc3d36a2afc2781e3018e2649d2be0680.tar.gz
barebox-326e4bddc3d36a2afc2781e3018e2649d2be0680.tar.xz
print_size() -> size_human_readable()
return a pointer to a human readable string rather than printingit directly
-rw-r--r--commands/bootm.c14
-rw-r--r--include/common.h3
-rw-r--r--lib/display_options.c17
-rw-r--r--net/nfs.c9
-rw-r--r--net/tftp.c12
5 files changed, 30 insertions, 25 deletions
diff --git a/commands/bootm.c b/commands/bootm.c
index 5f2bec9383..8f45d4c348 100644
--- a/commands/bootm.c
+++ b/commands/bootm.c
@@ -754,11 +754,13 @@ print_image_hdr (image_header_t *hdr)
printf (" Image Type: %s %s %s (%s)\n", image_arch(hdr), image_os(hdr),
image_type(hdr), image_compression(hdr));
#endif
- printf (" Data Size: %d Bytes = ", ntohl(hdr->ih_size));
- print_size (ntohl(hdr->ih_size), "\n");
- printf (" Load Address: %08x\n"
+ printf (" Data Size: %d Bytes = %s\n"
+ " Load Address: %08x\n"
" Entry Point: %08x\n",
- ntohl(hdr->ih_load), ntohl(hdr->ih_ep));
+ ntohl(hdr->ih_size),
+ size_human_readable(ntohl(hdr->ih_size)),
+ ntohl(hdr->ih_load),
+ ntohl(hdr->ih_ep));
if (hdr->ih_type == IH_TYPE_MULTI) {
int i;
@@ -767,8 +769,8 @@ print_image_hdr (image_header_t *hdr)
puts (" Contents:\n");
for (i=0; (len = ntohl(*len_ptr)); ++i, ++len_ptr) {
- printf (" Image %d: %8ld Bytes = ", i, len);
- print_size (len, "\n");
+ printf (" Image %d: %8ld Bytes = %s", i, len,
+ size_human_readable (len));
}
}
}
diff --git a/include/common.h b/include/common.h
index f786fe9b86..de6d473348 100644
--- a/include/common.h
+++ b/include/common.h
@@ -73,8 +73,7 @@ void panic(const char *fmt, ...);
/* */
long int initdram (int);
-int display_options (void);
-void print_size (ulong, const char *);
+char *size_human_readable(ulong size);
/* common/main.c */
void main_loop (void);
diff --git a/lib/display_options.c b/lib/display_options.c
index 6b84145734..5d92403272 100644
--- a/lib/display_options.c
+++ b/lib/display_options.c
@@ -24,14 +24,16 @@
#include <common.h>
/*
- * print sizes as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
- * allow for optional trailing string (like "\n")
+ * return a pointer to a string containing the size
+ * as "xxx kB", "xxx.y kB", "xxx MB" or "xxx.y MB" as needed;
*/
-void print_size (ulong size, const char *s)
+char *size_human_readable(ulong size)
{
+ static char buf[20];
ulong m, n;
ulong d = 1 << 20; /* 1 MB */
char c = 'M';
+ char *ptr = buf;
if (size < d) { /* print in kB */
c = 'k';
@@ -47,9 +49,12 @@ void print_size (ulong size, const char *s)
n += 1;
}
- printf ("%2ld", n);
+ ptr += sprintf(buf, "%2ld", n);
if (m) {
- printf (".%ld", m);
+ ptr += sprintf (ptr,".%ld", m);
}
- printf (" %cB%s", c, s);
+ sprintf(ptr, " %cB", c);
+
+ return buf;
}
+
diff --git a/net/nfs.c b/net/nfs.c
index d0d11ccec5..3770fe8f28 100644
--- a/net/nfs.c
+++ b/net/nfs.c
@@ -705,10 +705,11 @@ NfsStart (void)
}
printf ("\nFilename '%s/%s'.", nfs_path, nfs_filename);
- if (NetBootFileSize) {
- printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
- print_size (NetBootFileSize<<9, "");
- }
+ if (NetBootFileSize)
+ printf (" Size is 0x%x Bytes = %s",
+ NetBootFileSize<<9);
+ size_human_readable (NetBootFileSize<<9));
+
printf ("\nLoad address: 0x%lx\n"
"Loading: *\b", load_addr);
diff --git a/net/tftp.c b/net/tftp.c
index e690c39345..c0b29df3bb 100644
--- a/net/tftp.c
+++ b/net/tftp.c
@@ -334,14 +334,12 @@ TftpStart (void)
printf ("Filename '%s'.", tftp_filename);
- if (NetBootFileSize) {
- printf (" Size is 0x%x Bytes = ", NetBootFileSize<<9);
- print_size (NetBootFileSize<<9, "");
- }
-
- putchar('\n');
+ if (NetBootFileSize)
+ printf (" Size is 0x%x Bytes = %s",
+ NetBootFileSize<<9,
+ size_human_readable(NetBootFileSize<<9));
- puts ("Loading: *\b");
+ puts ("\nLoading: *\b");
NetSetTimeout (TIMEOUT * SECOND, TftpTimeout);
NetSetHandler (TftpHandler);