Stub out FILE*, stdout/stdin/stderr and implement fprintf on these
authorPatrick Georgi <patrick.georgi@secunet.com>
Mon, 14 Feb 2011 19:25:27 +0000 (19:25 +0000)
committerPatrick Georgi <patrick.georgi@coresystems.de>
Mon, 14 Feb 2011 19:25:27 +0000 (19:25 +0000)
- Add FILE*
- Add stdout, stdin, stderr stubs
- Add fprintf that redirects to printf for stdout and stderr and fails otherwise

Signed-off-by: Patrick Georgi <patrick.georgi@secunet.com>
Acked-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
git-svn-id: svn://svn.coreboot.org/coreboot/trunk@6358 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1

payloads/libpayload/include/stdio.h
payloads/libpayload/libc/printf.c

index 73af2d18e60991ba3e457a56de067bd00d5cf004..fb40a0dc7e2e48c3dca55b3b2cc2f991a363d498 100644 (file)
 
 #include <stddef.h>
 
+struct _FILE {
+} _stdout, _stdin, _stderr;
+
+typedef struct _FILE FILE;
+
+FILE *stdout = &_stdout;
+FILE *stdin = &_stdin;
+FILE *stderr = &_stderr;
+
 /**
  * @defgroup printf Print functions
  * @{
@@ -39,6 +48,7 @@
 int snprintf(char *str, size_t size, const char *fmt, ...);
 int sprintf(char *str, const char *fmt, ...);
 int printf(const char *fmt, ...);
+int fprintf(FILE *file, const char *fmt, ...);
 /** @} */
 
 void perror(const char *s);
@@ -47,5 +57,4 @@ void perror(const char *s);
 #define SEEK_CUR 1 /**< The seek offset is against the current position. */
 #define SEEK_END 2 /**< The seek offset is against the end of the file. */
 
-
 #endif
index 04d39319bc6d8608bc0fca4da7b2de8493fdeddb..a1ebb140923224102a9c16d363fbfdda66e112d9 100644 (file)
@@ -723,6 +723,20 @@ int sprintf(char *str, const char *fmt, ...)
        return ret;
 }
 
+int fprintf(FILE *file, const char *fmt, ...)
+{
+       int ret;
+       if ((file == stdout) || (file == stderr)) {
+               va_list args;
+               va_start(args, fmt);
+               ret = vprintf(fmt, args);
+               va_end(args);
+
+               return ret;
+       }
+       return -1;
+}
+
 struct vsnprintf_data {
        size_t size;            /* Total space for string */
        size_t len;             /* Count of currently used characters */