segfault problem



i'm really not sure why this is happening.. could anyone bring it to
light?

/* This file was modified from a file extracted from the GTK tutorial. */
/* list.c */

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

char *cmd;
FILE	    *pfile;

void addtolist (gpointer data, gint source, GdkInputCondition condition)
{
    static int i = 1;
    gchar buffer[64];
    GtkWidget *list_item;
    GtkWidget *list;
    char	    *filedata;
    
    if (fgets(filedata, 2047, pfile)!=NULL) {
      printf("Error in file");
      filedata="blah";
    }
    sprintf (buffer, filedata);
    list_item = gtk_list_item_new_with_label(buffer);
    gtk_widget_show(list_item);
    gtk_container_add(GTK_CONTAINER (GTK_WIDGET (data)), list_item);
}

gint main (int argc, gchar *argv[])
{                                  
    GtkWidget       *separator;
    GtkWidget       *window;
    GtkWidget       *vbox;
    GtkWidget       *scrolled_window;
    GtkWidget       *button;
    GtkWidget       *list_item;
    GtkWidget       *gtklist;
    GList           *dlist;
    gchar           buffer[64];
    guint           i;
/*    static int      listtimer = 0; */
    gint	    infile;
	    
    
/*    for(;fgets(filedata, PATH_MAX+1, pfile)!=NULL;) {
      printf("DATA: %s", filedata);
    }
*/
    
    /* initialize gtk+ (and subsequently gdk) */

    gtk_init(&argc, &argv);
    
    
    /* create a window to put all the widgets in
     * connect gtk_main_quit() to the "destroy" event of
     * the window to handle window manager close-window-events
     */
    window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "GtkList Example");
    gtk_signal_connect(GTK_OBJECT(window),
		       "destroy",
		       GTK_SIGNAL_FUNC(gtk_main_quit),
		       NULL);
    
    
    /* inside the window we need a box to arrange the widgets
     * vertically */
    vbox=gtk_vbox_new(FALSE, 5);
    gtk_container_border_width(GTK_CONTAINER(vbox), 5);
    gtk_container_add(GTK_CONTAINER(window), vbox);
    gtk_widget_show(vbox);
    
    /* this is the scolled window to put the GtkList widget inside */
    scrolled_window=gtk_scrolled_window_new(NULL, NULL);
    gtk_widget_set_usize(scrolled_window, 250, 150);
    gtk_container_add(GTK_CONTAINER(vbox), scrolled_window);
    gtk_widget_show(scrolled_window);
    
    gtklist=gtk_list_new();
    gtk_container_add(GTK_CONTAINER(scrolled_window), gtklist);
    gtk_widget_show(gtklist);
    
    separator=gtk_hseparator_new();
    gtk_container_add(GTK_CONTAINER(vbox), separator);
    gtk_widget_show(separator);
    
    button=gtk_button_new_with_label("Close");
    gtk_container_add(GTK_CONTAINER(vbox), button);
    gtk_widget_show(button);
    gtk_signal_connect_object(GTK_OBJECT(button),
			      "clicked",
			      GTK_SIGNAL_FUNC(gtk_widget_destroy),
			      GTK_OBJECT(window));
    
/*    listtimer = gtk_timeout_add (100, addtolist, gtklist); */
    gtk_widget_show(window);
    
    dlist=NULL;
    
    pfile = popen("/sbin/ifconfig", "r");
    if (pfile == NULL)
    {
	printf("Error opening file!");
	return;
    }

    infile = gdk_input_add (fileno(pfile), GDK_INPUT_READ, addtolist, gtklist);
    
    gtk_main();
    
    return 0;
}


 _        _  __     __             _ _                                  _
|        / |/ /_ __/ /_____         |       Nuke Skyjumper               |
|       /    / // /  '_/ -_)        |         "Master of the Farce"      |
|_     /_/|_/\_,_/_/\_\\__/        _|_           nuke@bayside.net       _|



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