Appends a command to the output buffer.
Definition at line 282 of file async.c. References mpd_async::error, mpd_async_send_command_v(), and mpd_async::output. Referenced by mpd_async_send_command(), mpd_async_send_command_v(), and mpd_sync_send_command_v(). { size_t room, length; char *dest, *end, *p; const char *arg; assert(async != NULL); assert(command != NULL); if (mpd_error_is_defined(&async->error)) return false; room = mpd_buffer_room(&async->output); length = strlen(command); if (room <= length) return false; dest = mpd_buffer_write(&async->output); /* -1 because we reserve space for the \n character */ end = dest + room - 1; /* copy the command (no quoting, we asumme it is "clean") */ memcpy(dest, command, length); p = dest + length; /* now append all arguments (quoted) */ while ((arg = va_arg(args, const char *)) != NULL) { /* append a space separator */ if (p >= end) return false; *p++ = ' '; /* quote the argument into the destination buffer */ p = quote(p, end, arg); assert(p == NULL || (p >= dest && p <= end)); if (p == NULL) return false; } /* append the newline to finish this command */ *p++ = '\n'; mpd_buffer_expand(&async->output, p - dest); return true; }
|