diff options
author | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-17 17:54:32 +0000 |
---|---|---|
committer | russell <russell@f38db490-d61c-443f-a65b-d21fe96a405b> | 2005-10-17 17:54:32 +0000 |
commit | a3a280b42bec3b6dde314022bf6d4087c0b6d9be (patch) | |
tree | a05269a8f105e6d73fd896b61a69ae0a917dce50 /funcs | |
parent | b425195dd25806f8f547b63c62a4e88c5856ee7b (diff) |
clean up function to be more consistent with coding guidelines
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@6808 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'funcs')
-rwxr-xr-x | funcs/func_strings.c | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/funcs/func_strings.c b/funcs/func_strings.c index 0350141d9..d25d5bb77 100755 --- a/funcs/func_strings.c +++ b/funcs/func_strings.c @@ -140,42 +140,43 @@ struct ast_custom_function len_function = { static char *acf_strftime(struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len) { - char *format, *epoch, *timezone; + char *format, *epoch, *timezone = NULL; long epochi; struct tm time; - if (data) { - format = ast_strdupa(data); - if (format) { - epoch = strsep(&format, "|"); - timezone = strsep(&format, "|"); - - if (epoch && !ast_strlen_zero(epoch) && sscanf(epoch, "%ld", &epochi) == 1) { - } else { - struct timeval tv = ast_tvnow(); - epochi = tv.tv_sec; - } - - ast_localtime(&epochi, &time, timezone); - - if (!format) { - format = "%c"; - } - - buf[0] = '\0'; - if (! strftime(buf, len, format, &time)) { - ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); - } - buf[len - 1] = '\0'; - - return buf; - } else { - ast_log(LOG_ERROR, "Out of memory\n"); - } - } else { + buf[0] = '\0'; + + if (!data) { ast_log(LOG_ERROR, "Asterisk function STRFTIME() requires an argument.\n"); + return buf; } - return ""; + + format = ast_strdupa(data); + if (!format) { + ast_log(LOG_ERROR, "Out of memory\n"); + return buf; + } + + epoch = strsep(&format, "|"); + timezone = strsep(&format, "|"); + + if (!epoch || ast_strlen_zero(epoch) || !sscanf(epoch, "%ld", &epochi)) { + struct timeval tv = ast_tvnow(); + epochi = tv.tv_sec; + } + + ast_localtime(&epochi, &time, timezone); + + if (!format) { + format = "%c"; + } + + if (!strftime(buf, len, format, &time)) { + ast_log(LOG_WARNING, "C function strftime() output nothing?!!\n"); + } + buf[len - 1] = '\0'; + + return buf; } #ifndef BUILTIN_FUNC |