On 01/10/2011 08:40, Blue Swirl wrote: > On Wed, Sep 28, 2011 at 4:28 PM, Fabien Chouteau <chout...@adacore.com> wrote: >> Simple implementation of an stdio char device on Windows. >> >> Signed-off-by: Fabien Chouteau <chout...@adacore.com> >> --- >> qemu-char.c | 216 >> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- >> 1 files changed, 214 insertions(+), 2 deletions(-) >> >> diff --git a/qemu-char.c b/qemu-char.c >> index 09d2309..0ec449b 100644 >> --- a/qemu-char.c >> +++ b/qemu-char.c >> @@ -538,6 +538,9 @@ int send_all(int fd, const void *_buf, int len1) >> } >> #endif /* !_WIN32 */ >> >> +#define STDIO_MAX_CLIENTS 1 >> +static int stdio_nb_clients; >> + >> #ifndef _WIN32 >> >> typedef struct { >> @@ -545,8 +548,6 @@ typedef struct { >> int max_size; >> } FDCharDriver; >> >> -#define STDIO_MAX_CLIENTS 1 >> -static int stdio_nb_clients = 0; >> >> static int fd_chr_write(CharDriverState *chr, const uint8_t *buf, int len) >> { >> @@ -1451,6 +1452,8 @@ static int qemu_chr_open_pp(QemuOpts *opts, >> CharDriverState **_chr) >> >> #else /* _WIN32 */ >> >> +static CharDriverState *stdio_clients[STDIO_MAX_CLIENTS]; >> + >> typedef struct { >> int max_size; >> HANDLE hcom, hrecv, hsend; >> @@ -1809,6 +1812,214 @@ static int qemu_chr_open_win_file_out(QemuOpts >> *opts, CharDriverState **_chr) >> >> return qemu_chr_open_win_file(fd_out, _chr); >> } >> + >> +static int win_stdio_write(CharDriverState *chr, const uint8_t *buf, int >> len) >> +{ >> + HANDLE *hStdOut = GetStdHandle(STD_OUTPUT_HANDLE); >> + DWORD dwSize; >> + int len1; >> + >> + len1 = len; >> + >> + while (len1 > 0) { >> + if (!WriteFile(hStdOut, buf, len1, &dwSize, NULL)) { >> + break; >> + } >> + buf += dwSize; >> + len1 -= dwSize; >> + } >> + >> + return len - len1; >> +} >> + >> +static HANDLE *hStdIn; > > I think you could avoid these variables by introducing a structure > that is passed as opaque in place of CharDriverState below. >
Alright, you're not the first one to ask for this, so I'll do it :) Thanks for the review, -- Fabien Chouteau