static int win_chr_pipe_init(CharDriverState *chr, const char *filename,

                             Error **errp)

{

    WinCharState *s = chr->opaque;

    OVERLAPPED ov;

    int ret;

    DWORD size;

    char openname[CHR_MAX_FILENAME_SIZE];



    s->fpipe = TRUE;



    s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hsend) {

        error_setg(errp, "Failed CreateEvent");

        goto fail;

    }

    s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hrecv) {

        error_setg(errp, "Failed CreateEvent");

        goto fail;

    }



    snprintf(openname, sizeof(openname), "\\\\.\\pipe\\%s", filename);

    s->hcom = CreateNamedPipe(openname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,

                              PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |

                              PIPE_WAIT,

                              MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);

    if (s->hcom == INVALID_HANDLE_VALUE) {

        error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());

        s->hcom = NULL;

        goto fail;

    }



    ZeroMemory(&ov, sizeof(ov));

    ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    ret = ConnectNamedPipe(s->hcom, &ov);

    if (ret) {

        error_setg(errp, "Failed ConnectNamedPipe");

        goto fail;

    }



    ret = GetOverlappedResult(s->hcom, &ov, &size, TRUE);

    if (!ret) {

        error_setg(errp, "Failed GetOverlappedResult");

        if (ov.hEvent) {

            CloseHandle(ov.hEvent);

            ov.hEvent = NULL;

        }

        goto fail;

    }



    if (ov.hEvent) {

        CloseHandle(ov.hEvent);

        ov.hEvent = NULL;

    }

    qemu_add_polling_cb(win_chr_pipe_poll, chr);

    return 0;



 fail:

    win_chr_close(chr);

    return -1;

}

static int win_chr_pipe_init(CharDriverState *chr, const char *filename,

                             Error **errp)

{

    WinCharState *s = chr->opaque;

    OVERLAPPED ov;

    int ret;

    DWORD size;

    char openname[CHR_MAX_FILENAME_SIZE];



    s->fpipe = TRUE;



    s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hsend) {

        error_setg(errp, "Failed CreateEvent");

        goto fail;

    }

    s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hrecv) {

        error_setg(errp, "Failed CreateEvent");

        goto fail;

    }



    snprintf(openname, sizeof(openname), "\\\\.\\pipe\\%s", filename);

    s->hcom = CreateNamedPipe(openname, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,

                              PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |

                              PIPE_WAIT,

                              MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);

    if (s->hcom == INVALID_HANDLE_VALUE) {

        error_setg(errp, "Failed CreateNamedPipe (%lu)", GetLastError());

        s->hcom = NULL;

        goto fail;

    }



    ZeroMemory(&ov, sizeof(ov));

    ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    ret = ConnectNamedPipe(s->hcom, &ov);

    if (ret) {

        error_setg(errp, "Failed ConnectNamedPipe");

        goto fail;

    }



    ret = GetOverlappedResult(s->hcom, &ov, &size, TRUE);

    if (!ret) {

        error_setg(errp, "Failed GetOverlappedResult");

        if (ov.hEvent) {

            CloseHandle(ov.hEvent);

            ov.hEvent = NULL;

        }

        goto fail;

    }



    if (ov.hEvent) {

        CloseHandle(ov.hEvent);

        ov.hEvent = NULL;

    }

    qemu_add_polling_cb(win_chr_pipe_poll, chr);

    return 0;



 fail:

    win_chr_close(chr);

    return -1;

}

static int FUNC_0(CharDriverState *VAR_0, const char *VAR_1,

                             Error **VAR_2)

{

    WinCharState *s = VAR_0->opaque;

    OVERLAPPED ov;

    int VAR_3;

    DWORD size;

    char VAR_4[CHR_MAX_FILENAME_SIZE];



    s->fpipe = TRUE;



    s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hsend) {

        error_setg(VAR_2, "Failed CreateEvent");

        goto fail;

    }

    s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL);

    if (!s->hrecv) {

        error_setg(VAR_2, "Failed CreateEvent");

        goto fail;

    }



    snprintf(VAR_4, sizeof(VAR_4), "\\\\.\\pipe\\%s", VAR_1);

    s->hcom = CreateNamedPipe(VAR_4, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,

                              PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |

                              PIPE_WAIT,

                              MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL);

    if (s->hcom == INVALID_HANDLE_VALUE) {

        error_setg(VAR_2, "Failed CreateNamedPipe (%lu)", GetLastError());

        s->hcom = NULL;

        goto fail;

    }



    ZeroMemory(&ov, sizeof(ov));

    ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);

    VAR_3 = ConnectNamedPipe(s->hcom, &ov);

    if (VAR_3) {

        error_setg(VAR_2, "Failed ConnectNamedPipe");

        goto fail;

    }



    VAR_3 = GetOverlappedResult(s->hcom, &ov, &size, TRUE);

    if (!VAR_3) {

        error_setg(VAR_2, "Failed GetOverlappedResult");

        if (ov.hEvent) {

            CloseHandle(ov.hEvent);

            ov.hEvent = NULL;

        }

        goto fail;

    }



    if (ov.hEvent) {

        CloseHandle(ov.hEvent);

        ov.hEvent = NULL;

    }

    qemu_add_polling_cb(win_chr_pipe_poll, VAR_0);

    return 0;



 fail:

    win_chr_close(VAR_0);

    return -1;

}

static int FUNC_0(CharDriverState *VAR_0, const char *VAR_1,
Error **VAR_2)
{ WinCharState *s = VAR_0->opaque; OVERLAPPED ov; int VAR_3; DWORD size; char VAR_4[CHR_MAX_FILENAME_SIZE]; s->fpipe = TRUE; s->hsend = CreateEvent(NULL, TRUE, FALSE, NULL); if (!s->hsend) { error_setg(VAR_2, "Failed CreateEvent"); goto fail; } s->hrecv = CreateEvent(NULL, TRUE, FALSE, NULL); if (!s->hrecv) { error_setg(VAR_2, "Failed CreateEvent"); goto fail; } snprintf(VAR_4, sizeof(VAR_4), "\\\\.\\pipe\\%s", VAR_1); s->hcom = CreateNamedPipe(VAR_4, PIPE_ACCESS_DUPLEX | FILE_FLAG_OVERLAPPED,
PIPE_TYPE_BYTE | PIPE_READMODE_BYTE |
PIPE_WAIT,
MAXCONNECT, NSENDBUF, NRECVBUF, NTIMEOUT, NULL); if (s->hcom == INVALID_HANDLE_VALUE) { error_setg(VAR_2, "Failed CreateNamedPipe (%lu)", GetLastError()); s->hcom = NULL; goto fail; } ZeroMemory(&ov, sizeof(ov)); ov.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL); VAR_3 = ConnectNamedPipe(s->hcom, &ov); if (VAR_3) { error_setg(VAR_2, "Failed ConnectNamedPipe"); goto fail; } VAR_3 = GetOverlappedResult(s->hcom, &ov, &size, TRUE); if (!VAR_3) { error_setg(VAR_2, "Failed GetOverlappedResult"); if (ov.hEvent) { CloseHandle(ov.hEvent); ov.hEvent = NULL; } goto fail; } if (ov.hEvent) { CloseHandle(ov.hEvent); ov.hEvent = NULL; } qemu_add_polling_cb(win_chr_pipe_poll, VAR_0); return 0; fail:
win_chr_close(VAR_0); return -1; }