summaryrefslogtreecommitdiff
path: root/libgcompat/stdio.c
diff options
context:
space:
mode:
authorWilliam Pitcock <nenolod@dereferenced.org>2017-06-14 13:09:23 -0500
committerWilliam Pitcock <nenolod@dereferenced.org>2017-06-14 13:09:23 -0500
commitf67416822a54109bd9cfa0fd210d7d8f53412ced (patch)
tree7d3d14933f39ca160d706d1bec25ce541a188962 /libgcompat/stdio.c
parent2b58008b911d9dc8354b9001e22b594fa6456dd1 (diff)
downloadgcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.gz
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.bz2
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.tar.xz
gcompat-f67416822a54109bd9cfa0fd210d7d8f53412ced.zip
move all compatibility library stuff into libgcompat/
Diffstat (limited to 'libgcompat/stdio.c')
-rw-r--r--libgcompat/stdio.c130
1 files changed, 130 insertions, 0 deletions
diff --git a/libgcompat/stdio.c b/libgcompat/stdio.c
new file mode 100644
index 0000000..89bd677
--- /dev/null
+++ b/libgcompat/stdio.c
@@ -0,0 +1,130 @@
+#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 __sprintf_chk(char *str, int flag, size_t strlen, const char *format, ...)
+{
+ va_list argp;
+ int result;
+
+ assert(strlen > 0);
+
+ va_start(argp, format);
+ result = vsnprintf(str, strlen, 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(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(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, int flag, const char *fmt, va_list ap)
+{
+ if(flag > 0)
+ {
+ 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(format != NULL);
+ }
+ // must always be done per LFS
+ assert(size <= strlen);
+ return vsnprintf(str, size, format, ap);
+}
+