From a8a0ecb509ce6537554e0546c3f36830a15ab90f Mon Sep 17 00:00:00 2001 From: Sean Bright Date: Wed, 3 Sep 2008 13:48:12 +0000 Subject: [PATCH] Move some duplicated code into a separate function. Also try to do some wacky stuff in the commit message, like: a newline \n a bell \a a tab \t a format specification %p That is all. git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@140821 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- cdr/cdr_sqlite.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/cdr/cdr_sqlite.c b/cdr/cdr_sqlite.c index 601e5b2454..4a3c9406df 100644 --- a/cdr/cdr_sqlite.c +++ b/cdr/cdr_sqlite.c @@ -87,24 +87,26 @@ static char sql_create_table[] = "CREATE TABLE cdr (" #endif ");"; +static void format_date(char *buffer, size_t length, struct timeval *when) +{ + struct ast_tm tm; + + ast_localtime(when, &tm, NULL); + ast_strftime(buffer, length, DATE_FORMAT, &tm); +} + static int sqlite_log(struct ast_cdr *cdr) { int res = 0; char *zErr = 0; - struct ast_tm tm; char startstr[80], answerstr[80], endstr[80]; int count; ast_mutex_lock(&sqlite_lock); - ast_localtime(&cdr->start, &tm, NULL); - ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm); - - ast_localtime(&cdr->answer, &tm, NULL); - ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm); - - ast_localtime(&cdr->end, &tm, NULL); - ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm); + format_date(startstr, sizeof(startstr), &cdr->start); + format_date(answerstr, sizeof(answerstr), &cdr->answer); + format_date(endstr, sizeof(endstr), &cdr->end); for(count=0; count<5; count++) { res = sqlite_exec_printf(db,