gsdll_stdin(void *instance, char *buf, int len)
{
    struct stdin_buf input;
    gint input_tag;
    GIOChannel *channel;
    GError *error = NULL;

    input.len = len;
    input.buf = buf;
    input.count = -1;

    channel = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_encoding(channel, NULL, &error);
    g_io_channel_set_buffered(channel, FALSE);
    if (error) {
        g_print("%s\n", error->message);
        g_error_free(error);
    }
    input_tag = g_io_add_watch(channel,
        (G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP),
        read_stdin_handler, &input);
    while (input.count < 0)
        gtk_main_iteration_do(TRUE);
    g_source_remove(input_tag);
    g_io_channel_unref(channel);

    return input.count;
}
gsdll_stdin(void *instance, char *buf, int len)
{
    struct stdin_buf input;
    gint input_tag;
    GIOChannel *channel;
    GError *error = NULL;

    input.len = len;
    input.buf = buf;
    input.count = -1;

    channel = g_io_channel_unix_new(fileno(stdin));
    g_io_channel_set_encoding(channel, NULL, &error);
    g_io_channel_set_buffered(channel, FALSE);
    if (error) {
        g_print("%s\n", error->message);
        g_error_free(error);
    }
    input_tag = g_io_add_watch(channel,
        (G_IO_IN | G_IO_PRI | G_IO_ERR | G_IO_HUP),
        read_stdin_handler, &input);
    while (input.count < 0)
        gtk_main_iteration_do(TRUE);
    g_source_remove(input_tag);
    g_io_channel_unref(channel);

    return input.count;
}