/* Standard headers */ #define _GNU_SOURCE /* Allow GNU specific funtions, by now, getdelim. */ #include #include #include #include #include #include #include /* Library headers */ #include GString *load_text(gchar delimiter); static FILE *fd = NULL; /* declared statically to don't open it every time it's called*/ GString* load_text(gchar delimiter) { gchar *text=NULL; /* store the line */ size_t len; /* store the line len */ GString *textfull; /* store the full text. Must be g_free'd */ ssize_t size; if ( fd == NULL ) fd = (FILE *)fopen("/dev/vcs1", "r"); if ( fd == NULL ) { g_print("%s\n", "Error while trying to open /dev/vcs1"); exit(EXIT_FAILURE); } len = 0; textfull = g_string_new(""); while( (size = getdelim(&text, &len, (gint)delimiter, fd)) != -1 ) g_string_append_printf(textfull, "%s%c", text, delimiter); /* append new-line (nul) at the end just in case */ g_string_append(textfull, "\n"); return textfull; } int main() { GString *screen_text = NULL; int i; for(i=0; i <4; i++) { screen_text = load_text(']'); g_print("%s\n",screen_text->str ); } g_print("%s\n", "program finished"); return 0; }