--- include/lutil.h 2006/01/03 22:12:06 1.63 +++ include/lutil.h 2007/02/13 20:22:08 1.63.2.1 @@ -1,7 +1,7 @@ -/* $OpenLDAP: pkg/ldap/include/lutil.h,v 1.62 2005/11/24 00:10:06 ando Exp $ */ +/* $OpenLDAP: pkg/ldap/include/lutil.h,v 1.69 2007/02/11 12:42:29 hyc Exp $ */ /* This work is part of OpenLDAP Software . * - * Copyright 1998-2006 The OpenLDAP Foundation. + * Copyright 1998-2007 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -158,6 +158,7 @@ typedef struct lutil_tm { int tm_mon; /* month 0-11 */ int tm_year; /* year - 1900 */ int tm_usec; /* microseconds */ + int tm_usub; /* submicro */ } lutil_tm; typedef struct lutil_timet { @@ -166,14 +167,20 @@ typedef struct lutil_timet { unsigned int tt_usec; /* microseconds */ } lutil_timet; +/* Parse a timestamp string into a structure */ LDAP_LUTIL_F( int ) lutil_parsetime LDAP_P(( char *atm, struct lutil_tm * )); +/* Convert structured time to time in seconds since 1900 */ LDAP_LUTIL_F( int ) lutil_tm2time LDAP_P(( struct lutil_tm *, struct lutil_timet * )); +/* Get current time as a structured time */ +LDAP_LUTIL_F( void ) +lutil_gettime LDAP_P(( struct lutil_tm * )); + #ifdef _WIN32 LDAP_LUTIL_F( void ) lutil_slashpath LDAP_P(( char* path )); @@ -290,12 +297,39 @@ lutil_atoulx( unsigned long *v, const ch #define lutil_atol(v, s) lutil_atolx((v), (s), 10) #define lutil_atoul(v, s) lutil_atoulx((v), (s), 10) +/* Parse and unparse time intervals */ LDAP_LUTIL_F (int) lutil_parse_time( const char *in, unsigned long *tp ); LDAP_LUTIL_F (int) lutil_unparse_time( char *buf, size_t buflen, unsigned long t ); +#ifdef timerdiv +#define lutil_timerdiv timerdiv +#else /* ! timerdiv */ +/* works inplace (x == t) */ +#define lutil_timerdiv(t,d,x) \ + do { \ + time_t s = (t)->tv_sec; \ + assert( d > 0 ); \ + (x)->tv_sec = s / d; \ + (x)->tv_usec = ( (t)->tv_usec + 1000000 * ( s % d ) ) / d; \ + } while ( 0 ) +#endif /* ! timerdiv */ + +#ifdef timermul +#define lutil_timermul timermul +#else /* ! timermul */ +/* works inplace (x == t) */ +#define lutil_timermul(t,m,x) \ + do { \ + time_t u = (t)->tv_usec * m; \ + assert( m > 0 ); \ + (x)->tv_sec = (t)->tv_sec * m + u / 1000000; \ + (x)->tv_usec = u % 1000000; \ + } while ( 0 ); +#endif /* ! timermul */ + LDAP_END_DECL #endif /* _LUTIL_H */