Re: gtk_input_add_full() and marshalling



On Wed, 10 Apr 2002, Andrei Zmievski wrote:
> Just a regular file. Here's a sample program that reads an arbitrary
> file. When I run it, the reader() function receives the data but then
> gets invoked over and over again.

If I modify the program to the following, it seems to work (with one
exception).

#include <stdio.h>
#include <gtk/gtk.h>

void reader(gpointer data, gint source, GdkInputCondition cond)
{
    char buf[256];
    int n;

    printf("\n ** reader called **\n");
    if ((n = read(source, buf, 256)) > 0) {
        buf[n] = 0;
        printf("%s", buf);
    } else {
        int *id = (int *)data;
        gtk_input_remove(*id);
        /* gtk_main_quit(); */
    }
}

int main(int argc, char **argv)
{
    FILE *fp;
    int id;

    if (argc != 2)
        exit(1);

    fp = fopen(argv[1], "r");
    id = gtk_input_add_full(fileno(fp), GDK_INPUT_READ, reader,
                            NULL, (gpointer)&id, NULL);
    gtk_main();

    fclose(fp);

    return 0;
}

If I uncomment gtk_main_quit() in reader(), the program segfaults. Any
hints on why?

-Andrei

The main reason Santa is so jolly is because he knows where
all the bad girls live.  -- George Carlin



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]