static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)

{

    int i, count, err;

    struct pollfd *pfds;



    count = snd_pcm_poll_descriptors_count (handle);

    if (count <= 0) {

        dolog ("Could not initialize poll mode\n"

               "Invalid number of poll descriptors %d\n", count);

        return -1;

    }



    pfds = audio_calloc ("alsa_poll_helper", count, sizeof (*pfds));

    if (!pfds) {

        dolog ("Could not initialize poll mode\n");

        return -1;

    }



    err = snd_pcm_poll_descriptors (handle, pfds, count);

    if (err < 0) {

        alsa_logerr (err, "Could not initialize poll mode\n"

                     "Could not obtain poll descriptors\n");

        g_free (pfds);

        return -1;

    }



    for (i = 0; i < count; ++i) {

        if (pfds[i].events & POLLIN) {

            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,

                                       NULL, hlp);

        }

        if (pfds[i].events & POLLOUT) {

            if (conf.verbose) {

                dolog ("POLLOUT %d %d\n", i, pfds[i].fd);

            }

            err = qemu_set_fd_handler (pfds[i].fd, NULL,

                                       alsa_poll_handler, hlp);

        }

        if (conf.verbose) {

            dolog ("Set handler events=%#x index=%d fd=%d err=%d\n",

                   pfds[i].events, i, pfds[i].fd, err);

        }



        if (err) {

            dolog ("Failed to set handler events=%#x index=%d fd=%d err=%d\n",

                   pfds[i].events, i, pfds[i].fd, err);



            while (i--) {

                qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);

            }

            g_free (pfds);

            return -1;

        }

    }

    hlp->pfds = pfds;

    hlp->count = count;

    hlp->handle = handle;

    hlp->mask = mask;

    return 0;

}

static int alsa_poll_helper (snd_pcm_t *handle, struct pollhlp *hlp, int mask)

{

    int i, count, err;

    struct pollfd *pfds;



    count = snd_pcm_poll_descriptors_count (handle);

    if (count <= 0) {

        dolog ("Could not initialize poll mode\n"

               "Invalid number of poll descriptors %d\n", count);

        return -1;

    }



    pfds = audio_calloc ("alsa_poll_helper", count, sizeof (*pfds));

    if (!pfds) {

        dolog ("Could not initialize poll mode\n");

        return -1;

    }



    err = snd_pcm_poll_descriptors (handle, pfds, count);

    if (err < 0) {

        alsa_logerr (err, "Could not initialize poll mode\n"

                     "Could not obtain poll descriptors\n");

        g_free (pfds);

        return -1;

    }



    for (i = 0; i < count; ++i) {

        if (pfds[i].events & POLLIN) {

            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,

                                       NULL, hlp);

        }

        if (pfds[i].events & POLLOUT) {

            if (conf.verbose) {

                dolog ("POLLOUT %d %d\n", i, pfds[i].fd);

            }

            err = qemu_set_fd_handler (pfds[i].fd, NULL,

                                       alsa_poll_handler, hlp);

        }

        if (conf.verbose) {

            dolog ("Set handler events=%#x index=%d fd=%d err=%d\n",

                   pfds[i].events, i, pfds[i].fd, err);

        }



        if (err) {

            dolog ("Failed to set handler events=%#x index=%d fd=%d err=%d\n",

                   pfds[i].events, i, pfds[i].fd, err);



            while (i--) {

                qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);

            }

            g_free (pfds);

            return -1;

        }

    }

    hlp->pfds = pfds;

    hlp->count = count;

    hlp->handle = handle;

    hlp->mask = mask;

    return 0;

}

            err = qemu_set_fd_handler (pfds[i].fd, alsa_poll_handler,                                        NULL, hlp);             err = qemu_set_fd_handler (pfds[i].fd, NULL,                                        alsa_poll_handler, hlp);         if (err) {             dolog ("Failed to set handler events=%#x index=%d fd=%d err=%d\n",                    pfds[i].events, i, pfds[i].fd, err);             while (i--) {                 qemu_set_fd_handler (pfds[i].fd, NULL, NULL, NULL);             g_free (pfds);             return -1;
static int FUNC_0 (snd_pcm_t *VAR_0, struct pollhlp *VAR_1, int VAR_2)

{

    int VAR_3, VAR_4, VAR_5;

    struct pollfd *VAR_6;



    VAR_4 = snd_pcm_poll_descriptors_count (VAR_0);

    if (VAR_4 <= 0) {

        dolog ("Could not initialize poll mode\n"

               "Invalid number of poll descriptors %d\n", VAR_4);

        return -1;

    }



    VAR_6 = audio_calloc ("FUNC_0", VAR_4, sizeof (*VAR_6));

    if (!VAR_6) {

        dolog ("Could not initialize poll mode\n");

        return -1;

    }



    VAR_5 = snd_pcm_poll_descriptors (VAR_0, VAR_6, VAR_4);

    if (VAR_5 < 0) {

        alsa_logerr (VAR_5, "Could not initialize poll mode\n"

                     "Could not obtain poll descriptors\n");

        g_free (VAR_6);

        return -1;

    }



    for (VAR_3 = 0; VAR_3 < VAR_4; ++VAR_3) {

        if (VAR_6[VAR_3].events & POLLIN) {

            VAR_5 = qemu_set_fd_handler (VAR_6[VAR_3].fd, alsa_poll_handler,

                                       NULL, VAR_1);

        }

        if (VAR_6[VAR_3].events & POLLOUT) {

            if (conf.verbose) {

                dolog ("POLLOUT %d %d\n", VAR_3, VAR_6[VAR_3].fd);

            }

            VAR_5 = qemu_set_fd_handler (VAR_6[VAR_3].fd, NULL,

                                       alsa_poll_handler, VAR_1);

        }

        if (conf.verbose) {

            dolog ("Set handler events=%#x index=%d fd=%d VAR_5=%d\n",

                   VAR_6[VAR_3].events, VAR_3, VAR_6[VAR_3].fd, VAR_5);

        }



        if (VAR_5) {

            dolog ("Failed to set handler events=%#x index=%d fd=%d VAR_5=%d\n",

                   VAR_6[VAR_3].events, VAR_3, VAR_6[VAR_3].fd, VAR_5);



            while (VAR_3--) {

                qemu_set_fd_handler (VAR_6[VAR_3].fd, NULL, NULL, NULL);

            }

            g_free (VAR_6);

            return -1;

        }

    }

    VAR_1->VAR_6 = VAR_6;

    VAR_1->VAR_4 = VAR_4;

    VAR_1->VAR_0 = VAR_0;

    VAR_1->VAR_2 = VAR_2;

    return 0;

}

static int FUNC_0 (snd_pcm_t *VAR_0, struct pollhlp *VAR_1, int VAR_2)
{ int VAR_3, VAR_4, VAR_5; struct pollfd *VAR_6; VAR_4 = snd_pcm_poll_descriptors_count (VAR_0); if (VAR_4 <= 0) { dolog ("Could not initialize poll mode\n"
"Invalid number of poll descriptors %d\n", VAR_4); return -1; } VAR_6 = audio_calloc ("FUNC_0", VAR_4, sizeof (*VAR_6)); if (!VAR_6) { dolog ("Could not initialize poll mode\n"); return -1; } VAR_5 = snd_pcm_poll_descriptors (VAR_0, VAR_6, VAR_4); if (VAR_5 < 0) { alsa_logerr (VAR_5, "Could not initialize poll mode\n"
"Could not obtain poll descriptors\n"); g_free (VAR_6); return -1; } for (VAR_3 = 0; VAR_3 < VAR_4; ++VAR_3) { if (VAR_6[VAR_3].events & POLLIN) { VAR_5 = qemu_set_fd_handler (VAR_6[VAR_3].fd, alsa_poll_handler,
NULL, VAR_1); } if (VAR_6[VAR_3].events & POLLOUT) { if (conf.verbose) { dolog ("POLLOUT %d %d\n", VAR_3, VAR_6[VAR_3].fd); } VAR_5 = qemu_set_fd_handler (VAR_6[VAR_3].fd, NULL,
alsa_poll_handler, VAR_1); } if (conf.verbose) { dolog ("Set handler events=%#x index=%d fd=%d VAR_5=%d\n",
VAR_6[VAR_3].events, VAR_3, VAR_6[VAR_3].fd, VAR_5); } if (VAR_5) { dolog ("Failed to set handler events=%#x index=%d fd=%d VAR_5=%d\n",
VAR_6[VAR_3].events, VAR_3, VAR_6[VAR_3].fd, VAR_5); while (VAR_3--) { qemu_set_fd_handler (VAR_6[VAR_3].fd, NULL, NULL, NULL); } g_free (VAR_6); return -1; } } VAR_1->VAR_6 = VAR_6; VAR_1->VAR_4 = VAR_4; VAR_1->VAR_0 = VAR_0; VAR_1->VAR_2 = VAR_2; return 0; }