On 11.02.2011, at 01:57, Patrick Georgi Patrick.Georgi@secunet.com wrote:
- 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
payloads/libpayload/include/stdio.h | 11 ++++++++++- payloads/libpayload/libc/printf.c | 14 ++++++++++++++ 2 files changed, 24 insertions(+), 1 deletions(-)
diff --git a/payloads/libpayload/include/stdio.h b/payloads/libpayload/include/stdio.h index 73af2d1..fb40a0d 100644 --- a/payloads/libpayload/include/stdio.h +++ b/payloads/libpayload/include/stdio.h @@ -32,6 +32,15 @@
#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 diff --git a/payloads/libpayload/libc/printf.c b/payloads/libpayload/libc/printf.c index 04d3931..a1ebb14 100644 --- a/payloads/libpayload/libc/printf.c +++ b/payloads/libpayload/libc/printf.c @@ -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 */ -- 1.7.1
-- coreboot mailing list: coreboot@coreboot.org http://www.coreboot.org/mailman/listinfo/coreboot