Index: uspace/lib/c/generic/elf/elf_mod.c
===================================================================
--- uspace/lib/c/generic/elf/elf_mod.c	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ uspace/lib/c/generic/elf/elf_mod.c	(revision b19e892c22afbf67aa5988554dd3f003efeadc04)
@@ -97,5 +97,5 @@
 
 	int ofile = vfs_clone(file, -1, true);
-	int rc = _vfs_open(ofile, MODE_READ);
+	int rc = vfs_open(ofile, MODE_READ);
 	if (rc != EOK) {
 		return rc;
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ uspace/lib/c/generic/io/io.c	(revision b19e892c22afbf67aa5988554dd3f003efeadc04)
@@ -35,5 +35,4 @@
 #include <stdio.h>
 #include <unistd.h>
-#include <fcntl.h>
 #include <assert.h>
 #include <str.h>
@@ -115,5 +114,5 @@
 		int stdinfd = vfs_clone(infd, -1, false);
 		assert(stdinfd == 0);
-		_vfs_open(stdinfd, MODE_READ);
+		vfs_open(stdinfd, MODE_READ);
 		stdin = fdopen(stdinfd, "r");
 	} else {
@@ -128,5 +127,5 @@
 		while (stdoutfd < 1)
 			stdoutfd = vfs_clone(outfd, -1, false);
-		_vfs_open(stdoutfd, MODE_APPEND);
+		vfs_open(stdoutfd, MODE_APPEND);
 		stdout = fdopen(stdoutfd, "a");
 	} else {
@@ -141,5 +140,5 @@
 		while (stderrfd < 2)
 			stderrfd = vfs_clone(errfd, -1, false);
-		_vfs_open(stderrfd, MODE_APPEND);
+		vfs_open(stderrfd, MODE_APPEND);
 		stderr = fdopen(stderrfd, "a");
 	} else {
@@ -157,8 +156,8 @@
 }
 
