mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
Add support for fprintf(stderr, ...).
This commit is contained in:
parent
f5cc6fb72d
commit
10f719a830
1 changed files with 20 additions and 1 deletions
|
@ -3,6 +3,8 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
|
FILE *stdin, *stdout, *stderr;
|
||||||
|
|
||||||
static console_write_hook write_hook;
|
static console_write_hook write_hook;
|
||||||
static console_read_hook read_hook;
|
static console_read_hook read_hook;
|
||||||
static console_read_nonblock_hook read_nonblock_hook;
|
static console_read_nonblock_hook read_nonblock_hook;
|
||||||
|
@ -60,11 +62,28 @@ void putsnonl(const char *s)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define PRINTF_BUFFER_SIZE 256
|
||||||
|
|
||||||
int printf(const char *fmt, ...)
|
int printf(const char *fmt, ...)
|
||||||
{
|
{
|
||||||
va_list args;
|
va_list args;
|
||||||
int len;
|
int len;
|
||||||
char outbuf[256];
|
char outbuf[PRINTF_BUFFER_SIZE];
|
||||||
|
|
||||||
|
va_start(args, fmt);
|
||||||
|
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
|
||||||
|
va_end(args);
|
||||||
|
outbuf[len] = 0;
|
||||||
|
putsnonl(outbuf);
|
||||||
|
|
||||||
|
return len;
|
||||||
|
}
|
||||||
|
|
||||||
|
int fprintf(FILE *stream, const char *fmt, ...)
|
||||||
|
{
|
||||||
|
va_list args;
|
||||||
|
int len;
|
||||||
|
char outbuf[PRINTF_BUFFER_SIZE];
|
||||||
|
|
||||||
va_start(args, fmt);
|
va_start(args, fmt);
|
||||||
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
|
len = vscnprintf(outbuf, sizeof(outbuf), fmt, args);
|
||||||
|
|
Loading…
Reference in a new issue