summaryrefslogtreecommitdiff
path: root/src/stdio
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2020-08-16 15:55:19 -0400
committerJakob Kaivo <jkk@ung.org>2020-08-16 15:55:19 -0400
commite223e635cc53fa11e473cdbc864eb69a3da5f290 (patch)
treed481ca6fb0b7f4184f3ec259a6f9c37d76e56a26 /src/stdio
parent700fbd205a1a428677876d322606b9a354221892 (diff)
add skeleton of symbols from C11 LIB_EXT1
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/L_tmpnam_s.c5
-rw-r--r--src/stdio/TMP_MAX_S.c5
-rw-r--r--src/stdio/fopen_s.c55
-rw-r--r--src/stdio/fprintf_s.c31
-rw-r--r--src/stdio/freopen_s.c36
-rw-r--r--src/stdio/fscanf_s.c32
-rw-r--r--src/stdio/gets_s.c33
-rw-r--r--src/stdio/printf_s.c32
-rw-r--r--src/stdio/scanf_s.c32
-rw-r--r--src/stdio/snprintf_s.c10
-rw-r--r--src/stdio/sprintf_s.c31
-rw-r--r--src/stdio/sscanf_s.c32
-rw-r--r--src/stdio/tmpfile_s.c26
-rw-r--r--src/stdio/tmpnam_s.c43
-rw-r--r--src/stdio/vfprintf_s.c38
-rw-r--r--src/stdio/vfscanf_s.c10
-rw-r--r--src/stdio/vprintf_s.c28
-rw-r--r--src/stdio/vscanf_s.c11
-rw-r--r--src/stdio/vsnprintf_s.c216
-rw-r--r--src/stdio/vsprintf_s.c29
-rw-r--r--src/stdio/vsscanf_s.c10
21 files changed, 745 insertions, 0 deletions
diff --git a/src/stdio/L_tmpnam_s.c b/src/stdio/L_tmpnam_s.c
new file mode 100644
index 00000000..c014796b
--- /dev/null
+++ b/src/stdio/L_tmpnam_s.c
@@ -0,0 +1,5 @@
+#define L_tmpnam_s (255)
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/TMP_MAX_S.c b/src/stdio/TMP_MAX_S.c
new file mode 100644
index 00000000..69822bb4
--- /dev/null
+++ b/src/stdio/TMP_MAX_S.c
@@ -0,0 +1,5 @@
+#define TMP_MAX_S (10000)
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/fopen_s.c b/src/stdio/fopen_s.c
new file mode 100644
index 00000000..59385515
--- /dev/null
+++ b/src/stdio/fopen_s.c
@@ -0,0 +1,55 @@
+#include "stdio.h"
+#include "__stdio.h"
+#include <string.h>
+#include <stdlib.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+/** open a file stream **/
+errno_t fopen_s(FILE * restrict * restrict streamptr,
+ const char * restrict filename,
+ const char * restrict mode);
+{
+ __C_EXT(1, 201112L);
+ return 0;
+}
+
+/***
+The fn(fopen) function opens a file stream associated with the file
+arg(filename).
+
+The type of file and allowed operations are determined by arg(mode):
+
+string(r) text file; read-only
+string(w) text file; write-only; truncate to 0 bytes
+string(a) text file; append
+string(rb) binary file; read-only
+string(wb) binary file; write-only; truncate to 0 bytes
+string(ab) binary file; append
+string(r+) text file; update (read and write)
+string(w+) text file; update (read and write); truncate to 0 bytes
+string(a+) text file; update (read and write); append data to end of file
+string(r+b) binary file; update (read and write)
+string(rb+) binary file; update (read and write)
+string(w+b) binary file; update (read and write); truncate to 0 bytes
+string(wb+) binary file; update (read and write); truncate to 0 bytes
+string(a+b) binary file; update (read and write); append data to end of file
+string(ab+) binary file; update (read and write); append data to end of file
+
+File streams are opened in fully buffered mode if and only if arg(filename) is
+not an interactive device.
+
+The error and end-of-file indicators are cleared.
+***/
+
+/* UNSPECIFIED: - */
+/* UNDEFINED: - */
+/* IMPLEMENTATION: - */
+/* LOCALE: - */
+
+/* RETURN(NULL): failure */
+/* RETURN: a pointer to the new file stream */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/fprintf_s.c b/src/stdio/fprintf_s.c
new file mode 100644
index 00000000..b633dee8
--- /dev/null
+++ b/src/stdio/fprintf_s.c
@@ -0,0 +1,31 @@
+#include "stdio.h"
+#include "stdarg.h"
+
+/** write formatted output to a file stream **/
+int fprintf_s(FILE * restrict stream, const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vfprintf_s(stream, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(fprintf) function writes a formatted string to arg(stream). The format
+of arg(format) and the variadic arguments is the same as that for fn(printf).
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(NEG): an error occurred */
+/* RETURN: the number of characters written */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/freopen_s.c b/src/stdio/freopen_s.c
new file mode 100644
index 00000000..d646bec8
--- /dev/null
+++ b/src/stdio/freopen_s.c
@@ -0,0 +1,36 @@
+#include "stdio.h"
+#include "__stdio.h"
+#include <fcntl.h>
+#include <string.h>
+
+/** reopen a file stream with a new file **/
+errno_t freopen_s(FILE * restrict * restrict newstreamptr,
+ const char * restrict filename,
+ const char * restrict mode,
+ FILE * restrict stream)
+{
+ __C_EXT(1, 201112L);
+ return 0;
+}
+
+/***
+The fn(freopen) function changes the file associated with arg(stream) to
+arg(filename). The meaning of arg(mode) is the same as with fn(fopen).
+
+Whatever file is currently associated with arg(stream) is closed, ignoring any
+errors.
+
+The error and end-of-file indicators are cleared.
+***/
+
+/* UNSPECIFIED: - */
+/* UNDEFINED: - */
+/* IMPLEMENTATION: - */
+/* LOCALE: - */
+
+/* RETURN(NULL): the open operation failed */
+/* RETURN: the value of arg(stream) */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/fscanf_s.c b/src/stdio/fscanf_s.c
new file mode 100644
index 00000000..de7f9e98
--- /dev/null
+++ b/src/stdio/fscanf_s.c
@@ -0,0 +1,32 @@
+#include "stdio.h"
+#include "stdio.h"
+#include "stdarg.h"
+
+/** read formatted input from a file stream **/
+int fscanf_s(FILE * restrict stream, const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vfscanf_s(stream, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(fscanf) function reads formatted input from arg(stream). The format of
+arg(format) at the variadic arguments is the same as that for fn(scanf).
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(EOF): an input failure occurred */
+/* RETURN: the number of input items assigned */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/gets_s.c b/src/stdio/gets_s.c
new file mode 100644
index 00000000..5af016dd
--- /dev/null
+++ b/src/stdio/gets_s.c
@@ -0,0 +1,33 @@
+#include "stdio.h"
+#include <limits.h>
+
+/** read a line from stdin **/
+char * gets_s(char *s, rsize_t n)
+{
+ __C_EXT(1, 201112L);
+ return fgets(s, INT_MAX, stdin);
+}
+
+/***
+The fn(gets) function does no bounds checking, is marked obsolete in C99, and
+has been removed from C11. It is a security risk and should not be used.
+
+The fn(gets) function reads a line of input from macro(stdin) into the array
+arg(s). Input characters are read until a newline or end-of-file is reached. The
+newline will not be appended to arg(s). A char(\0) character will be written
+after the last character read into the array.
+
+If end-of-file is reached before any characters are read, the contents of arg(s)
+remain unchanged.
+***/
+
+/* UNSPECIFIED: - */
+/* UNDEFINED: - */
+/* IMPLEMENTATION: - */
+/* LOCALE: - */
+
+/* RETURN(EOF): end-of-file was reached with no characters read; or, an error occurred */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/printf_s.c b/src/stdio/printf_s.c
new file mode 100644
index 00000000..b5917062
--- /dev/null
+++ b/src/stdio/printf_s.c
@@ -0,0 +1,32 @@
+#include "stdio.h"
+#include "stdarg.h"
+
+/** write formatted output **/
+int printf_s(const char *format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vfprintf_s(stdout, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(fprintf) function writes a formatted string to macro(stdout).
+
+FIXME: printf format goes here
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(NEG): an error occurred */
+/* RETURN: the number of characters written */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/scanf_s.c b/src/stdio/scanf_s.c
new file mode 100644
index 00000000..f67335f7
--- /dev/null
+++ b/src/stdio/scanf_s.c
@@ -0,0 +1,32 @@
+#include "stdio.h"
+#include "stdarg.h"
+
+/** read formatted input **/
+int scanf_s(const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vfscanf_s(stdin, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(scanf) function reads formatted input from macro(stdin).
+
+FIXME: scanf format goes here
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(EOF): an input failure occurred */
+/* RETURN: the number of input items assigned */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/snprintf_s.c b/src/stdio/snprintf_s.c
new file mode 100644
index 00000000..dcbdafaa
--- /dev/null
+++ b/src/stdio/snprintf_s.c
@@ -0,0 +1,10 @@
+#include "stdio.h"
+
+int snprintf_s( char * restrict s, rsize_t n, const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+}
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/sprintf_s.c b/src/stdio/sprintf_s.c
new file mode 100644
index 00000000..223e84c8
--- /dev/null
+++ b/src/stdio/sprintf_s.c
@@ -0,0 +1,31 @@
+#include "stdio.h"
+#include "stdarg.h"
+
+/** write formatted output to a string **/
+int sprintf_s(char * restrict s, rsize_t n, const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vsprintf(s, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(sprintf) function writes a formatted string to the buffer at arg(s). The
+format of arg(format) and the variadic arguments is the same as that for
+fn(printf).
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN: the number of characters written, not including the final char(\0) */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/sscanf_s.c b/src/stdio/sscanf_s.c
new file mode 100644
index 00000000..c91786f6
--- /dev/null
+++ b/src/stdio/sscanf_s.c
@@ -0,0 +1,32 @@
+#include "stdio.h"
+#include "stdarg.h"
+
+/** read formatted input from a string **/
+int sscanf_s(const char * restrict s, const char * restrict format, ...)
+{
+ __C_EXT(1, 201112L);
+ int retval;
+ va_list ap;
+ va_start(ap, format);
+ retval = vsscanf(s, format, ap);
+ va_end(ap);
+ return retval;
+}
+
+/***
+The fn(sscanf) function reads formatted input from the string arg(s). The
+format of arg(format) at the variadic arguments is the same as that for
+fn(scanf).
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(EOF): an input failure occurred */
+/* RETURN: the number of input items assigned */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/tmpfile_s.c b/src/stdio/tmpfile_s.c
new file mode 100644
index 00000000..948425ad
--- /dev/null
+++ b/src/stdio/tmpfile_s.c
@@ -0,0 +1,26 @@
+#include "stdio.h"
+
+/* open a temporary file stream */
+errno_t tmpfile_s(FILE * restrict * restrict streamptr)
+{
+ __C_EXT(1, 201112L);
+ return 0;
+}
+
+/***
+The fn(tmpfile) function creates a temporary binary file stream for update (as
+when arg(mode) is specified as string(wb+) to fn(fopen)). The file stream will
+be automatically removed when closed by fn(fclose) or when the program exits.
+***/
+
+/* UNSPECIFIED: - */
+/* UNDEFINED: - */
+/* IMPLEMENTATION: whether the temporary file is removed if the program terminates abnormally */
+/* LOCALE: - */
+
+/* RETURN(NULL): a temporary file stream could not be created */
+/* RETURN: a pointer to the temporary file stream */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/tmpnam_s.c b/src/stdio/tmpnam_s.c
new file mode 100644
index 00000000..176eb982
--- /dev/null
+++ b/src/stdio/tmpnam_s.c
@@ -0,0 +1,43 @@
+#include "stdio.h"
+
+/** generate a temporary file name **/
+errno_t tmpnam_s(char *s, rsize_t maxsize)
+{
+ __C_EXT(1, 201112L);
+ static int ntimescalled = 0;
+ static char path[L_tmpnam];
+
+ if (ntimescalled >= TMP_MAX) {
+ return 0;
+ }
+ ntimescalled++;
+
+ if (s == NULL) {
+ s = path;
+ }
+
+ return 0;
+}
+
+/***
+The fn(tmpnam) function generates a unique file name that can be used as a
+temporary file. A new file name is generated every time the function is called
+up to macro(TMP_MAX) times.
+
+If arg(s) is macro(NULL), the temporary name is stored in a static internal
+buffer. This buffer may be overwritten by additional calls to fn(tmpnam).
+
+If arg(s) is not macro(NULL), it should point to a type(char) array of at least
+macro(L_tmpnam) characters. The temporary name will be copied to this array.
+***/
+
+/* UNSPECIFIED: - */
+/* UNDEFINED: - */
+/* IMPLEMENTATION: behavior if fn(tmpnam) is called more than macro(TMP_MAX) times */
+/* LOCALE: - */
+
+/* RETURN: a pointer to the temporary file name */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vfprintf_s.c b/src/stdio/vfprintf_s.c
new file mode 100644
index 00000000..e2d94c71
--- /dev/null
+++ b/src/stdio/vfprintf_s.c
@@ -0,0 +1,38 @@
+#include "stdio.h"
+#include "__stdio.h"
+#include <stdarg.h>
+
+/** write formatted output to a file stream **/
+int vfprintf_s(FILE * restrict stream, const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+ va_list ap;
+ va_copy(ap, arg);
+ int len = vsnprintf(NULL, 0, format, arg);
+ char *buf = malloc(len + 1);
+ len = vsnprintf(buf, len, format, ap);
+ va_end(ap);
+ len = (int)fwrite(buf, sizeof(*buf), len, stream);
+ free(buf);
+ return len;
+}
+
+/***
+The fn(vfprintf) function is equivalent to fn(fprintf), but with a type(va_list)
+argument instead of variadic arguments. The argument arg(arg) must be
+initialized with fnmacro(va_start) prior to calling fn(vfprintf). The
+fn(vfprintf) function does not call fnmacro(va_end), so the calling function is
+responsible for this.
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(NEG): an error occurred */
+/* RETURN: the number of characters written */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vfscanf_s.c b/src/stdio/vfscanf_s.c
new file mode 100644
index 00000000..82fb238c
--- /dev/null
+++ b/src/stdio/vfscanf_s.c
@@ -0,0 +1,10 @@
+#include "stdio.h"
+
+int vfscanf_s(FILE * restrict stream, const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+}
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vprintf_s.c b/src/stdio/vprintf_s.c
new file mode 100644
index 00000000..c13b1ead
--- /dev/null
+++ b/src/stdio/vprintf_s.c
@@ -0,0 +1,28 @@
+#include "stdio.h"
+
+/** write formatted output **/
+int vprintf_s(const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+ return vfprintf(stdout, format, arg);
+}
+
+/***
+The fn(vprintf) function is equivalent to fn(printf), but with a type(va_list)
+argument instead of variadic arguments. The argument arg(arg) must be
+initialized with fnmacro(va_start) prior to calling fn(vprintf). The
+fn(vprintf) function does not call fnmacro(va_end), so the calling function is
+responsible for this.
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN(NEG): an error occurred */
+/* RETURN: the number of characters written */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vscanf_s.c b/src/stdio/vscanf_s.c
new file mode 100644
index 00000000..85f34e07
--- /dev/null
+++ b/src/stdio/vscanf_s.c
@@ -0,0 +1,11 @@
+#include "stdio.h"
+
+int vscanf_s(const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+ return vfscanf(stdin, format, arg);
+}
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vsnprintf_s.c b/src/stdio/vsnprintf_s.c
new file mode 100644
index 00000000..48fbe425
--- /dev/null
+++ b/src/stdio/vsnprintf_s.c
@@ -0,0 +1,216 @@
+#include "internal_vsnprintf.c"
+#include <inttypes.h>
+
+int vsnprintf_s(char * restrict s, rsize_t n, const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+ int nout = 0;
+
+ intmax_t argint = 0;
+ void *argptr = NULL;
+ char numbuf[NUMBUFLEN];
+
+ for (size_t i = 0; format[i] != 0; i++) {
+ if (format[i] != '%') {
+ if (nout < (int)n) {
+ s[nout] = format[i];
+ }
+ nout++;
+ continue;
+ }
+
+ //__asm int 3;
+ // zero of more flags "-+ #0"
+ // optional width "*" or decimal integer
+ // optional precision ".*" or ".[decimal]"
+ // optional length modifier "hh", "h", "l", "ll", "j",
+ // "z", "t", "L"
+ // conversion specifier "diouxXfFeEgGaAcspn%"
+ int flags = 0;
+ uintmax_t width = 0;
+ int step = 0;
+ int precision = 0;
+ int base = 10;
+ enum { def, hh, h, l, ll, j, z, t, L } length = def;
+
+ while (step == 0) {
+ i++;
+ switch (format[i]) {
+ case '-': flags |= LEFT; break;
+ case '+': flags |= SIGN; break;
+ case ' ': flags |= SPACE; break;
+ case '#': flags |= ALT; break;
+ case '0': flags |= ZERO; break;
+ default: step = 1; break;
+ }
+ }
+
+ if (format[i] == '*') {
+ i++;
+ } else if (isdigit(format[i])) {
+ char *end;
+ width = strtoumax(format + i, &end, 10);
+ i = end - format;
+ }
+
+ if (format[i] == '.') {
+ i++;
+ if (format[i] == '*') {
+ i++;
+ } else if (isdigit(format[i])) {
+ char *end;
+ precision = (int)strtoumax(format + i, &end, 10);
+ i = end - format;
+ } else {
+ // invalid precision
+ return -nout;
+ }
+ }
+
+ if (format[i] == 'h') {
+ i++;
+ if (format[i] == 'h') {
+ i++;
+ length = hh;
+ } else {
+ length = h;
+ }
+ } else if (format[i] == 'l') {
+ i++;
+ if (format[i] == 'l') {
+ i++;
+ length = ll;
+ } else {
+ length = l;
+ }
+ } else if (format[i] == 'j') {
+ i++;
+ length = j;
+ } else if (format[i] == 'z') {
+ i++;
+ length = z;
+ } else if (format[i] == 't') {
+ i++;
+ length = t;
+ } else if (format[i] == 'L') {
+ i++;
+ length = L;
+ }
+
+ if (isupper(format[i])) {
+ flags |= UPPER;
+ }
+
+ switch (format[i]) {
+ case 'o': // unsigned int
+ case 'u':
+ case 'x':
+ case 'X':
+ flags |= UNSIGNED;
+
+ case 'd': // int
+ case 'i':
+ switch (length) {
+ case hh: argint = (signed char)va_arg(arg, int); break;
+ case h: argint = (short int)va_arg(arg, int); break;
+ case l: argint = va_arg(arg, long int); break;
+ case ll: argint = va_arg(arg, long long int); break;
+ case j: argint = va_arg(arg, intmax_t); break;
+ case z: argint = va_arg(arg, size_t); break;
+ case t: argint = va_arg(arg, ptrdiff_t); break;
+ case L: return -nout;
+ default: argint = va_arg(arg, int); break;
+ }
+ if (format[i] == 'o') {
+ base = 8;
+ } else if (format[i] == 'x') {
+ base = 16;
+ } else if (format[i] == 'X') {
+ base = 16;
+ flags |= UPPER;
+ } else {
+ base = 10;
+ }
+ itos(numbuf, (long int)argint, flags, precision, base);
+ nout = append(s, numbuf, nout, n);
+ break;
+
+
+ case 'f': // double [-]ddd.ddd
+ case 'F':
+ break;
+
+ case 'e': // double [-]d.ddde+/-dd
+ case 'E':
+ break;
+
+ case 'g': // double f or e see docs
+ case 'G':
+ break;
+
+ case 'a': // double as hex
+ case 'A':
+ break;
+
+ case 'c': // char
+ if (length == def) {
+ char c = va_arg(arg, int);
+ if (nout < (int)n) {
+ s[nout] = c;
+ }
+ nout++;
+ } else if (length == l) {
+ //wint_t wc = va_arg(arg, wint_t);
+ //char mb[MB_CUR_MAX + 1] = "WC";
+ //wctomb(mb, wc);
+ //nout = append(s, mb, nout, n);
+ } else {
+ return -nout;
+ }
+ break;
+
+ case 's': // string
+ if (length == def) {
+ char *string = va_arg(arg, char *);
+ nout = append(s, string, nout, n);
+ } else if (length == l) {
+ //wchar_t *ws = va_arg(arg, wchar_t *);
+ //char *mbs = malloc(wcslen(ws) * MB_CUR_MAX + 1);
+ //wcstombs(mbs, ws, wcslen(ws) * MB_CUR_MAX + 1);
+ //nout = append(s, mbs, nout, n);
+ //free(mbs);
+ nout = append(s, "WIDE STRING", nout, n);
+ } else {
+ return -nout;
+ }
+
+ break;
+
+ case 'p': // pointer
+ argptr = va_arg(arg, void *);
+ nout = append(s, "0x", nout, n);
+ itos(numbuf, (intptr_t)argptr, ZERO, sizeof(argptr) * 2, 16);
+ nout = append(s, numbuf, nout, n);
+ break;
+
+ case 'n': // write-back
+ break;
+
+ case '%': // literal '%'
+ if (nout < (int)n) {
+ s[nout] = '%';
+ }
+ nout++;
+ break;
+
+ default: // undefined
+ return -nout;
+ }
+ }
+
+ return nout;
+}
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vsprintf_s.c b/src/stdio/vsprintf_s.c
new file mode 100644
index 00000000..98a7794f
--- /dev/null
+++ b/src/stdio/vsprintf_s.c
@@ -0,0 +1,29 @@
+#include "stdio.h"
+#include <stdarg.h>
+#include <stdint.h>
+
+/** write formatted output to a string **/
+int vsprintf_s(char *s, rsize_t n, const char *format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+ return vsnprintf(s, SIZE_MAX, format, arg);
+}
+
+/***
+The fn(vsprintf) function is equivalent to fn(sprintf), but with a type(va_list)
+argument instead of variadic arguments. The argument arg(arg) must be
+initialized with fnmacro(va_start) prior to calling fn(vsprintf). The
+fn(vsprintf) function does not call fnmacro(va_end), so the calling function is
+responsible for this.
+***/
+
+/* UNSPECIFIED: ??? */
+/* UNDEFINED: ??? */
+/* IMPLEMENTATION: ??? */
+/* LOCALE: ??? */
+
+/* RETURN: the number of characters written, not including the final char(\0) */
+
+/*
+CEXT1(201112)
+*/
diff --git a/src/stdio/vsscanf_s.c b/src/stdio/vsscanf_s.c
new file mode 100644
index 00000000..6ac2e6fa
--- /dev/null
+++ b/src/stdio/vsscanf_s.c
@@ -0,0 +1,10 @@
+#include "stdarg.h"
+
+int vsscanf_s(const char * restrict s, const char * restrict format, va_list arg)
+{
+ __C_EXT(1, 201112L);
+}
+
+/*
+CEXT1(201112)
+*/