summaryrefslogtreecommitdiff
path: root/src/stdio/sprintf.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/sprintf.c')
-rw-r--r--src/stdio/sprintf.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/stdio/sprintf.c b/src/stdio/sprintf.c
new file mode 100644
index 00000000..babd4ba3
--- /dev/null
+++ b/src/stdio/sprintf.c
@@ -0,0 +1,31 @@
+#include <stdio.h>
+#include "stdarg.h"
+#include "nonstd/io.h"
+#include "nonstd/internal.h"
+
+/** write formatted output to a string **/
+int sprintf(char * restrict s, const char * restrict format, ...)
+{
+ int ret = 0;
+ va_list ap;
+ struct io_options opt = {0};
+ opt.fnname = "sprintf";
+ opt.string = s;
+ opt.maxlen = (size_t)-1;
+ va_start(ap, format);
+ ret = __printf(&opt, format, ap);
+ va_end(ap);
+ /*
+ RETURN_SUCCESS(the number of characters written to the array, not counting the terminating null);
+ */
+ return ret;
+}
+
+/***
+writes a formatted string to the buffer at ARGUMENT(s). The format of
+ARGUMENT(format) and the variadic arguments is the same as that for
+FUNCTION(printf).
+***/
+/*
+STDC(1)
+*/