int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len)

{

    int offset = 0, counter = 10;

    int res;



    if (!s->chr_sync_read) {

        return 0;

    }

    

    if (s->replay && replay_mode == REPLAY_MODE_PLAY) {

        return replay_char_read_all_load(buf);

    }



    while (offset < len) {

        do {

            res = s->chr_sync_read(s, buf + offset, len - offset);

            if (res == -1 && errno == EAGAIN) {

                g_usleep(100);

            }

        } while (res == -1 && errno == EAGAIN);



        if (res == 0) {

            break;

        }



        if (res < 0) {

            if (s->replay && replay_mode == REPLAY_MODE_RECORD) {

                replay_char_read_all_save_error(res);

            }

            return res;

        }



        offset += res;



        if (!counter--) {

            break;

        }

    }



    if (s->replay && replay_mode == REPLAY_MODE_RECORD) {

        replay_char_read_all_save_buf(buf, offset);

    }

    return offset;

}

int qemu_chr_fe_read_all(CharDriverState *s, uint8_t *buf, int len)

{

    int offset = 0, counter = 10;

    int res;



    if (!s->chr_sync_read) {

        return 0;

    }

    

    if (s->replay && replay_mode == REPLAY_MODE_PLAY) {

        return replay_char_read_all_load(buf);

    }



    while (offset < len) {

        do {

            res = s->chr_sync_read(s, buf + offset, len - offset);

            if (res == -1 && errno == EAGAIN) {

                g_usleep(100);

            }

        } while (res == -1 && errno == EAGAIN);



        if (res == 0) {

            break;

        }



        if (res < 0) {

            if (s->replay && replay_mode == REPLAY_MODE_RECORD) {

                replay_char_read_all_save_error(res);

            }

            return res;

        }



        offset += res;



        if (!counter--) {

            break;

        }

    }



    if (s->replay && replay_mode == REPLAY_MODE_RECORD) {

        replay_char_read_all_save_buf(buf, offset);

    }

    return offset;

}

        do {                 g_usleep(100);         do {             if (res == -1 && errno == EAGAIN) {                 g_usleep(100);         } while (res == -1 && errno == EAGAIN);         do {             res = s->chr_sync_read(s, buf + offset, len - offset);             if (res == -1 && errno == EAGAIN) {                 g_usleep(100);         } while (res == -1 && errno == EAGAIN);
int FUNC_0(CharDriverState *VAR_0, uint8_t *VAR_1, int VAR_2)

{

    int VAR_3 = 0, VAR_4 = 10;

    int VAR_5;



    if (!VAR_0->chr_sync_read) {

        return 0;

    }

    

    if (VAR_0->replay && replay_mode == REPLAY_MODE_PLAY) {

        return replay_char_read_all_load(VAR_1);

    }



    while (VAR_3 < VAR_2) {

        do {

            VAR_5 = VAR_0->chr_sync_read(VAR_0, VAR_1 + VAR_3, VAR_2 - VAR_3);

            if (VAR_5 == -1 && errno == EAGAIN) {

                g_usleep(100);

            }

        } while (VAR_5 == -1 && errno == EAGAIN);



        if (VAR_5 == 0) {

            break;

        }



        if (VAR_5 < 0) {

            if (VAR_0->replay && replay_mode == REPLAY_MODE_RECORD) {

                replay_char_read_all_save_error(VAR_5);

            }

            return VAR_5;

        }



        VAR_3 += VAR_5;



        if (!VAR_4--) {

            break;

        }

    }



    if (VAR_0->replay && replay_mode == REPLAY_MODE_RECORD) {

        replay_char_read_all_save_buf(VAR_1, VAR_3);

    }

    return VAR_3;

}

int FUNC_0(CharDriverState *VAR_0, uint8_t *VAR_1, int VAR_2)
{ int VAR_3 = 0, VAR_4 = 10; int VAR_5; if (!VAR_0->chr_sync_read) { return 0; } if (VAR_0->replay && replay_mode == REPLAY_MODE_PLAY) { return replay_char_read_all_load(VAR_1); } while (VAR_3 < VAR_2) { do { VAR_5 = VAR_0->chr_sync_read(VAR_0, VAR_1 + VAR_3, VAR_2 - VAR_3); if (VAR_5 == -1 && errno == EAGAIN) { g_usleep(100); } } while (VAR_5 == -1 && errno == EAGAIN); if (VAR_5 == 0) { break; } if (VAR_5 < 0) { if (VAR_0->replay && replay_mode == REPLAY_MODE_RECORD) { replay_char_read_all_save_error(VAR_5); } return VAR_5; } VAR_3 += VAR_5; if (!VAR_4--) { break; } } if (VAR_0->replay && replay_mode == REPLAY_MODE_RECORD) { replay_char_read_all_save_buf(VAR_1, VAR_3); } return VAR_3; }