aboutsummaryrefslogtreecommitdiffstats
path: root/src/stdio
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio')
-rw-r--r--src/stdio/printf.c72
-rw-r--r--src/stdio/scanf.c74
2 files changed, 144 insertions, 2 deletions
diff --git a/src/stdio/printf.c b/src/stdio/printf.c
index fa5dce9..4c5bae9 100644
--- a/src/stdio/printf.c
+++ b/src/stdio/printf.c
@@ -184,7 +184,7 @@ static int wwrite_fd(const wchar_t* text, size_t length, int* fdp)
/**
- * Write a string segment to a file.
+ * Write a string segment to a socket with `send`.
*
* @param text The text to write, not NUL terminated.
* @param length The length of `text`.
@@ -204,7 +204,7 @@ static int send_fd(const char* text, size_t length, int* input)
/**
- * Write a string segment to a file.
+ * Write a string segment to a socket with `send`.
*
* @param text The text to write, not NUL terminated.
* @param length The length of `text`.
@@ -361,6 +361,8 @@ static int wwrite_buffer(const wchar_t* text, size_t length, struct buffer* buff
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int printf(const char* restrict format, ...)
{
@@ -387,6 +389,8 @@ int printf(const char* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int fprintf(FILE* restrict stream, const char* restrict format, ...)
{
@@ -414,6 +418,8 @@ int fprintf(FILE* restrict stream, const char* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite_unlocked`.
+ *
+ * @since Always.
*/
int fprintf_unlocked(FILE* restrict stream, const char* restrict format, ...)
{
@@ -441,6 +447,8 @@ int fprintf_unlocked(FILE* restrict stream, const char* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int dprintf(int fd, const char* restrict format, ...)
{
@@ -471,6 +479,8 @@ int dprintf(int fd, const char* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int sockprintf(int fd, int flags, const char* format restrict, ...)
{
@@ -498,6 +508,8 @@ int sockprintf(int fd, int flags, const char* format restrict, ...)
* use "%zn" to find the actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int sprintf(char* restrict buffer, const char* restrict format, ...)
{
@@ -525,6 +537,8 @@ int sprintf(char* restrict buffer, const char* restrict format, ...)
* actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int snprintf(char* restrict buffer, size_t size, const char* restrict format, ...)
{
@@ -555,6 +569,8 @@ int snprintf(char* restrict buffer, size_t size, const char* restrict format, ..
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int asprintf(char** restrict buffer, const char* restrict format, ...)
{
@@ -602,6 +618,8 @@ int asprintf(char** restrict buffer, const char* restrict format, ...)
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int bprintf(char** restrict buffer, size_t* restrict size, size_t offset,
int secure, const char* restrict format, ...)
@@ -627,6 +645,8 @@ int bprintf(char** restrict buffer, size_t* restrict size, size_t offset,
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int vprintf(const char* restrict format, va_list args)
{
@@ -652,6 +672,8 @@ int vprintf(const char* restrict format, va_list args)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int vfprintf(FILE* restrict stream, const char* restrict format, va_list args)
{
@@ -684,6 +706,8 @@ int vfprintf(FILE* restrict stream, const char* restrict format, va_list args)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite_unlocked`.
+ *
+ * @since Always.
*/
int vfprintf_unlocked(FILE* restrict stream, const char* restrict format, va_list args)
{
@@ -709,6 +733,8 @@ int vfprintf_unlocked(FILE* restrict stream, const char* restrict format, va_lis
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int vdprintf(int fd, const char* restrict format, va_list args)
{
@@ -738,6 +764,8 @@ int vdprintf(int fd, const char* restrict format, va_list args)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int vsockprintf(int fd, int flags, const char* restrict format, va_list args)
{
@@ -763,6 +791,8 @@ int vsockprintf(int fd, int flags, const char* restrict format, va_list args)
* use "%zn" to find the actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int vsprintf(char* restrict buffer, const char* restrict format, va_list args)
{
@@ -791,6 +821,8 @@ int vsprintf(char* restrict buffer, const char* restrict format, va_list args)
* actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int vsnprintf(char* restrict buffer, size_t size, const char* restrict format, va_list args)
{
@@ -821,6 +853,8 @@ int vsnprintf(char* restrict buffer, size_t size, const char* restrict format, v
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int vasprintf(char** restrict buffer, const char* restrict format, va_list args)
{
@@ -871,6 +905,8 @@ int vasprintf(char** restrict buffer, const char* restrict format, va_list args)
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int vbprintf(char** restrict buffer, size_t* restrict size, size_t offset,
int secure, const char* restrict format, va_list args)
@@ -904,6 +940,8 @@ int vbprintf(char** restrict buffer, size_t* restrict size, size_t offset,
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int wprintf(const wchar_t* restrict format, ...)
{
@@ -929,6 +967,8 @@ int wprintf(const wchar_t* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...)
{
@@ -956,6 +996,8 @@ int fwprintf(FILE* restrict stream, const wchar_t* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite_unlocked`.
+ *
+ * @since Always.
*/
int fwprintf_unlocked(FILE* restrict stream, const wchar_t* restrict format, ...)
{
@@ -983,6 +1025,8 @@ int fwprintf_unlocked(FILE* restrict stream, const wchar_t* restrict format, ...
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int dwprintf(int fd, const wchar_t* restrict format, ...)
{
@@ -1012,6 +1056,8 @@ int dwprintf(int fd, const wchar_t* restrict format, ...)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int sockwprintf(int fd, int flags, const wchar_t* restrict format, ...)
{
@@ -1039,6 +1085,8 @@ int sockwprintf(int fd, int flags, const wchar_t* restrict format, ...)
* actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int swprintf(wchar_t* restrict buffer, size_t size, const wchar_t* restrict format, ...)
{
@@ -1069,6 +1117,8 @@ int swprintf(wchar_t* restrict buffer, size_t size, const wchar_t* restrict form
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int aswprintf(wchar_t** restrict buffer, const wchar_t* restrict format, ...)
{
@@ -1117,6 +1167,8 @@ int aswprintf(wchar_t** restrict buffer, const wchar_t* restrict format, ...)
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int bwprintf(wchar_t** restrict buffer, size_t* restrict size, size_t offset,
int secure, const wchar_t* restrict format, ...)
@@ -1142,6 +1194,8 @@ int bwprintf(wchar_t** restrict buffer, size_t* restrict size, size_t offset,
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int vwprintf(const wchar_t* restrict format, va_list args)
{
@@ -1167,6 +1221,8 @@ int vwprintf(const wchar_t* restrict format, va_list args)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite`.
+ *
+ * @since Always.
*/
int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list args)
{
@@ -1199,6 +1255,8 @@ int vfwprintf(FILE* restrict stream, const wchar_t* restrict format, va_list arg
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `fwrite_unlocked`.
+ *
+ * @since Always.
*/
int vfwprintf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va_list args)
{
@@ -1226,6 +1284,8 @@ int vfwprintf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int vdwprintf(int fd, const wchar_t* restrict format, va_list args)
{
@@ -1255,6 +1315,8 @@ int vdwprintf(int fd, const wchar_t* restrict format, va_list args)
*
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws Any error specified for `write`.
+ *
+ * @since Always.
*/
int vsockwprintf(int fd, int flags, const wchar_t* restrict format, va_list args)
{
@@ -1283,6 +1345,8 @@ int vsockwprintf(int fd, int flags, const wchar_t* restrict format, va_list args
* actual length.
*
* @throws EINVAL `format` contained unsupported formatting codes.
+ *
+ * @since Always.
*/
int vswprintf(wchar_t* restrict buffer, size_t size, const wchar_t* restrict format, va_list args)
{
@@ -1314,6 +1378,8 @@ int vswprintf(wchar_t* restrict buffer, size_t size, const wchar_t* restrict for
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int vaswprintf(wchar_t** restrict buffer, const wchar_t* restrict format, va_list args)
{
@@ -1365,6 +1431,8 @@ int vaswprintf(wchar_t** restrict buffer, const wchar_t* restrict format, va_lis
* @throws EINVAL `format` contained unsupported formatting codes.
* @throws ENOMEM The process cannot allocation the
* sufficient amount of memory.
+ *
+ * @since Always.
*/
int vbwprintf(wchar_t** restrict buffer, size_t* restrict size, size_t offset,
int secure, const wchar_t* restrict format, va_list args)
diff --git a/src/stdio/scanf.c b/src/stdio/scanf.c
index 9a88ec4..f5147dd 100644
--- a/src/stdio/scanf.c
+++ b/src/stdio/scanf.c
@@ -27,6 +27,8 @@
# pragma GCC diagnostic ignored "-Wcast-qual"
# pragma GCC diagnostic ignored "-Wdiscarded-qualifiers"
+/* TODO [v]sock[w]scanf (can use MSG_PEEK) */
+/* TODO doc: performance issue on [v]d[w]scanf */
@@ -80,6 +82,8 @@ extern int wread_fd(void);
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int scanf(const char* restrict format, ...)
{
@@ -100,6 +104,8 @@ int scanf(const char* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int fscanf(FILE* restrict stream, const char* restrict format, ...)
{
@@ -120,6 +126,8 @@ int fscanf(FILE* restrict stream, const char* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int sscanf(const char* restrict input, const char* restrict format, ...)
{
@@ -141,6 +149,8 @@ int sscanf(const char* restrict input, const char* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int fscanf_unlocked(FILE* restrict stream, const char* restrict format, ...)
{
@@ -165,6 +175,8 @@ int fscanf_unlocked(FILE* restrict stream, const char* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int snscanf(const char* restrict input, size_t length, const char* restrict format, ...)
{
@@ -188,6 +200,8 @@ int snscanf(const char* restrict input, size_t length, const char* restrict form
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int dscanf(int fd, const char* restrict format, ...)
{
@@ -206,6 +220,8 @@ int dscanf(int fd, const char* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vscanf(const char* restrict format, va_list args)
{
@@ -225,6 +241,8 @@ int vscanf(const char* restrict format, va_list args)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vfscanf(FILE* restrict stream, const char* restrict format, va_list args)
{
@@ -249,6 +267,8 @@ int vfscanf(FILE* restrict stream, const char* restrict format, va_list args)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vsscanf(const char* restrict input, const char* restrict format, va_list args)
{
@@ -270,6 +290,8 @@ int vsscanf(const char* restrict input, const char* restrict format, va_list arg
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vfscanf_unlocked(FILE* restrict stream, const char* restrict format, va_list args)
{
@@ -292,6 +314,8 @@ int vfscanf_unlocked(FILE* restrict stream, const char* restrict format, va_list
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vsnscanf(const char* restrict input, size_t length, const char* restrict format, va_list args)
{
@@ -313,6 +337,8 @@ int vsnscanf(const char* restrict input, size_t length, const char* restrict for
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vdscanf(int fd, const char* restrict format, va_list args)
{
@@ -331,6 +357,8 @@ int vdscanf(int fd, const char* restrict format, va_list args)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int wscanf(const wchar_t* restrict format, ...)
{
@@ -350,6 +378,8 @@ int wscanf(const wchar_t* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...)
{
@@ -369,6 +399,8 @@ int fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int swscanf(const wchar_t* restrict input, const wchar_t* restrict format, ...)
{
@@ -390,6 +422,8 @@ int swscanf(const wchar_t* restrict input, const wchar_t* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int fwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, ...)
{
@@ -412,6 +446,8 @@ int fwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int snwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restrict format, ...)
{
@@ -433,6 +469,8 @@ int snwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restri
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int dwscanf(int fd, const wchar_t* restrict format, ...)
{
@@ -451,6 +489,8 @@ int dwscanf(int fd, const wchar_t* restrict format, ...)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vwscanf(const wchar_t* restrict format, va_list args)
{
@@ -470,6 +510,8 @@ int vwscanf(const wchar_t* restrict format, va_list args)
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list args)
{
@@ -494,6 +536,8 @@ int vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list args
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vswscanf(const wchar_t* restrict input, const wchar_t* restrict format, va_list args)
{
@@ -515,6 +559,8 @@ int vswscanf(const wchar_t* restrict input, const wchar_t* restrict format, va_l
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vfwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va_list args)
{
@@ -537,6 +583,8 @@ int vfwscanf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va_
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vsnwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restrict format, va_list args)
{
@@ -558,6 +606,8 @@ int vsnwscanf(const wchar_t* restrict input, size_t length, const wchar_t* restr
* if the end of the input is reached before the
* first argument is successfully converted, or
* on error.
+ *
+ * @since Always.
*/
int vdwscanf(int fd, const wchar_t* restrict format, va_list args)
{
@@ -568,6 +618,8 @@ int vdwscanf(int fd, const wchar_t* restrict format, va_list args)
/**
* This function is identical to `scanf`.
+ *
+ * @since Always.
*/
int __isoc99_scanf(const char* restrict format, ...)
{
@@ -576,6 +628,8 @@ int __isoc99_scanf(const char* restrict format, ...)
/**
* This function is identical to `fscanf`.
+ *
+ * @since Always.
*/
int __isoc99_fscanf(FILE* restrict stream, const char* restrict format, ...)
{
@@ -584,6 +638,8 @@ int __isoc99_fscanf(FILE* restrict stream, const char* restrict format, ...)
/**
* This function is identical to `sscanf`.
+ *
+ * @since Always.
*/
int __isoc99_sscanf(const char* restrict input, const char* restrict format, ...)
{
@@ -592,6 +648,8 @@ int __isoc99_sscanf(const char* restrict input, const char* restrict format, ...
/**
* This function is identical to `vscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vscanf(const char* restrict format, va_list args)
{
@@ -600,6 +658,8 @@ int __isoc99_vscanf(const char* restrict format, va_list args)
/**
* This function is identical to `vfscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vfscanf(FILE* restrict stream, const char* restrict format, va_list args)
{
@@ -608,6 +668,8 @@ int __isoc99_vfscanf(FILE* restrict stream, const char* restrict format, va_list
/**
* This function is identical to `vsscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vsscanf(const char* restrict input, const char* restrict format, va_list args)
{
@@ -616,6 +678,8 @@ int __isoc99_vsscanf(const char* restrict input, const char* restrict format, va
/**
* This function is identical to `wscanf`.
+ *
+ * @since Always.
*/
int __isoc99_wscanf(const wchar_t* restrict format, ...)
{
@@ -624,6 +688,8 @@ int __isoc99_wscanf(const wchar_t* restrict format, ...)
/**
* This function is identical to `fwscanf`.
+ *
+ * @since Always.
*/
int __isoc99_fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...)
{
@@ -632,6 +698,8 @@ int __isoc99_fwscanf(FILE* restrict stream, const wchar_t* restrict format, ...)
/**
* This function is identical to `swscanf`.
+ *
+ * @since Always.
*/
int __isoc99_swscanf(const wchar_t* restrict input, const wchar_t* restrict format, ...)
{
@@ -640,6 +708,8 @@ int __isoc99_swscanf(const wchar_t* restrict input, const wchar_t* restrict form
/**
* This function is identical to `vwscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vwscanf(const wchar_t* restrict format, va_list args)
{
@@ -648,6 +718,8 @@ int __isoc99_vwscanf(const wchar_t* restrict format, va_list args)
/**
* This function is identical to `vfwscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_list args)
{
@@ -656,6 +728,8 @@ int __isoc99_vfwscanf(FILE* restrict stream, const wchar_t* restrict format, va_
/**
* This function is identical to `vswscanf`.
+ *
+ * @since Always.
*/
int __isoc99_vswscanf(const wchar_t* restrict input, const wchar_t* restrict format, va_list args)
{