Index: uspace/lib/posix/source/stdio.c
===================================================================
--- uspace/lib/posix/source/stdio.c	(revision 7db5cfdf9880d55d20d1c9ff67cdd1d2890e72f1)
+++ uspace/lib/posix/source/stdio.c	(revision a955fccc48da56c66c06fc89b21e01671d0bfc4e)
@@ -55,10 +55,4 @@
 #include "libc/sys/stat.h"
 
-
-/* not the best of solutions, but freopen and ungetc will eventually
- * need to be implemented in libc anyway
- */
-#include "../../c/generic/private/stdio.h"
-
 /** Clears the stream's error and end-of-file indicators.
  *
@@ -67,6 +61,5 @@
 void posix_clearerr(FILE *stream)
 {
-	stream->error = 0;
-	stream->eof = 0;
+	clearerr(stream);
 }
 
@@ -221,43 +214,5 @@
     const char *restrict mode, FILE *restrict stream)
 {
-	assert(mode != NULL);
-	assert(stream != NULL);
-	
-	if (filename == NULL) {
-		/* POSIX allows this to be imlementation-defined. HelenOS currently
-		 * does not support changing the mode. */
-		// FIXME: handle mode change once it is supported
-		return stream;
-	}
-	
-	/* Open a new stream. */
-	FILE* new = fopen(filename, mode);
-	if (new == NULL) {
-		fclose(stream);
-		/* errno was set by fopen() */
-		return NULL;
-	}
-	
-	/* Close the original stream without freeing it (ignoring errors). */
-	if (stream->buf != NULL) {
-		fflush(stream);
-	}
-	if (stream->sess != NULL) {
-		async_hangup(stream->sess);
-	}
-	if (stream->fd >= 0) {
-		close(stream->fd);
-	}
-	list_remove(&stream->link);
-	
-	/* Move the new stream to the original location. */
-	memcpy(stream, new, sizeof (FILE));
-	free(new);
-	
-	/* Update references in the file list. */
-	stream->link.next->prev = &stream->link;
-	stream->link.prev->next = &stream->link;
-	
-	return stream;
+	return freopen(filename, mode, stream);
 }
 
