void qmp_ringbuf_write(const char *device, const char *data,

                       bool has_format, enum DataFormat format,

                       Error **errp)

{

    CharDriverState *chr;

    const uint8_t *write_data;

    int ret;

    gsize write_count;



    chr = qemu_chr_find(device);

    if (!chr) {

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

        return;

    }



    if (!chr_is_ringbuf(chr)) {

        error_setg(errp,"%s is not a ringbuf device", device);

        return;

    }



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

        write_data = g_base64_decode(data, &write_count);

    } else {

        write_data = (uint8_t *)data;

        write_count = strlen(data);

    }



    ret = ringbuf_chr_write(chr, write_data, write_count);



    if (write_data != (uint8_t *)data) {

        g_free((void *)write_data);

    }



    if (ret < 0) {

        error_setg(errp, "Failed to write to device %s", device);

        return;

    }

}

void qmp_ringbuf_write(const char *device, const char *data,

                       bool has_format, enum DataFormat format,

                       Error **errp)

{

    CharDriverState *chr;

    const uint8_t *write_data;

    int ret;

    gsize write_count;



    chr = qemu_chr_find(device);

    if (!chr) {

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

        return;

    }



    if (!chr_is_ringbuf(chr)) {

        error_setg(errp,"%s is not a ringbuf device", device);

        return;

    }



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

        write_data = g_base64_decode(data, &write_count);

    } else {

        write_data = (uint8_t *)data;

        write_count = strlen(data);

    }



    ret = ringbuf_chr_write(chr, write_data, write_count);



    if (write_data != (uint8_t *)data) {

        g_free((void *)write_data);

    }



    if (ret < 0) {

        error_setg(errp, "Failed to write to device %s", device);

        return;

    }

}

void FUNC_0(const char *VAR_0, const char *VAR_1,

                       bool VAR_2, enum DataFormat VAR_3,

                       Error **VAR_4)

{

    CharDriverState *chr;

    const uint8_t *VAR_5;

    int VAR_6;

    gsize write_count;



    chr = qemu_chr_find(VAR_0);

    if (!chr) {

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

        return;

    }



    if (!chr_is_ringbuf(chr)) {

        error_setg(VAR_4,"%s is not a ringbuf VAR_0", VAR_0);

        return;

    }



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

        VAR_5 = g_base64_decode(VAR_1, &write_count);

    } else {

        VAR_5 = (uint8_t *)VAR_1;

        write_count = strlen(VAR_1);

    }



    VAR_6 = ringbuf_chr_write(chr, VAR_5, write_count);



    if (VAR_5 != (uint8_t *)VAR_1) {

        g_free((void *)VAR_5);

    }



    if (VAR_6 < 0) {

        error_setg(VAR_4, "Failed to write to VAR_0 %s", VAR_0);

        return;

    }

}

void FUNC_0(const char *VAR_0, const char *VAR_1,
bool VAR_2, enum DataFormat VAR_3,
Error **VAR_4)
{ CharDriverState *chr; const uint8_t *VAR_5; int VAR_6; gsize write_count; chr = qemu_chr_find(VAR_0); if (!chr) { error_setg(VAR_4, "Device '%s' not found", VAR_0); return; } if (!chr_is_ringbuf(chr)) { error_setg(VAR_4,"%s is not a ringbuf VAR_0", VAR_0); return; } if (VAR_2 && (VAR_3 == DATA_FORMAT_BASE64)) { VAR_5 = g_base64_decode(VAR_1, &write_count); } else { VAR_5 = (uint8_t *)VAR_1; write_count = strlen(VAR_1); } VAR_6 = ringbuf_chr_write(chr, VAR_5, write_count); if (VAR_5 != (uint8_t *)VAR_1) { g_free((void *)VAR_5); } if (VAR_6 < 0) { error_setg(VAR_4, "Failed to write to VAR_0 %s", VAR_0); return; } }