struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
                                          int64_t count, Error **errp)
{
    GuestFileHandle *gfh = guest_file_handle_find(handle, errp);
    GuestFileRead *read_data = NULL;
    guchar *buf;
    FILE *fh;
    size_t read_count;
    if (!gfh) {
    if (!has_count) {
        count = QGA_READ_COUNT_DEFAULT;
    } else if (count < 0) {
        error_setg(errp, "value '%" PRId64 "' is invalid for argument count",
                   count);
    fh = gfh->fh;
    buf = g_malloc0(count+1);
    read_count = fread(buf, 1, count, fh);
    if (ferror(fh)) {
        error_setg_errno(errp, errno, "failed to read file");
        slog("guest-file-read failed, handle: %" PRId64, handle);
    } else {
        buf[read_count] = 0;
        read_data = g_new0(GuestFileRead, 1);
        read_data->count = read_count;
        read_data->eof = feof(fh);
        if (read_count) {
            read_data->buf_b64 = g_base64_encode(buf, read_count);
        gfh->state = RW_STATE_READING;
    g_free(buf);
    clearerr(fh);
    return read_data;
struct GuestFileRead *qmp_guest_file_read(int64_t handle, bool has_count,
                                          int64_t count, Error **errp)
{
    GuestFileHandle *gfh = guest_file_handle_find(handle, errp);
    GuestFileRead *read_data = NULL;
    guchar *buf;
    FILE *fh;
    size_t read_count;
    if (!gfh) {
    if (!has_count) {
        count = QGA_READ_COUNT_DEFAULT;
    } else if (count < 0) {
        error_setg(errp, "value '%" PRId64 "' is invalid for argument count",
                   count);
    fh = gfh->fh;
    buf = g_malloc0(count+1);
    read_count = fread(buf, 1, count, fh);
    if (ferror(fh)) {
        error_setg_errno(errp, errno, "failed to read file");
        slog("guest-file-read failed, handle: %" PRId64, handle);
    } else {
        buf[read_count] = 0;
        read_data = g_new0(GuestFileRead, 1);
        read_data->count = read_count;
        read_data->eof = feof(fh);
        if (read_count) {
            read_data->buf_b64 = g_base64_encode(buf, read_count);
        gfh->state = RW_STATE_READING;
    g_free(buf);
    clearerr(fh);
    return read_data;
struct GuestFileRead *FUNC_0(int64_t VAR_0, bool VAR_1,
                                          int64_t VAR_2, Error **VAR_3)
{
    GuestFileHandle *gfh = guest_file_handle_find(VAR_0, VAR_3);
    GuestFileRead *VAR_4 = NULL;
    guchar *buf;
    FILE *fh;
    size_t read_count;
    if (!gfh) {
    if (!VAR_1) {
        VAR_2 = QGA_READ_COUNT_DEFAULT;
    } else if (VAR_2 < 0) {
        error_setg(VAR_3, "value '%" PRId64 "' is invalid for argument VAR_2",
                   VAR_2);
    fh = gfh->fh;
    buf = g_malloc0(VAR_2+1);
    read_count = fread(buf, 1, VAR_2, fh);
    if (ferror(fh)) {
        error_setg_errno(VAR_3, errno, "failed to read file");
        slog("guest-file-read failed, VAR_0: %" PRId64, VAR_0);
    } else {
        buf[read_count] = 0;
        VAR_4 = g_new0(GuestFileRead, 1);
        VAR_4->VAR_2 = read_count;
        VAR_4->eof = feof(fh);
        if (read_count) {
            VAR_4->buf_b64 = g_base64_encode(buf, read_count);
        gfh->state = RW_STATE_READING;
    g_free(buf);
    clearerr(fh);
    return VAR_4;
struct GuestFileRead *FUNC_0(int64_t VAR_0, bool VAR_1,
int64_t VAR_2, Error **VAR_3)
{ GuestFileHandle *gfh = guest_file_handle_find(VAR_0, VAR_3); GuestFileRead *VAR_4 = NULL; guchar *buf; FILE *fh; size_t read_count; if (!gfh) { if (!VAR_1) { VAR_2 = QGA_READ_COUNT_DEFAULT; } else if (VAR_2 < 0) { error_setg(VAR_3, "value '%" PRId64 "' is invalid for argument VAR_2",
VAR_2); fh = gfh->fh; buf = g_malloc0(VAR_2+1); read_count = fread(buf, 1, VAR_2, fh); if (ferror(fh)) { error_setg_errno(VAR_3, errno, "failed to read file"); slog("guest-file-read failed, VAR_0: %" PRId64, VAR_0); } else { buf[read_count] = 0; VAR_4 = g_new0(GuestFileRead, 1); VAR_4->VAR_2 = read_count; VAR_4->eof = feof(fh); if (read_count) { VAR_4->buf_b64 = g_base64_encode(buf, read_count); gfh->state = RW_STATE_READING; g_free(buf); clearerr(fh); return VAR_4;