summaryrefslogtreecommitdiff
path: root/stdio.c
diff options
context:
space:
mode:
authorA. Wilcox <AWilcox@Wilcox-Tech.com>2016-10-04 05:25:26 -0500
committerA. Wilcox <AWilcox@Wilcox-Tech.com>2016-10-04 05:25:26 -0500
commit6b43a6a6c1f238b5ddea05964e19de86fe2fcda1 (patch)
tree0539ab871f01518a0eb26fad9ebe823025bdeaee /stdio.c
parent7515ce3fa8b30f7b7d67bc2a659e15276c0923d7 (diff)
downloadgcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.gz
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.bz2
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.tar.xz
gcompat-6b43a6a6c1f238b5ddea05964e19de86fe2fcda1.zip
Add some _chk interfaces
Diffstat (limited to 'stdio.c')
-rw-r--r--stdio.c115
1 files changed, 114 insertions, 1 deletions
diff --git a/stdio.c b/stdio.c
index f26b69b..bef7ef8 100644
--- a/stdio.c
+++ b/stdio.c
@@ -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");