static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)

{

    CharDriverState *chr;

    PtyCharDriver *s;

    struct termios tty;

    int master_fd, slave_fd, len;

#if defined(__OpenBSD__) || defined(__DragonFly__)

    char pty_name[PATH_MAX];

#define q_ptsname(x) pty_name

#else

    char *pty_name = NULL;

#define q_ptsname(x) ptsname(x)

#endif



    if (openpty(&master_fd, &slave_fd, pty_name, NULL, NULL) < 0) {

        return NULL;

    }



    /* Set raw attributes on the pty. */

    tcgetattr(slave_fd, &tty);

    cfmakeraw(&tty);

    tcsetattr(slave_fd, TCSAFLUSH, &tty);

    close(slave_fd);



    chr = g_malloc0(sizeof(CharDriverState));



    len = strlen(q_ptsname(master_fd)) + 5;

    chr->filename = g_malloc(len);

    snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd));

    qemu_opt_set(opts, "path", q_ptsname(master_fd));

    fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));



    s = g_malloc0(sizeof(PtyCharDriver));

    chr->opaque = s;

    chr->chr_write = pty_chr_write;

    chr->chr_update_read_handler = pty_chr_update_read_handler;

    chr->chr_close = pty_chr_close;



    s->fd = master_fd;

    s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr);



    return chr;

}

static CharDriverState *qemu_chr_open_pty(QemuOpts *opts)

{

    CharDriverState *chr;

    PtyCharDriver *s;

    struct termios tty;

    int master_fd, slave_fd, len;

#if defined(__OpenBSD__) || defined(__DragonFly__)

    char pty_name[PATH_MAX];

#define q_ptsname(x) pty_name

#else

    char *pty_name = NULL;

#define q_ptsname(x) ptsname(x)

#endif



    if (openpty(&master_fd, &slave_fd, pty_name, NULL, NULL) < 0) {

        return NULL;

    }



    

    tcgetattr(slave_fd, &tty);

    cfmakeraw(&tty);

    tcsetattr(slave_fd, TCSAFLUSH, &tty);

    close(slave_fd);



    chr = g_malloc0(sizeof(CharDriverState));



    len = strlen(q_ptsname(master_fd)) + 5;

    chr->filename = g_malloc(len);

    snprintf(chr->filename, len, "pty:%s", q_ptsname(master_fd));

    qemu_opt_set(opts, "path", q_ptsname(master_fd));

    fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));



    s = g_malloc0(sizeof(PtyCharDriver));

    chr->opaque = s;

    chr->chr_write = pty_chr_write;

    chr->chr_update_read_handler = pty_chr_update_read_handler;

    chr->chr_close = pty_chr_close;



    s->fd = master_fd;

    s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr);



    return chr;

}

    fprintf(stderr, "char device redirected to %s\n", q_ptsname(master_fd));
static CharDriverState *FUNC_0(QemuOpts *opts)

{

    CharDriverState *chr;

    PtyCharDriver *s;

    struct termios VAR_0;

    int VAR_1, VAR_2, VAR_3;

#if defined(__OpenBSD__) || defined(__DragonFly__)

    char VAR_4[PATH_MAX];

#define q_ptsname(x) VAR_4

#else

    char *VAR_4 = NULL;

#define q_ptsname(x) ptsname(x)

#endif



    if (openpty(&VAR_1, &VAR_2, VAR_4, NULL, NULL) < 0) {

        return NULL;

    }



    

    tcgetattr(VAR_2, &VAR_0);

    cfmakeraw(&VAR_0);

    tcsetattr(VAR_2, TCSAFLUSH, &VAR_0);

    close(VAR_2);



    chr = g_malloc0(sizeof(CharDriverState));



    VAR_3 = strlen(q_ptsname(VAR_1)) + 5;

    chr->filename = g_malloc(VAR_3);

    snprintf(chr->filename, VAR_3, "pty:%s", q_ptsname(VAR_1));

    qemu_opt_set(opts, "path", q_ptsname(VAR_1));

    fprintf(stderr, "char device redirected to %s\n", q_ptsname(VAR_1));



    s = g_malloc0(sizeof(PtyCharDriver));

    chr->opaque = s;

    chr->chr_write = pty_chr_write;

    chr->chr_update_read_handler = pty_chr_update_read_handler;

    chr->chr_close = pty_chr_close;



    s->fd = VAR_1;

    s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr);



    return chr;

}

static CharDriverState *FUNC_0(QemuOpts *opts)
{ CharDriverState *chr; PtyCharDriver *s; struct termios VAR_0; int VAR_1, VAR_2, VAR_3; #if defined(__OpenBSD__) || defined(__DragonFly__)
char VAR_4[PATH_MAX]; #define q_ptsname(x) VAR_4
#else
char *VAR_4 = NULL; #define q_ptsname(x) ptsname(x)
#endif
if (openpty(&VAR_1, &VAR_2, VAR_4, NULL, NULL) < 0) { return NULL; } tcgetattr(VAR_2, &VAR_0); cfmakeraw(&VAR_0); tcsetattr(VAR_2, TCSAFLUSH, &VAR_0); close(VAR_2); chr = g_malloc0(sizeof(CharDriverState)); VAR_3 = strlen(q_ptsname(VAR_1)) + 5; chr->filename = g_malloc(VAR_3); snprintf(chr->filename, VAR_3, "pty:%s", q_ptsname(VAR_1)); qemu_opt_set(opts, "path", q_ptsname(VAR_1)); fprintf(stderr, "char device redirected to %s\n", q_ptsname(VAR_1)); s = g_malloc0(sizeof(PtyCharDriver)); chr->opaque = s; chr->chr_write = pty_chr_write; chr->chr_update_read_handler = pty_chr_update_read_handler; chr->chr_close = pty_chr_close; s->fd = VAR_1; s->timer = qemu_new_timer_ms(rt_clock, pty_chr_timer, chr); return chr; }