From: Andre Noll Date: Sat, 5 May 2012 09:04:23 +0000 (+0200) Subject: command.c: Improve get_status(). X-Git-Tag: v0.4.11~14^2~5 X-Git-Url: http://git.tue.mpg.de/?a=commitdiff_plain;h=3667d75edd30f45f6b909bcf5203689c866a77b5;p=paraslash.git 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. --- 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;