char *qmp_memchar_read(const char *device, int64_t size,

                       bool has_format, enum DataFormat format,

                       Error **errp)

{

    CharDriverState *chr;

    uint8_t *read_data;

    size_t count;

    char *data;



    chr = qemu_chr_find(device);

    if (!chr) {

        error_setg(errp, "Device '%s' not found", device);

        return NULL;

    }



    if (qemu_is_chr(chr, "memory")) {

        error_setg(errp,"%s is not memory char device", device);

        return NULL;

    }



    if (size <= 0) {

        error_setg(errp, "size must be greater than zero");

        return NULL;

    }



    count = qemu_chr_cirmem_count(chr);

    if (count == 0) {

        return g_strdup("");

    }



    size = size > count ? count : size;

    read_data = g_malloc0(size + 1);



    cirmem_chr_read(chr, read_data, size);



    if (has_format && (format == DATA_FORMAT_BASE64)) {

        data = g_base64_encode(read_data, size);


    } else {

        data = (char *)read_data;

    }



    return data;

}
char *qmp_memchar_read(const char *device, int64_t size,

                       bool has_format, enum DataFormat format,

                       Error **errp)

{

    CharDriverState *chr;

    uint8_t *read_data;

    size_t count;

    char *data;



    chr = qemu_chr_find(device);

    if (!chr) {

        error_setg(errp, "Device '%s' not found", device);

        return NULL;

    }



    if (qemu_is_chr(chr, "memory")) {

        error_setg(errp,"%s is not memory char device", device);

        return NULL;

    }



    if (size <= 0) {

        error_setg(errp, "size must be greater than zero");

        return NULL;

    }



    count = qemu_chr_cirmem_count(chr);

    if (count == 0) {

        return g_strdup("");

    }



    size = size > count ? count : size;

    read_data = g_malloc0(size + 1);



    cirmem_chr_read(chr, read_data, size);



    if (has_format && (format == DATA_FORMAT_BASE64)) {

        data = g_base64_encode(read_data, size);


    } else {

        data = (char *)read_data;

    }



    return data;

}
char *FUNC_0(const char *VAR_0, int64_t VAR_1,

                       bool VAR_2, enum DataFormat VAR_3,

                       Error **VAR_4)

{

    CharDriverState *chr;

    uint8_t *read_data;

    size_t count;

    char *VAR_5;



    chr = qemu_chr_find(VAR_0);

    if (!chr) {

        error_setg(VAR_4, "Device '%s' not found", VAR_0);

        return NULL;

    }



    if (qemu_is_chr(chr, "memory")) {

        error_setg(VAR_4,"%s is not memory char VAR_0", VAR_0);

        return NULL;

    }



    if (VAR_1 <= 0) {

        error_setg(VAR_4, "VAR_1 must be greater than zero");

        return NULL;

    }



    count = qemu_chr_cirmem_count(chr);

    if (count == 0) {

        return g_strdup("");

    }



    VAR_1 = VAR_1 > count ? count : VAR_1;

    read_data = g_malloc0(VAR_1 + 1);



    cirmem_chr_read(chr, read_data, VAR_1);



    if (VAR_2 && (VAR_3 == DATA_FORMAT_BASE64)) {

        VAR_5 = g_base64_encode(read_data, VAR_1);


    } else {

        VAR_5 = (char *)read_data;

    }



    return VAR_5;

}
char *FUNC_0(const char *VAR_0, int64_t VAR_1,
bool VAR_2, enum DataFormat VAR_3,
Error **VAR_4)
{ CharDriverState *chr; uint8_t *read_data; size_t count; char *VAR_5; chr = qemu_chr_find(VAR_0); if (!chr) { error_setg(VAR_4, "Device '%s' not found", VAR_0); return NULL; } if (qemu_is_chr(chr, "memory")) { error_setg(VAR_4,"%s is not memory char VAR_0", VAR_0); return NULL; } if (VAR_1 <= 0) { error_setg(VAR_4, "VAR_1 must be greater than zero"); return NULL; } count = qemu_chr_cirmem_count(chr); if (count == 0) { return g_strdup(""); } VAR_1 = VAR_1 > count ? count : VAR_1; read_data = g_malloc0(VAR_1 + 1); cirmem_chr_read(chr, read_data, VAR_1); if (VAR_2 && (VAR_3 == DATA_FORMAT_BASE64)) { VAR_5 = g_base64_encode(read_data, VAR_1); } else { VAR_5 = (char *)read_data; } return VAR_5; }