Skip to content
Snippets Groups Projects
Commit ad4a21f1 authored by Pierangelo Masarati's avatar Pierangelo Masarati
Browse files

cleanup time unparsing (don't add trailing 0s if other multiples have already been used)

parent 1fd9d40e
No related branches found
No related tags found
No related merge requests found
......@@ -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;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment