]> git.sur5r.net Git - openldap/commitdiff
cleanup time unparsing (don't add trailing 0s if other multiples have already been...
authorPierangelo Masarati <ando@openldap.org>
Mon, 2 Jan 2006 08:14:55 +0000 (08:14 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 2 Jan 2006 08:14:55 +0000 (08:14 +0000)
libraries/liblutil/utils.c

index f2a1a2c91d8391b9e6ce4f9b7a00ae5c6e5d4724..314cb37da599141bcdbe49f966797ae2ae308a8d 100644 (file)
@@ -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;
                }
        }