-static bool parse_mode(const char *mode, int *flags)
+static bool parse_mode(const char *fmode, int *mode, bool *create, bool *truncate)
 {
 	/* Parse mode except first character. */
-	const char *mp = mode;
+	const char *mp = fmode;
 	if (*mp++ == 0) {
 		errno = EINVAL;
@@ -180,12 +179,18 @@
 		return false;
 	}
-	
-	/* Parse first character of mode and determine flags for open(). */
-	switch (mode[0]) {
+
+	*create = false;
+	*truncate = false;
+	
+	/* Parse first character of fmode and determine mode for vfs_open(). */
+	switch (fmode[0]) {
 	case 'r':
-		*flags = plus ? O_RDWR : O_RDONLY;
+		*mode = plus ? MODE_READ | MODE_WRITE : MODE_READ;
 		break;
 	case 'w':
-		*flags = (O_TRUNC | O_CREAT) | (plus ? O_RDWR : O_WRONLY);
+		*mode = plus ? MODE_READ | MODE_WRITE : MODE_WRITE;
+		*create = true;
+		if (!plus)
+			*truncate = true;
 		break;
 	case 'a':
@@ -195,5 +200,7 @@
 			return false;
 		}
-		*flags = (O_APPEND | O_CREAT) | (plus ? O_RDWR : O_WRONLY);
+
+		*mode = MODE_APPEND | (plus ? MODE_READ | MODE_WRITE : MODE_WRITE);
+		*create = true;
 		break;
 	default:
@@ -269,8 +276,11 @@
  *
  */
-FILE *fopen(const char *path, const char *mode)
-{
-	int flags;
-	if (!parse_mode(mode, &flags))
+FILE *fopen(const char *path, const char *fmode)
+{
+	int mode;
+	bool create;
+	bool truncate;
+
+	if (!parse_mode(fmode, &mode, &create, &truncate))
 		return NULL;
 	
@@ -281,12 +291,34 @@
 		return NULL;
 	}
-	
-	stream->fd = open(path, flags, 0666);
-	if (stream->fd < 0) {
-		/* errno was set by open() */
+
+	int flags = WALK_REGULAR;
+	if (create)
+		flags |= WALK_MAY_CREATE;
+	int file = vfs_lookup(path, flags);
+	if (file < 0) {
+		errno = file;
 		free(stream);
 		return NULL;
 	}
-	
+
+	int rc = vfs_open(file, mode);
+	if (rc != EOK) {
+		errno = rc;
+		close(file);
+		free(stream);
+		return NULL;
+	}
+	
+	if (truncate) {
+		rc = vfs_resize(file, 0);
+		if (rc != EOK) {
+			errno = rc;
+			close(file);
+			free(stream);
+			return NULL;
+		}
+	}
+
+	stream->fd = file;
 	stream->pos = 0;
 	stream->error = false;
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ uspace/lib/c/generic/rtld/module.c	(revision b19e892c22afbf67aa5988554dd3f003efeadc04)
@@ -38,5 +38,4 @@
 #include <elf/elf_load.h>
 #include <errno.h>
-#include <fcntl.h>
 #include <loader/pcb.h>
 #include <stdio.h>
Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision b19e892c22afbf67aa5988554dd3f003efeadc04)
@@ -41,5 +41,4 @@
 #include <unistd.h>
 #include <dirent.h>
-#include <fcntl.h>
 #include <stdio.h>
 #include <sys/types.h>
@@ -155,11 +154,26 @@
 }
 
-int _vfs_open(int fildes, int mode)
-{
-	async_exch_t *exch = vfs_exchange_begin();
-	sysarg_t rc = async_req_2_0(exch, VFS_IN_OPEN, fildes, mode);
-	vfs_exchange_end(exch);
-	
-	return (int) rc;
+int vfs_open(int file, int mode)
+{
+	async_exch_t *exch = vfs_exchange_begin();
+	int rc = async_req_2_0(exch, VFS_IN_OPEN, file, mode);
+	vfs_exchange_end(exch);
+	
+	return rc;
+}
+
+int vfs_lookup_open(const char *path, int flags, int mode)
+{
+	int file = vfs_lookup(path, flags);
+	if (file < 0)
+		return file;
+
+	int rc = vfs_open(file, mode);
+	if (rc != EOK) {
+		close(file);
+		return rc;
+	}
+	
+	return file;
 }
 
@@ -353,64 +367,4 @@
 }
 
-static int walk_flags(int oflags)
-{
-	int flags = 0;
-	if (oflags & O_CREAT) {
-		if (oflags & O_EXCL)
-			flags |= WALK_MUST_CREATE;
-		else
-			flags |= WALK_MAY_CREATE;
-	}
-	return flags;
-}
-
-/** Open file.
- *
- * @param path File path
- * @param oflag O_xxx flags
- * @param mode File mode (only with O_CREAT)
- *
- * @return Nonnegative file descriptor on success. On error -1 is returned
- *         and errno is set.
- */
-int open(const char *path, int oflag, ...)
-{
-	if (((oflag & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) ||
-	    ((oflag & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) ||
-	    ((oflag & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) ||
-	    ((oflag & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) {
-		errno = EINVAL;
-		return -1;
-	}
-	
-	int fd = vfs_lookup(path, walk_flags(oflag) | WALK_REGULAR);
-	if (fd < 0) {
-		errno = fd;
-		return -1;
-	}
-	
-	int mode =
-	    ((oflag & O_RDWR) ? MODE_READ | MODE_WRITE : 0) |
-	    ((oflag & O_RDONLY) ? MODE_READ : 0) |
-	    ((oflag & O_WRONLY) ? MODE_WRITE : 0) |
-	    ((oflag & O_APPEND) ? MODE_APPEND : 0);
-	
-	int rc = _vfs_open(fd, mode); 
-	if (rc < 0) {
-		close(fd);
-		errno = rc;
-		return -1;
-	}
-	
-	if (oflag & O_TRUNC) {
-		assert(oflag & O_WRONLY || oflag & O_RDWR);
-		assert(!(oflag & O_APPEND));
-		
-		(void) vfs_resize(fd, 0);
-	}
-
-	return fd;
-}
-
 /** Close file.
  *
@@ -703,5 +657,5 @@
 	}
 	
-	int rc = _vfs_open(fd, MODE_READ);
+	int rc = vfs_open(fd, MODE_READ);
 	if (rc < 0) {
 		free(dirp);
Index: uspace/lib/c/include/fcntl.h
===================================================================
--- uspace/lib/c/include/fcntl.h	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2007 Jakub Jermar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#ifndef LIBC_FCNTL_H_
-#define LIBC_FCNTL_H_
-
-#define O_CREAT   1
-#define O_EXCL    2
-#define O_TRUNC   4
-#define O_APPEND  8
-#define O_RDONLY  16
-#define O_RDWR    32
-#define O_WRONLY  64
-#define O_DESC    128
-
-extern int open(const char *, int, ...);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision 80743a1b2ba5306f70559161509a3376fa381a08)
+++ uspace/lib/c/include/vfs/vfs.h	(revision b19e892c22afbf67aa5988554dd3f003efeadc04)
@@ -83,6 +83,4 @@
 
 extern int _vfs_walk(int, const char *, int);
-extern int _vfs_open(int, int);
-extern int vfs_lookup(const char *, int);
 
 extern int vfs_pass_handle(async_exch_t *, int, async_exch_t *);
@@ -92,8 +90,11 @@
 extern int vfs_link(int, const char *, vfs_file_kind_t);
 extern int vfs_link_path(const char *, vfs_file_kind_t);
+extern int vfs_lookup(const char *, int);
+extern int vfs_lookup_open(const char *, int, int);
 extern int vfs_mount_path(const char *, const char *, const char *,
     const char *, unsigned int, unsigned int);
 extern int vfs_mount(int, const char *, service_id_t, const char *, unsigned,
     unsigned, int *);
+extern int vfs_open(int, int);
 extern int vfs_resize(int, aoff64_t);
 extern int vfs_root(void);
