From ad4a21f1a488f54a73e96772c7e456e8aece76e6 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 2 Jan 2006 08:14:55 +0000 Subject: [PATCH] cleanup time unparsing (don't add trailing 0s if other multiples have already been used) --- libraries/liblutil/utils.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/libraries/liblutil/utils.c b/libraries/liblutil/utils.c index f2a1a2c91d..314cb37da5 100644 --- a/libraries/liblutil/utils.c +++ b/libraries/liblutil/utils.c @@ -471,6 +471,7 @@ lutil_unparse_time( { int len, i; unsigned long v[ 4 ]; + char *ptr = buf; v[ 0 ] = t/86400; v[ 1 ] = (t%86400)/3600; @@ -478,13 +479,13 @@ lutil_unparse_time( v[ 3 ] = t%60; for ( i = 0; i < 4; i++ ) { - if ( v[i] > 0 || i == 3 ) { - len = snprintf( buf, buflen, "%lu%c", v[ i ], time_unit[ i ] ); + if ( v[i] > 0 || ( i == 3 && ptr == buf ) ) { + len = snprintf( ptr, buflen, "%lu%c", v[ i ], time_unit[ i ] ); if ( len < 0 || (unsigned)len >= buflen ) { return -1; } buflen -= len; - buf += len; + ptr += len; } } -- 2.39.5