Index: uspace/lib/libc/generic/io/io.c
===================================================================
--- uspace/lib/libc/generic/io/io.c	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/generic/io/io.c	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -43,6 +43,7 @@
 #include <vfs/vfs.h>
 #include <ipc/devmap.h>
-
-FILE stdin_null = {
+#include <libadt/list.h>
+
+static FILE stdin_null = {
 	.fd = -1,
 	.error = true,
@@ -52,5 +53,5 @@
 };
 
-FILE stdout_klog = {
+static FILE stdout_klog = {
 	.fd = -1,
 	.error = false,
@@ -60,7 +61,52 @@
 };
 
-FILE *stdin = &stdin_null;
-FILE *stdout = &stdout_klog;
-FILE *stderr = &stdout_klog;
+static FILE stderr_klog = {
+	.fd = -1,
+	.error = false,
+	.eof = false,
+	.klog = true,
+	.phone = -1
+};
+
+FILE *stdin = NULL;
+FILE *stdout = NULL;
+FILE *stderr = NULL;
+
+static LIST_INITIALIZE(files);
+
+void stdio_init(int filc, fdi_node_t *filv[])
+{
+	if (filc > 0) {
+		stdin = fopen_node(filv[0], "r");
+	} else {
+		stdin = &stdin_null;
+		list_append(&stdin->link, &files);
+	}
+	
+	if (filc > 1) {
+		stdout = fopen_node(filv[1], "w");
+	} else {
+		stdout = &stdout_klog;
+		list_append(&stdout->link, &files);
+	}
+	
+	if (filc > 2) {
+		stderr = fopen_node(filv[2], "w");
+	} else {
+		stderr = &stderr_klog;
+		list_append(&stderr->link, &files);
+	}
+}
+
+void stdio_done(void)
+{
+	link_t *link = files.next;
+	
+	while (link != &files) {
+		FILE *file = list_get_instance(link, FILE, link);
+		fclose(file);
+		link = files.next;
+	}
+}
 
 static bool parse_mode(const char *mode, int *flags)
@@ -142,4 +188,6 @@
 	stream->phone = -1;
 	
+	list_append(&stream->link, &files);
+	
 	return stream;
 }
@@ -170,4 +218,6 @@
 	stream->phone = -1;
 	
+	list_append(&stream->link, &files);
+	
 	return stream;
 }
@@ -185,5 +235,9 @@
 		rc = close(stream->fd);
 	
-	if ((stream != &stdin_null) && (stream != &stdout_klog))
+	list_remove(&stream->link);
+	
+	if ((stream != &stdin_null)
+	    && (stream != &stdout_klog)
+	    && (stream != &stderr_klog))
 		free(stream);
 	
@@ -354,13 +408,10 @@
 }
 
-void fnode(FILE *stream, fdi_node_t *node)
-{
-	if (stream->fd >= 0) {
-		fd_node(stream->fd, node);
-	} else {
-		node->fs_handle = 0;
-		node->dev_handle = 0;
-		node->index = 0;
-	}
+int fnode(FILE *stream, fdi_node_t *node)
+{
+	if (stream->fd >= 0)
+		return fd_node(stream->fd, node);
+	
+	return ENOENT;
 }
 
Index: uspace/lib/libc/generic/libc.c
===================================================================
--- uspace/lib/libc/generic/libc.c	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/generic/libc.c	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -80,28 +80,13 @@
 		argc = 0;
 		argv = NULL;
+		stdio_init(0, NULL);
 	} else {
 		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");
+		stdio_init(__pcb->filc, __pcb->filv);
 	}
 	
 	main(argc, argv);
-	
-	if (stdin != NULL)
-		fclose(stdin);
-	
-	if (stdout != NULL)
-		fclose(stdout);
-	
-	if (stderr != NULL)
-		fclose(stderr);
+	stdio_done();
 }
 
Index: uspace/lib/libc/generic/task.c
===================================================================
--- uspace/lib/libc/generic/task.c	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/generic/task.c	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -106,20 +106,17 @@
 	fdi_node_t stderr_node;
 	
-	if ((stdin != NULL) && (stdin != &stdin_null)) {
-		fnode(stdin, &stdin_node);
+	if ((stdin != NULL) && (fnode(stdin, &stdin_node) == EOK))
 		files[0] = &stdin_node;
-	} else
+	else
 		files[0] = NULL;
 	
-	if ((stdout != NULL) && (stdout != &stdout_klog)) {
-		fnode(stdout, &stdout_node);
+	if ((stdout != NULL) && (fnode(stdout, &stdout_node) == EOK))
 		files[1] = &stdout_node;
-	} else
+	else
 		files[1] = NULL;
 	
-	if ((stderr != NULL) && (stderr != &stdout_klog)) {
-		fnode(stderr, &stderr_node);
+	if ((stderr != NULL) && (fnode(stderr, &stderr_node) == EOK))
 		files[2] = &stderr_node;
-	} else
+	else
 		files[2] = NULL;
 	
Index: uspace/lib/libc/generic/vfs/vfs.c
===================================================================
--- uspace/lib/libc/generic/vfs/vfs.c	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/generic/vfs/vfs.c	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -333,5 +333,5 @@
 }
 
-void fd_node(int fildes, fdi_node_t *node)
+int fd_node(int fildes, fdi_node_t *node)
 {
 	futex_down(&vfs_phone_futex);
@@ -352,9 +352,7 @@
 		node->dev_handle = (dev_handle_t) dev_handle;
 		node->index = (fs_index_t) index;
-	} else {
-		node->fs_handle = 0;
-		node->dev_handle = 0;
-		node->index = 0;
-	}
+	}
+	
+	return rc;
 }
 
Index: uspace/lib/libc/include/stdio.h
===================================================================
--- uspace/lib/libc/include/stdio.h	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/include/stdio.h	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -38,4 +38,5 @@
 #include <sys/types.h>
 #include <stdarg.h>
+#include <libadt/list.h>
 
 #define EOF  (-1)
@@ -56,4 +57,7 @@
 
 typedef struct {
+	/** Linked list pointer. */
+	link_t link;
+	
 	/** Underlying file descriptor. */
 	int fd;
@@ -71,7 +75,4 @@
 	int phone;
 } FILE;
-
-extern FILE stdin_null;
-extern FILE stdout_klog;
 
 extern FILE *stdin;
Index: uspace/lib/libc/include/vfs/vfs.h
===================================================================
--- uspace/lib/libc/include/vfs/vfs.h	(revision 3bf907ab10516755767898b1ff0d5485f3c73729)
+++ uspace/lib/libc/include/vfs/vfs.h	(revision a68f7375e3e4f83a6876853e429edc329d00e4e4)
@@ -56,11 +56,14 @@
     unsigned int);
 
+extern void stdio_init(int filc, fdi_node_t *filv[]);
+extern void stdio_done(void);
+
 extern int open_node(fdi_node_t *, int);
 extern int fd_phone(int);
-extern void fd_node(int, fdi_node_t *);
+extern int fd_node(int, fdi_node_t *);
 
 extern FILE *fopen_node(fdi_node_t *, const char *);
 extern int fphone(FILE *);
-extern void fnode(FILE *, fdi_node_t *);
+extern int fnode(FILE *, fdi_node_t *);
 
 #endif
