[U-Boot] [PATCH] improved strmhz()

Ilko Iliev iliev at ronetix.at
Tue Oct 21 14:44:38 CEST 2008


This patch prevents the displaying of results like this:
hz = 1999170000
buf = "200.-83"

Signed-off-by: Ilko Iliev <iliev at ronetix.at>

index 342cf2b..981a75a 100644
--- a/lib_generic/strmhz.c
+++ b/lib_generic/strmhz.c
@@ -28,10 +28,15 @@ char *strmhz (char *buf, long hz)
        long m;

        n = DIV_ROUND(hz, 1000000L);
-       l = sprintf (buf, "%ld", n);

        hz -= n * 1000000L;
        m = DIV_ROUND(hz, 1000L);
+       if ( m < 0 ) {
+               n--;
+               m += 1000L;
+       }
+
+       l = sprintf (buf, "%ld", n);
        if (m != 0)
                sprintf (buf + l, ".%03ld", m);
        return (buf);




More information about the U-Boot mailing list