aboutsummaryrefslogtreecommitdiffstats
path: root/main/cli.c
diff options
context:
space:
mode:
authorrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-16 09:56:31 +0000
committerrizzo <rizzo@f38db490-d61c-443f-a65b-d21fe96a405b>2006-12-16 09:56:31 +0000
commitee5146aeb7ab6e91c4275c7fa0a015302ef49b4c (patch)
treec4a05cb8778ff2d553a9b5a02968febaa5f49bb8 /main/cli.c
parentc811946a9e4b08bada039f6914b6f9ec8a11558a (diff)
another conversion from ast_build_str to ast_str
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@48517 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'main/cli.c')
-rw-r--r--main/cli.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/main/cli.c b/main/cli.c
index acc003e4c..e2a3a6db8 100644
--- a/main/cli.c
+++ b/main/cli.c
@@ -332,8 +332,7 @@ static int modlist_modentry(const char *module, const char *description, int use
static void print_uptimestr(int fd, time_t timeval, const char *prefix, int printsec)
{
int x; /* the main part - years, weeks, etc. */
- char timestr[256]="", *s = timestr;
- size_t maxbytes = sizeof(timestr);
+ struct ast_str *out;
#define SECOND (1)
#define MINUTE (SECOND*60)
@@ -344,40 +343,41 @@ static void print_uptimestr(int fd, time_t timeval, const char *prefix, int prin
#define NEEDCOMMA(x) ((x)? ",": "") /* define if we need a comma */
if (timeval < 0) /* invalid, nothing to show */
return;
+
if (printsec) { /* plain seconds output */
- ast_build_string(&s, &maxbytes, "%lu", (u_long)timeval);
- timeval = 0; /* bypass the other cases */
+ ast_cli(fd, "%s: %lu\n", prefix, (u_long)timeval);
+ return;
}
+ out = ast_str_alloca(256);
if (timeval > YEAR) {
x = (timeval / YEAR);
timeval -= (x * YEAR);
- ast_build_string(&s, &maxbytes, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval));
+ ast_str_append(&out, 0, "%d year%s%s ", x, ESS(x),NEEDCOMMA(timeval));
}
if (timeval > WEEK) {
x = (timeval / WEEK);
timeval -= (x * WEEK);
- ast_build_string(&s, &maxbytes, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval));
+ ast_str_append(&out, 0, "%d week%s%s ", x, ESS(x),NEEDCOMMA(timeval));
}
if (timeval > DAY) {
x = (timeval / DAY);
timeval -= (x * DAY);
- ast_build_string(&s, &maxbytes, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval));
+ ast_str_append(&out, 0, "%d day%s%s ", x, ESS(x),NEEDCOMMA(timeval));
}
if (timeval > HOUR) {
x = (timeval / HOUR);
timeval -= (x * HOUR);
- ast_build_string(&s, &maxbytes, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval));
+ ast_str_append(&out, 0, "%d hour%s%s ", x, ESS(x),NEEDCOMMA(timeval));
}
if (timeval > MINUTE) {
x = (timeval / MINUTE);
timeval -= (x * MINUTE);
- ast_build_string(&s, &maxbytes, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval));
+ ast_str_append(&out, 0, "%d minute%s%s ", x, ESS(x),NEEDCOMMA(timeval));
}
x = timeval;
- if (x > 0)
- ast_build_string(&s, &maxbytes, "%d second%s ", x, ESS(x));
- if (timestr[0] != '\0')
- ast_cli(fd, "%s: %s\n", prefix, timestr);
+ if (x > 0 || out->used == 0) /* if there is nothing, print 0 seconds */
+ ast_str_append(&out, 0, "%d second%s ", x, ESS(x));
+ ast_cli(fd, "%s: %s\n", prefix, out->str);
}
static char * handle_showuptime(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a)