[asterisk-commits] tilghman: branch group/ast_strftime r73820 - in /team/group/ast_strftime: app...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Sat Jul 7 11:27:41 CDT 2007
Author: tilghman
Date: Sat Jul 7 11:27:40 2007
New Revision: 73820
URL: http://svn.digium.com/view/asterisk?view=rev&rev=73820
Log:
Create ast_strftime() function and integrate it into the tree
Modified:
team/group/ast_strftime/apps/app_alarmreceiver.c
team/group/ast_strftime/apps/app_minivm.c
team/group/ast_strftime/apps/app_sms.c
team/group/ast_strftime/apps/app_voicemail.c
team/group/ast_strftime/cdr/cdr_csv.c
team/group/ast_strftime/cdr/cdr_manager.c
team/group/ast_strftime/cdr/cdr_odbc.c
team/group/ast_strftime/cdr/cdr_pgsql.c
team/group/ast_strftime/cdr/cdr_sqlite.c
team/group/ast_strftime/cdr/cdr_tds.c
team/group/ast_strftime/channels/chan_sip.c
team/group/ast_strftime/channels/iax2-parser.c
team/group/ast_strftime/funcs/func_strings.c
team/group/ast_strftime/include/asterisk/localtime.h
team/group/ast_strftime/main/asterisk.c
team/group/ast_strftime/main/cdr.c
team/group/ast_strftime/main/logger.c
team/group/ast_strftime/main/manager.c
team/group/ast_strftime/main/say.c
team/group/ast_strftime/main/stdtime/localtime.c
Modified: team/group/ast_strftime/apps/app_alarmreceiver.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_alarmreceiver.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/apps/app_alarmreceiver.c (original)
+++ team/group/ast_strftime/apps/app_alarmreceiver.c Sat Jul 7 11:27:40 2007
@@ -329,7 +329,7 @@
/* Format the time */
- strftime(timestamp, sizeof(timestamp), time_stamp_format, (struct tm *)&now);
+ ast_strftime(timestamp, sizeof(timestamp), time_stamp_format, &now);
res = fprintf(logfile, "\n\n[metadata]\n\n");
Modified: team/group/ast_strftime/apps/app_minivm.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_minivm.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/apps/app_minivm.c (original)
+++ team/group/ast_strftime/apps/app_minivm.c Sat Jul 7 11:27:40 2007
@@ -714,10 +714,10 @@
static int get_date(char *s, int len)
{
struct ast_tm tm;
- struct timeval t = ast_tvnow();
-
- ast_localtime(&t, &tm, NULL);
- return strftime(s, len, "%a %b %e %r %Z %Y", (struct tm *)&tm);
+ struct timeval tv = ast_tvnow();
+
+ ast_localtime(&tv, &tm, NULL);
+ return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm);
}
@@ -987,13 +987,13 @@
now = ast_tvnow();
ast_localtime(&now, &tm, the_zone ? the_zone->timezone : NULL);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)&tm);
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", &tm);
/* Start printing the email to the temporary file */
fprintf(p, "Date: %s\n", date);
/* Set date format for voicemail mail */
- strftime(date, sizeof(date), template->dateformat, (struct tm *)&tm);
+ ast_strftime(date, sizeof(date), template->dateformat, &tm);
/* Populate channel with channel variables for substitution */
@@ -1555,7 +1555,7 @@
char logbuf[BUFSIZ];
get_date(date, sizeof(date));
ast_localtime(&now, &tm, NULL);
- strftime(timebuf, sizeof(timebuf), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(timebuf, sizeof(timebuf), "%H:%M:%S", &tm);
snprintf(logbuf, sizeof(logbuf),
/* "Mailbox:domain:macrocontext:exten:priority:callerchan:callerid:origdate:origtime:duration:durationstatus:accountcode" */
@@ -2709,11 +2709,11 @@
} else {
ast_cli(fd, " Received messages since last reset: %d\n", global_stats.receivedmessages);
ast_localtime(&global_stats.lastreceived, &time, NULL);
- strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", (struct tm *)&time);
+ ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
ast_cli(fd, " Last received voicemail: %s\n", buf);
}
ast_localtime(&global_stats.reset, &time, NULL);
- strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", (struct tm *)&time);
+ ast_strftime(buf, sizeof(buf), "%a %b %e %r %Z %Y", &time);
ast_cli(fd, " Last reset: %s\n", buf);
ast_cli(fd, "\n");
Modified: team/group/ast_strftime/apps/app_sms.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_sms.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/apps/app_sms.c (original)
+++ team/group/ast_strftime/apps/app_sms.c Sat Jul 7 11:27:40 2007
@@ -280,7 +280,7 @@
struct ast_tm tm;
struct timeval tv = { t, 0 };
ast_localtime(&tv, &tm, NULL);
- strftime(buf, len, "%Y-%m-%dT%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(buf, len, "%Y-%m-%dT%H:%M:%S", &tm);
return buf;
}
Modified: team/group/ast_strftime/apps/app_voicemail.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/apps/app_voicemail.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/apps/app_voicemail.c (original)
+++ team/group/ast_strftime/apps/app_voicemail.c Sat Jul 7 11:27:40 2007
@@ -2032,11 +2032,11 @@
*greeting_attachment++ = '\0';
snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)vmu_tm(vmu, &tm));
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
fprintf(p, "Date: %s" ENDL, date);
/* Set date format for voicemail mail */
- strftime(date, sizeof(date), emaildateformat, (struct tm *)&tm);
+ ast_strftime(date, sizeof(date), emaildateformat, &tm);
if (!ast_strlen_zero(fromstring)) {
struct ast_channel *ast;
@@ -2230,7 +2230,7 @@
else
snprintf(who, sizeof(who), "%s@%s", srcemail, host);
snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60);
- strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", (struct tm *)vmu_tm(vmu, &tm));
+ ast_strftime(date, sizeof(date), "%a, %d %b %Y %H:%M:%S %z", vmu_tm(vmu, &tm));
fprintf(p, "Date: %s\n", date);
if (*pagerfromstring) {
@@ -2269,7 +2269,7 @@
} else
fprintf(p, "Subject: New VM\n\n");
- strftime(date, sizeof(date), "%A, %B %d, %Y at %r", (struct tm *)&tm);
+ ast_strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm);
if (pagerbody) {
struct ast_channel *ast;
if ((ast = ast_channel_alloc(0, AST_STATE_DOWN, 0, 0, "", "", "", 0, 0))) {
@@ -2299,7 +2299,7 @@
struct ast_tm tm;
struct timeval t = ast_tvnow();
ast_localtime(&t, &tm, NULL);
- return strftime(s, len, "%a %b %e %r %Z %Y", (struct tm *)&tm);
+ return ast_strftime(s, len, "%a %b %e %r %Z %Y", &tm);
}
static int invent_message(struct ast_channel *chan, char *context, char *ext, int busy, char *ecodes)
Modified: team/group/ast_strftime/cdr/cdr_csv.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_csv.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_csv.c (original)
+++ team/group/ast_strftime/cdr/cdr_csv.c Sat Jul 7 11:27:40 2007
@@ -196,7 +196,7 @@
return 0;
}
ast_localtime(&tv, &tm, usegmtime ? "GMT" : NULL);
- strftime(tmp, sizeof(tmp), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(tmp, sizeof(tmp), DATE_FORMAT, &tm);
return append_string(buf, tmp, bufsize);
}
Modified: team/group/ast_strftime/cdr/cdr_manager.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_manager.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_manager.c (original)
+++ team/group/ast_strftime/cdr/cdr_manager.c Sat Jul 7 11:27:40 2007
@@ -103,8 +103,7 @@
static int manager_log(struct ast_cdr *cdr)
{
- time_t t;
- struct tm timeresult;
+ struct ast_tm timeresult;
char strStartTime[80] = "";
char strAnswerTime[80] = "";
char strEndTime[80] = "";
@@ -114,19 +113,16 @@
if (!enablecdr)
return 0;
- t = cdr->start.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->start, &timeresult, NULL);
+ ast_strftime(strStartTime, sizeof(strStartTime), DATE_FORMAT, &timeresult);
if (cdr->answer.tv_sec) {
- t = cdr->answer.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
- }
-
- t = cdr->end.tv_sec;
- ast_localtime(&t, &timeresult, NULL);
- strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
+ ast_localtime(&cdr->answer, &timeresult, NULL);
+ ast_strftime(strAnswerTime, sizeof(strAnswerTime), DATE_FORMAT, &timeresult);
+ }
+
+ ast_localtime(&cdr->end, &timeresult, NULL);
+ ast_strftime(strEndTime, sizeof(strEndTime), DATE_FORMAT, &timeresult);
/* Custom fields handling */
memset(buf, 0 , sizeof(buf));
Modified: team/group/ast_strftime/cdr/cdr_odbc.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_odbc.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_odbc.c (original)
+++ team/group/ast_strftime/cdr/cdr_odbc.c Sat Jul 7 11:27:40 2007
@@ -100,7 +100,7 @@
ast_localtime(&cdr->start, &tm, usegmtime ? "GMT" : NULL);
ast_mutex_lock(&odbc_lock);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
memset(sqlcmd,0,2048);
if (loguniqueid) {
snprintf(sqlcmd,sizeof(sqlcmd),"INSERT INTO %s "
Modified: team/group/ast_strftime/cdr/cdr_pgsql.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_pgsql.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_pgsql.c (original)
+++ team/group/ast_strftime/cdr/cdr_pgsql.c Sat Jul 7 11:27:40 2007
@@ -79,7 +79,7 @@
ast_mutex_lock(&pgsql_lock);
ast_localtime(&cdr->start, &tm, NULL);
- strftime(timestr, sizeof(timestr), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(timestr, sizeof(timestr), DATE_FORMAT, &tm);
if ((!connected) && pghostname && pgdbuser && pgpassword && pgdbname) {
conn = PQsetdbLogin(pghostname, pgdbport, NULL, NULL, pgdbname, pgdbuser, pgpassword);
Modified: team/group/ast_strftime/cdr/cdr_sqlite.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_sqlite.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_sqlite.c (original)
+++ team/group/ast_strftime/cdr/cdr_sqlite.c Sat Jul 7 11:27:40 2007
@@ -103,13 +103,13 @@
ast_mutex_lock(&sqlite_lock);
ast_localtime(&cdr->start, &tm, NULL);
- strftime(startstr, sizeof(startstr), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(startstr, sizeof(startstr), DATE_FORMAT, &tm);
ast_localtime(&cdr->answer, &tm, NULL);
- strftime(answerstr, sizeof(answerstr), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(answerstr, sizeof(answerstr), DATE_FORMAT, &tm);
ast_localtime(&cdr->end, &tm, NULL);
- strftime(endstr, sizeof(endstr), DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(endstr, sizeof(endstr), DATE_FORMAT, &tm);
for(count=0; count<5; count++) {
res = sqlite_exec_printf(db,
Modified: team/group/ast_strftime/cdr/cdr_tds.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/cdr/cdr_tds.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/cdr/cdr_tds.c (original)
+++ team/group/ast_strftime/cdr/cdr_tds.c Sat Jul 7 11:27:40 2007
@@ -285,7 +285,7 @@
if (!ast_tvzero(tv))
{
ast_localtime(&tv, &tm, NULL);
- strftime(buf, 80, DATE_FORMAT, (struct tm *)&tm);
+ ast_strftime(buf, 80, DATE_FORMAT, &tm);
sprintf(dateField, "'%s'", buf);
}
else
Modified: team/group/ast_strftime/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/chan_sip.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/channels/chan_sip.c (original)
+++ team/group/ast_strftime/channels/chan_sip.c Sat Jul 7 11:27:40 2007
@@ -11041,7 +11041,7 @@
snprintf(host, sizeof(host), "%s:%d", iterator->hostname, iterator->portno ? iterator->portno : STANDARD_SIP_PORT);
if (iterator->regtime.tv_sec) {
ast_localtime(&iterator->regtime, &tm, NULL);
- strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", (struct tm *)&tm);
+ ast_strftime(tmpdat, sizeof(tmpdat), "%a, %d %b %Y %T", &tm);
} else
tmpdat[0] = '\0';
ast_cli(fd, FORMAT, host, iterator->username, iterator->refresh, regstate2str(iterator->regstate), tmpdat);
Modified: team/group/ast_strftime/channels/iax2-parser.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/channels/iax2-parser.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/channels/iax2-parser.c (original)
+++ team/group/ast_strftime/channels/iax2-parser.c Sat Jul 7 11:27:40 2007
@@ -140,7 +140,7 @@
static void dump_datetime(char *output, int maxlen, void *value, int len)
{
- struct tm tm;
+ struct ast_tm tm;
unsigned long val = (unsigned long) ntohl(get_unaligned_uint32(value));
if (len == (int)sizeof(unsigned int)) {
tm.tm_sec = (val & 0x1f) << 1;
@@ -149,7 +149,7 @@
tm.tm_mday = (val >> 16) & 0x1f;
tm.tm_mon = ((val >> 21) & 0x0f) - 1;
tm.tm_year = ((val >> 25) & 0x7f) + 100;
- strftime(output, maxlen, "%Y-%m-%d %T", &tm);
+ ast_strftime(output, maxlen, "%Y-%m-%d %T", &tm);
} else
ast_copy_string(output, "Invalid DATETIME format!", maxlen);
}
Modified: team/group/ast_strftime/funcs/func_strings.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/funcs/func_strings.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/funcs/func_strings.c (original)
+++ team/group/ast_strftime/funcs/func_strings.c Sat Jul 7 11:27:40 2007
@@ -612,7 +612,7 @@
if (!args.format)
args.format = "%c";
- if (!strftime(buf, len, args.format, (struct tm *)&tm))
+ if (ast_strftime(buf, len, args.format, &tm) <= 0)
ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n");
buf[len - 1] = '\0';
@@ -624,6 +624,14 @@
.name = "STRFTIME",
.synopsis = "Returns the current date/time in a specified format.",
.syntax = "STRFTIME([<epoch>][|[timezone][|format]])",
+ .desc =
+"STRFTIME sports all of the same formats as the underlying C function\n"
+"strftime(3) - see the man page for details. It also supports the\n"
+"following format:\n"
+" %[n]q - fractions of a second, with leading zeroes. For example, %3q will\n"
+" give milliseconds and %1q will give tenths of a second. The default\n"
+" is to output milliseconds (n=3). The common case is to use it in\n"
+" combination with %S, as in \"%S.%3q\".\n",
.read = acf_strftime,
};
Modified: team/group/ast_strftime/include/asterisk/localtime.h
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/include/asterisk/localtime.h?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/include/asterisk/localtime.h (original)
+++ team/group/ast_strftime/include/asterisk/localtime.h Sat Jul 7 11:27:40 2007
@@ -45,5 +45,6 @@
struct ast_tm *ast_localtime(const struct timeval *timep, struct ast_tm *p_tm, const char *zone);
time_t ast_mktime(struct ast_tm * const tmp, const char *zone);
char *ast_ctime(const struct timeval * const timep, char *buf);
+int ast_strftime(char *buf, size_t len, const char *format, const struct ast_tm *tm);
#endif /* _ASTERISK_LOCALTIME_H */
Modified: team/group/ast_strftime/main/asterisk.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/asterisk.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/asterisk.c (original)
+++ team/group/ast_strftime/main/asterisk.c Sat Jul 7 11:27:40 2007
@@ -366,11 +366,11 @@
ast_cli(fd, " Min Free Memory: %ld MB\n", option_minmemfree);
#endif
if (ast_localtime(&ast_startuptime, &tm, NULL)) {
- strftime(buf, sizeof(buf), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
ast_cli(fd, " Startup time: %s\n", buf);
}
if (ast_localtime(&ast_lastreloadtime, &tm, NULL)) {
- strftime(buf, sizeof(buf), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(buf, sizeof(buf), "%H:%M:%S", &tm);
ast_cli(fd, " Last reload time: %s\n", buf);
}
ast_cli(fd, " System: %s/%s built by %s on %s %s\n", ast_build_os, ast_build_kernel, ast_build_user, ast_build_machine, ast_build_date);
@@ -1784,7 +1784,7 @@
break;
case 'd': /* date */
if (ast_localtime(&ts, &tm, NULL))
- strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", (struct tm *)&tm);
+ ast_strftime(p, sizeof(prompt) - strlen(prompt), "%Y-%m-%d", &tm);
break;
case 'h': /* hostname */
if (!gethostname(hostname, sizeof(hostname) - 1))
@@ -1839,7 +1839,7 @@
break;
case 't': /* time */
if (ast_localtime(&ts, &tm, NULL))
- strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(p, sizeof(prompt) - strlen(prompt), "%H:%M:%S", &tm);
break;
case '#': /* process console or remote? */
if (!ast_opt_remote)
Modified: team/group/ast_strftime/main/cdr.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/cdr.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/cdr.c (original)
+++ team/group/ast_strftime/main/cdr.c Sat Jul 7 11:27:40 2007
@@ -209,7 +209,7 @@
struct ast_tm tm;
ast_localtime(&tv, &tm, NULL);
- strftime(buf, bufsize, fmt, (struct tm *)&tm);
+ ast_strftime(buf, bufsize, fmt, &tm);
}
}
Modified: team/group/ast_strftime/main/logger.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/logger.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/logger.c (original)
+++ team/group/ast_strftime/main/logger.c Sat Jul 7 11:27:40 2007
@@ -930,7 +930,7 @@
/* Create our date/time */
ast_localtime(&tv, &tm, NULL);
- strftime(logmsg->date, sizeof(logmsg->date), dateformat, (struct tm *)&tm);
+ ast_strftime(logmsg->date, sizeof(logmsg->date), dateformat, &tm);
/* Copy over data */
logmsg->level = level;
@@ -999,7 +999,7 @@
tv = ast_tvnow();
ast_localtime(&tv, &tm, NULL);
- strftime(date, sizeof(date), dateformat, (struct tm *)&tm);
+ ast_strftime(date, sizeof(date), dateformat, &tm);
datefmt = alloca(strlen(date) + 3 + strlen(fmt) + 1);
sprintf(datefmt, "[%s] %s", date, fmt);
fmt = datefmt;
Modified: team/group/ast_strftime/main/manager.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/manager.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/manager.c (original)
+++ team/group/ast_strftime/main/manager.c Sat Jul 7 11:27:40 2007
@@ -2294,9 +2294,9 @@
snprintf(idText, sizeof(idText), "ActionID: %s\r\n", actionid);
ast_localtime(&ast_startuptime, &tm, NULL);
- strftime(startuptime, sizeof(startuptime), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(startuptime, sizeof(startuptime), "%H:%M:%S", &tm);
ast_localtime(&ast_lastreloadtime, &tm, NULL);
- strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", (struct tm *)&tm);
+ ast_strftime(reloadtime, sizeof(reloadtime), "%H:%M:%S", &tm);
astman_append(s, "Response: Success\r\n"
"%s"
Modified: team/group/ast_strftime/main/say.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/say.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/say.c (original)
+++ team/group/ast_strftime/main/say.c Sat Jul 7 11:27:40 2007
@@ -4645,7 +4645,7 @@
/* Literal name of a sound file */
sndoffset=0;
for (sndoffset=0 ; (format[++offset] != '\'') && (sndoffset < 256) ; sndoffset++)
- sndfile[sndoffset] = format[offset];
+ sndfile[sndoffset] = format[offset];
sndfile[sndoffset] = '\0';
res = wait_file(chan,ints,sndfile,lang);
break;
Modified: team/group/ast_strftime/main/stdtime/localtime.c
URL: http://svn.digium.com/view/asterisk/team/group/ast_strftime/main/stdtime/localtime.c?view=diff&rev=73820&r1=73819&r2=73820
==============================================================================
--- team/group/ast_strftime/main/stdtime/localtime.c (original)
+++ team/group/ast_strftime/main/stdtime/localtime.c Sat Jul 7 11:27:40 2007
@@ -1494,3 +1494,62 @@
return(mktime_return_value);
}
+int ast_strftime(char *buf, size_t len, const char *tmp, const struct ast_tm *tm)
+{
+ size_t fmtlen = strlen(tmp) + 1;
+ char *format = ast_calloc(1, fmtlen), *fptr = format, *newfmt;
+ int decimals = -1, i, res;
+ long fraction;
+
+ if (!format)
+ return -1;
+ for (; *tmp; tmp++) {
+ if (*tmp == '%') {
+ switch (tmp[1]) {
+ case '1':
+ case '2':
+ case '3':
+ case '4':
+ case '5':
+ case '6':
+ if (tmp[2] != 'q')
+ goto defcase;
+ decimals = tmp[1] - '0';
+ tmp++;
+ /* Fall through */
+ case 'q': /* Milliseconds */
+ if (decimals == -1)
+ decimals = 3;
+
+ /* Juggle some memory to fit the item */
+ newfmt = ast_realloc(format, fmtlen + decimals);
+ if (!newfmt) {
+ ast_free(format);
+ return -1;
+ }
+ fptr = fptr - format + newfmt;
+ format = newfmt;
+ fmtlen += decimals;
+
+ /* Reduce the fraction of time to the accuracy needed */
+ for (i = 6, fraction = tm->tm_usec; i > decimals; i--)
+ fraction /= 10;
+ fptr += sprintf(fptr, "%0*ld", decimals, fraction);
+
+ /* Reset, in case more than one 'q' specifier exists */
+ decimals = -1;
+ tmp++;
+ break;
+ default:
+ goto defcase;
+ }
+ } else
+defcase: *fptr++ = *tmp;
+ }
+ *fptr = '\0';
+#undef strftime
+ res = (int)strftime(buf, len, format, (struct tm *)tm);
+ ast_free(format);
+ return res;
+}
+
More information about the asterisk-commits
mailing list