dovecot-2.1: Added t_strflocaltime().
dovecot at dovecot.org
dovecot at dovecot.org
Tue Jan 10 22:57:16 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/22cfba724675
changeset: 13923:22cfba724675
user: Timo Sirainen <tss at iki.fi>
date: Tue Jan 10 22:51:52 2012 +0200
description:
Added t_strflocaltime().
diffstat:
src/lib/macros.h | 5 ++++-
src/lib/time-util.c | 21 +++++++++++++++++++++
src/lib/time-util.h | 3 +++
3 files changed, 28 insertions(+), 1 deletions(-)
diffs (68 lines):
diff -r 1362d8bda03c -r 22cfba724675 src/lib/macros.h
--- a/src/lib/macros.h Tue Jan 10 21:39:13 2012 +0200
+++ b/src/lib/macros.h Tue Jan 10 22:51:52 2012 +0200
@@ -93,6 +93,8 @@
__attribute__((format_arg (arg_idx)))
# define ATTR_SCANF(format_idx, arg_idx) \
__attribute__((format (scanf, format_idx, arg_idx)))
+# define ATTR_STRFTIME(format_idx) \
+ __attribute__((format (strftime, format_idx, 0)))
# define ATTR_UNUSED __attribute__((unused))
# define ATTR_NORETURN __attribute__((noreturn))
# define ATTR_CONST __attribute__((const))
@@ -100,7 +102,8 @@
#else
# define ATTR_FORMAT(format_idx, arg_idx)
# define ATTR_FORMAT_ARG(arg_idx)
-# define ATTR_SCANF
+# define ATTR_SCANF(format_idx, arg_idx)
+# define ATTR_STRFTIME(format_idx)
# define ATTR_UNUSED
# define ATTR_NORETURN
# define ATTR_CONST
diff -r 1362d8bda03c -r 22cfba724675 src/lib/time-util.c
--- a/src/lib/time-util.c Tue Jan 10 21:39:13 2012 +0200
+++ b/src/lib/time-util.c Tue Jan 10 22:51:52 2012 +0200
@@ -3,6 +3,10 @@
#include "lib.h"
#include "time-util.h"
+#include <time.h>
+
+#define STRFTIME_MAX_BUFSIZE (1024*64)
+
int timeval_cmp(const struct timeval *tv1, const struct timeval *tv2)
{
if (tv1->tv_sec < tv2->tv_sec)
@@ -35,3 +39,20 @@
}
return ((long long)secs * 1000000ULL) + usecs;
}
+
+const char *t_strflocaltime(const char *fmt, time_t t)
+{
+ const struct tm *tm;
+ size_t bufsize = strlen(fmt) + 32;
+ char *buf = t_buffer_get(bufsize);
+ size_t ret;
+
+ tm = localtime(&t);
+ while ((ret = strftime(buf, bufsize, fmt, tm)) == 0) {
+ bufsize *= 2;
+ i_assert(bufsize <= STRFTIME_MAX_BUFSIZE);
+ buf = t_buffer_get(bufsize);
+ }
+ t_buffer_alloc(ret + 1);
+ return buf;
+}
diff -r 1362d8bda03c -r 22cfba724675 src/lib/time-util.h
--- a/src/lib/time-util.h Tue Jan 10 21:39:13 2012 +0200
+++ b/src/lib/time-util.h Tue Jan 10 22:51:52 2012 +0200
@@ -11,4 +11,7 @@
long long timeval_diff_usecs(const struct timeval *tv1,
const struct timeval *tv2);
+/* Wrapper to strftime() */
+const char *t_strflocaltime(const char *fmt, time_t t) ATTR_STRFTIME(1);
+
#endif
More information about the dovecot-cvs
mailing list