diff options
author | Luigi Rizzo <rizzo@icir.org> | 2006-12-16 09:56:31 +0000 |
---|---|---|
committer | Luigi Rizzo <rizzo@icir.org> | 2006-12-16 09:56:31 +0000 |
commit | 97ce2f8fd882c5eb8a1c8065602cce39a29f3dfe (patch) | |
tree | c4a05cb8778ff2d553a9b5a02968febaa5f49bb8 /main/cli.c | |
parent | c1220dd27ee62481f9f49f2d83ab06e322b894ae (diff) |
another conversion from ast_build_str to ast_str
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@48517 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/cli.c')
-rw-r--r-- | main/cli.c | 26 |
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) |