Index: uspace/app/bdsh/cmds/builtins/cd/cd.c
===================================================================
--- uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -29,7 +29,7 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <str.h>
 #include <errno.h>
+#include <vfs/vfs.h>
 
 #include "util.h"
@@ -51,12 +51,14 @@
 static bool previous_directory_set = false;
 
-static int chdir_and_remember(const char *new_dir) {
+static int chdir_and_remember(const char *new_dir)
+{
 
-	char *ok = getcwd(previous_directory_tmp, PATH_MAX);
-	previous_directory_valid = ok != NULL;
+	int rc = vfs_cwd_get(previous_directory_tmp, PATH_MAX);
+	previous_directory_valid = (rc == EOK);
 	previous_directory_set = true;
 
-	if (chdir(new_dir) != 0)
-		return errno;
+	rc = vfs_cwd_set(new_dir);
+	if (rc != EOK)
+		return rc;
 
 	str_cpy(previous_directory, PATH_MAX, previous_directory_tmp);
Index: uspace/app/bdsh/cmds/modules/ls/ls.c
===================================================================
--- uspace/app/bdsh/cmds/modules/ls/ls.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/cmds/modules/ls/ls.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -34,5 +34,4 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <dirent.h>
 #include <getopt.h>
@@ -387,5 +386,5 @@
 
 	if (argc == 0) {
-		if (getcwd(de.name, PATH_MAX) == NULL) {
+		if (vfs_cwd_get(de.name, PATH_MAX) != EOK) {
 			cli_error(CL_EFAIL, "%s: Failed determining working "
 			    "directory", cmdname);
Index: uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -208,5 +208,5 @@
 
 	if (follow && (argv[optind] != NULL)) {
-		if (chdir(argv[optind]) != 0)
+		if (vfs_cwd_set(argv[optind]) != EOK)
 			printf("%s: Error switching to directory.", cmdname);
 	}
Index: uspace/app/bdsh/cmds/modules/pwd/pwd.c
===================================================================
--- uspace/app/bdsh/cmds/modules/pwd/pwd.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/cmds/modules/pwd/pwd.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -30,4 +30,6 @@
 #include <stdlib.h>
 #include <mem.h>
+#include <vfs/vfs.h>
+#include <abi/errno.h>
 
 #include "config.h"
@@ -57,5 +59,5 @@
 	memset(buff, 0, PATH_MAX);
 
-	if (getcwd(buff, PATH_MAX) == NULL) {
+	if (vfs_cwd_get(buff, PATH_MAX) != EOK) {
 		cli_error(CL_EFAIL,
 			"Unable to determine the current working directory");
Index: uspace/app/bdsh/cmds/modules/rm/rm.c
===================================================================
--- uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -30,5 +30,4 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <unistd.h>
 #include <dirent.h>
 #include <getopt.h>
@@ -110,7 +109,7 @@
 	memset(rm->cwd, 0, PATH_MAX);
 
-	chdir(".");
-
-	if (NULL == (getcwd(rm->owd, PATH_MAX)))
+	vfs_cwd_set(".");
+
+	if (EOK != vfs_cwd_get(rm->owd, PATH_MAX))
 		return 0;
 
Index: uspace/app/bdsh/util.c
===================================================================
--- uspace/app/bdsh/util.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/app/bdsh/util.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -31,4 +31,6 @@
 #include <stdarg.h>
 #include <stdlib.h>
+#include <vfs/vfs.h>
+#include <abi/errno.h>
 
 #include "config.h"
@@ -58,5 +60,5 @@
 		return 1;
 	}
-	if (!getcwd(usr->cwd, PATH_MAX)) 
+	if (vfs_cwd_get(usr->cwd, PATH_MAX) != EOK)
 		snprintf(usr->cwd, PATH_MAX, "(unknown)");
 
Index: uspace/lib/c/generic/libc.c
===================================================================
--- uspace/lib/c/generic/libc.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/c/generic/libc.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -116,5 +116,5 @@
 		__stdio_init();
 		vfs_root_set(inbox_get("root"));
-		(void) chdir(__pcb->cwd);
+		(void) vfs_cwd_set(__pcb->cwd);
 	}
 	
Index: uspace/lib/c/generic/loader.c
===================================================================
--- uspace/lib/c/generic/loader.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/c/generic/loader.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -124,5 +124,5 @@
 		return ENOMEM;
 	
-	if (getcwd(cwd, MAX_PATH_LEN + 1) == NULL)
+	if (vfs_cwd_get(cwd, MAX_PATH_LEN + 1) != EOK)
 		str_cpy(cwd, MAX_PATH_LEN + 1, "/");
 	
Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -808,20 +808,17 @@
  *
  * @param path Path
- * @return 0 on success. On error returns -1 and sets errno.
- */
-int chdir(const char *path)
+ * @return EOK on success or a negative error code otherwise.
+ */
+int vfs_cwd_set(const char *path)
 {
 	size_t abs_size;
 	char *abs = vfs_absolutize(path, &abs_size);
-	if (!abs) {
-		errno = ENOMEM;
-		return -1;
-	}
+	if (!abs)
+		return ENOMEM;
 	
 	int fd = vfs_lookup(abs, WALK_DIRECTORY);
 	if (fd < 0) {
 		free(abs);
-		errno = fd;
-		return -1;
+		return fd;
 	}
 	
@@ -839,5 +836,5 @@
 	
 	fibril_mutex_unlock(&cwd_mutex);
-	return 0;
+	return EOK;
 }
 
@@ -846,19 +843,13 @@
  * @param buf Buffer
  * @param size Size of @a buf
- * @return On success returns @a buf. On failure returns @c NULL and sets errno.
- */
-char *getcwd(char *buf, size_t size)
-{
-	if (size == 0) {
-		errno = EINVAL;
-		return NULL;
-	}
-	
+ * @return EOK on success and a non-negative error code otherwise.
+ */
+int vfs_cwd_get(char *buf, size_t size)
+{
 	fibril_mutex_lock(&cwd_mutex);
 	
 	if ((cwd_size == 0) || (size < cwd_size + 1)) {
 		fibril_mutex_unlock(&cwd_mutex);
-		errno = ERANGE;
-		return NULL;
+		return ERANGE;
 	}
 	
@@ -866,5 +857,5 @@
 	fibril_mutex_unlock(&cwd_mutex);
 	
-	return buf;
+	return EOK;
 }
 
Index: uspace/lib/c/include/unistd.h
===================================================================
--- uspace/lib/c/include/unistd.h	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/c/include/unistd.h	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -58,7 +58,4 @@
 #define getpagesize()  (PAGE_SIZE)
 
-extern char *getcwd(char *, size_t);
-extern int chdir(const char *);
-
 extern void exit(int) __attribute__((noreturn));
 extern int usleep(useconds_t);
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/c/include/vfs/vfs.h	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -74,4 +74,6 @@
 
 extern char *vfs_absolutize(const char *, size_t *);
+extern int vfs_cwd_set(const char *path);
+extern int vfs_cwd_get(char *path, size_t);
 
 extern int vfs_fhandle(FILE *, int *);
Index: uspace/lib/posix/source/unistd.c
===================================================================
--- uspace/lib/posix/source/unistd.c	(revision 1e2e579533f6448e05e8644a674457f8a81b25ec)
+++ uspace/lib/posix/source/unistd.c	(revision d96d9bc5bc83bd59f4423a29c4c4ee459b2c9b44)
@@ -108,12 +108,8 @@
 char *posix_getcwd(char *buf, size_t size)
 {
-	char *p = getcwd(buf, size);
-
-	if (p == NULL) {
-		errno = -errno;
+	int rc = rcerrno(vfs_cwd_get, buf, size);
+	if (rc != EOK) 
 		return NULL;
-	}
-
-	return p;
+	return buf;
 }
 
@@ -125,5 +121,8 @@
 int posix_chdir(const char *path)
 {
-	return negerrno(chdir, path);
+	int rc = rcerrno(vfs_cwd_set, path);
+	if (rc != EOK)
+		return -1;
+	return 0;
 }
 
