From 9cd0af113249d8193c8932a6bcae6b266dcad4f7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 8 May 2013 16:17:06 +1000 Subject: [PATCH] HAL_PX4: make PX4 snprintf support %S format just maps it to %s for normal printf --- libraries/AP_HAL_PX4/Util.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/libraries/AP_HAL_PX4/Util.cpp b/libraries/AP_HAL_PX4/Util.cpp index 1155d191ea..29881f1480 100644 --- a/libraries/AP_HAL_PX4/Util.cpp +++ b/libraries/AP_HAL_PX4/Util.cpp @@ -12,9 +12,27 @@ extern const AP_HAL::HAL& hal; -static int libc_vsnprintf(char* str, size_t size, const char *format, va_list ap) +/* + implement vsnprintf with support for %S meaning a progmem string + */ +static int libc_vsnprintf(char* str, size_t size, const char *fmt, va_list ap) { - return vsnprintf(str, size, format, ap); + int i, ret; + char *fmt2 = (char *)fmt; + if (strstr(fmt2, "%S") != NULL) { + fmt2 = strdup(fmt); + for (i=0; fmt2[i]; i++) { + // cope with %S + if (fmt2[i] == '%' && fmt2[i+1] == 'S') { + fmt2[i+1] = 's'; + } + } + } + ret = vsnprintf(str, size, fmt2, ap); + if (fmt2 != fmt) { + free(fmt2); + } + return ret; } #include "Util.h"