Index: uspace/lib/libc/generic/libc.c
===================================================================
--- uspace/lib/libc/generic/libc.c	(revision 937aeee42214efb789506bfba8421857cfa89416)
+++ uspace/lib/libc/generic/libc.c	(revision 433131d83567990d0acc7aeb2d50b2871040216b)
@@ -28,16 +28,19 @@
 
 /** @addtogroup lc Libc
- * @brief	HelenOS C library
+ * @brief HelenOS C library
  * @{
  * @}
  */
+
 /** @addtogroup libc generic
  * @ingroup lc
  * @{
  */
+
 /** @file
- */ 
+ */
 
 #include <libc.h>
+#include <stdio.h>
 #include <unistd.h>
 #include <malloc.h>
@@ -45,9 +48,7 @@
 #include <thread.h>
 #include <fibril.h>
-#include <io/stream.h>
 #include <ipc/ipc.h>
 #include <async.h>
 #include <as.h>
-#include <console.h>
 #include <loader/pcb.h>
 
@@ -64,16 +65,16 @@
 void __main(void *pcb_ptr)
 {
-	fibril_t *f;
+	(void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ);
+	
+	_async_init();
+	fibril_t *fibril = fibril_setup();
+	__tcb_set(fibril->tcb);
+	
+	/* Save the PCB pointer */
+	__pcb = (pcb_t *) pcb_ptr;
+	
 	int argc;
 	char **argv;
-
-	(void) as_area_create(&_heap, 1, AS_AREA_WRITE | AS_AREA_READ);
-	_async_init();
-	f = fibril_setup();
-	__tcb_set(f->tcb);
 	
-	/* Save the PCB pointer */
-	__pcb = (pcb_t *)pcb_ptr;
-
 	if (__pcb == NULL) {
 		argc = 0;
@@ -82,8 +83,25 @@
 		argc = __pcb->argc;
 		argv = __pcb->argv;
+		
+		if (__pcb->filc > 0)
+			stdin = fopen_node(__pcb->filv[0], "r");
+		
+		if (__pcb->filc > 1)
+			stdout = fopen_node(__pcb->filv[1], "w");
+		
+		if (__pcb->filc > 2)
+			stderr = fopen_node(__pcb->filv[2], "w");
 	}
-
+	
 	main(argc, argv);
-	console_flush();
+	
+	if (stdin != NULL)
+		fclose(stdin);
+	
+	if (stdout != NULL)
+		fclose(stdout);
+	
+	if (stderr != NULL)
+		fclose(stderr);
 }
 
