summaryrefslogtreecommitdiff
path: root/src/stdio/sprintf.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
committerJakob Kaivo <jkk@ung.org>2019-02-08 18:42:39 -0500
commit7ef8a7379f7f7d09e71ccae2a0b688c3cd80423f (patch)
tree092ab0aed1769117fd7b28b8592f6f96b0e0d5af /src/stdio/sprintf.c
parent6acf19370e8adff79cd83b257d3f04aeaf2a59dd (diff)
merge sources into single tree
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)
+*/