diff options
author | Mattias Andrée <maandree@operamail.com> | 2015-11-23 21:31:28 +0100 |
---|---|---|
committer | Mattias Andrée <maandree@operamail.com> | 2015-11-23 21:31:28 +0100 |
commit | a6ccf32e773d805c7e240e843b683ea1385a4172 (patch) | |
tree | 934353f12f780888f86bbbd7665f78721d6e893b | |
parent | typo (diff) | |
download | slibc-a6ccf32e773d805c7e240e843b683ea1385a4172.tar.gz slibc-a6ccf32e773d805c7e240e843b683ea1385a4172.tar.bz2 slibc-a6ccf32e773d805c7e240e843b683ea1385a4172.tar.xz |
add sockprintf, vsockprintf, sockwprintf, and vsockwprintf
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r-- | include/stdio.h | 113 | ||||
-rw-r--r-- | src/stdio/printf.c | 163 |
2 files changed, 272 insertions, 4 deletions
diff --git a/include/stdio.h b/include/stdio.h index c092440..0f78e6e 100644 --- a/include/stdio.h +++ b/include/stdio.h @@ -138,6 +138,35 @@ int fprintf_unlocked(FILE* restrict, const char* restrict, ...) int dprintf(int, const char* restrict, ...) __GCC_ONLY(__attribute__((__nonnull__(2), __format__(__slibc_printf__, 2, 3)))); +#if defined(__SLIBC_SOURCE) +/** + * This function is identical to `dprintf`, + * except it uses `send` instead of `write` + * and supports transmissions flags. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param ... The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int sockprintf(int, int, const char* restrict, ...) + __GCC_ONLY(__attribute__((__nonnull__(3), __format__(__slibc_printf__, 3, 4)))); +#endif + /** * This function is identical to `fprintf`, * it prints to a buffer rather than a stream. @@ -380,7 +409,7 @@ int vfprintf_unlocked(FILE* restrict, const char* restrict, va_list) #endif /** - * This function is identical to `vdprintf`, + * This function is identical to `dprintf`, * except it uses `va_list` instead of variadic argument. * * @param fd The file descriptor. @@ -401,6 +430,34 @@ int vfprintf_unlocked(FILE* restrict, const char* restrict, va_list) int vdprintf(int, const char* restrict, va_list) __GCC_ONLY(__attribute__((__nonnull__(2)))); +#if defined(__SLIBC_SOURCE) +/** + * This function is identical to `sockprintf`, + * except it uses `va_list` instead of variadic argument. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param args The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int vsockprintf(int, int, const char* restrict, va_list) + __GCC_ONLY(__attribute__((__nonnull__(3), __format__(__slibc_printf__, 3, 4)))); +#endif + /** * This function is identical to `sprintf`, * except it uses `va_list` instead of variadic argument. @@ -619,6 +676,32 @@ int fwprintf_unlocked(FILE* restrict, const wchar_t* restrict, ...) */ int dwprintf(int, const wchar_t* restrict, ...) __GCC_ONLY(__attribute__((__nonnull__(2)))); + +/** + * This function is identical to `sockprintf` + * except it uses wide characters. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param ... The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int sockwprintf(int, int, const wchar_t* restrict, ...) + __GCC_ONLY(__attribute__((__nonnull__(3)))); # endif /** @@ -839,7 +922,7 @@ int vfwprintf_unlocked(FILE* restrict, const wchar_t* restrict, va_list) __GCC_ONLY(__attribute__((__nonnull__(1, 2)))); /** - * This function is identical to `vdprintf`, + * This function is identical to `dwprintf`, * except it uses `va_list` instead of variadic argument. * * This is a slibc extension added for completeness. @@ -861,6 +944,32 @@ int vfwprintf_unlocked(FILE* restrict, const wchar_t* restrict, va_list) */ int vdwprintf(int, const wchar_t* restrict, va_list) __GCC_ONLY(__attribute__((__nonnull__(2)))); + +/** + * This function is identical to `sockwprintf` + * except it uses `va_list` instead of variadic argument. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param args The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int vsockwprintf(int, int, const wchar_t* restrict, va_list) + __GCC_ONLY(__attribute__((__nonnull__(3)))); # endif /** diff --git a/src/stdio/printf.c b/src/stdio/printf.c index c88fc99..e927ab7 100644 --- a/src/stdio/printf.c +++ b/src/stdio/printf.c @@ -184,6 +184,46 @@ static int wwrite_fd(const wchar_t* text, size_t length, int* fdp) /** + * Write a string segment to a file. + * + * @param text The text to write, not NUL terminated. + * @param length The length of `text`. + * @param input Element 0: pointer to the file descriptor of the file. + * Element 1: flags for `send`. + * @return Zero on success, -1 on error. + * + * @throws Any error specified for `write`. + */ +static int send_fd(const char* text, size_t length, int* input) +{ + int fd = input[0], flags = input[1]; + /* TODO send_fd */ + return 0; + (void) text, (void) length, (void) fd, (void) flags; +} + + +/** + * Write a string segment to a file. + * + * @param text The text to write, not NUL terminated. + * @param length The length of `text`. + * @param input Element 0: pointer to the file descriptor of the file. + * Element 1: flags for `send`. + * @return Zero on success, -1 on error. + * + * @throws Any error specified for `write`. + */ +static int wsend_fd(const wchar_t* text, size_t length, int* input) +{ + int fd = input[0], flags = input[1]; + /* TODO wsend_fd */ + return 0; + (void) text, (void) length, (void) fd, (void) flags; +} + + +/** * Write a string segment to a stream. * * @param text The text to write, not NUL terminated. @@ -409,6 +449,36 @@ int dprintf(int fd, const char* restrict format, ...) /** + * This function is identical to `dprintf`, + * except it uses `send` instead of `write` + * and supports transmissions flags. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param ... The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int sockprintf(int fd, int flags, const char* format restrict, ...) +{ + V(sockprintf(fd, flags, format, args)); +} + + +/** * This function is identical to `fprintf`, * it prints to a buffer rather than a stream. * @@ -622,7 +692,7 @@ int vfprintf_unlocked(FILE* restrict stream, const char* restrict format, va_lis /** - * This function is identical to `vdprintf`, + * This function is identical to `dprintf`, * except it uses `va_list` instead of variadic argument. * * @param fd The file descriptor. @@ -647,6 +717,36 @@ int vdprintf(int fd, const char* restrict format, va_list args) /** + * This function is identical to `sockprintf`, + * except it uses `va_list` instead of variadic argument. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param args The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int vsockprintf(int fd, int flags, const char* restrict format, va_list args) +{ + int input[] = {fd, flags}; + P_CHAR(send_fd, 0, 0, 0, input); +} + + +/** * This function is identical to `sprintf`, * except it uses `va_list` instead of variadic argument. * @@ -891,6 +991,35 @@ int dwprintf(int fd, const wchar_t* restrict format, ...) /** + * This function is identical to `sockprintf` + * except it uses wide characters. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param ... The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int sockwprintf(int fd, int flags, const wchar_t* restrict format, ...) +{ + V(sockwprintf(fd, flags, format, args)); +} + + +/** * This function is identical to `snprintf` * (not `sprintf`) except it uses wide characters. * @@ -1078,7 +1207,7 @@ int vfwprintf_unlocked(FILE* restrict stream, const wchar_t* restrict format, va /** - * This function is identical to `vdprintf`, + * This function is identical to `dwprintf`, * except it uses `va_list` instead of variadic argument. * * This is a slibc extension added for completeness. @@ -1105,6 +1234,36 @@ int vdwprintf(int fd, const wchar_t* restrict format, va_list args) /** + * This function is identical to `sockwprintf` + * except it uses `va_list` instead of variadic argument. + * + * This is a slibc extension added for completeness. + * + * @param fd The file descriptor. + * @parma flags Flags to pass to `send`, see `send` + * for more information. + * @param format The formatting-string. + * @param args The formatting-arguments. + * @return The number of written bytes. + * On error, a negative value (namely -1 + * in this implementation) is returned. + * It is unspecified what shall happen if + * more than `INT_MAX` bytes are written; + * in slibc, `INT_MAX` is returned if more + * is written, you can use "%zn" to find + * the actual length. + * + * @throws EINVAL `format` contained unsupported formatting codes. + * @throws Any error specified for `write`. + */ +int vsockwprintf(int fd, int flags, const wchar_t* restrict format, va_list args) +{ + int input[] = {fd, flags}; + P_WCHAR(wsend_fd, 0, 0, 0, input); +} + + +/** * This function is identical to `swprintf`, * except it uses `va_list` instead of variadic argument. * |