diff options
Diffstat (limited to 'stdio.c')
-rw-r--r-- | stdio.c | 115 |
1 files changed, 114 insertions, 1 deletions
@@ -1,3 +1,116 @@ +#include <assert.h> +#include <stdarg.h> #include <stdio.h> +#include <wchar.h> + +size_t __fread_chk(void *ptr, size_t size, size_t nmemb, FILE *stream) +{ + assert(ptr != NULL); + assert(stream != NULL); + return fread(ptr, size, nmemb, stream); +} + +int __printf_chk(int flag, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(format != NULL); + } + + va_start(argp, format); + result = vprintf(format, argp); + va_end(argp); + + return result; +} + +int __fprintf_chk(FILE *stream, int flag, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(stream != NULL); + assert(format != NULL); + } + + va_start(argp, format); + result = vfprintf(stream, format, argp); + va_end(argp); + + return result; +} + +int __snprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(str != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(size <= strlen); + + va_start(argp, format); + result = vsnprintf(str, size, format, argp); + va_end(argp); + + return result; +} + +int __swprintf_chk(wchar_t *wcs, size_t maxlen, int flag, size_t wcslen, const wchar_t *format, ...) +{ + va_list argp; + int result; + + if(flag > 0) + { + assert(wcs != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(maxlen <= wcslen); + + va_start(argp, format); + result = vswprintf(wcs, maxlen, format, argp); + va_end(argp); + + return result; +} + +int __vasprintf_chk(char **strp, const char *fmt, va_list ap) +{ + assert(strp != NULL); + assert(fmt != NULL); + return vasprintf(strp, fmt, ap); +} + +int __vfprintf_chk(FILE *stream, int flag, const char *format, va_list ap) +{ + if(flag > 0) + { + assert(stream != NULL); + assert(format != NULL); + } + return vfprintf(stream, format, ap); +} + +int __vsnprintf_chk(char *str, size_t size, int flag, size_t strlen, const char *format, va_list ap) +{ + if(flag > 0) + { + assert(str != NULL); + assert(format != NULL); + } + // must always be done per LFS + assert(size <= strlen); + return vsnprintf(str, size, format, ap); +} -asm(".equ __IO_2_1_stdout_, _stdout"); |