]> git.sur5r.net Git - openldap/blobdiff - libraries/liblutil/csn.c
cleanup
[openldap] / libraries / liblutil / csn.c
index 9c9273772418be53d3ff6d6285583cc89c98d95f..752ee35f89a3f2b7f6e656ab0711acd9f827331e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 /* Portions
@@ -32,6 +32,8 @@
 #include <stdio.h>
 #include <ac/time.h>
 
+#include <lutil.h>
+
 size_t
 lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
 {
@@ -52,17 +54,18 @@ lutil_csnstr(char *buf, size_t len, unsigned int replica, unsigned int mod)
 
        ltm = gmtime( &t );
        n = snprintf( buf, len, "%4d%02d%02d%02d:%02d:%02dZ#0x%04x#%d#%04x",
-           ltm->tm_year + 1900, ltm->tm_mon, ltm->tm_mday, ltm->tm_hour,
+           ltm->tm_year + 1900, ltm->tm_mon + 1, ltm->tm_mday, ltm->tm_hour,
            ltm->tm_min, ltm->tm_sec, op, replica, mod );
 
-       return ( n < len ) ? n : 0;
+       if( n < 0 ) return 0;
+       return ( (size_t) n < len ) ? n : 0;
 }
 
 #ifdef TEST
 int
 main(int argc, char **argv)
 {
-       char buf[256];
+       char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ];
 
        if ( ! lutil_csnstr( buf, (size_t) 10, 0, 0 ) ) {
                fprintf(stderr, "failed lutil_csnstr\n");