@@ -13,14 +13,34 @@
#include <common.h>
#include <fastboot.h>
+/**
+ * Writes a response to response buffer of the form "$tag$reason".
+ *
+ * @param tag The first part of the response
+ * @param response Pointer to fastboot response buffer
+ * @param format printf style format string
+ */
+void fastboot_response(const char *tag, char *response,
+ const char *format, ...)
+{
+ va_list args;
+
+ strlcpy(response, tag, FASTBOOT_RESPONSE_LEN);
+ if (format) {
+ va_start(args, format);
+ vsnprintf(response + strlen(response),
+ FASTBOOT_RESPONSE_LEN - strlen(response) - 1,
+ format, args);
+ va_end(args);
+ }
+}
+
void fastboot_fail(const char *reason, char *response)
{
- strncpy(response, "FAIL\0", 5);
- strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+ fastboot_response("FAIL", response, "%s", reason);
}
void fastboot_okay(const char *reason, char *response)
{
- strncpy(response, "OKAY\0", 5);
- strncat(response, reason, FASTBOOT_RESPONSE_LEN - 4 - 1);
+ fastboot_response("OKAY", response, "%s", reason);
}
@@ -16,6 +16,10 @@
/* The 64 defined bytes plus \0 */
#define FASTBOOT_RESPONSE_LEN (64 + 1)
+void fastboot_response(const char *tag, char *response,
+ const char *format, ...)
+ __attribute__ ((format (__printf__, 3, 4)));
+
void fastboot_fail(const char *reason, char *response);
void fastboot_okay(const char *reason, char *response);
Introduce fastboot_response which takes varargs parameters so we can use it to generate formatted response strings. Refactor fastboot_okay/fail to use it. Signed-off-by: Alex Kiernan <alex.kiernan@gmail.com> --- Changes in v2: None drivers/fastboot/fb_common.c | 28 ++++++++++++++++++++++++---- include/fastboot.h | 4 ++++ 2 files changed, 28 insertions(+), 4 deletions(-)