From 3667d75edd30f45f6b909bcf5203689c866a77b5 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sat, 5 May 2012 11:04:23 +0200 Subject: [PATCH] command.c: Improve get_status(). We know exactly the number of bytes in the result buffer. By returning this information, the caller can use sc_send_bin_buffer() instead of sc_send_buffer(), which safes one strlen() call. --- command.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/command.c b/command.c index c18cd4dd..9c175f35 100644 --- a/command.c +++ b/command.c @@ -102,7 +102,8 @@ static char *vss_get_status_flags(unsigned int flags) return msg; } -static char *get_status(struct misc_meta_data *nmmd, int parser_friendly) +static unsigned get_status(struct misc_meta_data *nmmd, int parser_friendly, + char **result) { char mtime[30] = ""; char *status, *flags; /* vss status info */ @@ -142,7 +143,8 @@ static char *get_status(struct misc_meta_data *nmmd, int parser_friendly) free(flags); free(status); free(ut); - return b.buf; + *result = b.buf; + return b.offset; } static int check_sender_args(int argc, char * const * argv, struct sender_command_data *scd) @@ -495,8 +497,8 @@ int com_stat(struct command_context *cc) return -E_COMMAND_SYNTAX; for (;;) { mmd_dup(nmmd); - s = get_status(nmmd, parser_friendly); - ret = sc_send_buffer(&cc->scc, s); + ret = get_status(nmmd, parser_friendly, &s); + ret = sc_send_bin_buffer(&cc->scc, s, ret); free(s); if (ret < 0) goto out; -- 2.39.5