summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarkus Pargmann <mpa@pengutronix.de>2015-12-08 10:39:27 +0100
committerSascha Hauer <s.hauer@pengutronix.de>2015-12-10 08:49:52 +0100
commit647fba8ee386bbbcd430979e41ab4bdda4273673 (patch)
treec2284ccf91d8a2a54a4a71ee1ae913c213f61a16
parent45885266f98577f71cca528538a8512a40228d03 (diff)
downloadbarebox-647fba8ee386bbbcd430979e41ab4bdda4273673.tar.gz
vsprintf: Add scnprintf from kernel
Signed-off-by: Markus Pargmann <mpa@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r--include/stdio.h1
-rw-r--r--lib/vsprintf.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
index f190911..d0817bd 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -13,6 +13,7 @@ void serial_printf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2
int sprintf(char *buf, const char *fmt, ...) __attribute__ ((format(__printf__, 2, 3)));
int snprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
+int scnprintf(char *buf, size_t size, const char *fmt, ...) __attribute__ ((format(__printf__, 3, 4)));
int vsprintf(char *buf, const char *fmt, va_list args);
char *asprintf(const char *fmt, ...) __attribute__ ((format(__printf__, 1, 2)));
char *vasprintf(const char *fmt, va_list ap);
diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 800ded7..9b8e8cf 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -595,6 +595,30 @@ int snprintf(char *buf, size_t size, const char *fmt, ...)
}
EXPORT_SYMBOL(snprintf);
+/**
+ * scnprintf - Format a string and place it in a buffer
+ * @buf: The buffer to place the result into
+ * @size: The size of the buffer, including the trailing null space
+ * @fmt: The format string to use
+ * @...: Arguments for the format string
+ *
+ * The return value is the number of characters written into @buf not including
+ * the trailing '\0'. If @size is == 0 the function returns 0.
+ */
+
+int scnprintf(char *buf, size_t size, const char *fmt, ...)
+{
+ va_list args;
+ int i;
+
+ va_start(args, fmt);
+ i = vscnprintf(buf, size, fmt, args);
+ va_end(args);
+
+ return i;
+}
+EXPORT_SYMBOL(scnprintf);
+
/* Simplified asprintf. */
char *vasprintf(const char *fmt, va_list ap)
{