Index: uspace/lib/bithenge/src/file.c
===================================================================
--- uspace/lib/bithenge/src/file.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/bithenge/src/file.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -77,6 +77,7 @@
 		return ELIMIT;
 
-	ssize_t amount_read = vfs_read(blob->fd, &offset, buffer, *size);
-	if (amount_read < 0)
+	size_t amount_read;
+	int rc = vfs_read(blob->fd, &offset, buffer, *size, &amount_read);
+	if (rc != EOK)
 		return errno;
 	*size += amount_read;
@@ -144,7 +145,8 @@
 	assert(filename);
 
-	int fd = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ);
-	if (fd < 0)
-		return errno;
+	int fd;
+	int rc = vfs_lookup_open(filename, WALK_REGULAR, MODE_READ, &fd);
+	if (rc != EOK)
+		return rc;
 
 	return new_file_blob(out, fd, true);
Index: uspace/lib/block/block.c
===================================================================
--- uspace/lib/block/block.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/block/block.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -49,7 +49,8 @@
 #include <macros.h>
 #include <mem.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <stacktrace.h>
+#include <str_error.h>
 #include <offset.h>
 #include <inttypes.h>
@@ -380,5 +381,5 @@
  *				device.
  *
- * @return			EOK on success or a negative error code.
+ * @return			EOK on success or an error code.
  */
 int block_get(block_t **block, service_id_t service_id, aoff64_t ba, int flags)
@@ -577,5 +578,5 @@
  * @param block		Block of which a reference is to be released.
  *
- * @return		EOK on success or a negative error code.
+ * @return		EOK on success or an error code.
  */
 int block_put(block_t *block)
@@ -698,5 +699,5 @@
  * @param block_size	Block size to be used for the transfer.
  *
- * @return		EOK on success or a negative return code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_seqread(service_id_t service_id, void *buf, size_t *bufpos,
@@ -757,5 +758,5 @@
  * @param src		Buffer for storing the data.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_read_direct(service_id_t service_id, aoff64_t ba, size_t cnt, void *buf)
@@ -776,5 +777,5 @@
  * @param src		The data to be written.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_write_direct(service_id_t service_id, aoff64_t ba, size_t cnt,
@@ -795,5 +796,5 @@
  * @param cnt		Number of blocks.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_sync_cache(service_id_t service_id, aoff64_t ba, size_t cnt)
@@ -812,5 +813,5 @@
  * @param bsize		Output block size.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_get_bsize(service_id_t service_id, size_t *bsize)
@@ -829,5 +830,5 @@
  * @param nblocks	Output number of blocks.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_get_nblocks(service_id_t service_id, aoff64_t *nblocks)
@@ -846,5 +847,5 @@
  * @param data			Buffer that receives the data
  * 
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 int block_read_bytes_direct(service_id_t service_id, aoff64_t abs_offset,
@@ -897,5 +898,5 @@
  *
  * @return Allocated TOC structure.
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  *
  */
@@ -916,5 +917,5 @@
  * @param src		Buffer for storing the data.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 static int read_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *buf,
@@ -925,6 +926,6 @@
 	int rc = bd_read_blocks(devcon->bd, ba, cnt, buf, size);
 	if (rc != EOK) {
-		printf("Error %d reading %zu blocks starting at block %" PRIuOFF64
-		    " from device handle %" PRIun "\n", rc, cnt, ba,
+		printf("Error %s reading %zu blocks starting at block %" PRIuOFF64
+		    " from device handle %" PRIun "\n", str_error_name(rc), cnt, ba,
 		    devcon->service_id);
 #ifndef NDEBUG
@@ -943,5 +944,5 @@
  * @param src		Buffer containing the data to write.
  *
- * @return		EOK on success or negative error code on failure.
+ * @return		EOK on success or an error code on failure.
  */
 static int write_blocks(devcon_t *devcon, aoff64_t ba, size_t cnt, void *data,
@@ -952,6 +953,6 @@
 	int rc = bd_write_blocks(devcon->bd, ba, cnt, data, size);
 	if (rc != EOK) {
-		printf("Error %d writing %zu blocks starting at block %" PRIuOFF64
-		    " to device handle %" PRIun "\n", rc, cnt, ba, devcon->service_id);
+		printf("Error %s writing %zu blocks starting at block %" PRIuOFF64
+		    " to device handle %" PRIun "\n", str_error_name(rc), cnt, ba, devcon->service_id);
 #ifndef NDEBUG
 		stacktrace_print();
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/Makefile	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -118,4 +118,5 @@
 	generic/io/kio.c \
 	generic/io/klog.c \
+	generic/io/serial.c \
 	generic/io/snprintf.c \
 	generic/io/vprintf.c \
@@ -142,4 +143,5 @@
 	generic/getopt.c \
 	generic/adt/checksum.c \
+	generic/adt/circ_buf.c \
 	generic/adt/list.c \
 	generic/adt/hash_table.c \
@@ -180,4 +182,5 @@
 
 TEST_SOURCES = \
+	test/adt/circ_buf.c \
 	test/fibril/timer.c \
 	test/main.c \
Index: uspace/lib/c/arch/arm32/include/libarch/atomic.h
===================================================================
--- uspace/lib/c/arch/arm32/include/libarch/atomic.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/arch/arm32/include/libarch/atomic.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -82,5 +82,5 @@
 	ras_page[1] = 0xffffffff;
 	
-	return (bool) ret;
+	return ret != 0;
 }
 
Index: uspace/lib/c/arch/ia64/src/tls.c
===================================================================
--- uspace/lib/c/arch/ia64/src/tls.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/arch/ia64/src/tls.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,4 @@
 
 #include <tls.h>
-#include <malloc.h>
 
 tcb_t *tls_alloc_arch(void **data, size_t size)
Index: uspace/lib/c/generic/adt/circ_buf.c
===================================================================
--- uspace/lib/c/generic/adt/circ_buf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
+++ uspace/lib/c/generic/adt/circ_buf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -0,0 +1,113 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * 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 Circular buffer
+ */
+
+#include <adt/circ_buf.h>
+#include <errno.h>
+#include <mem.h>
+#include <stddef.h>
+
+/** Initialize circular buffer.
+ *
+ * @param cbuf Circular buffer
+ * @param buf Buffer for storing data
+ * @param nmemb Number of entries in @a buf
+ * @param size Size of individual buffer entry
+ */
+void circ_buf_init(circ_buf_t *cbuf, void *buf, size_t nmemb, size_t size)
+{
+	cbuf->buf = buf;
+	cbuf->nmemb = nmemb;
+	cbuf->size = size;
+	cbuf->rp = 0;
+	cbuf->wp = 0;
+	cbuf->nused = 0;
+}
+
+/** Return number of free buffer entries.
+ *
+ * @param cbuf Circular buffer
+ * @return Number of free buffer entries
+ */
+size_t circ_buf_nfree(circ_buf_t *cbuf)
+{
+	return cbuf->nmemb - cbuf->nused;
+}
+
+/** Return number of used buffer entries.
+ *
+ * @param cbuf Circular buffer
+ * @return Number of used buffer entries
+ */
+size_t circ_buf_nused(circ_buf_t *cbuf)
+{
+	return cbuf->nused;
+}
+
+/** Push new entry into circular buffer.
+ *
+ * @param cbuf Circular buffer
+ * @param data Pointer to entry data
+ * @return EOK on success, EAGAIN if circular buffer is full
+ */
+int circ_buf_push(circ_buf_t *cbuf, const void *data)
+{
+	if (circ_buf_nfree(cbuf) == 0)
+		return EAGAIN;
+
+	memcpy(cbuf->buf + cbuf->size * cbuf->wp, data, cbuf->size);
+	cbuf->wp = (cbuf->wp + 1) % cbuf->nmemb;
+	cbuf->nused++;
+	return EOK;
+}
+
+/** Pop entry from circular buffer.
+ *
+ * @param cbuf Circular buffer
+ * @param datab Pointer to data buffer for storing entry
+ * @return EOK on success, EAGAIN if circular buffer is full
+ */
+int circ_buf_pop(circ_buf_t *cbuf, void *datab)
+{
+	if (cbuf->nused == 0)
+		return EAGAIN;
+
+	memcpy(datab, cbuf->buf + cbuf->size * cbuf->rp, cbuf->size);
+	cbuf->rp = (cbuf->rp + 1) % cbuf->nmemb;
+	cbuf->nused--;
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/adt/hash_table.c
===================================================================
--- uspace/lib/c/generic/adt/hash_table.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/adt/hash_table.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -51,6 +51,6 @@
 #include <adt/hash_table.h>
 #include <adt/list.h>
-#include <malloc.h>
 #include <assert.h>
+#include <stdlib.h>
 #include <str.h>
 
Index: uspace/lib/c/generic/as.c
===================================================================
--- uspace/lib/c/generic/as.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/as.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,4 @@
 #include <stdint.h>
 #include <bitops.h>
-#include <malloc.h>
 #include "private/libc.h"
 
@@ -77,5 +76,5 @@
 int as_area_resize(void *address, size_t size, unsigned int flags)
 {
-	return __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
+	return (int) __SYSCALL3(SYS_AS_AREA_RESIZE, (sysarg_t) address,
 	    (sysarg_t) size, (sysarg_t) flags);
 }
@@ -91,5 +90,5 @@
 int as_area_destroy(void *address)
 {
-	return __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t) address);
+	return (int) __SYSCALL1(SYS_AS_AREA_DESTROY, (sysarg_t) address);
 }
 
@@ -105,5 +104,5 @@
 int as_area_change_flags(void *address, unsigned int flags)
 {
-	return __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
+	return (int) __SYSCALL2(SYS_AS_AREA_CHANGE_FLAGS, (sysarg_t) address,
 	    (sysarg_t) flags);
 }
Index: uspace/lib/c/generic/async.c
===================================================================
--- uspace/lib/c/generic/async.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/async.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -77,17 +77,17 @@
  *   }
  *
- *   port_handler(icallid, *icall)
+ *   port_handler(ichandle, *icall)
  *   {
  *     if (want_refuse) {
- *       async_answer_0(icallid, ELIMIT);
+ *       async_answer_0(ichandle, ELIMIT);
  *       return;
  *     }
- *     async_answer_0(icallid, EOK);
- *
- *     callid = async_get_call(&call);
- *     somehow_handle_the_call(callid, call);
- *     async_answer_2(callid, 1, 2, 3);
- *
- *     callid = async_get_call(&call);
+ *     async_answer_0(ichandle, EOK);
+ *
+ *     chandle = async_get_call(&call);
+ *     somehow_handle_the_call(chandle, call);
+ *     async_answer_2(chandle, 1, 2, 3);
+ *
+ *     chandle = async_get_call(&call);
  *     ...
  *   }
@@ -113,5 +113,5 @@
 #include <libarch/barrier.h>
 #include <stdbool.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <mem.h>
 #include <stdlib.h>
@@ -185,5 +185,5 @@
 	link_t link;
 	
-	ipc_callid_t callid;
+	cap_handle_t chandle;
 	ipc_call_t call;
 } msg_t;
@@ -205,5 +205,5 @@
 	ipc_call_t *dataptr;
 	
-	sysarg_t retval;
+	int retval;
 } amsg_t;
 
@@ -237,5 +237,5 @@
 	
 	/** Identification of the opening call. */
-	ipc_callid_t callid;
+	cap_handle_t chandle;
 	
 	/** Call data of the opening call. */
@@ -243,5 +243,5 @@
 	
 	/** Identification of the closing call. */
-	ipc_callid_t close_callid;
+	cap_handle_t close_chandle;
 	
 	/** Fibril function that will be used to handle the connection. */
@@ -332,5 +332,5 @@
 		msg->destroyed = false;
 		msg->dataptr = NULL;
-		msg->retval = (sysarg_t) EINVAL;
+		msg->retval = EINVAL;
 		awaiter_initialize(&msg->wdata);
 	}
@@ -374,16 +374,16 @@
 /** Default fallback fibril function.
  *
- * This fallback fibril function gets called on incomming
- * connections that do not have a specific handler defined.
- *
- * @param callid Hash of the incoming call.
- * @param call   Data of the incoming call.
- * @param arg    Local argument
- *
- */
-static void default_fallback_port_handler(ipc_callid_t callid, ipc_call_t *call,
-    void *arg)
-{
-	ipc_answer_0(callid, ENOENT);
+ * This fallback fibril function gets called on incomming connections that do
+ * not have a specific handler defined.
+ *
+ * @param chandle  Handle of the incoming call.
+ * @param call     Data of the incoming call.
+ * @param arg      Local argument
+ *
+ */
+static void default_fallback_port_handler(cap_handle_t chandle,
+    ipc_call_t *call, void *arg)
+{
+	ipc_answer_0(chandle, ENOENT);
 }
 
@@ -715,5 +715,5 @@
 	client_t *client = async_client_get(fibril_connection->in_task_id, true);
 	if (!client) {
-		ipc_answer_0(fibril_connection->callid, ENOMEM);
+		ipc_answer_0(fibril_connection->chandle, ENOMEM);
 		return 0;
 	}
@@ -724,5 +724,5 @@
 	 * Call the connection handler function.
 	 */
-	fibril_connection->handler(fibril_connection->callid,
+	fibril_connection->handler(fibril_connection->chandle,
 	    &fibril_connection->call, fibril_connection->data);
 	
@@ -751,5 +751,5 @@
 		
 		list_remove(&msg->link);
-		ipc_answer_0(msg->callid, EHANGUP);
+		ipc_answer_0(msg->chandle, EHANGUP);
 		free(msg);
 	}
@@ -759,38 +759,38 @@
 	 * i.e. IPC_M_PHONE_HUNGUP.
 	 */
-	if (fibril_connection->close_callid)
-		ipc_answer_0(fibril_connection->close_callid, EOK);
+	if (fibril_connection->close_chandle)
+		ipc_answer_0(fibril_connection->close_chandle, EOK);
 	
 	free(fibril_connection);
-	return 0;
+	return EOK;
 }
 
 /** Create a new fibril for a new connection.
  *
- * Create new fibril for connection, fill in connection structures
- * and insert it into the hash table, so that later we can easily
- * do routing of messages to particular fibrils.
- *
- * @param in_task_id    Identification of the incoming connection.
- * @param in_phone_hash Identification of the incoming connection.
- * @param callid        Hash of the opening IPC_M_CONNECT_ME_TO call.
- *                      If callid is zero, the connection was opened by
- *                      accepting the IPC_M_CONNECT_TO_ME call and this
- *                      function is called directly by the server.
- * @param call          Call data of the opening call.
- * @param handler       Connection handler.
- * @param data          Client argument to pass to the connection handler.
- *
- * @return New fibril id or NULL on failure.
+ * Create new fibril for connection, fill in connection structures and insert it
+ * into the hash table, so that later we can easily do routing of messages to
+ * particular fibrils.
+ *
+ * @param in_task_id     Identification of the incoming connection.
+ * @param in_phone_hash  Identification of the incoming connection.
+ * @param chandle        Handle of the opening IPC_M_CONNECT_ME_TO call.
+ *                       If chandle is CAP_NIL, the connection was opened by
+ *                       accepting the IPC_M_CONNECT_TO_ME call and this
+ *                       function is called directly by the server.
+ * @param call           Call data of the opening call.
+ * @param handler        Connection handler.
+ * @param data           Client argument to pass to the connection handler.
+ *
+ * @return  New fibril id or NULL on failure.
  *
  */
 static fid_t async_new_connection(task_id_t in_task_id, sysarg_t in_phone_hash,
-    ipc_callid_t callid, ipc_call_t *call, async_port_handler_t handler,
+    cap_handle_t chandle, ipc_call_t *call, async_port_handler_t handler,
     void *data)
 {
 	connection_t *conn = malloc(sizeof(*conn));
 	if (!conn) {
-		if (callid)
-			ipc_answer_0(callid, ENOMEM);
+		if (chandle != CAP_NIL)
+			ipc_answer_0(chandle, ENOMEM);
 		
 		return (uintptr_t) NULL;
@@ -800,6 +800,6 @@
 	conn->in_phone_hash = in_phone_hash;
 	list_initialize(&conn->msg_queue);
-	conn->callid = callid;
-	conn->close_callid = 0;
+	conn->chandle = chandle;
+	conn->close_chandle = CAP_NIL;
 	conn->handler = handler;
 	conn->data = data;
@@ -815,6 +815,6 @@
 		free(conn);
 		
-		if (callid)
-			ipc_answer_0(callid, ENOMEM);
+		if (chandle != CAP_NIL)
+			ipc_answer_0(chandle, ENOMEM);
 		
 		return (uintptr_t) NULL;
@@ -844,5 +844,5 @@
  * @param port_id ID of the newly created port.
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -860,5 +860,5 @@
 	    &answer);
 	
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 	if (ret != EOK)
@@ -892,5 +892,5 @@
 	
 	fid_t fid = async_new_connection(answer.in_task_id, phone_hash,
-	    0, NULL, handler, data);
+	    CAP_NIL, NULL, handler, data);
 	if (fid == (uintptr_t) NULL)
 		return ENOMEM;
@@ -961,6 +961,6 @@
  * timeouts are unregistered.
  *
- * @param callid Hash of the incoming call.
- * @param call   Data of the incoming call.
+ * @param chandle  Handle of the incoming call.
+ * @param call     Data of the incoming call.
  *
  * @return False if the call doesn't match any connection.
@@ -968,5 +968,5 @@
  *
  */
-static bool route_call(ipc_callid_t callid, ipc_call_t *call)
+static bool route_call(cap_handle_t chandle, ipc_call_t *call)
 {
 	assert(call);
@@ -991,10 +991,10 @@
 	}
 	
-	msg->callid = callid;
+	msg->chandle = chandle;
 	msg->call = *call;
 	list_append(&msg->link, &conn->msg_queue);
 	
 	if (IPC_GET_IMETHOD(*call) == IPC_M_PHONE_HUNGUP)
-		conn->close_callid = callid;
+		conn->close_chandle = chandle;
 	
 	/* If the connection fibril is waiting for an event, activate it */
@@ -1017,9 +1017,8 @@
 /** Process notification.
  *
- * @param callid Hash of the incoming call.
  * @param call   Data of the incoming call.
  *
  */
-static void process_notification(ipc_callid_t callid, ipc_call_t *call)
+static void process_notification(ipc_call_t *call)
 {
 	async_notification_handler_t handler = NULL;
@@ -1042,5 +1041,5 @@
 	
 	if (handler)
-		handler(callid, call, data);
+		handler(call, data);
 }
 
@@ -1052,10 +1051,11 @@
  * @param ucode   Top-half pseudocode handler.
  *
- * @return IRQ capability handle on success.
- * @return Negative error code.
+ * @param[out] handle  IRQ capability handle on success.
+ *
+ * @return An error code.
  *
  */
 int async_irq_subscribe(int inr, async_notification_handler_t handler,
-    void *data, const irq_code_t *ucode)
+    void *data, const irq_code_t *ucode, cap_handle_t *handle)
 {
 	notification_t *notification =
@@ -1077,5 +1077,10 @@
 	futex_up(&async_futex);
 	
-	return ipc_irq_subscribe(inr, imethod, ucode);
+	cap_handle_t cap;
+	int rc = ipc_irq_subscribe(inr, imethod, ucode, &cap);
+	if (rc == EOK && handle != NULL) {
+		*handle = cap;
+	}
+	return rc;
 }
 
@@ -1084,5 +1089,5 @@
  * @param cap     IRQ capability handle. 
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -1101,5 +1106,5 @@
  * @param data    Notification handler client data.
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -1134,5 +1139,5 @@
  * @param data    Notification handler client data.
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -1187,15 +1192,13 @@
 /** Return new incoming message for the current (fibril-local) connection.
  *
- * @param call  Storage where the incoming call data will be stored.
- * @param usecs Timeout in microseconds. Zero denotes no timeout.
- *
- * @return If no timeout was specified, then a hash of the
- *         incoming call is returned. If a timeout is specified,
- *         then a hash of the incoming call is returned unless
- *         the timeout expires prior to receiving a message. In
- *         that case zero is returned.
- *
- */
-ipc_callid_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
+ * @param call   Storage where the incoming call data will be stored.
+ * @param usecs  Timeout in microseconds. Zero denotes no timeout.
+ *
+ * @return  If no timeout was specified, then a handle of the incoming call is
+ *          returned. If a timeout is specified, then a handle of the incoming
+ *          call is returned unless the timeout expires prior to receiving a
+ *          message. In that case zero CAP_NIL is returned.
+ */
+cap_handle_t async_get_call_timeout(ipc_call_t *call, suseconds_t usecs)
 {
 	assert(call);
@@ -1220,5 +1223,5 @@
 	/* If nothing in queue, wait until something arrives */
 	while (list_empty(&conn->msg_queue)) {
-		if (conn->close_callid) {
+		if (conn->close_chandle) {
 			/*
 			 * Handle the case when the connection was already
@@ -1231,5 +1234,5 @@
 			IPC_SET_IMETHOD(*call, IPC_M_PHONE_HUNGUP);
 			futex_up(&async_futex);
-			return conn->close_callid;
+			return conn->close_chandle;
 		}
 		
@@ -1256,5 +1259,5 @@
 			/* If we timed out -> exit */
 			futex_up(&async_futex);
-			return 0;
+			return CAP_NIL;
 		}
 	}
@@ -1264,10 +1267,10 @@
 	list_remove(&msg->link);
 	
-	ipc_callid_t callid = msg->callid;
+	cap_handle_t chandle = msg->chandle;
 	*call = msg->call;
 	free(msg);
 	
 	futex_up(&async_futex);
-	return callid;
+	return chandle;
 }
 
@@ -1332,18 +1335,18 @@
  * Otherwise the call is routed to its connection fibril.
  *
- * @param callid Hash of the incoming call.
- * @param call   Data of the incoming call.
- *
- */
-static void handle_call(ipc_callid_t callid, ipc_call_t *call)
+ * @param chandle  Handle of the incoming call.
+ * @param call     Data of the incoming call.
+ *
+ */
+static void handle_call(cap_handle_t chandle, ipc_call_t *call)
 {
 	assert(call);
 	
 	/* Kernel notification */
-	if ((callid & IPC_CALLID_NOTIFICATION)) {
+	if ((chandle == CAP_NIL) && (call->flags & IPC_CALL_NOTIF)) {
 		fibril_t *fibril = (fibril_t *) __tcb_get()->fibril_data;
 		unsigned oldsw = fibril->switches;
 		
-		process_notification(callid, call);
+		process_notification(call);
 		
 		if (oldsw != fibril->switches) {
@@ -1371,5 +1374,5 @@
 		sysarg_t in_phone_hash = IPC_GET_ARG5(*call);
 		
-		async_notification_handler_t handler = fallback_port_handler;
+		async_port_handler_t handler = fallback_port_handler;
 		void *data = fallback_port_data;
 		
@@ -1381,5 +1384,5 @@
 		}
 		
-		async_new_connection(call->in_task_id, in_phone_hash, callid,
+		async_new_connection(call->in_task_id, in_phone_hash, chandle,
 		    call, handler, data);
 		return;
@@ -1387,9 +1390,9 @@
 	
 	/* Try to route the call through the connection hash table */
-	if (route_call(callid, call))
+	if (route_call(chandle, call))
 		return;
 	
 	/* Unknown call from unknown phone - hang it up */
-	ipc_answer_0(callid, EHANGUP);
+	ipc_answer_0(chandle, EHANGUP);
 }
 
@@ -1486,19 +1489,25 @@
 		
 		ipc_call_t call;
-		ipc_callid_t callid = ipc_wait_cycle(&call, timeout, flags);
+		int rc = ipc_wait_cycle(&call, timeout, flags);
 		
 		atomic_dec(&threads_in_ipc_wait);
 		
-		if (!callid) {
-			handle_expired_timeouts();
+		assert(rc == EOK);
+
+		if (call.cap_handle == CAP_NIL) {
+			if ((call.flags &
+			    (IPC_CALL_NOTIF | IPC_CALL_ANSWERED)) == 0) {
+				/* Neither a notification nor an answer. */
+				handle_expired_timeouts();
+				continue;
+			}
+		}
+
+		if (call.flags & IPC_CALL_ANSWERED)
 			continue;
-		}
-		
-		if (callid & IPC_CALLID_ANSWERED)
-			continue;
-		
-		handle_call(callid, &call);
-	}
-	
+
+		handle_call(call.cap_handle, &call);
+	}
+
 	return 0;
 }
@@ -1631,6 +1640,5 @@
  * @param arg3    Service-defined payload argument.
  * @param arg4    Service-defined payload argument.
- * @param dataptr If non-NULL, storage where the reply data will be
- *                stored.
+ * @param dataptr If non-NULL, storage where the reply data will be stored.
  *
  * @return Hash of the sent message or 0 on error.
@@ -1701,5 +1709,5 @@
  *
  */
-void async_wait_for(aid_t amsgid, sysarg_t *retval)
+void async_wait_for(aid_t amsgid, int *retval)
 {
 	assert(amsgid);
@@ -1747,5 +1755,5 @@
  *
  */
-int async_wait_timeout(aid_t amsgid, sysarg_t *retval, suseconds_t timeout)
+int async_wait_timeout(aid_t amsgid, int *retval, suseconds_t timeout)
 {
 	assert(amsgid);
@@ -1848,16 +1856,15 @@
 void async_usleep(suseconds_t timeout)
 {
-	amsg_t *msg = amsg_create();
-	if (!msg)
-		return;
-	
-	msg->wdata.fid = fibril_get_id();
-	
-	getuptime(&msg->wdata.to_event.expires);
-	tv_add_diff(&msg->wdata.to_event.expires, timeout);
+	awaiter_t awaiter;
+	awaiter_initialize(&awaiter);
+	
+	awaiter.fid = fibril_get_id();
+	
+	getuptime(&awaiter.to_event.expires);
+	tv_add_diff(&awaiter.to_event.expires, timeout);
 	
 	futex_down(&async_futex);
 	
-	async_insert_timeout(&msg->wdata);
+	async_insert_timeout(&awaiter);
 	
 	/* Leave the async_futex locked when entering this function */
@@ -1865,6 +1872,23 @@
 	
 	/* Futex is up automatically after fibril_switch() */
-	
-	amsg_destroy(msg);
+}
+
+/** Delay execution for the specified number of seconds
+ *
+ * @param sec Number of seconds to sleep
+ */
+void async_sleep(unsigned int sec)
+{
+	/*
+	 * Sleep in 1000 second steps to support
+	 * full argument range
+	 */
+
+	while (sec > 0) {
+		unsigned int period = (sec > 1000) ? 1000 : sec;
+
+		async_usleep(period * 1000000);
+		sec -= period;
+	}
 }
 
@@ -1888,8 +1912,8 @@
  * @param r5      If non-NULL, storage for the 5th reply argument.
  *
- * @return Return code of the reply or a negative error code.
- *
- */
-sysarg_t async_req_fast(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
+ * @return Return code of the reply or an error code.
+ *
+ */
+int async_req_fast(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t *r1, sysarg_t *r2,
     sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
@@ -1902,5 +1926,5 @@
 	    &result);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(aid, &rc);
 	
@@ -1940,8 +1964,8 @@
  * @param r5      If non-NULL, storage for the 5th reply argument.
  *
- * @return Return code of the reply or a negative error code.
- *
- */
-sysarg_t async_req_slow(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
+ * @return Return code of the reply or an error code.
+ *
+ */
+int async_req_slow(async_exch_t *exch, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, sysarg_t *r1,
     sysarg_t *r2, sysarg_t *r3, sysarg_t *r4, sysarg_t *r5)
@@ -1954,5 +1978,5 @@
 	    &result);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(aid, &rc);
 	
@@ -2018,39 +2042,39 @@
 }
 
-sysarg_t async_answer_0(ipc_callid_t callid, sysarg_t retval)
-{
-	return ipc_answer_0(callid, retval);
-}
-
-sysarg_t async_answer_1(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1)
-{
-	return ipc_answer_1(callid, retval, arg1);
-}
-
-sysarg_t async_answer_2(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+int async_answer_0(cap_handle_t chandle, int retval)
+{
+	return ipc_answer_0(chandle, retval);
+}
+
+int async_answer_1(cap_handle_t chandle, int retval, sysarg_t arg1)
+{
+	return ipc_answer_1(chandle, retval, arg1);
+}
+
+int async_answer_2(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2)
 {
-	return ipc_answer_2(callid, retval, arg1, arg2);
-}
-
-sysarg_t async_answer_3(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+	return ipc_answer_2(chandle, retval, arg1, arg2);
+}
+
+int async_answer_3(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3)
 {
-	return ipc_answer_3(callid, retval, arg1, arg2, arg3);
-}
-
-sysarg_t async_answer_4(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+	return ipc_answer_3(chandle, retval, arg1, arg2, arg3);
+}
+
+int async_answer_4(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
 {
-	return ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4);
-}
-
-sysarg_t async_answer_5(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+	return ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4);
+}
+
+int async_answer_5(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
 {
-	return ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5);
-}
-
-int async_forward_fast(ipc_callid_t callid, async_exch_t *exch,
+	return ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5);
+}
+
+int async_forward_fast(cap_handle_t chandle, async_exch_t *exch,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
 {
@@ -2058,8 +2082,8 @@
 		return ENOENT;
 	
-	return ipc_forward_fast(callid, exch->phone, imethod, arg1, arg2, mode);
-}
-
-int async_forward_slow(ipc_callid_t callid, async_exch_t *exch,
+	return ipc_forward_fast(chandle, exch->phone, imethod, arg1, arg2, mode);
+}
+
+int async_forward_slow(cap_handle_t chandle, async_exch_t *exch,
     sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
     sysarg_t arg4, sysarg_t arg5, unsigned int mode)
@@ -2068,5 +2092,5 @@
 		return ENOENT;
 	
-	return ipc_forward_slow(callid, exch->phone, imethod, arg1, arg2, arg3,
+	return ipc_forward_slow(chandle, exch->phone, imethod, arg1, arg2, arg3,
 	    arg4, arg5, mode);
 }
@@ -2081,5 +2105,5 @@
  * @param arg3            User defined argument.
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -2094,5 +2118,5 @@
 	    &answer);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(req, &rc);
 	if (rc != EOK)
@@ -2103,7 +2127,11 @@
 
 static int async_connect_me_to_internal(int phone, sysarg_t arg1, sysarg_t arg2,
-    sysarg_t arg3, sysarg_t arg4)
+    sysarg_t arg3, sysarg_t arg4, int *out_phone)
 {
 	ipc_call_t result;
+	
+	// XXX: Workaround for GCC's inability to infer association between
+	// rc == EOK and *out_phone being assigned.
+	*out_phone = -1;
 	
 	amsg_t *msg = amsg_create();
@@ -2117,5 +2145,5 @@
 	    msg, reply_received);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for((aid_t) msg, &rc);
 	
@@ -2123,5 +2151,6 @@
 		return rc;
 	
-	return (int) IPC_GET_ARG5(result);
+	*out_phone = (int) IPC_GET_ARG5(result);
+	return EOK;
 }
 
@@ -2153,8 +2182,9 @@
 	}
 	
-	int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
-	    0);
-	if (phone < 0) {
-		errno = phone;
+	int phone;
+	int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
+	    0, &phone);
+	if (rc != EOK) {
+		errno = rc;
 		free(sess);
 		return NULL;
@@ -2205,8 +2235,9 @@
 	}
 	
-	int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
-	    arg3, 0);
-	if (phone < 0) {
-		errno = phone;
+	int phone;
+	int rc = async_connect_me_to_internal(exch->phone, iface, arg2,
+	    arg3, 0, &phone);
+	if (rc != EOK) {
+		errno = rc;
 		free(sess);
 		return NULL;
@@ -2275,9 +2306,10 @@
 	}
 	
-	int phone = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
-	    IPC_FLAG_BLOCKING);
-	
-	if (phone < 0) {
-		errno = phone;
+	int phone;
+	int rc = async_connect_me_to_internal(exch->phone, arg1, arg2, arg3,
+	    IPC_FLAG_BLOCKING, &phone);
+	
+	if (rc != EOK) {
+		errno = rc;
 		free(sess);
 		return NULL;
@@ -2328,8 +2360,9 @@
 	}
 	
-	int phone = async_connect_me_to_internal(exch->phone, iface, arg2,
-	    arg3, IPC_FLAG_BLOCKING);
-	if (phone < 0) {
-		errno = phone;
+	int phone;
+	int rc = async_connect_me_to_internal(exch->phone, iface, arg2,
+	    arg3, IPC_FLAG_BLOCKING, &phone);
+	if (rc != EOK) {
+		errno = rc;
 		free(sess);
 		return NULL;
@@ -2363,7 +2396,8 @@
 	}
 	
-	int phone = ipc_connect_kbox(id);
-	if (phone < 0) {
-		errno = phone;
+	cap_handle_t phone;
+	int rc = ipc_connect_kbox(id, &phone);
+	if (rc != EOK) {
+		errno = rc;
 		free(sess);
 		return NULL;
@@ -2396,5 +2430,5 @@
  * @param sess Session to hung up.
  *
- * @return Zero on success or a negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -2482,4 +2516,5 @@
 		} else if (mgmt == EXCHANGE_PARALLEL) {
 			int phone;
+			int rc;
 			
 		retry:
@@ -2487,7 +2522,7 @@
 			 * Make a one-time attempt to connect a new data phone.
 			 */
-			phone = async_connect_me_to_internal(sess->phone, sess->arg1,
-			    sess->arg2, sess->arg3, 0);
-			if (phone >= 0) {
+			rc = async_connect_me_to_internal(sess->phone, sess->arg1,
+			    sess->arg2, sess->arg3, 0, &phone);
+			if (rc == EOK) {
 				exch = (async_exch_t *) malloc(sizeof(async_exch_t));
 				if (exch != NULL) {
@@ -2575,5 +2610,5 @@
  *              base address. Cannot be NULL.
  *
- * @return Zero on success or a negative error code from errno.h.
+ * @return Zero on success or an error code from errno.h.
  *
  */
@@ -2604,17 +2639,17 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_SHARE_IN call.
- * @param size   Destination address space area size.
+ * @param chandle  Storage for the handle of the IPC_M_SHARE_IN call.
+ * @param size     Destination address space area size.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_share_in_receive(ipc_callid_t *callid, size_t *size)
-{
-	assert(callid);
+bool async_share_in_receive(cap_handle_t *chandle, size_t *size)
+{
+	assert(chandle);
 	assert(size);
 	
 	ipc_call_t data;
-	*callid = async_get_call(&data);
+	*chandle = async_get_call(&data);
 	
 	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_IN)
@@ -2631,14 +2666,14 @@
  * argument.
  *
- * @param callid Hash of the IPC_M_DATA_READ call to answer.
- * @param src    Source address space base.
- * @param flags  Flags to be used for sharing. Bits can be only cleared.
+ * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
+ * @param src      Source address space base.
+ * @param flags    Flags to be used for sharing. Bits can be only cleared.
  *
  * @return Zero on success or a value from @ref errno.h on failure.
  *
  */
-int async_share_in_finalize(ipc_callid_t callid, void *src, unsigned int flags)
-{
-	return ipc_answer_3(callid, EOK, (sysarg_t) src, (sysarg_t) flags,
+int async_share_in_finalize(cap_handle_t chandle, void *src, unsigned int flags)
+{
+	return ipc_answer_3(chandle, EOK, (sysarg_t) src, (sysarg_t) flags,
 	    (sysarg_t) __entry);
 }
@@ -2650,5 +2685,5 @@
  * @param flags Flags to be used for sharing. Bits can be only cleared.
  *
- * @return Zero on success or a negative error code from errno.h.
+ * @return Zero on success or an error code from errno.h.
  *
  */
@@ -2670,19 +2705,20 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_SHARE_OUT call.
- * @param size   Storage for the source address space area size.
- * @param flags  Storage for the sharing flags.
+ * @param chandle  Storage for the hash of the IPC_M_SHARE_OUT call.
+ * @param size     Storage for the source address space area size.
+ * @param flags    Storage for the sharing flags.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_share_out_receive(ipc_callid_t *callid, size_t *size, unsigned int *flags)
-{
-	assert(callid);
+bool async_share_out_receive(cap_handle_t *chandle, size_t *size,
+    unsigned int *flags)
+{
+	assert(chandle);
 	assert(size);
 	assert(flags);
 	
 	ipc_call_t data;
-	*callid = async_get_call(&data);
+	*chandle = async_get_call(&data);
 	
 	if (IPC_GET_IMETHOD(data) != IPC_M_SHARE_OUT)
@@ -2700,14 +2736,14 @@
  * argument.
  *
- * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
- * @param dst    Address of the storage for the destination address space area
- *               base address.
- *
- * @return Zero on success or a value from @ref errno.h on failure.
- *
- */
-int async_share_out_finalize(ipc_callid_t callid, void **dst)
-{
-	return ipc_answer_2(callid, EOK, (sysarg_t) __entry, (sysarg_t) dst);
+ * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
+ * @param dst      Address of the storage for the destination address space area
+ *                 base address.
+ *
+ * @return  Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int async_share_out_finalize(cap_handle_t chandle, void **dst)
+{
+	return ipc_answer_2(chandle, EOK, (sysarg_t) __entry, (sysarg_t) dst);
 }
 
@@ -2735,5 +2771,5 @@
  * @param size Size of the destination buffer.
  *
- * @return Zero on success or a negative error code from errno.h.
+ * @return Zero on success or an error code from errno.h.
  *
  */
@@ -2755,14 +2791,14 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_DATA_READ.
- * @param size   Storage for the maximum size. Can be NULL.
+ * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
+ * @param size     Storage for the maximum size. Can be NULL.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_data_read_receive(ipc_callid_t *callid, size_t *size)
+bool async_data_read_receive(cap_handle_t *chandle, size_t *size)
 {
 	ipc_call_t data;
-	return async_data_read_receive_call(callid, &data, size);
+	return async_data_read_receive_call(chandle, &data, size);
 }
 
@@ -2775,17 +2811,17 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_DATA_READ.
- * @param size   Storage for the maximum size. Can be NULL.
+ * @param chandle  Storage for the handle of the IPC_M_DATA_READ.
+ * @param size     Storage for the maximum size. Can be NULL.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_data_read_receive_call(ipc_callid_t *callid, ipc_call_t *data,
+bool async_data_read_receive_call(cap_handle_t *chandle, ipc_call_t *data,
     size_t *size)
 {
-	assert(callid);
+	assert(chandle);
 	assert(data);
 	
-	*callid = async_get_call(data);
+	*chandle = async_get_call(data);
 	
 	if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_READ)
@@ -2804,15 +2840,15 @@
  * argument.
  *
- * @param callid Hash of the IPC_M_DATA_READ call to answer.
- * @param src    Source address for the IPC_M_DATA_READ call.
- * @param size   Size for the IPC_M_DATA_READ call. Can be smaller than
- *               the maximum size announced by the sender.
- *
- * @return Zero on success or a value from @ref errno.h on failure.
- *
- */
-int async_data_read_finalize(ipc_callid_t callid, const void *src, size_t size)
-{
-	return ipc_answer_2(callid, EOK, (sysarg_t) src, (sysarg_t) size);
+ * @param chandle  Handle of the IPC_M_DATA_READ call to answer.
+ * @param src      Source address for the IPC_M_DATA_READ call.
+ * @param size     Size for the IPC_M_DATA_READ call. Can be smaller than
+ *                 the maximum size announced by the sender.
+ *
+ * @return  Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int async_data_read_finalize(cap_handle_t chandle, const void *src, size_t size)
+{
+	return ipc_answer_2(chandle, EOK, (sysarg_t) src, (sysarg_t) size);
 }
 
@@ -2827,7 +2863,7 @@
 		return ENOENT;
 	
-	ipc_callid_t callid;
-	if (!async_data_read_receive(&callid, NULL)) {
-		ipc_answer_0(callid, EINVAL);
+	cap_handle_t chandle;
+	if (!async_data_read_receive(&chandle, NULL)) {
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
@@ -2836,17 +2872,17 @@
 	    dataptr);
 	if (msg == 0) {
-		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
 	
-	int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
+	int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
 	    IPC_FF_ROUTE_FROM_ME);
 	if (retval != EOK) {
 		async_forget(msg);
-		ipc_answer_0(callid, retval);
+		ipc_answer_0(chandle, retval);
 		return retval;
 	}
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(msg, &rc);
 	
@@ -2860,5 +2896,5 @@
  * @param size Size of the source buffer.
  *
- * @return Zero on success or a negative error code from errno.h.
+ * @return Zero on success or an error code from errno.h.
  *
  */
@@ -2880,14 +2916,14 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
- * @param size   Storage for the suggested size. May be NULL.
- *
- * @return True on success, false on failure.
- *
- */
-bool async_data_write_receive(ipc_callid_t *callid, size_t *size)
+ * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
+ * @param size     Storage for the suggested size. May be NULL.
+ *
+ * @return  True on success, false on failure.
+ *
+ */
+bool async_data_write_receive(cap_handle_t *chandle, size_t *size)
 {
 	ipc_call_t data;
-	return async_data_write_receive_call(callid, &data, size);
+	return async_data_write_receive_call(chandle, &data, size);
 }
 
@@ -2900,18 +2936,18 @@
  * So far, this wrapper is to be used from within a connection fibril.
  *
- * @param callid Storage for the hash of the IPC_M_DATA_WRITE.
- * @param data   Storage for the ipc call data.
- * @param size   Storage for the suggested size. May be NULL.
+ * @param chandle  Storage for the handle of the IPC_M_DATA_WRITE.
+ * @param data     Storage for the ipc call data.
+ * @param size     Storage for the suggested size. May be NULL.
  *
  * @return True on success, false on failure.
  *
  */
-bool async_data_write_receive_call(ipc_callid_t *callid, ipc_call_t *data,
+bool async_data_write_receive_call(cap_handle_t *chandle, ipc_call_t *data,
     size_t *size)
 {
-	assert(callid);
+	assert(chandle);
 	assert(data);
 	
-	*callid = async_get_call(data);
+	*chandle = async_get_call(data);
 	
 	if (IPC_GET_IMETHOD(*data) != IPC_M_DATA_WRITE)
@@ -2930,14 +2966,14 @@
  * argument.
  *
- * @param callid Hash of the IPC_M_DATA_WRITE call to answer.
- * @param dst    Final destination address for the IPC_M_DATA_WRITE call.
- * @param size   Final size for the IPC_M_DATA_WRITE call.
- *
- * @return Zero on success or a value from @ref errno.h on failure.
- *
- */
-int async_data_write_finalize(ipc_callid_t callid, void *dst, size_t size)
-{
-	return ipc_answer_2(callid, EOK, (sysarg_t) dst, (sysarg_t) size);
+ * @param chandle  Handle of the IPC_M_DATA_WRITE call to answer.
+ * @param dst      Final destination address for the IPC_M_DATA_WRITE call.
+ * @param size     Final size for the IPC_M_DATA_WRITE call.
+ *
+ * @return  Zero on success or a value from @ref errno.h on failure.
+ *
+ */
+int async_data_write_finalize(cap_handle_t chandle, void *dst, size_t size)
+{
+	return ipc_answer_2(chandle, EOK, (sysarg_t) dst, (sysarg_t) size);
 }
 
@@ -2969,23 +3005,23 @@
 	assert(data);
 	
-	ipc_callid_t callid;
+	cap_handle_t chandle;
 	size_t size;
-	if (!async_data_write_receive(&callid, &size)) {
-		ipc_answer_0(callid, EINVAL);
+	if (!async_data_write_receive(&chandle, &size)) {
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
 	
 	if (size < min_size) {
-		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
 	
 	if ((max_size > 0) && (size > max_size)) {
-		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
 	
 	if ((granularity > 0) && ((size % granularity) != 0)) {
-		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
@@ -2999,9 +3035,9 @@
 	
 	if (arg_data == NULL) {
-		ipc_answer_0(callid, ENOMEM);
+		ipc_answer_0(chandle, ENOMEM);
 		return ENOMEM;
 	}
 	
-	int rc = async_data_write_finalize(callid, arg_data, size);
+	int rc = async_data_write_finalize(chandle, arg_data, size);
 	if (rc != EOK) {
 		free(arg_data);
@@ -3026,9 +3062,9 @@
  *
  */
-void async_data_write_void(sysarg_t retval)
-{
-	ipc_callid_t callid;
-	async_data_write_receive(&callid, NULL);
-	ipc_answer_0(callid, retval);
+void async_data_write_void(int retval)
+{
+	cap_handle_t chandle;
+	async_data_write_receive(&chandle, NULL);
+	ipc_answer_0(chandle, retval);
 }
 
@@ -3043,7 +3079,7 @@
 		return ENOENT;
 	
-	ipc_callid_t callid;
-	if (!async_data_write_receive(&callid, NULL)) {
-		ipc_answer_0(callid, EINVAL);
+	cap_handle_t chandle;
+	if (!async_data_write_receive(&chandle, NULL)) {
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
@@ -3052,17 +3088,17 @@
 	    dataptr);
 	if (msg == 0) {
-		ipc_answer_0(callid, EINVAL);
+		ipc_answer_0(chandle, EINVAL);
 		return EINVAL;
 	}
 	
-	int retval = ipc_forward_fast(callid, exch->phone, 0, 0, 0,
+	int retval = ipc_forward_fast(chandle, exch->phone, 0, 0, 0,
 	    IPC_FF_ROUTE_FROM_ME);
 	if (retval != EOK) {
 		async_forget(msg);
-		ipc_answer_0(callid, retval);
+		ipc_answer_0(chandle, retval);
 		return retval;
 	}
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(msg, &rc);
 	
@@ -3085,10 +3121,9 @@
 	/* Accept the phone */
 	ipc_call_t call;
-	ipc_callid_t callid = async_get_call(&call);
-	int phone = (int) IPC_GET_ARG5(call);
-	
-	if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) ||
-	    (phone < 0)) {
-		async_answer_0(callid, EINVAL);
+	cap_handle_t chandle = async_get_call(&call);
+	cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(call);
+	
+	if ((IPC_GET_IMETHOD(call) != IPC_M_CONNECT_TO_ME) || (phandle < 0)) {
+		async_answer_0(chandle, EINVAL);
 		return NULL;
 	}
@@ -3096,5 +3131,5 @@
 	async_sess_t *sess = (async_sess_t *) malloc(sizeof(async_sess_t));
 	if (sess == NULL) {
-		async_answer_0(callid, ENOMEM);
+		async_answer_0(chandle, ENOMEM);
 		return NULL;
 	}
@@ -3102,5 +3137,5 @@
 	sess->iface = 0;
 	sess->mgmt = mgmt;
-	sess->phone = phone;
+	sess->phone = phandle;
 	sess->arg1 = 0;
 	sess->arg2 = 0;
@@ -3115,5 +3150,5 @@
 	
 	/* Acknowledge the connected phone */
-	async_answer_0(callid, EOK);
+	async_answer_0(chandle, EOK);
 	
 	return sess;
@@ -3136,8 +3171,7 @@
 async_sess_t *async_callback_receive_start(exch_mgmt_t mgmt, ipc_call_t *call)
 {
-	int phone = (int) IPC_GET_ARG5(*call);
-	
-	if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) ||
-	    (phone < 0))
+	cap_handle_t phandle = (cap_handle_t) IPC_GET_ARG5(*call);
+	
+	if ((IPC_GET_IMETHOD(*call) != IPC_M_CONNECT_TO_ME) || (phandle < 0))
 		return NULL;
 	
@@ -3148,5 +3182,5 @@
 	sess->iface = 0;
 	sess->mgmt = mgmt;
-	sess->phone = phone;
+	sess->phone = phandle;
 	sess->arg1 = 0;
 	sess->arg2 = 0;
@@ -3170,11 +3204,11 @@
 }
 
-bool async_state_change_receive(ipc_callid_t *callid, sysarg_t *arg1,
+bool async_state_change_receive(cap_handle_t *chandle, sysarg_t *arg1,
     sysarg_t *arg2, sysarg_t *arg3)
 {
-	assert(callid);
+	assert(chandle);
 	
 	ipc_call_t call;
-	*callid = async_get_call(&call);
+	*chandle = async_get_call(&call);
 	
 	if (IPC_GET_IMETHOD(call) != IPC_M_STATE_CHANGE_AUTHORIZE)
@@ -3191,7 +3225,7 @@
 }
 
-int async_state_change_finalize(ipc_callid_t callid, async_exch_t *other_exch)
-{
-	return ipc_answer_1(callid, EOK, other_exch->phone);
+int async_state_change_finalize(cap_handle_t chandle, async_exch_t *other_exch)
+{
+	return ipc_answer_1(chandle, EOK, other_exch->phone);
 }
 
Index: uspace/lib/c/generic/bd.c
===================================================================
--- uspace/lib/c/generic/bd.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/bd.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -32,5 +32,5 @@
 /**
  * @file
- * @brief IP link client stub
+ * @brief Block device client interface
  */
 
@@ -98,5 +98,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -121,5 +121,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -146,5 +146,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK)
Index: uspace/lib/c/generic/cap.c
===================================================================
--- uspace/lib/c/generic/cap.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/cap.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -178,4 +178,5 @@
 {
 	int rc;
+	int ret;
 	const char *sunit;
 	uint64_t ipart;
@@ -196,10 +197,10 @@
 	sunit = cu_str[cap->cunit];
 	if (cap->dp > 0) {
-		rc = asprintf(rstr, "%" PRIu64 ".%0*" PRIu64 " %s", ipart,
+		ret = asprintf(rstr, "%" PRIu64 ".%0*" PRIu64 " %s", ipart,
 		    (int)cap->dp, fpart, sunit);
 	} else {
-		rc = asprintf(rstr, "%" PRIu64 " %s", ipart, sunit);
-	}
-	if (rc < 0)
+		ret = asprintf(rstr, "%" PRIu64 " %s", ipart, sunit);
+	}
+	if (ret < 0)
 		return ENOMEM;
 
Index: uspace/lib/c/generic/clipboard.c
===================================================================
--- uspace/lib/c/generic/clipboard.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/clipboard.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -45,5 +45,5 @@
 #include <ipc/services.h>
 #include <loc.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <str.h>
 
@@ -95,5 +95,5 @@
  * @param str String to put to clipboard or NULL.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -104,5 +104,5 @@
 	if (size == 0) {
 		async_exch_t *exch = clip_exchange_begin();
-		sysarg_t rc = async_req_1_0(exch, CLIPBOARD_PUT_DATA,
+		int rc = async_req_1_0(exch, CLIPBOARD_PUT_DATA,
 		    CLIPBOARD_TAG_NONE);
 		clip_exchange_end(exch);
@@ -113,9 +113,9 @@
 		aid_t req = async_send_1(exch, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_DATA,
 		    NULL);
-		sysarg_t rc = async_data_write_start(exch, (void *) str, size);
+		int rc = async_data_write_start(exch, (void *) str, size);
 		clip_exchange_end(exch);
 		
 		if (rc != EOK) {
-			sysarg_t rc_orig;
+			int rc_orig;
 			async_wait_for(req, &rc_orig);
 			if (rc_orig == EOK)
@@ -137,5 +137,5 @@
  * @param str Here pointer to the newly allocated string is stored.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -148,5 +148,5 @@
 		sysarg_t size;
 		sysarg_t tag;
-		sysarg_t rc = async_req_0_2(exch, CLIPBOARD_CONTENT, &size, &tag);
+		int rc = async_req_0_2(exch, CLIPBOARD_CONTENT, &size, &tag);
 		
 		clip_exchange_end(exch);
@@ -185,5 +185,5 @@
 			
 			if (rc != EOK) {
-				sysarg_t rc_orig;
+				int rc_orig;
 				async_wait_for(req, &rc_orig);
 				if (rc_orig == EOK)
Index: uspace/lib/c/generic/ddi.c
===================================================================
--- uspace/lib/c/generic/ddi.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/ddi.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -71,5 +71,5 @@
 int physmem_map(uintptr_t phys, size_t pages, unsigned int flags, void **virt)
 {
-	return __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
+	return (int) __SYSCALL5(SYS_PHYSMEM_MAP, (sysarg_t) phys,
 	    pages, flags, (sysarg_t) virt, (sysarg_t) __entry);
 }
@@ -87,5 +87,5 @@
 int physmem_unmap(void *virt)
 {
-	return __SYSCALL1(SYS_PHYSMEM_UNMAP, (sysarg_t) virt);
+	return (int) __SYSCALL1(SYS_PHYSMEM_UNMAP, (sysarg_t) virt);
 }
 
@@ -150,10 +150,10 @@
 int dmamem_unmap(void *virt, size_t size)
 {
-	return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0);
+	return (int) __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, (sysarg_t) size, 0);
 }
 
 int dmamem_unmap_anonymous(void *virt)
 {
-	return __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
+	return (int) __SYSCALL3(SYS_DMAMEM_UNMAP, (sysarg_t) virt, 0,
 	    DMAMEM_FLAGS_ANONYMOUS);
 }
@@ -181,5 +181,5 @@
 	};
 	
-	return __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
+	return (int) __SYSCALL1(SYS_IOSPACE_ENABLE, (sysarg_t) &arg);
 }
 
@@ -205,5 +205,5 @@
 	};
 	
-	return __SYSCALL1(SYS_IOSPACE_DISABLE, (sysarg_t) &arg);
+	return (int) __SYSCALL1(SYS_IOSPACE_DISABLE, (sysarg_t) &arg);
 }
 
@@ -226,5 +226,5 @@
  *
  * @return EOK on success.
- * @return Negative error code on failure.
+ * @return An error code on failure.
  *
  */
@@ -268,5 +268,5 @@
  *
  * @return EOK on success.
- * @return Negative error code on failure.
+ * @return An error code on failure.
  *
  */
@@ -306,5 +306,5 @@
  *
  * @return EOK on success.
- * @return Negative error code on failure.
+ * @return An error code on failure.
  *
  */
Index: uspace/lib/c/generic/device/clock_dev.c
===================================================================
--- uspace/lib/c/generic/device/clock_dev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/device/clock_dev.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,5 +44,5 @@
  * @param t        The current time that will be read from the device
  *
- * @return         EOK on success or a negative error code
+ * @return         EOK on success or an error code
  */
 int
@@ -60,5 +60,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t rc;
+	int rc;
 	if (ret != EOK) {
 		async_forget(req);
@@ -75,5 +75,5 @@
  * @param t      The current time that will be written to the device
  *
- * @return       EOK on success or a negative error code
+ * @return       EOK on success or an error code
  */
 int
@@ -91,5 +91,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t rc;
+	int rc;
 	if (ret != EOK) {
 		async_forget(req);
Index: uspace/lib/c/generic/device/hw_res.c
===================================================================
--- uspace/lib/c/generic/device/hw_res.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/device/hw_res.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,5 @@
 #include <errno.h>
 #include <async.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 int hw_res_get_resource_list(async_sess_t *sess,
@@ -140,9 +140,10 @@
  * @param channel DMA channel.
  *
- * @return Number of bytes remaining in the buffer if positive.
- * @return Error code if negative.
+ * @param[out] rem Number of bytes remaining in the buffer if positive.
+ *
+ * @return Error code.
  *
  */
-int hw_res_dma_channel_remain(async_sess_t *sess, unsigned channel)
+int hw_res_dma_channel_remain(async_sess_t *sess, unsigned channel, size_t *rem)
 {
 	async_exch_t *exch = async_exchange_begin(sess);
@@ -155,5 +156,5 @@
 	
 	if (ret == EOK)
-		return remain;
+		*rem = remain;
 	
 	return ret;
Index: uspace/lib/c/generic/device/hw_res_parsed.c
===================================================================
--- uspace/lib/c/generic/device/hw_res_parsed.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/device/hw_res_parsed.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,7 +34,7 @@
 
 #include <device/hw_res_parsed.h>
-#include <malloc.h>
 #include <assert.h>
 #include <errno.h>
+#include <stdlib.h>
 
 static void hw_res_parse_add_dma_channel(hw_res_list_parsed_t *out,
Index: uspace/lib/c/generic/device/led_dev.c
===================================================================
--- uspace/lib/c/generic/device/led_dev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/device/led_dev.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,5 +48,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(req, &rc);
 	
Index: uspace/lib/c/generic/devman.c
===================================================================
--- uspace/lib/c/generic/devman.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/devman.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,5 +44,5 @@
 #include <async.h>
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 static FIBRIL_MUTEX_INITIALIZE(devman_driver_block_mutex);
@@ -182,5 +182,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_2(exch, DEVMAN_DRIVER_REGISTER, 0, 0, &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 	
 	devman_exchange_end(exch);
@@ -210,5 +210,5 @@
  * @param funh      Place to store handle of the new function
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  *
  */
@@ -222,5 +222,5 @@
 	aid_t req = async_send_3(exch, DEVMAN_ADD_FUNCTION, (sysarg_t) ftype,
 	    devh, match_count, &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 	if (retval != EOK) {
 		devman_exchange_end(exch);
@@ -272,5 +272,5 @@
 	aid_t req = async_send_1(exch, DEVMAN_ADD_DEVICE_TO_CATEGORY,
 	    devman_handle, &answer);
-	sysarg_t retval = async_data_write_start(exch, cat_name,
+	int retval = async_data_write_start(exch, cat_name,
 	    str_size(cat_name));
 	
@@ -305,10 +305,10 @@
  * @param funh      Devman handle of the function
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 int devman_remove_function(devman_handle_t funh)
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	
 	exch = devman_exchange_begin_blocking(INTERFACE_DDF_DRIVER);
@@ -316,5 +316,5 @@
 	devman_exchange_end(exch);
 	
-	return (int) retval;
+	return retval;
 }
 
@@ -325,8 +325,8 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh);
-	
-	devman_exchange_end(exch);
-	return (int) retval;
+	int retval = async_req_1_0(exch, DEVMAN_DRV_FUN_ONLINE, funh);
+	
+	devman_exchange_end(exch);
+	return retval;
 }
 
@@ -337,8 +337,8 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh);
-	
-	devman_exchange_end(exch);
-	return (int) retval;
+	int retval = async_req_1_0(exch, DEVMAN_DRV_FUN_OFFLINE, funh);
+	
+	devman_exchange_end(exch);
+	return retval;
 }
 
@@ -374,5 +374,5 @@
 	aid_t req = async_send_2(exch, DEVMAN_DEVICE_GET_HANDLE, flags, 0,
 	    &answer);
-	sysarg_t retval = async_data_write_start(exch, pathname,
+	int retval = async_data_write_start(exch, pathname,
 	    str_size(pathname));
 	
@@ -405,5 +405,5 @@
 	ipc_call_t dreply;
 	size_t act_size;
-	sysarg_t dretval;
+	int dretval;
 	
 	exch = devman_exchange_begin_blocking(INTERFACE_DDF_CLIENT);
@@ -421,5 +421,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -476,8 +476,8 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh);
-	
-	devman_exchange_end(exch);
-	return (int) retval;
+	int retval = async_req_1_0(exch, DEVMAN_FUN_ONLINE, funh);
+	
+	devman_exchange_end(exch);
+	return retval;
 }
 
@@ -488,8 +488,8 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh);
-	
-	devman_exchange_end(exch);
-	return (int) retval;
+	int retval = async_req_1_0(exch, DEVMAN_FUN_OFFLINE, funh);
+	
+	devman_exchange_end(exch);
+	return retval;
 }
 
@@ -510,5 +510,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -529,5 +529,5 @@
  * @param data		Place to store pointer to array of handles
  * @param count		Place to store number of handles
- * @return 		EOK on success or negative error code
+ * @return 		EOK on success or an error code
  */
 static int devman_get_handles_internal(sysarg_t method, sysarg_t arg1,
@@ -580,9 +580,9 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
+	int retval = async_req_1_1(exch, DEVMAN_FUN_GET_CHILD,
 	    funh, devh);
 	
 	devman_exchange_end(exch);
-	return (int) retval;
+	return retval;
 }
 
@@ -600,9 +600,9 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_1(exch, DEVMAN_DEV_GET_PARENT,
+	int retval = async_req_1_1(exch, DEVMAN_DEV_GET_PARENT,
 	    devh, funh);
 	
 	devman_exchange_end(exch);
-	return (int) retval;
+	return retval;
 }
 
@@ -613,9 +613,9 @@
 		return ENOMEM;
 	
-	sysarg_t retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
+	int retval = async_req_1_1(exch, DEVMAN_FUN_SID_TO_HANDLE,
 	    sid, handle);
 	
 	devman_exchange_end(exch);
-	return (int) retval;
+	return retval;
 }
 
@@ -643,5 +643,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, DEVMAN_DRIVER_GET_HANDLE, &answer);
-	sysarg_t retval = async_data_write_start(exch, drvname,
+	int retval = async_data_write_start(exch, drvname,
 	    str_size(drvname));
 	
Index: uspace/lib/c/generic/dirent.c
===================================================================
--- uspace/lib/c/generic/dirent.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/dirent.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -54,13 +54,14 @@
 	}
 	
-	int fd = vfs_lookup(dirname, WALK_DIRECTORY);
-	if (fd < 0) {
+	int fd;
+	int rc = vfs_lookup(dirname, WALK_DIRECTORY, &fd);
+	if (rc != EOK) {
 		free(dirp);
-		errno = fd;
+		errno = rc;
 		return NULL;
 	}
 	
-	int rc = vfs_open(fd, MODE_READ);
-	if (rc < 0) {
+	rc = vfs_open(fd, MODE_READ);
+	if (rc != EOK) {
 		free(dirp);
 		vfs_put(fd);
@@ -113,11 +114,13 @@
 int closedir(DIR *dirp)
 {
-	int rc;
-	
-	rc = vfs_put(dirp->fd);
+	int rc = vfs_put(dirp->fd);
 	free(dirp);
 
-	/* On error errno was set by close() */
-	return rc;
+	if (rc == EOK) {
+		return 0;
+	} else {
+		errno = rc;
+		return -1;
+	}
 }
 
Index: uspace/lib/c/generic/dnsr.c
===================================================================
--- uspace/lib/c/generic/dnsr.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/dnsr.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -90,5 +90,5 @@
 	    sizeof(inet_addr_t), &answer_addr);
 	
-	sysarg_t retval_addr;
+	int retval_addr;
 	async_wait_for(req_addr, &retval_addr);
 	
@@ -97,5 +97,5 @@
 		async_forget(req);
 		free(info);
-		return (int) retval_addr;
+		return retval_addr;
 	}
 	
@@ -107,5 +107,5 @@
 	dnsr_exchange_end(exch);
 	
-	sysarg_t retval_cname;
+	int retval_cname;
 	async_wait_for(req_cname, &retval_cname);
 	
@@ -113,8 +113,8 @@
 		async_forget(req);
 		free(info);
-		return (int) retval_cname;
+		return retval_cname;
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -122,5 +122,5 @@
 		async_forget(req);
 		free(info);
-		return (int) retval;
+		return retval;
 	}
 	
@@ -165,8 +165,8 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
-	return (int) retval;
+	return retval;
 }
 
@@ -186,8 +186,8 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
-	return (int) retval;
+	return retval;
 }
 
Index: uspace/lib/c/generic/elf/elf_load.c
===================================================================
--- uspace/lib/c/generic/elf/elf_load.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/elf/elf_load.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -53,5 +53,5 @@
  * @param file File handle 
  * @param info Place to store ELF program information
- * @return EOK on success or non-zero error code
+ * @return EE_OK on success or an EE_x error code
  */
 int elf_load(int file, elf_info_t *info)
@@ -79,5 +79,17 @@
 	DPRINTF( "- prog dynamic: %p\n", info->finfo.dynamic);
 
-	rc = rtld_prog_process(&info->finfo, &env);
+	int rc2 = rtld_prog_process(&info->finfo, &env);
+	switch (rc2) {
+	case EOK:
+		rc = EE_OK;
+		break;
+	case ENOMEM:
+		rc = EE_MEMORY;
+		break;
+	default:
+		DPRINTF("Unexpected error code from rtld_prog_process(): %s\n", str_error_name(rc2));
+		rc = EE_INVALID;
+	}
+
 	info->env = env;
 #else
Index: uspace/lib/c/generic/elf/elf_mod.c
===================================================================
--- uspace/lib/c/generic/elf/elf_mod.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/elf/elf_mod.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -69,5 +69,6 @@
 	"incompatible image",
 	"unsupported image type",
-	"irrecoverable error"
+	"irrecoverable error",
+	"file io error"
 };
 
@@ -90,5 +91,5 @@
  *                  extracted from the binary.
  *
- * @return EOK on success or negative error code.
+ * @return EE_OK on success or EE_xx error code.
  *
  */
@@ -97,8 +98,11 @@
 	elf_ld_t elf;
 
-	int ofile = vfs_clone(file, -1, true);
-	int rc = vfs_open(ofile, MODE_READ);
+	int ofile;
+	int rc = vfs_clone(file, -1, true, &ofile);
+	if (rc == EOK) {
+		rc = vfs_open(ofile, MODE_READ);
+	}
 	if (rc != EOK) {
-		return rc;
+		return EE_IO;
 	}
 
@@ -107,8 +111,8 @@
 	elf.flags = flags;
 
-	rc = elf_load_module(&elf, so_bias);
+	int ret = elf_load_module(&elf, so_bias);
 
 	vfs_put(ofile);
-	return rc;
+	return ret;
 }
 
@@ -116,8 +120,13 @@
     elf_finfo_t *info)
 {
-	int file = vfs_lookup(path, 0);
-	int rc = elf_load_file(file, so_bias, flags, info);
-	vfs_put(file);
-	return rc;
+	int file;
+	int rc = vfs_lookup(path, 0, &file);
+	if (rc == EOK) {
+		int ret = elf_load_file(file, so_bias, flags, info);
+		vfs_put(file);
+		return ret;
+	} else {
+		return EE_IO;
+	}
 }
 
@@ -137,10 +146,12 @@
 	elf_header_t *header = &header_buf;
 	aoff64_t pos = 0;
-	int i, rc;
-
-	rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t));
-	if (rc != sizeof(elf_header_t)) {
+	size_t nr;
+	int i, ret;
+	int rc;
+
+	rc = vfs_read(elf->fd, &pos, header, sizeof(elf_header_t), &nr);
+	if (rc != EOK || nr != sizeof(elf_header_t)) {
 		DPRINTF("Read error.\n"); 
-		return EE_INVALID;
+		return EE_IO;
 	}
 
@@ -199,13 +210,13 @@
 		pos = header->e_phoff + i * sizeof(elf_segment_header_t);
 		rc = vfs_read(elf->fd, &pos, &segment_hdr,
-		    sizeof(elf_segment_header_t));
-		if (rc != sizeof(elf_segment_header_t)) {
+		    sizeof(elf_segment_header_t), &nr);
+		if (rc != EOK || nr != sizeof(elf_segment_header_t)) {
 			DPRINTF("Read error.\n");
-			return EE_INVALID;
+			return EE_IO;
 		}
 
-		rc = segment_header(elf, &segment_hdr);
-		if (rc != EE_OK)
-			return rc;
+		ret = segment_header(elf, &segment_hdr);
+		if (ret != EE_OK)
+			return ret;
 	}
 
@@ -218,13 +229,13 @@
 		pos = header->e_shoff + i * sizeof(elf_section_header_t);
 		rc = vfs_read(elf->fd, &pos, &section_hdr,
-		    sizeof(elf_section_header_t));
-		if (rc != sizeof(elf_section_header_t)) {
+		    sizeof(elf_section_header_t), &nr);
+		if (rc != EOK || nr != sizeof(elf_section_header_t)) {
 			DPRINTF("Read error.\n");
-			return EE_INVALID;
+			return EE_IO;
 		}
 
-		rc = section_header(elf, &section_hdr);
-		if (rc != EE_OK)
-			return rc;
+		ret = section_header(elf, &section_hdr);
+		if (ret != EE_OK)
+			return ret;
 	}
 
@@ -330,5 +341,6 @@
 	size_t mem_sz;
 	aoff64_t pos;
-	ssize_t rc;
+	int rc;
+	size_t nr;
 
 	bias = elf->bias;
@@ -388,8 +400,8 @@
 	 */
 	pos = entry->p_offset;
-	rc = vfs_read(elf->fd, &pos, seg_ptr, entry->p_filesz);
-	if (rc < 0) {
+	rc = vfs_read(elf->fd, &pos, seg_ptr, entry->p_filesz, &nr);
+	if (rc != EOK || nr != entry->p_filesz) {
 		DPRINTF("read error\n");
-		return EE_INVALID;
+		return EE_IO;
 	}
 
Index: uspace/lib/c/generic/errno.c
===================================================================
--- uspace/lib/c/generic/errno.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/errno.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,7 +36,7 @@
 #include <fibril.h>
 
-static fibril_local int fibril_errno;
+static fibril_local errno_t fibril_errno;
 
-int *__errno(void)
+errno_t *__errno(void)
 {
 	return &fibril_errno;
Index: uspace/lib/c/generic/event.c
===================================================================
--- uspace/lib/c/generic/event.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/event.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -45,10 +45,10 @@
  * @param imethod Use this interface and method for notifying me.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_subscribe(event_type_t evno, sysarg_t imethod)
 {
-	return __SYSCALL2(SYS_IPC_EVENT_SUBSCRIBE, (sysarg_t) evno,
+	return (int) __SYSCALL2(SYS_IPC_EVENT_SUBSCRIBE, (sysarg_t) evno,
 	    (sysarg_t) imethod);
 }
@@ -59,10 +59,10 @@
  * @param imethod Use this interface and method for notifying me.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_task_subscribe(event_task_type_t evno, sysarg_t imethod)
 {
-	return __SYSCALL2(SYS_IPC_EVENT_SUBSCRIBE, (sysarg_t) evno,
+	return (int) __SYSCALL2(SYS_IPC_EVENT_SUBSCRIBE, (sysarg_t) evno,
 	    (sysarg_t) imethod);
 }
@@ -72,10 +72,10 @@
  * @param evno    Event type to unsubscribe.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_unsubscribe(event_type_t evno)
 {
-	return __SYSCALL1(SYS_IPC_EVENT_UNSUBSCRIBE, (sysarg_t) evno);
+	return (int) __SYSCALL1(SYS_IPC_EVENT_UNSUBSCRIBE, (sysarg_t) evno);
 }
 
@@ -84,10 +84,10 @@
  * @param evno    Event type to unsubscribe.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_task_unsubscribe(event_task_type_t evno)
 {
-	return __SYSCALL1(SYS_IPC_EVENT_UNSUBSCRIBE, (sysarg_t) evno);
+	return (int) __SYSCALL1(SYS_IPC_EVENT_UNSUBSCRIBE, (sysarg_t) evno);
 }
 
@@ -96,10 +96,10 @@
  * @param evno Event type to unmask.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_unmask(event_type_t evno)
 {
-	return __SYSCALL1(SYS_IPC_EVENT_UNMASK, (sysarg_t) evno);
+	return (int) __SYSCALL1(SYS_IPC_EVENT_UNMASK, (sysarg_t) evno);
 }
 
@@ -108,10 +108,10 @@
  * @param evno Event type to unmask.
  *
- * @return Value returned by the kernel.
+ * @return Error code returned by the kernel.
  *
  */
 int ipc_event_task_unmask(event_task_type_t evno)
 {
-	return __SYSCALL1(SYS_IPC_EVENT_UNMASK, (sysarg_t) evno);
+	return (int) __SYSCALL1(SYS_IPC_EVENT_UNMASK, (sysarg_t) evno);
 }
 
Index: uspace/lib/c/generic/fibril.c
===================================================================
--- uspace/lib/c/generic/fibril.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/fibril.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 #include <stack.h>
 #include <tls.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <abi/mm/as.h>
 #include <as.h>
Index: uspace/lib/c/generic/fibril_synch.c
===================================================================
--- uspace/lib/c/generic/fibril_synch.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/fibril_synch.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -629,40 +629,4 @@
 }
 
-/** Delay fibril execution for the specified number of microseconds
- *
- * @param usec Number of microseconds to sleep
- */
-void fibril_usleep(useconds_t usec)
-{
-	fibril_condvar_t cv;
-	fibril_mutex_t lock;
-
-	fibril_condvar_initialize(&cv);
-	fibril_mutex_initialize(&lock);
-	fibril_mutex_lock(&lock);
-	fibril_condvar_wait_timeout(&cv, &lock, usec);
-	fibril_mutex_unlock(&lock);
-}
-
-/** Delay fibril execution for the specified number of seconds
- *
- * @param sec Number of seconds to sleep
- */
-void fibril_sleep(unsigned int sec)
-{
-	/*
-	 * Sleep in 1000 second steps to support
-	 * full argument range
-	 */
-
-	while (sec > 0) {
-		unsigned int period = (sec > 1000) ? 1000 : sec;
-
-		fibril_usleep(period * 1000000);
-		sec -= period;
-	}
-}
-
-
 /** @}
  */
Index: uspace/lib/c/generic/gsort.c
===================================================================
--- uspace/lib/c/generic/gsort.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/gsort.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -43,5 +43,5 @@
 #include <inttypes.h>
 #include <mem.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 /** Immediate buffer size.
Index: uspace/lib/c/generic/inet.c
===================================================================
--- uspace/lib/c/generic/inet.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inet.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -58,5 +58,5 @@
 		return rc;
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -141,8 +141,8 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
-	return (int) retval;
+	return retval;
 }
 
@@ -170,8 +170,8 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
-	return (int) retval;
+	return retval;
 }
 
Index: uspace/lib/c/generic/inet/addr.c
===================================================================
--- uspace/lib/c/generic/inet/addr.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inet/addr.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 #include <stdio.h>
 #include <stddef.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <bitops.h>
 #include <inttypes.h>
@@ -584,4 +584,5 @@
 {
 	int rc;
+	int ret;
 
 	rc = ENOTSUP;
@@ -589,6 +590,6 @@
 	switch (addr->version) {
 	case ip_any:
-		rc = asprintf(bufp, "none");
-		if (rc < 0)
+		ret = asprintf(bufp, "none");
+		if (ret < 0)
 			return ENOMEM;
 		rc = EOK;
@@ -618,4 +619,5 @@
 {
 	int rc;
+	int ret;
 	char *astr;
 
@@ -624,6 +626,6 @@
 	switch (naddr->version) {
 	case ip_any:
-		rc = asprintf(bufp, "none");
-		if (rc < 0)
+		ret = asprintf(bufp, "none");
+		if (ret < 0)
 			return ENOMEM;
 		rc = EOK;
@@ -634,6 +636,6 @@
 			return ENOMEM;
 
-		rc = asprintf(bufp, "%s/%" PRIu8, astr, naddr->prefix);
-		if (rc < 0) {
+		ret = asprintf(bufp, "%s/%" PRIu8, astr, naddr->prefix);
+		if (ret < 0) {
 			free(astr);
 			return ENOMEM;
@@ -647,6 +649,6 @@
 			return ENOMEM;
 
-		rc = asprintf(bufp, "%s/%" PRIu8, astr, naddr->prefix);
-		if (rc < 0) {
+		ret = asprintf(bufp, "%s/%" PRIu8, astr, naddr->prefix);
+		if (ret < 0) {
 			free(astr);
 			return ENOMEM;
Index: uspace/lib/c/generic/inet/hostport.c
===================================================================
--- uspace/lib/c/generic/inet/hostport.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inet/hostport.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -140,4 +140,5 @@
 {
 	int rc;
+	int ret;
 	char *astr, *str;
 	char *hstr = NULL;
@@ -154,6 +155,6 @@
 			hstr = astr;
 		} else {
-			rc = asprintf(&hstr, "[%s]", astr);
-			if (rc < 0) {
+			ret = asprintf(&hstr, "[%s]", astr);
+			if (ret < 0) {
 				free(astr);
 				return ENOMEM;
@@ -171,6 +172,6 @@
 	}
 
-	rc = asprintf(&str, "%s:%u", hstr, hp->port);
-	if (rc < 0)
+	ret = asprintf(&str, "%s:%u", hstr, hp->port);
+	if (ret < 0)
 		return ENOMEM;
 
Index: uspace/lib/c/generic/inet/tcp.c
===================================================================
--- uspace/lib/c/generic/inet/tcp.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inet/tcp.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -59,5 +59,5 @@
  *
  * @param tcp TCP service
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 static int tcp_callback_create(tcp_t *tcp)
@@ -76,5 +76,5 @@
 		return rc;
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -205,5 +205,5 @@
  * @param rconn Place to store pointer to new connection
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 int tcp_conn_create(tcp_t *tcp, inet_ep2_t *epp, tcp_cb_t *cb, void *arg,
@@ -216,10 +216,10 @@
 	exch = async_exchange_begin(tcp->sess);
 	aid_t req = async_send_0(exch, TCP_CONN_CREATE, &answer);
-	sysarg_t rc = async_data_write_start(exch, (void *)epp,
+	int rc = async_data_write_start(exch, (void *)epp,
 	    sizeof(inet_ep2_t));
 	async_exchange_end(exch);
 
 	if (rc != EOK) {
-		sysarg_t rc_orig;
+		int rc_orig;
 		async_wait_for(req, &rc_orig);
 		if (rc_orig != EOK)
@@ -260,5 +260,5 @@
 
 	exch = async_exchange_begin(conn->tcp->sess);
-	sysarg_t rc = async_req_1_0(exch, TCP_CONN_DESTROY, conn->id);
+	int rc = async_req_1_0(exch, TCP_CONN_DESTROY, conn->id);
 	async_exchange_end(exch);
 
@@ -316,5 +316,5 @@
  * @param rlst Place to store pointer to new listener
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_listener_create(tcp_t *tcp, inet_ep_t *ep, tcp_listen_cb_t *lcb,
@@ -331,10 +331,10 @@
 	exch = async_exchange_begin(tcp->sess);
 	aid_t req = async_send_0(exch, TCP_LISTENER_CREATE, &answer);
-	sysarg_t rc = async_data_write_start(exch, (void *)ep,
+	int rc = async_data_write_start(exch, (void *)ep,
 	    sizeof(inet_ep_t));
 	async_exchange_end(exch);
 
 	if (rc != EOK) {
-		sysarg_t rc_orig;
+		int rc_orig;
 		async_wait_for(req, &rc_orig);
 		if (rc_orig != EOK)
@@ -377,5 +377,5 @@
 
 	exch = async_exchange_begin(lst->tcp->sess);
-	sysarg_t rc = async_req_1_0(exch, TCP_LISTENER_DESTROY, lst->id);
+	int rc = async_req_1_0(exch, TCP_LISTENER_DESTROY, lst->id);
 	async_exchange_end(exch);
 
@@ -446,10 +446,10 @@
  * @param bytes Data size in bytes
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_conn_send(tcp_conn_t *conn, const void *data, size_t bytes)
 {
 	async_exch_t *exch;
-	sysarg_t rc;
+	int rc;
 
 	exch = async_exchange_begin(conn->tcp->sess);
@@ -478,5 +478,5 @@
  *
  * @param conn Connection
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_conn_send_fin(tcp_conn_t *conn)
@@ -485,5 +485,5 @@
 
 	exch = async_exchange_begin(conn->tcp->sess);
-	sysarg_t rc = async_req_1_0(exch, TCP_CONN_SEND_FIN, conn->id);
+	int rc = async_req_1_0(exch, TCP_CONN_SEND_FIN, conn->id);
 	async_exchange_end(exch);
 
@@ -494,5 +494,5 @@
  *
  * @param conn Connection
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_conn_push(tcp_conn_t *conn)
@@ -501,5 +501,5 @@
 
 	exch = async_exchange_begin(conn->tcp->sess);
-	sysarg_t rc = async_req_1_0(exch, TCP_CONN_PUSH, conn->id);
+	int rc = async_req_1_0(exch, TCP_CONN_PUSH, conn->id);
 	async_exchange_end(exch);
 
@@ -510,5 +510,5 @@
  *
  * @param conn Connection
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_conn_reset(tcp_conn_t *conn)
@@ -517,5 +517,5 @@
 
 	exch = async_exchange_begin(conn->tcp->sess);
-	sysarg_t rc = async_req_1_0(exch, TCP_CONN_RESET, conn->id);
+	int rc = async_req_1_0(exch, TCP_CONN_RESET, conn->id);
 	async_exchange_end(exch);
 
@@ -538,5 +538,5 @@
  *
  * @return EOK on success, EAGAIN if no received data is pending, or other
- *         negative error code in case of other error
+ *         error code in case of other error
  */
 int tcp_conn_recv(tcp_conn_t *conn, void *buf, size_t bsize, size_t *nrecv)
@@ -562,5 +562,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK) {
@@ -586,5 +586,5 @@
  * @param nrecv Place to store actual number of received bytes
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int tcp_conn_recv_wait(tcp_conn_t *conn, void *buf, size_t bsize,
@@ -616,5 +616,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK) {
Index: uspace/lib/c/generic/inet/udp.c
===================================================================
--- uspace/lib/c/generic/inet/udp.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inet/udp.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -46,5 +46,5 @@
  *
  * @param udp UDP service
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 static int udp_callback_create(udp_t *udp)
@@ -63,5 +63,5 @@
 		return rc;
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -158,5 +158,5 @@
  * @param rassoc Place to store pointer to new association
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 int udp_assoc_create(udp_t *udp, inet_ep2_t *epp, udp_cb_t *cb, void *arg,
@@ -173,10 +173,10 @@
 	exch = async_exchange_begin(udp->sess);
 	aid_t req = async_send_0(exch, UDP_ASSOC_CREATE, &answer);
-	sysarg_t rc = async_data_write_start(exch, (void *)epp,
+	int rc = async_data_write_start(exch, (void *)epp,
 	    sizeof(inet_ep2_t));
 	async_exchange_end(exch);
 
 	if (rc != EOK) {
-		sysarg_t rc_orig;
+		int rc_orig;
 		async_wait_for(req, &rc_orig);
 		if (rc_orig != EOK)
@@ -220,5 +220,5 @@
 
 	exch = async_exchange_begin(assoc->udp->sess);
-	sysarg_t rc = async_req_1_0(exch, UDP_ASSOC_DESTROY, assoc->id);
+	int rc = async_req_1_0(exch, UDP_ASSOC_DESTROY, assoc->id);
 	async_exchange_end(exch);
 
@@ -237,5 +237,5 @@
 
 	exch = async_exchange_begin(assoc->udp->sess);
-	sysarg_t rc = async_req_1_0(exch, UDP_ASSOC_SET_NOLOCAL, assoc->id);
+	int rc = async_req_1_0(exch, UDP_ASSOC_SET_NOLOCAL, assoc->id);
 	async_exchange_end(exch);
 
@@ -250,5 +250,5 @@
  * @param bytes Message size in bytes
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int udp_assoc_send_msg(udp_assoc_t *assoc, inet_ep_t *dest, void *data,
@@ -260,5 +260,5 @@
 	aid_t req = async_send_1(exch, UDP_ASSOC_SEND_MSG, assoc->id, NULL);
 
-	sysarg_t rc = async_data_write_start(exch, (void *)dest,
+	int rc = async_data_write_start(exch, (void *)dest,
 	    sizeof(inet_ep_t));
 	if (rc != EOK) {
@@ -316,5 +316,5 @@
  * @param bsize Buffer size
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 int udp_rmsg_read(udp_rmsg_t *rmsg, size_t off, void *buf, size_t bsize)
@@ -333,5 +333,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK) {
@@ -380,5 +380,5 @@
  * @param rmsg Place to store message information
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 static int udp_rmsg_info(udp_t *udp, udp_rmsg_t *rmsg)
@@ -398,5 +398,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK)
@@ -413,5 +413,5 @@
  *
  * @param udp UDP client
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 static int udp_rmsg_discard(udp_t *udp)
@@ -420,5 +420,5 @@
 
 	exch = async_exchange_begin(udp->sess);
-	sysarg_t rc = async_req_0_0(exch, UDP_RMSG_DISCARD);
+	int rc = async_req_0_0(exch, UDP_RMSG_DISCARD);
 	async_exchange_end(exch);
 
Index: uspace/lib/c/generic/inetcfg.c
===================================================================
--- uspace/lib/c/generic/inetcfg.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inetcfg.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -55,5 +55,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -74,5 +74,5 @@
  * @param data		Place to store pointer to array of IDs
  * @param count		Place to store number of IDs
- * @return 		EOK on success or negative error code
+ * @return 		EOK on success or an error code
  */
 static int inetcfg_get_ids_internal(sysarg_t method, sysarg_t arg1,
@@ -158,10 +158,10 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
 	*addr_id = IPC_GET_ARG1(answer);
 	
-	return (int) retval;
+	return retval;
 }
 
@@ -187,5 +187,5 @@
 	    sizeof(inet_naddr_t), &answer_naddr);
 	
-	sysarg_t retval_naddr;
+	int retval_naddr;
 	async_wait_for(req_naddr, &retval_naddr);
 	
@@ -193,5 +193,5 @@
 		async_exchange_end(exch);
 		async_forget(req);
-		return (int) retval_naddr;
+		return retval_naddr;
 	}
 	
@@ -203,17 +203,17 @@
 	async_exchange_end(exch);
 	
-	sysarg_t retval_name;
+	int retval_name;
 	async_wait_for(req_name, &retval_name);
 	
 	if (retval_name != EOK) {
 		async_forget(req);
-		return (int) retval_name;
-	}
-	
-	sysarg_t retval;
+		return retval_name;
+	}
+	
+	int retval;
 	async_wait_for(req, &retval);
 	
 	if (retval != EOK)
-		return (int) retval;
+		return retval;
 	
 	size_t act_size = IPC_GET_ARG2(answer_name);
@@ -234,5 +234,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_1(exch, INETCFG_ADDR_GET_ID, link_id, &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 
 	async_exchange_end(exch);
@@ -280,5 +280,5 @@
 {
 	ipc_call_t dreply;
-	sysarg_t dretval;
+	int dretval;
 	size_t act_size;
 	char name_buf[LOC_NAME_MAXLEN + 1];
@@ -299,5 +299,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -356,10 +356,10 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
 	*sroute_id = IPC_GET_ARG1(answer);
 	
-	return (int) retval;
+	return retval;
 }
 
@@ -385,5 +385,5 @@
 	    sizeof(inet_naddr_t), &answer_dest);
 	
-	sysarg_t retval_dest;
+	int retval_dest;
 	async_wait_for(req_dest, &retval_dest);
 	
@@ -391,5 +391,5 @@
 		async_exchange_end(exch);
 		async_forget(req);
-		return (int) retval_dest;
+		return retval_dest;
 	}
 	
@@ -398,5 +398,5 @@
 	    sizeof(inet_addr_t), &answer_router);
 	
-	sysarg_t retval_router;
+	int retval_router;
 	async_wait_for(req_router, &retval_router);
 	
@@ -404,5 +404,5 @@
 		async_exchange_end(exch);
 		async_forget(req);
-		return (int) retval_router;
+		return retval_router;
 	}
 	
@@ -414,17 +414,17 @@
 	async_exchange_end(exch);
 	
-	sysarg_t retval_name;
+	int retval_name;
 	async_wait_for(req_name, &retval_name);
 	
 	if (retval_name != EOK) {
 		async_forget(req);
-		return (int) retval_name;
-	}
-	
-	sysarg_t retval;
+		return retval_name;
+	}
+	
+	int retval;
 	async_wait_for(req, &retval);
 	
 	if (retval != EOK)
-		return (int) retval;
+		return retval;
 	
 	size_t act_size = IPC_GET_ARG2(answer_name);
@@ -444,5 +444,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, INETCFG_SROUTE_GET_ID, &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 
 	async_exchange_end(exch);
Index: uspace/lib/c/generic/inetping.c
===================================================================
--- uspace/lib/c/generic/inetping.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/inetping.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -110,8 +110,8 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
-	return (int) retval;
+	return retval;
 }
 
@@ -136,16 +136,16 @@
 	async_exchange_end(exch);
 
-	sysarg_t retval_local;
+	int retval_local;
 	async_wait_for(req_local, &retval_local);
 
 	if (retval_local != EOK) {
 		async_forget(req);
-		return (int) retval_local;
-	}
-
-	sysarg_t retval;
+		return retval_local;
+	}
+
+	int retval;
 	async_wait_for(req, &retval);
 
-	return (int) retval;
+	return retval;
 }
 
Index: uspace/lib/c/generic/io/asprintf.c
===================================================================
--- uspace/lib/c/generic/io/asprintf.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/asprintf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -79,5 +79,5 @@
  * @args       Variable argument list
  *
- * @return Number of characters printed or a negative error code.
+ * @return Number of characters printed or an error code.
  *
  */
@@ -106,5 +106,5 @@
  * @fmt        Format string.
  *
- * @return Number of characters printed or a negative error code.
+ * @return Number of characters printed or an error code.
  *
  */
Index: uspace/lib/c/generic/io/chardev.c
===================================================================
--- uspace/lib/c/generic/io/chardev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/chardev.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2011 Jan Vesely
+ * Copyright (c) 2017 Jiri Svoboda
  * All rights reserved.
  *
@@ -27,34 +28,193 @@
  */
 
+/** @addtogroup libc
+ * @{
+ */
+/**
+ * @file
+ * @brief Character device client interface
+ */
+
 #include <errno.h>
 #include <mem.h>
 #include <io/chardev.h>
 #include <ipc/chardev.h>
-
-ssize_t chardev_read(async_exch_t *exch, void *data, size_t size)
-{
-	if (!exch)
-		return EBADMEM;
-	if (size > 4 * sizeof(sysarg_t))
-		return ELIMIT;
-
-	sysarg_t message[4] = { 0 };
-	const ssize_t ret = async_req_1_4(exch, CHARDEV_READ, size,
-	    &message[0], &message[1], &message[2], &message[3]);
-	if (ret > 0 && (size_t)ret <= size)
-		memcpy(data, message, size);
-	return ret;
-}
-
-ssize_t chardev_write(async_exch_t *exch, const void *data, size_t size)
-{
-	if (!exch)
-		return EBADMEM;
-	if (size > 3 * sizeof(sysarg_t))
-		return ELIMIT;
-
-	sysarg_t message[3] = { 0 };
-	memcpy(message, data, size);
-	return async_req_4_0(exch, CHARDEV_WRITE, size,
-	    message[0], message[1], message[2]);
-}
+#include <stddef.h>
+#include <stdlib.h>
+
+/** Open character device.
+ *
+ * @param sess Session with the character device
+ * @param rchardev Place to store pointer to the new character device structure
+ *
+ * @return EOK on success, ENOMEM if out of memory, EIO on I/O error
+ */
+int chardev_open(async_sess_t *sess, chardev_t **rchardev)
+{
+	chardev_t *chardev;
+
+	chardev = calloc(1, sizeof(chardev_t));
+	if (chardev == NULL)
+		return ENOMEM;
+
+	chardev->sess = sess;
+	*rchardev = chardev;
+
+	/* EIO might be used in a future implementation */
+	return EOK;
+}
+
+/** Close character device.
+ *
+ * Frees the character device structure. The underlying session is
+ * not affected.
+ *
+ * @param chardev Character device or @c NULL
+ */
+void chardev_close(chardev_t *chardev)
+{
+	free(chardev);
+}
+
+/** Read from character device.
+ *
+ * Read as much data as is available from character device up to @a size
+ * bytes into @a buf. On success EOK is returned and at least one byte
+ * is read (if no byte is available the function blocks). The number
+ * of bytes read is stored in @a *nread.
+ *
+ * On error a non-zero error code is returned and @a *nread is filled with
+ * the number of bytes that were successfully transferred.
+ *
+ * @param chardev Character device
+ * @param buf Destination buffer
+ * @param size Maximum number of bytes to read
+ * @param nread Place to store actual number of bytes read
+ *
+ * @return EOK on success or non-zero error code
+ */
+int chardev_read(chardev_t *chardev, void *buf, size_t size, size_t *nread)
+{
+	async_exch_t *exch = async_exchange_begin(chardev->sess);
+
+	if (size > DATA_XFER_LIMIT) {
+		/* This should not hurt anything. */
+		size = DATA_XFER_LIMIT;
+	}
+
+	ipc_call_t answer;
+	aid_t req = async_send_0(exch, CHARDEV_READ, &answer);
+	int rc = async_data_read_start(exch, buf, size);
+	async_exchange_end(exch);
+
+	if (rc != EOK) {
+		async_forget(req);
+		*nread = 0;
+		return rc;
+	}
+
+	int retval;
+	async_wait_for(req, &retval);
+
+	if (retval != EOK) {
+		*nread = 0;
+		return retval;
+	}
+
+	*nread = IPC_GET_ARG2(answer);
+	/* In case of partial success, ARG1 contains the error code */
+	return (int) IPC_GET_ARG1(answer);
+
+}
+
+/** Write up to DATA_XFER_LIMIT bytes to character device.
+ *
+ * Write up to @a size or DATA_XFER_LIMIT bytes from @a data to character
+ * device. On success EOK is returned, bytes were written and @a *nwritten
+ * is set to min(@a size, DATA_XFER_LIMIT)
+ *
+ * On error a non-zero error code is returned and @a *nwritten is filled with
+ * the number of bytes that were successfully transferred.
+ *
+ * @param chardev Character device
+ * @param buf Destination buffer
+ * @param size Maximum number of bytes to read
+ * @param nwritten Place to store actual number of bytes written
+ *
+ * @return EOK on success or non-zero error code
+ */
+static int chardev_write_once(chardev_t *chardev, const void *data,
+    size_t size, size_t *nwritten)
+{
+	async_exch_t *exch = async_exchange_begin(chardev->sess);
+	ipc_call_t answer;
+	aid_t req;
+	int rc;
+
+	/* Break down large transfers */
+	if (size > DATA_XFER_LIMIT)
+		size = DATA_XFER_LIMIT;
+
+	req = async_send_0(exch, CHARDEV_WRITE, &answer);
+	rc = async_data_write_start(exch, data, size);
+	async_exchange_end(exch);
+
+	if (rc != EOK) {
+		async_forget(req);
+		*nwritten = 0;
+		return rc;
+	}
+
+	int retval;
+	async_wait_for(req, &retval);
+	if (retval != EOK) {
+		*nwritten = 0;
+		return retval;
+	}
+
+	*nwritten = IPC_GET_ARG2(answer);
+	/* In case of partial success, ARG1 contains the error code */
+	return (int) IPC_GET_ARG1(answer);
+}
+
+/** Write to character device.
+ *
+ * Write @a size bytes from @a data to character device. On success EOK
+ * is returned, all bytes were written and @a *nwritten is set to @a size.
+ *
+ * On error a non-zero error code is returned and @a *nwritten is filled with
+ * the number of bytes that were successfully transferred.
+ *
+ * @param chardev Character device
+ * @param buf Destination buffer
+ * @param size Maximum number of bytes to read
+ * @param nwritten Place to store actual number of bytes written
+ *
+ * @return EOK on success or non-zero error code
+ */
+int chardev_write(chardev_t *chardev, const void *data, size_t size,
+    size_t *nwritten)
+{
+	size_t nw;
+	size_t p;
+	int rc;
+
+	p = 0;
+	while (p < size) {
+		rc = chardev_write_once(chardev, data + p, size - p, &nw);
+		/* nw is always valid, we can have partial success */
+		p += nw;
+
+		if (rc != EOK) {
+			/* We can return partial success */
+			*nwritten = p;
+			return rc;
+		}
+	}
+
+	*nwritten = p;
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/io/chardev_srv.c
===================================================================
--- uspace/lib/c/generic/io/chardev_srv.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/chardev_srv.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -46,21 +46,41 @@
     ipc_call_t *call)
 {
-	size_t size = IPC_GET_ARG1(*call);
+	void *buf;
+	size_t size;
+	size_t nread;
 	int rc;
+	ipc_callid_t rcallid;
 
-	if (srv->srvs->ops->read == NULL) {
-		async_answer_0(callid, ENOTSUP);
+	if (!async_data_read_receive(&rcallid, &size)) {
+		async_answer_0(callid, EINVAL);
 		return;
 	}
 
-	if (size <= 4 * sizeof(sysarg_t)) {
-		sysarg_t message[4] = {};
+	buf = malloc(size);
+	if (buf == NULL) {
+		async_answer_0(rcallid, ENOMEM);
+		async_answer_0(callid, ENOMEM);
+		return;
+	}
 
-		rc = srv->srvs->ops->read(srv, (char *)message, size);
-		async_answer_4(callid, rc, message[0], message[1],
-		    message[2], message[3]);
-	} else {
-		async_answer_0(callid, ELIMIT);
+	if (srv->srvs->ops->read == NULL) {
+		async_answer_0(rcallid, ENOTSUP);
+		async_answer_0(callid, ENOTSUP);
+		free(buf);
+		return;
 	}
+
+	rc = srv->srvs->ops->read(srv, buf, size, &nread);
+	if (rc != EOK && nread == 0) {
+		async_answer_0(rcallid, rc);
+		async_answer_0(callid, rc);
+		free(buf);
+		return;
+	}
+
+	async_data_read_finalize(rcallid, buf, nread);
+
+	free(buf);
+	async_answer_2(callid, EOK, (sysarg_t) rc, nread);
 }
 
@@ -68,6 +88,14 @@
     ipc_call_t *call)
 {
-	size_t size = IPC_GET_ARG1(*call);
+	void *data;
+	size_t size;
+	size_t nwr;
 	int rc;
+
+	rc = async_data_write_accept(&data, false, 0, 0, 0, &size);
+	if (rc != EOK) {
+		async_answer_0(callid, rc);
+		return;
+	}
 
 	if (srv->srvs->ops->write == NULL) {
@@ -76,16 +104,12 @@
 	}
 
-	if (size <= 3 * sizeof(sysarg_t)) {
-		const sysarg_t message[3] = {
-			IPC_GET_ARG2(*call),
-			IPC_GET_ARG3(*call),
-			IPC_GET_ARG4(*call)
-		};
+	rc = srv->srvs->ops->write(srv, data, size, &nwr);
+	free(data);
+	if (rc != EOK && nwr == 0) {
+		async_answer_0(callid, rc);
+		return;
+	}
 
-		rc = srv->srvs->ops->write(srv, (char *)message, size);
-		async_answer_0(callid, rc);
-	} else {
-		async_answer_0(callid, ELIMIT);
-	}
+	async_answer_2(callid, EOK, (sysarg_t) rc, nwr);
 }
 
@@ -145,5 +169,8 @@
 			break;
 		default:
-			async_answer_0(callid, EINVAL);
+			if (srv->srvs->ops->def_handler != NULL)
+				srv->srvs->ops->def_handler(srv, callid, &call);
+			else
+				async_answer_0(callid, ENOTSUP);
 		}
 	}
Index: uspace/lib/c/generic/io/chargrid.c
===================================================================
--- uspace/lib/c/generic/io/chargrid.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/chargrid.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,5 +34,5 @@
 
 #include <io/style.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <assert.h>
 #include <stdbool.h>
Index: uspace/lib/c/generic/io/con_srv.c
===================================================================
--- uspace/lib/c/generic/io/con_srv.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/con_srv.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -93,6 +93,7 @@
 	}
 
-	rc = srv->srvs->ops->read(srv, buf, size);
-	if (rc < 0) {
+	size_t nread;
+	rc = srv->srvs->ops->read(srv, buf, size, &nread);
+	if (rc != EOK) {
 		async_answer_0(rcallid, rc);
 		async_answer_0(callid, rc);
@@ -101,11 +102,8 @@
 	}
 
-	async_data_read_finalize(rcallid, buf, size);
+	async_data_read_finalize(rcallid, buf, nread);
 	free(buf);
 
-	if (rc >= 0)
-		async_answer_1(callid, EOK, rc);
-	else
-		async_answer_0(callid, rc);
+	async_answer_1(callid, EOK, nread);
 }
 
@@ -128,11 +126,9 @@
 	}
 
-	rc = srv->srvs->ops->write(srv, data, size);
+	size_t nwritten = 0;
+	rc = srv->srvs->ops->write(srv, data, size, &nwritten);
 	free(data);
 
-	if (rc >= 0)
-		async_answer_1(callid, EOK, rc);
-	else
-		async_answer_0(callid, rc);
+	async_answer_1(callid, rc, nwritten);
 }
 
Index: uspace/lib/c/generic/io/console.c
===================================================================
--- uspace/lib/c/generic/io/console.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/console.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,5 +38,5 @@
 #include <async.h>
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <vfs/vfs_sess.h>
 #include <io/console.h>
@@ -188,5 +188,5 @@
 		async_exchange_end(exch);
 		
-		sysarg_t rc;
+		int rc;
 		async_wait_for(aid, &rc);
 		
@@ -202,5 +202,5 @@
 		}
 	} else {
-		sysarg_t retval;
+		int retval;
 		async_wait_for(ctrl->input_aid, &retval);
 		
@@ -208,5 +208,5 @@
 		
 		if (retval != EOK) {
-			errno = (int) retval;
+			errno = retval;
 			return false;
 		}
@@ -235,5 +235,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	int rc = async_wait_timeout(ctrl->input_aid, &retval, *timeout);
 	if (rc != EOK) {
@@ -246,5 +246,5 @@
 	
 	if (retval != EOK) {
-		errno = (int) retval;
+		errno = retval;
 		return false;
 	}
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/io.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,5 +38,5 @@
 #include <errno.h>
 #include <stdbool.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <async.h>
 #include <io/kio.h>
@@ -108,8 +108,8 @@
 	 * This will probably be removed later.
 	 */
-	 
 	int infd = inbox_get("stdin");
 	if (infd >= 0) {
-		int stdinfd = vfs_clone(infd, -1, false);
+		int stdinfd = -1;
+		(void) vfs_clone(infd, -1, false, &stdinfd);
 		assert(stdinfd == 0);
 		vfs_open(stdinfd, MODE_READ);
@@ -122,8 +122,9 @@
 	int outfd = inbox_get("stdout");
 	if (outfd >= 0) {
-		int stdoutfd = vfs_clone(outfd, -1, false);
+		int stdoutfd = -1;
+		(void) vfs_clone(outfd, -1, false, &stdoutfd);
 		assert(stdoutfd <= 1);
 		while (stdoutfd < 1)
-			stdoutfd = vfs_clone(outfd, -1, false);
+			(void) vfs_clone(outfd, -1, false, &stdoutfd);
 		vfs_open(stdoutfd, MODE_APPEND);
 		stdout = fdopen(stdoutfd, "a");
@@ -135,8 +136,9 @@
 	int errfd = inbox_get("stderr");
 	if (errfd >= 0) {
-		int stderrfd = vfs_clone(errfd, -1, false);
+		int stderrfd = -1;
+		(void) vfs_clone(errfd, -1, false, &stderrfd);
 		assert(stderrfd <= 2);
 		while (stderrfd < 2)
-			stderrfd = vfs_clone(errfd, -1, false);
+			(void) vfs_clone(errfd, -1, false, &stderrfd);
 		vfs_open(stderrfd, MODE_APPEND);
 		stderr = fdopen(stderrfd, "a");
@@ -294,12 +296,13 @@
 	if (create)
 		flags |= WALK_MAY_CREATE;
-	int file = vfs_lookup(path, flags);
-	if (file < 0) {
-		errno = file;
+	int file;
+	int rc = vfs_lookup(path, flags, &file);
+	if (rc != EOK) {
+		errno = rc;
 		free(stream);
 		return NULL;
 	}
 
-	int rc = vfs_open(file, mode);
+	rc = vfs_open(file, mode);
 	if (rc != EOK) {
 		errno = rc;
@@ -373,6 +376,6 @@
 	list_remove(&stream->link);
 	
-	if (rc != 0) {
-		/* errno was set by close() */
+	if (rc != EOK) {
+		errno = rc;
 		return EOF;
 	}
@@ -430,17 +433,19 @@
 static size_t _fread(void *buf, size_t size, size_t nmemb, FILE *stream)
 {
+	int rc;
+	size_t nread;
+
 	if (size == 0 || nmemb == 0)
 		return 0;
 
-	ssize_t rd = vfs_read(stream->fd, &stream->pos, buf, size * nmemb);
-	if (rd < 0) {
-		errno = rd;
+	rc = vfs_read(stream->fd, &stream->pos, buf, size * nmemb, &nread);
+	if (rc != EOK) {
+		errno = rc;
 		stream->error = true;
-		rd = 0;
-	} else if (rd == 0) {
+	} else if (nread == 0) {
 		stream->eof = true;
 	}
-	
-	return (rd / size);
+
+	return (nread / size);
 }
 
@@ -457,30 +462,29 @@
 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
 {
+	int rc;
+	size_t nwritten;
+
 	if (size == 0 || nmemb == 0)
 		return 0;
 
-	ssize_t wr;
 	if (stream->kio) {
-		size_t nwritten;
-		wr = kio_write(buf, size * nmemb, &nwritten);
-		if (wr != EOK) {
+		rc = kio_write(buf, size * nmemb, &nwritten);
+		if (rc != EOK) {
 			stream->error = true;
-			wr = 0;
-		} else {
-			wr = nwritten;
+			nwritten = 0;
 		}
 	} else {
-		wr = vfs_write(stream->fd, &stream->pos, buf, size * nmemb);
-		if (wr < 0) {
-			errno = wr;
+		rc = vfs_write(stream->fd, &stream->pos, buf, size * nmemb,
+		    &nwritten);
+		if (rc != EOK) {
+			errno = rc;
 			stream->error = true;
-			wr = 0;
 		}
 	}
 
-	if (wr > 0)
+	if (nwritten > 0)
 		stream->need_sync = true;
-	
-	return (wr / size);
+
+	return (nwritten / size);
 }
 
@@ -491,10 +495,12 @@
 static void _ffillbuf(FILE *stream)
 {
-	ssize_t rc;
+	int rc;
+	size_t nread;
 
 	stream->buf_head = stream->buf_tail = stream->buf;
 
-	rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size);
-	if (rc < 0) {
+	rc = vfs_read(stream->fd, &stream->pos, stream->buf, stream->buf_size,
+	    &nread);
+	if (rc != EOK) {
 		errno = rc;
 		stream->error = true;
@@ -502,10 +508,10 @@
 	}
 
-	if (rc == 0) {
+	if (nread == 0) {
 		stream->eof = true;
 		return;
 	}
 
-	stream->buf_head += rc;
+	stream->buf_head += nread;
 	stream->buf_state = _bs_read;
 }
Index: uspace/lib/c/generic/io/klog.c
===================================================================
--- uspace/lib/c/generic/io/klog.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/klog.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,18 +42,14 @@
 #include <abi/log.h>
 
-size_t klog_write(log_level_t lvl, const void *buf, size_t size)
+int klog_write(log_level_t lvl, const void *buf, size_t size)
 {
-	ssize_t ret = (ssize_t) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf,
+	return (int) __SYSCALL4(SYS_KLOG, KLOG_WRITE, (sysarg_t) buf,
 	    size, lvl);
-	
-	if (ret >= 0)
-		return (size_t) ret;
-	
-	return 0;
 }
 
-int klog_read(void *data, size_t size)
+int klog_read(void *data, size_t size, size_t *nread)
 {
-	return (int) __SYSCALL4(SYS_KLOG, KLOG_READ, (uintptr_t) data, size, 0);
+	return (int) __SYSCALL5(SYS_KLOG, KLOG_READ, (uintptr_t) data,
+	    size, 0, (sysarg_t) nread);
 }
 
Index: uspace/lib/c/generic/io/log.c
===================================================================
--- uspace/lib/c/generic/io/log.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/log.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -89,5 +89,5 @@
 	    log, level, NULL);
 	int rc = async_data_write_start(exchange, message, str_size(message));
-	sysarg_t reg_msg_rc;
+	int reg_msg_rc;
 	async_wait_for(reg_msg, &reg_msg_rc);
 
@@ -199,5 +199,5 @@
 	    parent, &answer);
 	int rc = async_data_write_start(exchange, name, str_size(name));
-	sysarg_t reg_msg_rc;
+	int reg_msg_rc;
 	async_wait_for(reg_msg, &reg_msg_rc);
 
Index: uspace/lib/c/generic/io/logctl.c
===================================================================
--- uspace/lib/c/generic/io/logctl.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/logctl.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -111,5 +111,5 @@
 	    new_level, NULL);
 	rc = async_data_write_start(exchange, logname, str_size(logname));
-	sysarg_t reg_msg_rc;
+	int reg_msg_rc;
 	async_wait_for(reg_msg, &reg_msg_rc);
 
@@ -137,5 +137,5 @@
 	rc = vfs_pass_handle(vfs_exch, vfs_root(), exchange);
 	vfs_exchange_end(vfs_exch);
-	sysarg_t reg_msg_rc;
+	int reg_msg_rc;
 	async_wait_for(reg_msg, &reg_msg_rc);
 
Index: uspace/lib/c/generic/io/output.c
===================================================================
--- uspace/lib/c/generic/io/output.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/output.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -94,5 +94,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 	
Index: uspace/lib/c/generic/io/serial.c
===================================================================
--- uspace/lib/c/generic/io/serial.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
+++ uspace/lib/c/generic/io/serial.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -0,0 +1,105 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * 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.
+ */
+
+#include <async.h>
+#include <errno.h>
+#include <io/serial.h>
+#include <ipc/serial_ctl.h>
+#include <ipc/services.h>
+#include <stdlib.h>
+
+/** Open serial port device.
+ *
+ * @param sess Session with the serial port device
+ * @param rchardev Place to store pointer to the new serial port device structure
+ *
+ * @return EOK on success, ENOMEM if out of memory, EIO on I/O error
+ */
+int serial_open(async_sess_t *sess, serial_t **rserial)
+{
+	serial_t *serial;
+
+	serial = calloc(1, sizeof(serial_t));
+	if (serial == NULL)
+		return ENOMEM;
+
+	serial->sess = sess;
+	*rserial = serial;
+
+	return EOK;
+}
+
+/** Close serial port device.
+ *
+ * Frees the serial port device structure. The underlying session is
+ * not affected.
+ *
+ * @param serial Serial port device or @c NULL
+ */
+void serial_close(serial_t *serial)
+{
+	free(serial);
+}
+
+/** Set serial port communication properties. */
+int serial_set_comm_props(serial_t *serial, unsigned rate,
+    serial_parity_t parity, unsigned datab, unsigned stopb)
+{
+	async_exch_t *exch = async_exchange_begin(serial->sess);
+
+	int rc = async_req_4_0(exch, SERIAL_SET_COM_PROPS, rate, parity,
+	    datab, stopb);
+
+	async_exchange_end(exch);
+	return rc;
+}
+
+/** Get serial port communication properties. */
+int serial_get_comm_props(serial_t *serial, unsigned *rrate,
+    serial_parity_t *rparity, unsigned *rdatab, unsigned *rstopb)
+{
+	async_exch_t *exch = async_exchange_begin(serial->sess);
+	sysarg_t rate, parity, datab, stopb;
+
+	int rc = async_req_0_4(exch, SERIAL_GET_COM_PROPS, &rate, &parity,
+	    &datab, &stopb);
+
+	async_exchange_end(exch);
+	if (rc != EOK)
+		return rc;
+
+	*rrate = rate;
+	*rparity = parity;
+	*rdatab = datab;
+	*rstopb = stopb;
+
+	return EOK;
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/io/table.c
===================================================================
--- uspace/lib/c/generic/io/table.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/table.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -478,4 +478,5 @@
 	va_list args;
 	int rc;
+	int ret;
 	char *str;
 	char *sp, *ep;
@@ -486,8 +487,8 @@
 
 	va_start(args, fmt);
-	rc = vasprintf(&str, fmt, args);
+	ret = vasprintf(&str, fmt, args);
 	va_end(args);
 
-	if (rc < 0) {
+	if (ret < 0) {
 		table->error = ENOMEM;
 		return table->error;
Index: uspace/lib/c/generic/io/visualizer.c
===================================================================
--- uspace/lib/c/generic/io/visualizer.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/visualizer.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -68,5 +68,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
@@ -91,5 +91,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
@@ -114,5 +114,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
@@ -137,5 +137,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
@@ -160,5 +160,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
Index: uspace/lib/c/generic/io/window.c
===================================================================
--- uspace/lib/c/generic/io/window.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/io/window.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -61,5 +61,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 
@@ -105,5 +105,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t ret;
+	int ret;
 	async_wait_for(req, &ret);
 	
Index: uspace/lib/c/generic/ipc.c
===================================================================
--- uspace/lib/c/generic/ipc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/ipc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2006 Ondrej Palkovsky
+ * Copyright (c) 2017 Jakub Jermar
  * All rights reserved.
  *
@@ -42,5 +43,5 @@
 #include <ipc/ipc.h>
 #include <libc.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <errno.h>
 #include <adt/list.h>
@@ -50,49 +51,14 @@
 
 /**
- * Structures of this type are used for keeping track
- * of sent asynchronous calls and queing unsent calls.
- */
-typedef struct {
-	link_t list;
-	
+ * Structures of this type are used for keeping track of sent asynchronous calls.
+ */
+typedef struct async_call {
 	ipc_async_callback_t callback;
 	void *private;
 	
-	union {
-		ipc_callid_t callid;
-		struct {
-			ipc_call_t data;
-			int phoneid;
-		} msg;
-	} u;
-	
-	/** Fibril waiting for sending this call. */
-	fid_t fid;
+	struct {
+		ipc_call_t data;
+	} msg;
 } async_call_t;
-
-LIST_INITIALIZE(dispatched_calls);
-
-/** List of asynchronous calls that were not accepted by kernel.
- *
- * Protected by async_futex, because if the call is not accepted
- * by the kernel, the async framework is used automatically.
- *
- */
-LIST_INITIALIZE(queued_calls);
-
-static futex_t ipc_futex = FUTEX_INITIALIZER;
-
-/** Send asynchronous message via syscall.
- *
- * @param phoneid Phone handle for the call.
- * @param data    Call data with the request.
- *
- * @return Hash of the call or an error code.
- *
- */
-static ipc_callid_t ipc_call_async_internal(int phoneid, ipc_call_t *data)
-{
-	return __SYSCALL2(SYS_IPC_CALL_ASYNC_SLOW, phoneid, (sysarg_t) data);
-}
 
 /** Prologue for ipc_call_async_*() functions.
@@ -124,20 +90,15 @@
 /** Epilogue for ipc_call_async_*() functions.
  *
- * @param callid      Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
- * @param phoneid     Phone handle through which the call was made.
- * @param call        Structure returned by ipc_prepare_async().
- */
-static inline void ipc_finish_async(ipc_callid_t callid, int phoneid,
-    async_call_t *call)
+ * @param rc       Value returned by the SYS_IPC_CALL_ASYNC_* syscall.
+ * @param call     Structure returned by ipc_prepare_async().
+ */
+static inline void ipc_finish_async(int rc, async_call_t *call)
 {
 	if (!call) {
 		/* Nothing to do regardless if failed or not */
-		futex_unlock(&ipc_futex);
 		return;
 	}
 	
-	if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
-		futex_unlock(&ipc_futex);
-		
+	if (rc != EOK) {
 		/* Call asynchronous handler with error code */
 		if (call->callback)
@@ -147,15 +108,9 @@
 		return;
 	}
-	
-	call->u.callid = callid;
-	
-	/* Add call to the list of dispatched calls */
-	list_append(&call->list, &dispatched_calls);
-	futex_unlock(&ipc_futex);
 }
 
 /** Fast asynchronous call.
  *
- * This function can only handle four arguments of payload. It is, however,
+ * This function can only handle three arguments of payload. It is, however,
  * faster than the more generic ipc_call_async_slow().
  *
@@ -166,35 +121,23 @@
  * error code. If the call cannot be temporarily made, it is queued.
  *
- * @param phoneid     Phone handle for the call.
- * @param imethod     Requested interface and method.
- * @param arg1        Service-defined payload argument.
- * @param arg2        Service-defined payload argument.
- * @param arg3        Service-defined payload argument.
- * @param arg4        Service-defined payload argument.
- * @param private     Argument to be passed to the answer/error callback.
- * @param callback    Answer or error callback.
- */
-void ipc_call_async_fast(int phoneid, sysarg_t imethod, sysarg_t arg1,
-    sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, void *private,
-    ipc_async_callback_t callback)
-{
-	async_call_t *call = NULL;
-	
-	if (callback) {
-		call = ipc_prepare_async(private, callback);
-		if (!call)
-			return;
-	}
-	
-	/*
-	 * We need to make sure that we get callid
-	 * before another thread accesses the queue again.
-	 */
-	
-	futex_lock(&ipc_futex);
-	ipc_callid_t callid = __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phoneid,
-	    imethod, arg1, arg2, arg3, arg4);
-	
-	ipc_finish_async(callid, phoneid, call);
+ * @param phandle   Phone handle for the call.
+ * @param imethod   Requested interface and method.
+ * @param arg1      Service-defined payload argument.
+ * @param arg2      Service-defined payload argument.
+ * @param arg3      Service-defined payload argument.
+ * @param private   Argument to be passed to the answer/error callback.
+ * @param callback  Answer or error callback.
+ */
+void ipc_call_async_fast(cap_handle_t phandle, sysarg_t imethod, sysarg_t arg1,
+    sysarg_t arg2, sysarg_t arg3, void *private, ipc_async_callback_t callback)
+{
+	async_call_t *call = ipc_prepare_async(private, callback);
+	if (!call)
+		return;
+	
+	int rc = (int) __SYSCALL6(SYS_IPC_CALL_ASYNC_FAST, phandle, imethod, arg1,
+	    arg2, arg3, (sysarg_t) call);
+	
+	ipc_finish_async(rc, call);
 }
 
@@ -207,15 +150,15 @@
  * error code. If the call cannot be temporarily made, it is queued.
  *
- * @param phoneid     Phone handle for the call.
- * @param imethod     Requested interface and method.
- * @param arg1        Service-defined payload argument.
- * @param arg2        Service-defined payload argument.
- * @param arg3        Service-defined payload argument.
- * @param arg4        Service-defined payload argument.
- * @param arg5        Service-defined payload argument.
- * @param private     Argument to be passed to the answer/error callback.
- * @param callback    Answer or error callback.
- */
-void ipc_call_async_slow(int phoneid, sysarg_t imethod, sysarg_t arg1,
+ * @param phandle   Phone handle for the call.
+ * @param imethod   Requested interface and method.
+ * @param arg1      Service-defined payload argument.
+ * @param arg2      Service-defined payload argument.
+ * @param arg3      Service-defined payload argument.
+ * @param arg4      Service-defined payload argument.
+ * @param arg5      Service-defined payload argument.
+ * @param private   Argument to be passed to the answer/error callback.
+ * @param callback  Answer or error callback.
+ */
+void ipc_call_async_slow(int phandle, sysarg_t imethod, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5, void *private,
     ipc_async_callback_t callback)
@@ -225,21 +168,15 @@
 		return;
 	
-	IPC_SET_IMETHOD(call->u.msg.data, imethod);
-	IPC_SET_ARG1(call->u.msg.data, arg1);
-	IPC_SET_ARG2(call->u.msg.data, arg2);
-	IPC_SET_ARG3(call->u.msg.data, arg3);
-	IPC_SET_ARG4(call->u.msg.data, arg4);
-	IPC_SET_ARG5(call->u.msg.data, arg5);
-	
-	/*
-	 * We need to make sure that we get callid
-	 * before another threadaccesses the queue again.
-	 */
-	
-	futex_lock(&ipc_futex);
-	ipc_callid_t callid =
-	    ipc_call_async_internal(phoneid, &call->u.msg.data);
-	
-	ipc_finish_async(callid, phoneid, call);
+	IPC_SET_IMETHOD(call->msg.data, imethod);
+	IPC_SET_ARG1(call->msg.data, arg1);
+	IPC_SET_ARG2(call->msg.data, arg2);
+	IPC_SET_ARG3(call->msg.data, arg3);
+	IPC_SET_ARG4(call->msg.data, arg4);
+	IPC_SET_ARG5(call->msg.data, arg5);
+	
+	int rc = (int) __SYSCALL3(SYS_IPC_CALL_ASYNC_SLOW, phandle,
+	    (sysarg_t) &call->msg.data, (sysarg_t) call);
+	
+	ipc_finish_async(rc, call);
 }
 
@@ -249,10 +186,10 @@
  * registers. If you need to return more, use the ipc_answer_slow() instead.
  *
- * @param callid Hash of the call being answered.
- * @param retval Return value.
- * @param arg1   First return argument.
- * @param arg2   Second return argument.
- * @param arg3   Third return argument.
- * @param arg4   Fourth return argument.
+ * @param chandle  Handle of the call being answered.
+ * @param retval   Return value.
+ * @param arg1     First return argument.
+ * @param arg2     Second return argument.
+ * @param arg3     Third return argument.
+ * @param arg4     Fourth return argument.
  *
  * @return Zero on success.
@@ -260,20 +197,20 @@
  *
  */
-sysarg_t ipc_answer_fast(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+int ipc_answer_fast(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4)
 {
-	return __SYSCALL6(SYS_IPC_ANSWER_FAST, callid, retval, arg1, arg2, arg3,
-	    arg4);
+	return (int) __SYSCALL6(SYS_IPC_ANSWER_FAST, chandle, (sysarg_t) retval, arg1, arg2,
+	    arg3, arg4);
 }
 
 /** Answer received call (entire payload).
  *
- * @param callid Hash of the call being answered.
- * @param retval Return value.
- * @param arg1   First return argument.
- * @param arg2   Second return argument.
- * @param arg3   Third return argument.
- * @param arg4   Fourth return argument.
- * @param arg5   Fifth return argument.
+ * @param chandle  Handle of the call being answered.
+ * @param retval   Return value.
+ * @param arg1     First return argument.
+ * @param arg2     Second return argument.
+ * @param arg3     Third return argument.
+ * @param arg4     Fourth return argument.
+ * @param arg5     Fifth return argument.
  *
  * @return Zero on success.
@@ -281,5 +218,5 @@
  *
  */
-sysarg_t ipc_answer_slow(ipc_callid_t callid, sysarg_t retval, sysarg_t arg1,
+int ipc_answer_slow(cap_handle_t chandle, int retval, sysarg_t arg1,
     sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5)
 {
@@ -293,208 +230,134 @@
 	IPC_SET_ARG5(data, arg5);
 	
-	return __SYSCALL2(SYS_IPC_ANSWER_SLOW, callid, (sysarg_t) &data);
-}
-
-/** Try to dispatch queued calls from the async queue.
- *
- */
-static void dispatch_queued_calls(void)
-{
-	/** @todo
-	 * Integrate intelligently ipc_futex so that it is locked during
-	 * ipc_call_async_*() until it is added to dispatched_calls.
-	 */
-	
-	futex_down(&async_futex);
-	
-	while (!list_empty(&queued_calls)) {
-		async_call_t *call =
-		    list_get_instance(list_first(&queued_calls), async_call_t, list);
-		ipc_callid_t callid =
-		    ipc_call_async_internal(call->u.msg.phoneid, &call->u.msg.data);
-		
-		list_remove(&call->list);
-		
-		futex_up(&async_futex);
-		
-		assert(call->fid);
-		fibril_add_ready(call->fid);
-		
-		if (callid == (ipc_callid_t) IPC_CALLRET_FATAL) {
-			if (call->callback)
-				call->callback(call->private, ENOENT, NULL);
-			
-			free(call);
-		} else {
-			call->u.callid = callid;
-			
-			futex_lock(&ipc_futex);
-			list_append(&call->list, &dispatched_calls);
-			futex_unlock(&ipc_futex);
-		}
-		
-		futex_down(&async_futex);
+	return (int) __SYSCALL2(SYS_IPC_ANSWER_SLOW, chandle, (sysarg_t) &data);
+}
+
+/** Handle received answer.
+ *
+ * @param data  Call data of the answer.
+ */
+static void handle_answer(ipc_call_t *data)
+{
+	async_call_t *call = data->label;
+
+	if (!call)
+		return;
+
+	if (call->callback)
+		call->callback(call->private, IPC_GET_RETVAL(*data), data);
+	free(call);
+}
+
+/** Wait for first IPC call to come.
+ *
+ * @param call   Incoming call storage.
+ * @param usec   Timeout in microseconds
+ * @param flags  Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
+ * @param[out] out_handle  Call handle.
+ *
+ * @return  Error code.
+ */
+int ipc_wait_cycle(ipc_call_t *call, sysarg_t usec, unsigned int flags)
+{
+	int rc = (int) __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
+	
+	/* Handle received answers */
+	if ((rc == EOK) && (call->cap_handle == CAP_NIL) &&
+	    (call->flags & IPC_CALL_ANSWERED)) {
+		handle_answer(call);
 	}
 	
-	futex_up(&async_futex);
-}
-
-/** Handle received answer.
- *
- * Find the hash of the answer and call the answer callback.
- *
- * The answer has the same hash as the request OR'ed with
- * the IPC_CALLID_ANSWERED bit.
- *
- * @todo Use hash table.
- *
- * @param callid Hash of the received answer.
- * @param data   Call data of the answer.
- *
- */
-static void handle_answer(ipc_callid_t callid, ipc_call_t *data)
-{
-	callid &= ~IPC_CALLID_ANSWERED;
-	
-	futex_lock(&ipc_futex);
-	
-	link_t *item;
-	for (item = dispatched_calls.head.next; item != &dispatched_calls.head;
-	    item = item->next) {
-		async_call_t *call =
-		    list_get_instance(item, async_call_t, list);
-		
-		if (call->u.callid == callid) {
-			list_remove(&call->list);
-			
-			futex_unlock(&ipc_futex);
-			
-			if (call->callback)
-				call->callback(call->private,
-				    IPC_GET_RETVAL(*data), data);
-			
-			free(call);
-			return;
-		}
-	}
-	
-	futex_unlock(&ipc_futex);
+	return rc;
+}
+
+/** Interrupt one thread of this task from waiting for IPC.
+ *
+ */
+void ipc_poke(void)
+{
+	__SYSCALL0(SYS_IPC_POKE);
 }
 
 /** Wait for first IPC call to come.
+ *
+ * Only requests are returned, answers are processed internally.
  *
  * @param call  Incoming call storage.
  * @param usec  Timeout in microseconds
- * @param flags Flags passed to SYS_IPC_WAIT (blocking, nonblocking).
- *
- * @return Hash of the call. Note that certain bits have special
- *         meaning: IPC_CALLID_ANSWERED is set in an answer
- *         and IPC_CALLID_NOTIFICATION is used for notifications.
- *
- */
-ipc_callid_t ipc_wait_cycle(ipc_call_t *call, sysarg_t usec,
-    unsigned int flags)
-{
-	ipc_callid_t callid =
-	    __SYSCALL3(SYS_IPC_WAIT, (sysarg_t) call, usec, flags);
-	
-	/* Handle received answers */
-	if (callid & IPC_CALLID_ANSWERED) {
-		handle_answer(callid, call);
-		dispatch_queued_calls();
-	}
-	
-	return callid;
-}
-
-/** Interrupt one thread of this task from waiting for IPC.
- *
- */
-void ipc_poke(void)
-{
-	__SYSCALL0(SYS_IPC_POKE);
-}
-
-/** Wait for first IPC call to come.
+ *
+ * @return  Error code.
+ *
+ */
+int ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
+{
+	int rc;
+	
+	do {
+		rc = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
+	} while ((rc == EOK) && (call->cap_handle == CAP_NIL) && (call->flags & IPC_CALL_ANSWERED));
+	
+	return rc;
+}
+
+/** Check if there is an IPC call waiting to be picked up.
  *
  * Only requests are returned, answers are processed internally.
  *
- * @param call Incoming call storage.
- * @param usec Timeout in microseconds
- *
- * @return Hash of the call.
- *
- */
-ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *call, sysarg_t usec)
-{
-	ipc_callid_t callid;
+ * @param call  Incoming call storage.
+ *
+ * @return  Error code.
+ *
+ */
+int ipc_trywait_for_call(ipc_call_t *call)
+{
+	int rc;
 	
 	do {
-		callid = ipc_wait_cycle(call, usec, SYNCH_FLAGS_NONE);
-	} while (callid & IPC_CALLID_ANSWERED);
-	
-	return callid;
-}
-
-/** Check if there is an IPC call waiting to be picked up.
- *
- * Only requests are returned, answers are processed internally.
- *
- * @param call Incoming call storage.
- *
- * @return Hash of the call.
- *
- */
-ipc_callid_t ipc_trywait_for_call(ipc_call_t *call)
-{
-	ipc_callid_t callid;
-	
-	do {
-		callid = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
+		rc = ipc_wait_cycle(call, SYNCH_NO_TIMEOUT,
 		    SYNCH_FLAGS_NON_BLOCKING);
-	} while (callid & IPC_CALLID_ANSWERED);
-	
-	return callid;
+	} while ((rc == EOK) && (call->cap_handle == CAP_NIL) && (call->flags & IPC_CALL_ANSWERED));
+	
+	return rc;
 }
 
 /** Hang up a phone.
  *
- * @param phoneid Handle of the phone to be hung up.
- *
- * @return Zero on success or a negative error code.
- *
- */
-int ipc_hangup(int phoneid)
-{
-	return __SYSCALL1(SYS_IPC_HANGUP, phoneid);
+ * @param phandle  Handle of the phone to be hung up.
+ *
+ * @return  Zero on success or an error code.
+ *
+ */
+int ipc_hangup(cap_handle_t phandle)
+{
+	return (int) __SYSCALL1(SYS_IPC_HANGUP, phandle);
 }
 
 /** Forward a received call to another destination.
  *
- * For non-system methods, the old method, arg1 and arg2 are rewritten
- * by the new values. For system methods, the new method, arg1 and arg2
- * are written to the old arg1, arg2 and arg3, respectivelly. Calls with
- * immutable methods are forwarded verbatim.
- *
- * @param callid  Hash of the call to forward.
- * @param phoneid Phone handle to use for forwarding.
- * @param imethod New interface and method for the forwarded call.
- * @param arg1    New value of the first argument for the forwarded call.
- * @param arg2    New value of the second argument for the forwarded call.
- * @param mode    Flags specifying mode of the forward operation.
- *
- * @return Zero on success or an error code.
- *
- */
-int ipc_forward_fast(ipc_callid_t callid, int phoneid, sysarg_t imethod,
-    sysarg_t arg1, sysarg_t arg2, unsigned int mode)
-{
-	return __SYSCALL6(SYS_IPC_FORWARD_FAST, callid, phoneid, imethod, arg1,
+ * For non-system methods, the old method, arg1 and arg2 are rewritten by the
+ * new values. For system methods, the new method, arg1 and arg2 are written to
+ * the old arg1, arg2 and arg3, respectivelly. Calls with immutable methods are
+ * forwarded verbatim.
+ *
+ * @param chandle  Handle of the call to forward.
+ * @param phandle  Phone handle to use for forwarding.
+ * @param imethod  New interface and method for the forwarded call.
+ * @param arg1     New value of the first argument for the forwarded call.
+ * @param arg2     New value of the second argument for the forwarded call.
+ * @param mode     Flags specifying mode of the forward operation.
+ *
+ * @return  Zero on success or an error code.
+ *
+ */
+int ipc_forward_fast(cap_handle_t chandle, cap_handle_t phandle,
+    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, unsigned int mode)
+{
+	return (int) __SYSCALL6(SYS_IPC_FORWARD_FAST, chandle, phandle, imethod, arg1,
 	    arg2, mode);
 }
 
-int ipc_forward_slow(ipc_callid_t callid, int phoneid, sysarg_t imethod,
-    sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4, sysarg_t arg5,
-    unsigned int mode)
+int ipc_forward_slow(cap_handle_t chandle, cap_handle_t phandle,
+    sysarg_t imethod, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
+    sysarg_t arg4, sysarg_t arg5, unsigned int mode)
 {
 	ipc_call_t data;
@@ -507,6 +370,6 @@
 	IPC_SET_ARG5(data, arg5);
 	
-	return __SYSCALL4(SYS_IPC_FORWARD_SLOW, callid, phoneid, (sysarg_t) &data,
-	    mode);
+	return (int) __SYSCALL4(SYS_IPC_FORWARD_SLOW, chandle, phandle,
+	    (sysarg_t) &data, mode);
 }
 
@@ -514,14 +377,7 @@
  *
  */
-int ipc_connect_kbox(task_id_t id)
-{
-#ifdef __32_BITS__
-	sysarg64_t arg = (sysarg64_t) id;
-	return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) &arg);
-#endif
-	
-#ifdef __64_BITS__
-	return __SYSCALL1(SYS_IPC_CONNECT_KBOX, (sysarg_t) id);
-#endif
+int ipc_connect_kbox(task_id_t id, cap_handle_t *phone)
+{
+	return (int) __SYSCALL2(SYS_IPC_CONNECT_KBOX, (sysarg_t) &id, (sysarg_t) phone);
 }
 
Index: uspace/lib/c/generic/iplink.c
===================================================================
--- uspace/lib/c/generic/iplink.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/iplink.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -102,8 +102,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
@@ -131,8 +131,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
@@ -169,8 +169,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
@@ -191,8 +191,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
@@ -213,8 +213,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
@@ -234,8 +234,8 @@
 	}
 	
-	sysarg_t retval;
-	async_wait_for(req, &retval);
-	
-	return (int) retval;
+	int retval;
+	async_wait_for(req, &retval);
+	
+	return retval;
 }
 
Index: uspace/lib/c/generic/iplink_srv.c
===================================================================
--- uspace/lib/c/generic/iplink_srv.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/iplink_srv.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -78,5 +78,5 @@
 		async_answer_0(callid, rc);
 	
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -89,8 +89,7 @@
 	ipc_callid_t callid;
 
-	rc = async_data_write_receive(&callid, &size);
-	if (rc != EOK) {
-		async_answer_0(callid, (sysarg_t) rc);
-		async_answer_0(iid, (sysarg_t) rc);
+	if (!async_data_write_receive(&callid, &size)) {
+		async_answer_0(callid, EREFUSED);
+		async_answer_0(iid, EREFUSED);
 	}
 
@@ -105,5 +104,5 @@
 		async_answer_0(callid, rc);
 	
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -128,10 +127,10 @@
 	int rc = async_data_write_finalize(callid, &addr, size);
 	if (rc != EOK) {
-		async_answer_0(callid, (sysarg_t) rc);
-		async_answer_0(iid, (sysarg_t) rc);
+		async_answer_0(callid, rc);
+		async_answer_0(iid, rc);
 	}
 	
 	rc = srv->ops->addr_add(srv, &addr);
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -156,10 +155,10 @@
 	int rc = async_data_write_finalize(callid, &addr, size);
 	if (rc != EOK) {
-		async_answer_0(callid, (sysarg_t) rc);
-		async_answer_0(iid, (sysarg_t) rc);
+		async_answer_0(callid, rc);
+		async_answer_0(iid, rc);
 	}
 	
 	rc = srv->ops->addr_remove(srv, &addr);
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -205,6 +204,6 @@
 	int rc = async_data_write_finalize(callid, &sdu.dest, size);
 	if (rc != EOK) {
-		async_answer_0(callid, (sysarg_t) rc);
-		async_answer_0(iid, (sysarg_t) rc);
+		async_answer_0(callid, rc);
+		async_answer_0(iid, rc);
 	}
 	
@@ -322,5 +321,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK)
@@ -348,5 +347,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	if (retval != EOK)
Index: uspace/lib/c/generic/irc.c
===================================================================
--- uspace/lib/c/generic/irc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/irc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,6 +34,6 @@
 
 #include <assert.h>
+#include <async.h>
 #include <errno.h>
-#include <fibril_synch.h>
 #include <ipc/irc.h>
 #include <ipc/services.h>
@@ -72,5 +72,5 @@
 
 		// XXX This is just a temporary hack
-		fibril_usleep(500 * 1000);
+		async_usleep(500 * 1000);
 	}
 
Index: uspace/lib/c/generic/irq.c
===================================================================
--- uspace/lib/c/generic/irq.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/irq.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -58,14 +58,17 @@
  * @param ucode  Top-half pseudocode handler.
  *
- * @return IRQ capability handle returned by the kernel.
+ * @param[out] out_handle  IRQ capability handle returned by the kernel.
+ *
  * @return Error code returned by the kernel.
  *
  */
-int ipc_irq_subscribe(int inr, sysarg_t method, const irq_code_t *ucode)
+int ipc_irq_subscribe(int inr, sysarg_t method, const irq_code_t *ucode,
+    cap_handle_t *out_handle)
 {
 	if (ucode == NULL)
 		ucode = &default_ucode;
 	
-	return __SYSCALL3(SYS_IPC_IRQ_SUBSCRIBE, inr, method, (sysarg_t) ucode);
+	return (int) __SYSCALL4(SYS_IPC_IRQ_SUBSCRIBE, inr, method, (sysarg_t) ucode,
+	    (sysarg_t) out_handle);
 }
 
@@ -77,7 +80,7 @@
  *
  */
-int ipc_irq_unsubscribe(int cap)
+int ipc_irq_unsubscribe(cap_handle_t cap)
 {
-	return __SYSCALL1(SYS_IPC_IRQ_UNSUBSCRIBE, cap);
+	return (int) __SYSCALL1(SYS_IPC_IRQ_UNSUBSCRIBE, cap);
 }
 
Index: uspace/lib/c/generic/loader.c
===================================================================
--- uspace/lib/c/generic/loader.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/loader.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -52,11 +52,9 @@
  * @param name Symbolic name to set on the newly created task.
  *
- * @return Pointer to the loader connection structure (should be
- *         deallocated using free() after use).
- *
+ * @return Error code.
  */
 int loader_spawn(const char *name)
 {
-	return __SYSCALL2(SYS_PROGRAM_SPAWN_LOADER,
+	return (int) __SYSCALL2(SYS_PROGRAM_SPAWN_LOADER,
 	    (sysarg_t) name, str_size(name));
 }
@@ -86,5 +84,5 @@
  * @param task_id Points to a variable where the ID should be stored.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -96,5 +94,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, LOADER_GET_TASKID, &answer);
-	sysarg_t rc = async_data_read_start(exch, task_id, sizeof(task_id_t));
+	int rc = async_data_read_start(exch, task_id, sizeof(task_id_t));
 	
 	async_exchange_end(exch);
@@ -115,5 +113,5 @@
  * @param ldr  Loader connection structure.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -133,5 +131,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, LOADER_SET_CWD, &answer);
-	sysarg_t rc = async_data_write_start(exch, cwd, len);
+	int rc = async_data_write_start(exch, cwd, len);
 	
 	async_exchange_end(exch);
@@ -153,5 +151,5 @@
  * @param file Program file.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -163,5 +161,5 @@
 	aid_t req = async_send_0(exch, LOADER_SET_PROGRAM, &answer);
 
-	sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1);
+	int rc = async_data_write_start(exch, name, str_size(name) + 1);
 	if (rc == EOK) {
 		async_exch_t *vfs_exch = vfs_exchange_begin();
@@ -186,5 +184,5 @@
  * @param path Program path.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -198,10 +196,11 @@
 	}
 	
-	int fd = vfs_lookup(path, 0);
-	if (fd < 0) {
-		return fd;
-	}
-	
-	int rc = loader_set_program(ldr, name, fd);
+	int fd;
+	int rc = vfs_lookup(path, 0, &fd);
+	if (rc != EOK) {
+		return rc;
+	}
+	
+	rc = loader_set_program(ldr, name, fd);
 	vfs_put(fd);
 	return rc;
@@ -218,5 +217,5 @@
  * @param argv NULL-terminated array of pointers to arguments.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -253,5 +252,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, LOADER_SET_ARGS, &answer);
-	sysarg_t rc = async_data_write_start(exch, (void *) arg_buf,
+	int rc = async_data_write_start(exch, (void *) arg_buf,
 	    buffer_size);
 	
@@ -274,5 +273,5 @@
  * @param file       The file's descriptor.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -284,5 +283,5 @@
 	aid_t req = async_send_0(exch, LOADER_ADD_INBOX, NULL);
 	
-	sysarg_t rc = async_data_write_start(exch, name, str_size(name) + 1);
+	int rc = async_data_write_start(exch, name, str_size(name) + 1);
 	if (rc == EOK) {
 		rc = vfs_pass_handle(vfs_exch, file, exch);
@@ -308,5 +307,5 @@
  * @param ldr Loader connection structure.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -331,5 +330,5 @@
  * @param ldr Loader connection structure.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -357,5 +356,5 @@
  * @param ldr Loader connection structure.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
Index: uspace/lib/c/generic/loc.c
===================================================================
--- uspace/lib/c/generic/loc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/loc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,5 @@
 #include <async.h>
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <stdbool.h>
 
@@ -121,5 +121,5 @@
 			return rc;
 		
-		sysarg_t retval;
+		int retval;
 		async_wait_for(req, &retval);
 		if (retval != EOK)
@@ -245,5 +245,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_2(exch, LOC_SERVER_REGISTER, 0, 0, &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 	
 	if (retval != EOK) {
@@ -278,5 +278,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, LOC_SERVICE_REGISTER, &answer);
-	sysarg_t retval = async_data_write_start(exch, fqsn, str_size(fqsn));
+	int retval = async_data_write_start(exch, fqsn, str_size(fqsn));
 	
 	if (retval != EOK) {
@@ -314,5 +314,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	
 	exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
@@ -339,5 +339,5 @@
 	aid_t req = async_send_2(exch, LOC_SERVICE_GET_ID, flags, 0,
 	    &answer);
-	sysarg_t retval = async_data_write_start(exch, fqdn, str_size(fqdn));
+	int retval = async_data_write_start(exch, fqdn, str_size(fqdn));
 	
 	loc_exchange_end(exch);
@@ -371,5 +371,5 @@
  * @param name		Place to store pointer to new string. Caller should
  *			free it using free().
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 static int loc_get_name_internal(sysarg_t method, sysarg_t id, char **name)
@@ -379,5 +379,5 @@
 	ipc_call_t dreply;
 	size_t act_size;
-	sysarg_t dretval;
+	int dretval;
 	
 	*name = NULL;
@@ -397,5 +397,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -421,5 +421,5 @@
  * @param name		Place to store pointer to new string. Caller should
  *			free it using free().
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 int loc_category_get_name(category_id_t cat_id, char **name)
@@ -435,5 +435,5 @@
  * @param name		Place to store pointer to new string. Caller should
  *			free it using free().
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 int loc_service_get_name(service_id_t svc_id, char **name)
@@ -449,5 +449,5 @@
  * @param name		Place to store pointer to new string. Caller should
  *			free it using free().
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 int loc_service_get_server_name(service_id_t svc_id, char **name)
@@ -472,5 +472,5 @@
 	aid_t req = async_send_2(exch, LOC_NAMESPACE_GET_ID, flags, 0,
 	    &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 	
 	loc_exchange_end(exch);
@@ -503,5 +503,5 @@
  * @param cat_id	Place to store ID
  * @param flags		IPC_FLAG_BLOCKING to wait for location service to start
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 int loc_category_get_id(const char *name, category_id_t *cat_id,
@@ -521,5 +521,5 @@
 	aid_t req = async_send_0(exch, LOC_CATEGORY_GET_ID,
 	    &answer);
-	sysarg_t retval = async_data_write_start(exch, name, str_size(name));
+	int retval = async_data_write_start(exch, name, str_size(name));
 	
 	loc_exchange_end(exch);
@@ -574,4 +574,7 @@
 }
 
+/**
+ * @return ID of a new NULL device, or -1 if failed.
+ */
 int loc_null_create(void)
 {
@@ -610,10 +613,10 @@
  * @param svc_id	Service ID
  * @param cat_id	Category ID
- * @return		EOK on success or negative error code
+ * @return		EOK on success or an error code
  */
 int loc_service_add_to_cat(service_id_t svc_id, service_id_t cat_id)
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	
 	exch = loc_exchange_begin_blocking(INTERFACE_LOC_SUPPLIER);
@@ -692,5 +695,5 @@
 		}
 		
-		sysarg_t retval;
+		int retval;
 		async_wait_for(req, &retval);
 		
@@ -741,5 +744,5 @@
 		}
 		
-		sysarg_t retval;
+		int retval;
 		async_wait_for(req, &retval);
 		
@@ -768,5 +771,5 @@
 	}
 	
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 	
@@ -787,5 +790,5 @@
  * @param data		Place to store pointer to array of IDs
  * @param count		Place to store number of IDs
- * @return 		EOK on success or negative error code
+ * @return 		EOK on success or an error code
  */
 static int loc_get_ids_internal(sysarg_t method, sysarg_t arg1,
@@ -833,5 +836,5 @@
  * @param data		Place to store pointer to array of IDs
  * @param count		Place to store number of IDs
- * @return 		EOK on success or negative error code
+ * @return 		EOK on success or an error code
  */
 int loc_category_get_svcs(category_id_t cat_id, service_id_t **data,
@@ -848,5 +851,5 @@
  * @param data		Place to store pointer to array of IDs
  * @param count		Place to store number of IDs
- * @return 		EOK on success or negative error code
+ * @return 		EOK on success or an error code
  */
 int loc_get_categories(category_id_t **data, size_t *count)
Index: uspace/lib/c/generic/ns.c
===================================================================
--- uspace/lib/c/generic/ns.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/ns.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,5 +48,5 @@
 int service_register(service_t service)
 {
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 	
Index: uspace/lib/c/generic/perm.c
===================================================================
--- uspace/lib/c/generic/perm.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/perm.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -52,9 +52,9 @@
 #ifdef __32_BITS__
 	sysarg64_t arg = (sysarg64_t) id;
-	return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) &arg, (sysarg_t) perms);
+	return (int) __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) &arg, (sysarg_t) perms);
 #endif
 	
 #ifdef __64_BITS__
-	return __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) id, (sysarg_t) perms);
+	return (int) __SYSCALL2(SYS_PERM_GRANT, (sysarg_t) id, (sysarg_t) perms);
 #endif
 }
@@ -72,9 +72,9 @@
 #ifdef __32_BITS__
 	sysarg64_t arg = (sysarg64_t) id;
-	return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) &arg, (sysarg_t) perms);
+	return (int) __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) &arg, (sysarg_t) perms);
 #endif
 	
 #ifdef __64_BITS__
-	return __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) id, (sysarg_t) perms);
+	return (int) __SYSCALL2(SYS_PERM_REVOKE, (sysarg_t) id, (sysarg_t) perms);
 #endif
 }
Index: uspace/lib/c/generic/pio_trace.c
===================================================================
--- uspace/lib/c/generic/pio_trace.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/pio_trace.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,5 +35,5 @@
 #include <assert.h>
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <adt/list.h>
 #include <fibril_synch.h>
Index: uspace/lib/c/generic/smc.c
===================================================================
--- uspace/lib/c/generic/smc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/smc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 int smc_coherence(void *address, size_t size)
 {
-	return __SYSCALL2(SYS_SMC_COHERENCE, (sysarg_t) address,
+	return (int) __SYSCALL2(SYS_SMC_COHERENCE, (sysarg_t) address,
 	    (sysarg_t) size);
 }
Index: uspace/lib/c/generic/stats.c
===================================================================
--- uspace/lib/c/generic/stats.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/stats.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 #include <stdio.h>
 #include <inttypes.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #define SYSINFO_STATS_MAX_PATH  64
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/str.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,10 +37,9 @@
 
 #include <str.h>
+#include <stddef.h>
+#include <stdint.h>
 #include <stdlib.h>
-#include <stddef.h>
 #include <assert.h>
-#include <stdint.h>
 #include <ctype.h>
-#include <malloc.h>
 #include <errno.h>
 #include <align.h>
@@ -919,5 +918,5 @@
  * @param src	Source utf16 string.
  *
- * @return EOK, if success, negative otherwise.
+ * @return EOK, if success, an error code otherwise.
  */
 int utf16_to_str(char *dest, size_t size, const uint16_t *src)
@@ -962,5 +961,5 @@
  * @param src	Source string.
  *
- * @return EOK, if success, negative otherwise.
+ * @return EOK, if success, an error code otherwise.
  */
 int str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
Index: uspace/lib/c/generic/str_error.c
===================================================================
--- uspace/lib/c/generic/str_error.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/str_error.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2010 Martin Decky
+ * Copyright (c) 2017 CZ.NIC, z.s.p.o.
  * All rights reserved.
  *
@@ -38,53 +39,74 @@
 #include <fibril.h>
 
-#define MIN_ERRNO  -17
 #define NOERR_LEN  64
 
+/* The arrays below are automatically generated from the same file that
+ * errno.h constants are generated from. Triple-include of the same list
+ * with redefinitions of __errno() macro are used to ensure that the
+ * information cannot get out of synch. This is inpired by musl libc.
+ */
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) name,
+
+static const errno_t err_num[] = {
+#include <abi/errno.in>
+};
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) #name,
+
+static const char* err_name[] = {
+#include <abi/errno.in>
+};
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) "[" #name "]" desc,
+
 static const char* err_desc[] = {
-	"No error",
-	"No such entry",
-	"Not enough memory",
-	"Limit exceeded", 
-	"Connection refused",
-	"Forwarding error",
-	"Permission denied",
-	"Answerbox closed connection",
-	"Other party error",
-	"Entry already exists",
-	"Bad memory pointer",
-	"Not supported",
-	"Address not available",
-	"Timeout expired",
-	"Invalid value",
-	"Resource is busy",
-	"Result does not fit its size",
-	"Operation interrupted"
+#include <abi/errno.in>
 };
 
 static fibril_local char noerr[NOERR_LEN];
 
-const char *str_error(const int e)
+/* Returns index corresponding to the given errno, or -1 if not found. */
+static int find_errno(errno_t e)
 {
-	if ((e <= 0) && (e >= MIN_ERRNO))
-		return err_desc[-e];
-	
-	/* Ad hoc descriptions of error codes interesting for USB. */
-	// FIXME: integrate these as first-class error values
-	switch (e) {
-		case ENOFS:
-			return "No such file system type";
-		case EBADCHECKSUM:
-			return "Bad checksum";
-		case ESTALL:
-			return "Operation stalled";
-		case EAGAIN:
-			return "Resource temporarily unavailable";
-		case EEMPTY:
-			return "Resource is empty";
-		default:
-			break;
+	/* Just a dumb linear search.
+	 * There are too few entries to warrant anything smarter.
+	 */
+
+	int len = sizeof(err_num) / sizeof(errno_t);
+
+	for (int i = 0; i < len; i++) {
+		if (err_num[i] == e) {
+			return i;
+		}
 	}
 
-	snprintf(noerr, NOERR_LEN, "Unkown error code %d", e);
+	return -1;
+}
+
+const char *str_error_name(errno_t e)
+{
+	int i = find_errno(e);
+
+	if (i >= 0) {
+		return err_name[i];
+	}
+
+	snprintf(noerr, NOERR_LEN, "(%d)", (int)e);
+	return noerr;
+}
+
+const char *str_error(errno_t e)
+{
+	int i = find_errno(e);
+
+	if (i >= 0) {
+		return err_desc[i];
+	}
+
+	snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)e);
 	return noerr;
 }
Index: uspace/lib/c/generic/sysinfo.c
===================================================================
--- uspace/lib/c/generic/sysinfo.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/sysinfo.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,5 +37,5 @@
 #include <str.h>
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <stdbool.h>
 #include <stddef.h>
@@ -92,5 +92,5 @@
 	/* Get the data */
 	size_t sz;
-	ret = __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path,
+	ret = (int) __SYSCALL5(SYS_SYSINFO_GET_KEYS, (sysarg_t) path,
 	    (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,
 	    (sysarg_t) &sz);
@@ -186,5 +186,5 @@
 	/* Get the data */
 	size_t sz;
-	ret = __SYSCALL5(SYS_SYSINFO_GET_DATA, (sysarg_t) path,
+	ret = (int) __SYSCALL5(SYS_SYSINFO_GET_DATA, (sysarg_t) path,
 	    (sysarg_t) str_size(path), (sysarg_t) data, (sysarg_t) *size,
 	    (sysarg_t) &sz);
Index: uspace/lib/c/generic/task.c
===================================================================
--- uspace/lib/c/generic/task.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/task.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -45,5 +45,5 @@
 #include <errno.h>
 #include <ns.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <libc.h>
 #include "private/ns.h"
@@ -69,5 +69,5 @@
  *             program.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  */
 int task_set_name(const char *name)
@@ -75,5 +75,5 @@
 	assert(name);
 	
-	return __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
+	return (int) __SYSCALL2(SYS_TASK_SET_NAME, (sysarg_t) name, str_size(name));
 }
 
@@ -82,5 +82,5 @@
  * @param task_id ID of task to kill.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  */
 
@@ -101,5 +101,5 @@
  * @param argv Command-line arguments.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -143,5 +143,5 @@
  * @param std_err File to use as stderr.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -249,5 +249,5 @@
  * @param ap   Command-line arguments.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -287,5 +287,5 @@
  * @param ...  Command-line arguments.
  *
- * @return Zero on success or negative error code.
+ * @return Zero on success or an error code.
  *
  */
@@ -369,5 +369,5 @@
 	assert(retval);
 
-	sysarg_t rc;
+	int rc;
 	async_wait_for(wait->aid, &rc);
 
Index: uspace/lib/c/generic/thread.c
===================================================================
--- uspace/lib/c/generic/thread.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/thread.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -132,5 +132,5 @@
 	uarg->uspace_uarg = uarg;
 	
-	int rc = __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg,
+	int rc = (int) __SYSCALL4(SYS_THREAD_CREATE, (sysarg_t) uarg,
 	    (sysarg_t) name, (sysarg_t) str_size(name), (sysarg_t) tid);
 	
Index: uspace/lib/c/generic/time.c
===================================================================
--- uspace/lib/c/generic/time.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/time.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -51,5 +51,4 @@
 #include <loc.h>
 #include <device/clock_dev.h>
-#include <malloc.h>
 #include <thread.h>
 
@@ -955,5 +954,5 @@
  * @param result Structure to store the result to
  *
- * @return EOK or a negative error code
+ * @return EOK or an error code
  *
  */
@@ -985,5 +984,5 @@
  *             ASCTIME_BUF_LEN bytes long.
  *
- * @return EOK or a negative error code.
+ * @return EOK or an error code.
  *
  */
@@ -1037,5 +1036,5 @@
  * @param result Structure to store the result to.
  *
- * @return EOK on success or a negative error code.
+ * @return EOK on success or an error code.
  *
  */
@@ -1067,5 +1066,5 @@
  * @param result Structure to store the result to.
  *
- * @return EOK on success or a negative error code.
+ * @return EOK on success or an error code.
  *
  */
@@ -1089,5 +1088,5 @@
  *              ASCTIME_BUF_LEN bytes long.
  *
- * @return EOK on success or a negative error code.
+ * @return EOK on success or an error code.
  *
  */
Index: uspace/lib/c/generic/tls.c
===================================================================
--- uspace/lib/c/generic/tls.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/tls.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 #include <align.h>
 #include <tls.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <str.h>
 
Index: uspace/lib/c/generic/uuid.c
===================================================================
--- uspace/lib/c/generic/uuid.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/uuid.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -43,5 +43,5 @@
  *
  * @param uuid Place to store generated UUID
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int uuid_generate(uuid_t *uuid)
@@ -100,5 +100,5 @@
  * @param endptr Place to store pointer to end of UUID or @c NULL
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int uuid_parse(const char *str, uuid_t *uuid, const char **endptr)
Index: uspace/lib/c/generic/vbd.c
===================================================================
--- uspace/lib/c/generic/vbd.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/vbd.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -95,5 +95,5 @@
  * @param count Place to store length of array (number of entries)
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int vbd_get_disks(vbd_t *vbd, service_id_t **data, size_t *count)
@@ -106,5 +106,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
@@ -165,5 +165,5 @@
  * @param act_size Place to store actual size of complete data.
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 static int vbd_get_ids_once(vbd_t *vbd, sysarg_t method, sysarg_t arg1,
@@ -183,5 +183,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -203,5 +203,5 @@
  * @param data   Place to store pointer to array of IDs
  * @param count  Place to store number of IDs
- * @return       EOK on success or negative error code
+ * @return       EOK on success or an error code
  */
 static int vbd_get_ids_internal(vbd_t *vbd, sysarg_t method, sysarg_t arg1,
@@ -247,5 +247,5 @@
  * @param count Place to store length of array (number of entries)
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int vbd_label_get_parts(vbd_t *vbd, service_id_t disk,
@@ -259,5 +259,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
@@ -283,5 +283,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
@@ -332,5 +332,5 @@
  * @param ptype Place to store suggested partition type
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int vbd_suggest_ptype(vbd_t *vbd, service_id_t disk, label_pcnt_t pcnt,
@@ -338,5 +338,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
Index: uspace/lib/c/generic/vfs/inbox.c
===================================================================
--- uspace/lib/c/generic/vfs/inbox.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/vfs/inbox.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -120,5 +120,5 @@
  *
  * @param name Name of the entry.
- * @return Requested file or ENOENT if not set.
+ * @return Requested file or -1 if not set.
  */
 int inbox_get(const char *name)
@@ -130,9 +130,9 @@
 			return e->file;
 		case 1:
-			return ENOENT;
+			return -1;
 		} 
 	}
 
-	return ENOENT;
+	return -1;
 }
 
Index: uspace/lib/c/generic/vfs/mtab.c
===================================================================
--- uspace/lib/c/generic/vfs/mtab.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/vfs/mtab.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -76,9 +76,10 @@
 		struct stat st;
 		int rc;
+		int ret;
 
-		rc = asprintf(&child, "%s/%s", path, dirent->d_name);
-		if (rc < 0) {
+		ret = asprintf(&child, "%s/%s", path, dirent->d_name);
+		if (ret < 0) {
 			closedir(dir);
-			return rc;
+			return ENOMEM;
 		}
 
Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -86,5 +86,5 @@
  * and consume system resources.
  *
- * Functions that return int return a negative error code on error and do not
+ * Functions that return int return an error code on error and do not
  * set errno. Depending on function, success is signalled by returning either
  * EOK or a non-negative file handle.
@@ -104,11 +104,12 @@
  * 	aoff64_t pos = 42;
  * 	char buf[512];
- * 	ssize_t size = vfs_read(file, &pos, buf, sizeof(buf));
- * 	if (size < 0) {
+ *	size_t nread;
+ * 	rc = vfs_read(file, &pos, buf, sizeof(buf), &nread);
+ * 	if (rc != EOK) {
  * 		vfs_put(file);
- * 		return size;
+ * 		return rc;
  * 	}
  *
- *	// buf is now filled with data from file
+ *	// buf is now filled with nread bytes from file
  *
  *	vfs_put(file);
@@ -127,5 +128,5 @@
 static int root_fd = -1;
 
-static int get_parent_and_child(const char *path, char **child)
+static int get_parent_and_child(const char *path, int *parent, char **child)
 {
 	size_t size;
@@ -135,14 +136,18 @@
 
 	char *slash = str_rchr(apath, L'/');
-	int parent;
 	if (slash == apath) {
-		parent = vfs_root();
+		*parent = vfs_root();
+		if (*parent < 0) {
+			free(apath);
+			return EBADF;
+		}
 		*child = apath;
+		return EOK;
 	} else {
 		*slash = '\0';
-		parent = vfs_lookup(apath, WALK_DIRECTORY);
-		if (parent < 0) {
+		int rc = vfs_lookup(apath, WALK_DIRECTORY, parent);
+		if (rc != EOK) {
 			free(apath);
-			return parent;
+			return rc;
 		}
 		*slash = '/';
@@ -150,10 +155,11 @@
 		free(apath);
 		if (!*child) {
-			vfs_put(parent);
+			vfs_put(*parent);
 			return ENOMEM;
 		}
-	}
-
-	return parent;
+
+		return rc;
+	}
+
 }
 
@@ -230,12 +236,19 @@
  *                      handle will be allocated from high indices
  *
- * @return              New file handle on success or a negative error code
- */
-int vfs_clone(int file_from, int file_to, bool high)
-{
+ * @return              New file handle on success or an error code
+ */
+int vfs_clone(int file_from, int file_to, bool high, int *handle)
+{
+	assert(handle != NULL);
+
 	async_exch_t *vfs_exch = vfs_exchange_begin();
-	int rc = async_req_3_0(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from,
-	    (sysarg_t) file_to, (sysarg_t) high);
+	sysarg_t ret;
+	int rc = async_req_3_1(vfs_exch, VFS_IN_CLONE, (sysarg_t) file_from,
+	    (sysarg_t) file_to, (sysarg_t) high, &ret);
 	vfs_exchange_end(vfs_exch);
+
+	if (rc == EOK) {
+		*handle = ret;
+	}
 	return rc;
 }
@@ -246,5 +259,5 @@
  * @param size          Size of @a buf
  *
- * @return              EOK on success or a non-negative error code
+ * @return              EOK on success or a non-error code
  */
 int vfs_cwd_get(char *buf, size_t size)
@@ -267,5 +280,5 @@
  * @param path  Path of the new working directory
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_cwd_set(const char *path)
@@ -276,8 +289,9 @@
 		return ENOMEM;
 	
-	int fd = vfs_lookup(abs, WALK_DIRECTORY);
-	if (fd < 0) {
+	int fd;
+	int rc = vfs_lookup(abs, WALK_DIRECTORY, &fd);
+	if (rc != EOK) {
 		free(abs);
-		return fd;
+		return rc;
 	}
 	
@@ -356,10 +370,10 @@
  * @param info    Place to store volume identification information
  *
- * @return                      EOK on success or a negative error code
+ * @return                      EOK on success or an error code
  */
 int vfs_fsprobe(const char *fs_name, service_id_t serv,
     vfs_fs_probe_info_t *info)
 {
-	sysarg_t rc;
+	int rc;
 	
 	ipc_call_t answer;
@@ -390,5 +404,5 @@
  *        fstypes->fstypes[0..]. To free the list use vfs_fstypes_free().
  *
- * @return                      EOK on success or a negative error code
+ * @return                      EOK on success or an error code
  */
 int vfs_fstypes(vfs_fstypes_t *fstypes)
@@ -485,13 +499,13 @@
  * @param[out] linkedfd If not NULL, will receive a file handle to the linked
  *                      child
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_link(int parent, const char *child, vfs_file_kind_t kind, int *linkedfd)
 {
 	int flags = (kind == KIND_DIRECTORY) ? WALK_DIRECTORY : WALK_REGULAR;
-	int file = vfs_walk(parent, child, WALK_MUST_CREATE | flags);
-
-	if (file < 0)
-		return file;
+	int file = -1;
+	int rc = vfs_walk(parent, child, WALK_MUST_CREATE | flags, &file);
+	if (rc != EOK)
+		return rc;
 
 	if (linkedfd)
@@ -515,19 +529,20 @@
  * @param[out] linkedfd If not NULL, will receive a file handle to the linked
  *                      child
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_link_path(const char *path, vfs_file_kind_t kind, int *linkedfd)
 {
 	char *child;
-	int parent = get_parent_and_child(path, &child);
-	if (parent < 0)
-		return parent;
-
-	int rc = vfs_link(parent, child, kind, linkedfd);
+	int parent;
+	int rc = get_parent_and_child(path, &parent, &child);
+	if (rc != EOK)
+		return rc;
+
+	rc = vfs_link(parent, child, kind, linkedfd);
 
 	free(child);
 	vfs_put(parent);
 	return rc;
-}	
+}
 
 /** Lookup a path relative to the local root
@@ -535,9 +550,9 @@
  * @param path  Path to be looked up
  * @param flags Walk flags
- *
- * @return      File handle representing the result on success or a negative
- *              error code on error
- */
-int vfs_lookup(const char *path, int flags)
+ * @param[out] handle Pointer to variable where handle is to be written.
+ *
+ * @return      EOK on success or an error code.
+ */
+int vfs_lookup(const char *path, int flags, int *handle)
 {
 	size_t size;
@@ -545,4 +560,5 @@
 	if (!p)
 		return ENOMEM;
+
 	int root = vfs_root();
 	if (root < 0) {
@@ -550,5 +566,9 @@
 		return ENOENT;
 	}
-	int rc = vfs_walk(root, p, flags);
+
+	// XXX: Workaround for GCC diagnostics.
+	*handle = -1;
+
+	int rc = vfs_walk(root, p, flags, handle);
 	vfs_put(root);
 	free(p);
@@ -563,20 +583,23 @@
  * @param flags Walk flags
  * @param mode  Mode in which to open file in
- *
- * @return      EOK on success or a negative error code
- */
-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);
+ * @param[out] handle Pointer to variable where handle is to be written.
+ *
+ * @return      EOK on success or an error code
+ */
+int vfs_lookup_open(const char *path, int flags, int mode, int *handle)
+{
+	int file;
+	int rc = vfs_lookup(path, flags, &file);
+	if (rc != EOK)
+		return rc;
+
+	rc = vfs_open(file, mode);
 	if (rc != EOK) {
 		vfs_put(file);
 		return rc;
 	}
-	
-	return file;
+
+	*handle = file;
+	return EOK;
 }
 
@@ -591,10 +614,10 @@
  * @param[out] mountedfd        File handle of the mounted root if not NULL
  *
- * @return                      EOK on success or a negative error code
+ * @return                      EOK on success or an error code
  */
 int vfs_mount(int mp, const char *fs_name, service_id_t serv, const char *opts,
     unsigned int flags, unsigned int instance, int *mountedfd)
 {
-	sysarg_t rc, rc1;
+	int rc, rc1;
 	
 	if (!mountedfd)
@@ -635,5 +658,5 @@
  * @param[in] instance          Instance number of the file system server
  *
- * @return                      EOK on success or a negative error code
+ * @return                      EOK on success or an error code
  */
 int vfs_mount_path(const char *mp, const char *fs_name, const char *fqsn,
@@ -706,11 +729,10 @@
 		}
 		
-		int mpfd = vfs_walk(root_fd, mpa, WALK_DIRECTORY);
-		if (mpfd >= 0) {
+		int mpfd;
+		rc = vfs_walk(root_fd, mpa, WALK_DIRECTORY, &mpfd);
+		if (rc == EOK) {
 			rc = vfs_mount(mpfd, fs_name, service_id, opts, flags,
 			    instance, NULL);
 			vfs_put(mpfd);
-		} else {
-			rc = mpfd;
 		}
 	}
@@ -730,5 +752,5 @@
  * @param mode  Mode in which to open file in
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_open(int file, int mode)
@@ -747,5 +769,5 @@
  * @param exch          Exchange to the acceptor
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_pass_handle(async_exch_t *vfs_exch, int file, async_exch_t *exch)
@@ -759,5 +781,5 @@
  * @param file  File handle to put
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_put(int file)
@@ -774,8 +796,9 @@
  * @param high   If true, the received file handle will be allocated from high
  *               indices
- *
- * @return       EOK on success or a negative error code
- */
-int vfs_receive_handle(bool high)
+ * @param[out] handle  Received handle.
+ *
+ * @return       EOK on success or an error code
+ */
+int vfs_receive_handle(bool high, int *handle)
 {
 	ipc_callid_t callid;
@@ -790,11 +813,13 @@
 
 	sysarg_t ret;
-	sysarg_t rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret);
+	int rc = async_req_1_1(vfs_exch, VFS_IN_WAIT_HANDLE, high, &ret);
 
 	async_exchange_end(vfs_exch);
 
-	if (rc != EOK)
-		return rc;
-	return ret;
+	if (rc == EOK) {
+		*handle = (int) ret;
+	}
+
+	return rc;
 }
 
@@ -808,12 +833,14 @@
  * @param buf		Buffer, @a nbytes bytes long
  * @param nbytes	Number of bytes to read
- *
- * @return              On success, non-negative number of bytes read
- * @return              On failure, a negative error code
- */
-ssize_t vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte)
+ * @param nread		Place to store number of bytes actually read
+ *
+ * @return              On success, EOK and @a *nread is filled with number
+ *			of bytes actually read.
+ * @return              On failure, an error code
+ */
+int vfs_read(int file, aoff64_t *pos, void *buf, size_t nbyte, size_t *nread)
 {
 	ssize_t cnt = 0;
-	size_t nread = 0;
+	size_t nr = 0;
 	uint8_t *bp = (uint8_t *) buf;
 	int rc;
@@ -821,14 +848,18 @@
 	do {
 		bp += cnt;
-		nread += cnt;
+		nr += cnt;
 		*pos += cnt;
-		rc = vfs_read_short(file, *pos, bp, nbyte - nread, &cnt);
-	} while (rc == EOK && cnt > 0 && (nbyte - nread - cnt) > 0);
-	
-	if (rc != EOK)
-		return rc;
-	
+		rc = vfs_read_short(file, *pos, bp, nbyte - nr, &cnt);
+	} while (rc == EOK && cnt > 0 && (nbyte - nr - cnt) > 0);
+	
+	if (rc != EOK) {
+		*nread = nr;
+		return rc;
+	}
+	
+	nr += cnt;
 	*pos += cnt;
-	return nread + cnt;
+	*nread = nr;
+	return EOK;
 }
 
@@ -846,10 +877,10 @@
  * @param[out] nread	Actual number of bytes read (0 or more)
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_read_short(int file, aoff64_t pos, void *buf, size_t nbyte,
     ssize_t *nread)
 {
-	sysarg_t rc;
+	int rc;
 	ipc_call_t answer;
 	aid_t req;
@@ -888,10 +919,10 @@
  * @param new   New path
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_rename_path(const char *old, const char *new)
 {
-	sysarg_t rc;
-	sysarg_t rc_orig;
+	int rc;
+	int rc_orig;
 	aid_t req;
 	
@@ -955,5 +986,5 @@
  * @param length        New length
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_resize(int file, aoff64_t length)
@@ -969,16 +1000,20 @@
 /** Return a new file handle representing the local root
  *
- * @return      A clone of the local root file handle or a negative error code
+ * @return      A clone of the local root file handle or -1
  */
 int vfs_root(void)
 {
-	fibril_mutex_lock(&root_mutex);	
-	int r;
-	if (root_fd < 0)
-		r = ENOENT;
-	else
-		r = vfs_clone(root_fd, -1, true);
+	fibril_mutex_lock(&root_mutex);
+	int fd;
+	if (root_fd < 0) {
+		fd = -1;
+	} else {
+		int rc = vfs_clone(root_fd, -1, true, &fd);
+		if (rc != EOK) {
+			fd = -1;
+		}
+	}
 	fibril_mutex_unlock(&root_mutex);
-	return r;
+	return fd;
 }
 
@@ -990,12 +1025,22 @@
  *
  * @param nroot The new local root file handle
- */
-void vfs_root_set(int nroot)
-{
+ *
+ * @return  Error code
+ */
+int vfs_root_set(int nroot)
+{
+	int new_root;
+	int rc = vfs_clone(nroot, -1, true, &new_root);
+	if (rc != EOK) {
+		return rc;
+	}
+
 	fibril_mutex_lock(&root_mutex);
 	if (root_fd >= 0)
 		vfs_put(root_fd);
-	root_fd = vfs_clone(nroot, -1, true);
+	root_fd = new_root;
 	fibril_mutex_unlock(&root_mutex);
+
+	return EOK;
 }
 
@@ -1005,9 +1050,9 @@
  * @param[out] stat     Place to store file information
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_stat(int file, struct stat *stat)
 {
-	sysarg_t rc;
+	int rc;
 	aid_t req;
 	
@@ -1019,5 +1064,5 @@
 		vfs_exchange_end(exch);
 		
-		sysarg_t rc_orig;
+		int rc_orig;
 		async_wait_for(req, &rc_orig);
 		
@@ -1039,13 +1084,14 @@
  * @param[out] stat     Place to store file information
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_stat_path(const char *path, struct stat *stat)
 {
-	int file = vfs_lookup(path, 0);
-	if (file < 0)
-		return file;
-	
-	int rc = vfs_stat(file, stat);
+	int file;
+	int rc = vfs_lookup(path, 0, &file);
+	if (rc != EOK)
+		return rc;
+	
+	rc = vfs_stat(file, stat);
 
 	vfs_put(file);
@@ -1059,9 +1105,9 @@
  * @param[out] st       Buffer for storing information
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_statfs(int file, struct statfs *st)
 {
-	sysarg_t rc, ret;
+	int rc, ret;
 	aid_t req;
 
@@ -1084,13 +1130,14 @@
  * @param[out] st       Buffer for storing information
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_statfs_path(const char *path, struct statfs *st)
 {
-	int file = vfs_lookup(path, 0);
-	if (file < 0)
-		return file;
-	
-	int rc = vfs_statfs(file, st);
+	int file;
+	int rc = vfs_lookup(path, 0, &file);
+	if (rc != EOK)
+		return rc;
+	
+	rc = vfs_statfs(file, st);
 
 	vfs_put(file);
@@ -1103,5 +1150,5 @@
  * @param file  File handle to synchronize
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_sync(int file)
@@ -1125,9 +1172,9 @@
  * @param expect        File handle of the unlinked child
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_unlink(int parent, const char *child, int expect)
 {
-	sysarg_t rc;
+	int rc;
 	aid_t req;
 	
@@ -1139,5 +1186,5 @@
 	vfs_exchange_end(exch);
 	
-	sysarg_t rc_orig;
+	int rc_orig;
 	async_wait_for(req, &rc_orig);
 	
@@ -1154,20 +1201,22 @@
  * @param path          Old path to be unlinked
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_unlink_path(const char *path)
 {
-	int expect = vfs_lookup(path, 0);
-	if (expect < 0)
-		return expect;
+	int expect;
+	int rc = vfs_lookup(path, 0, &expect);
+	if (rc != EOK)
+		return rc;
 
 	char *child;
-	int parent = get_parent_and_child(path, &child);
-	if (parent < 0) {
+	int parent;
+	rc = get_parent_and_child(path, &parent, &child);
+	if (rc != EOK) {
 		vfs_put(expect);
-		return parent;
-	}
-
-	int rc = vfs_unlink(parent, child, expect);
+		return rc;
+	}
+
+	rc = vfs_unlink(parent, child, expect);
 	
 	free(child);
@@ -1181,5 +1230,5 @@
  * @param mp    File handle representing the mount-point
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_unmount(int mp)
@@ -1195,13 +1244,14 @@
  * @param mpp   Mount-point path
  *
- * @return      EOK on success or a negative error code
+ * @return      EOK on success or an error code
  */
 int vfs_unmount_path(const char *mpp)
 {
-	int mp = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY);
-	if (mp < 0)
-		return mp;
-	
-	int rc = vfs_unmount(mp);
+	int mp;
+	int rc = vfs_lookup(mpp, WALK_MOUNT_POINT | WALK_DIRECTORY, &mp);
+	if (rc != EOK)
+		return rc;
+	
+	rc = vfs_unmount(mp);
 	vfs_put(mp);
 	return rc;
@@ -1213,9 +1263,9 @@
  * @param path          Parent-relative path to be walked
  * @param flags         Flags influencing the walk
- *
- * @retrun              File handle representing the result on success or
- *                      a negative error code on error
- */
-int vfs_walk(int parent, const char *path, int flags)
+ * @param[out] handle   File handle representing the result on success.
+ *
+ * @return              Error code.
+ */
+int vfs_walk(int parent, const char *path, int flags, int *handle)
 {
 	async_exch_t *exch = vfs_exchange_begin();
@@ -1223,8 +1273,8 @@
 	ipc_call_t answer;
 	aid_t req = async_send_2(exch, VFS_IN_WALK, parent, flags, &answer);
-	sysarg_t rc = async_data_write_start(exch, path, str_size(path));
+	int rc = async_data_write_start(exch, path, str_size(path));
 	vfs_exchange_end(exch);
 		
-	sysarg_t rc_orig;
+	int rc_orig;
 	async_wait_for(req, &rc_orig);
 
@@ -1235,5 +1285,6 @@
 		return (int) rc;
 	
-	return (int) IPC_GET_ARG1(answer);
+	*handle = (int) IPC_GET_ARG1(answer);
+	return EOK;
 }
 
@@ -1247,12 +1298,15 @@
  * @param buf           Data, @a nbytes bytes long
  * @param nbytes        Number of bytes to write
- *
- * @return		On success, non-negative number of bytes written
- * @return              On failure, a negative error code
- */
-ssize_t vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte)
+ * @param nwritten	Place to store number of bytes written
+ *
+ * @return		On success, EOK, @a *nwr is filled with number
+ *			of bytes written
+ * @return              On failure, an error code
+ */
+int vfs_write(int file, aoff64_t *pos, const void *buf, size_t nbyte,
+    size_t *nwritten)
 {
 	ssize_t cnt = 0;
-	ssize_t nwritten = 0;
+	ssize_t nwr = 0;
 	const uint8_t *bp = (uint8_t *) buf;
 	int rc;
@@ -1260,14 +1314,18 @@
 	do {
 		bp += cnt;
-		nwritten += cnt;
+		nwr += cnt;
 		*pos += cnt;
-		rc = vfs_write_short(file, *pos, bp, nbyte - nwritten, &cnt);
-	} while (rc == EOK && ((ssize_t )nbyte - nwritten - cnt) > 0);
-
-	if (rc != EOK)
-		return rc;
-
+		rc = vfs_write_short(file, *pos, bp, nbyte - nwr, &cnt);
+	} while (rc == EOK && ((ssize_t )nbyte - nwr - cnt) > 0);
+
+	if (rc != EOK) {
+		*nwritten = nwr;
+		return rc;
+	}
+
+	nwr += cnt;
 	*pos += cnt;
-	return nbyte;
+	*nwritten = nwr;
+	return EOK;
 }
 
@@ -1283,10 +1341,10 @@
  * @param[out] nread    Actual number of bytes written (0 or more)
  *
- * @return              EOK on success or a negative error code
+ * @return              EOK on success or an error code
  */
 int vfs_write_short(int file, aoff64_t pos, const void *buf, size_t nbyte,
     ssize_t *nwritten)
 {
-	sysarg_t rc;
+	int rc;
 	ipc_call_t answer;
 	aid_t req;
Index: uspace/lib/c/generic/vol.c
===================================================================
--- uspace/lib/c/generic/vol.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/generic/vol.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -101,5 +101,5 @@
  * @param act_size Place to store actual size of complete data.
  *
- * @return EOK on success or negative error code.
+ * @return EOK on success or an error code.
  */
 static int vol_get_ids_once(vol_t *vol, sysarg_t method, sysarg_t arg1,
@@ -119,5 +119,5 @@
 	}
 
-	sysarg_t retval;
+	int retval;
 	async_wait_for(req, &retval);
 
@@ -139,5 +139,5 @@
  * @param data   Place to store pointer to array of IDs
  * @param count  Place to store number of IDs
- * @return       EOK on success or negative error code
+ * @return       EOK on success or an error code
  */
 static int vol_get_ids_internal(vol_t *vol, sysarg_t method, sysarg_t arg1,
@@ -183,5 +183,5 @@
  * @param count Place to store length of array (number of entries)
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  */
 int vol_get_parts(vol_t *vol, service_id_t **data, size_t *count)
@@ -215,5 +215,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
@@ -257,5 +257,5 @@
 {
 	async_exch_t *exch;
-	sysarg_t retval;
+	int retval;
 	ipc_call_t answer;
 
@@ -283,5 +283,5 @@
 	async_exch_t *exch;
 	ipc_call_t answer;
-	sysarg_t retval;
+	int retval;
 
 	exch = async_exchange_begin(vol->sess);
Index: uspace/lib/c/include/adt/circ_buf.h
===================================================================
--- uspace/lib/c/include/adt/circ_buf.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
+++ uspace/lib/c/include/adt/circ_buf.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -0,0 +1,65 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * 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 Circular buffer
+ */
+
+#ifndef LIBC_CIRC_BUF_H_
+#define LIBC_CIRC_BUF_H_
+
+#include <stddef.h>
+
+/** Circular buffer */
+typedef struct {
+	/** Buffer */
+	void *buf;
+	/** Number of buffer members */
+	size_t nmemb;
+	/** Member size */
+	size_t size;
+	/** Read position */
+	size_t rp;
+	/** Write position */
+	size_t wp;
+	/** Number of used entries */
+	size_t nused;
+} circ_buf_t;
+
+extern void circ_buf_init(circ_buf_t *, void *, size_t, size_t);
+extern size_t circ_buf_nfree(circ_buf_t *);
+extern size_t circ_buf_nused(circ_buf_t *);
+extern int circ_buf_push(circ_buf_t *, const void *);
+extern int circ_buf_pop(circ_buf_t *, void *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/adt/fifo.h
===================================================================
--- uspace/lib/c/include/adt/fifo.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/adt/fifo.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -46,5 +46,5 @@
 #define LIBC_FIFO_H_
 
-#include <malloc.h>
+#include <stdlib.h>
 
 typedef unsigned long fifo_count_t;
Index: uspace/lib/c/include/async.h
===================================================================
--- uspace/lib/c/include/async.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/async.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -49,6 +49,7 @@
 #include <abi/ipc/event.h>
 #include <abi/ipc/interfaces.h>
-
-typedef ipc_callid_t aid_t;
+#include <abi/cap.h>
+
+typedef sysarg_t aid_t;
 typedef sysarg_t port_id_t;
 
@@ -58,16 +59,15 @@
 /** Port connection handler
  *
- * @param callid ID of incoming call or 0 if connection initiated from
- *               inside using async_create_callback_port()
- * @param call   Incoming call or 0 if connection initiated from inside
- *               using async_create_callback_port()
- * @param arg    Local argument.
- *
- */
-typedef void (*async_port_handler_t)(ipc_callid_t, ipc_call_t *, void *);
+ * @param chandle  Handle of the incoming call or CAP_NIL if connection
+ *                 initiated from inside using async_create_callback_port()
+ * @param call     Incoming call or 0 if connection initiated from inside
+ *                 using async_create_callback_port()
+ * @param arg      Local argument.
+ *
+ */
+typedef void (*async_port_handler_t)(cap_handle_t, ipc_call_t *, void *);
 
 /** Notification handler */
-typedef void (*async_notification_handler_t)(ipc_callid_t, ipc_call_t *,
-    void *);
+typedef void (*async_notification_handler_t)(ipc_call_t *, void *);
 
 /** Exchange management style
@@ -119,5 +119,5 @@
 	async_get_call_timeout(data, 0)
 
-extern ipc_callid_t async_get_call_timeout(ipc_call_t *, suseconds_t);
+extern cap_handle_t async_get_call_timeout(ipc_call_t *, suseconds_t);
 
 /*
@@ -146,9 +146,11 @@
     sysarg_t, sysarg_t, sysarg_t, ipc_call_t *);
 
-extern void async_wait_for(aid_t, sysarg_t *);
-extern int async_wait_timeout(aid_t, sysarg_t *, suseconds_t);
+extern void async_wait_for(aid_t, int *);
+extern int async_wait_timeout(aid_t, int *, suseconds_t);
 extern void async_forget(aid_t);
 
 extern void async_usleep(suseconds_t);
+extern void async_sleep(unsigned int);
+
 extern void async_create_manager(void);
 extern void async_destroy_manager(void);
@@ -167,6 +169,6 @@
 
 extern int async_irq_subscribe(int, async_notification_handler_t, void *,
-    const irq_code_t *);
-extern int async_irq_unsubscribe(int);
+    const irq_code_t *, cap_handle_t *);
+extern int async_irq_unsubscribe(cap_handle_t);
 
 extern int async_event_subscribe(event_type_t, async_notification_handler_t,
@@ -196,12 +198,12 @@
  */
 
-extern sysarg_t async_answer_0(ipc_callid_t, sysarg_t);
-extern sysarg_t async_answer_1(ipc_callid_t, sysarg_t, sysarg_t);
-extern sysarg_t async_answer_2(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t);
-extern sysarg_t async_answer_3(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
+extern int async_answer_0(cap_handle_t, int);
+extern int async_answer_1(cap_handle_t, int, sysarg_t);
+extern int async_answer_2(cap_handle_t, int, sysarg_t, sysarg_t);
+extern int async_answer_3(cap_handle_t, int, sysarg_t, sysarg_t,
     sysarg_t);
-extern sysarg_t async_answer_4(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
+extern int async_answer_4(cap_handle_t, int, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t);
-extern sysarg_t async_answer_5(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
+extern int async_answer_5(cap_handle_t, int, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t, sysarg_t);
 
@@ -210,7 +212,7 @@
  */
 
-extern int async_forward_fast(ipc_callid_t, async_exch_t *, sysarg_t, sysarg_t,
+extern int async_forward_fast(cap_handle_t, async_exch_t *, sysarg_t, sysarg_t,
     sysarg_t, unsigned int);
-extern int async_forward_slow(ipc_callid_t, async_exch_t *, sysarg_t, sysarg_t,
+extern int async_forward_slow(cap_handle_t, async_exch_t *, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t, sysarg_t, sysarg_t, unsigned int);
 
@@ -336,8 +338,8 @@
 	    rc3, rc4, rc5)
 
-extern sysarg_t async_req_fast(async_exch_t *, sysarg_t, sysarg_t, sysarg_t,
+extern int async_req_fast(async_exch_t *, sysarg_t, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *, sysarg_t *,
     sysarg_t *);
-extern sysarg_t async_req_slow(async_exch_t *, sysarg_t, sysarg_t, sysarg_t,
+extern int async_req_slow(async_exch_t *, sysarg_t, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t, sysarg_t, sysarg_t *, sysarg_t *, sysarg_t *,
     sysarg_t *, sysarg_t *);
@@ -382,10 +384,10 @@
 extern int async_share_in_start(async_exch_t *, size_t, sysarg_t,
     unsigned int *, void **);
-extern bool async_share_in_receive(ipc_callid_t *, size_t *);
-extern int async_share_in_finalize(ipc_callid_t, void *, unsigned int);
+extern bool async_share_in_receive(cap_handle_t *, size_t *);
+extern int async_share_in_finalize(cap_handle_t, void *, unsigned int);
 
 extern int async_share_out_start(async_exch_t *, void *, unsigned int);
-extern bool async_share_out_receive(ipc_callid_t *, size_t *, unsigned int *);
-extern int async_share_out_finalize(ipc_callid_t, void **);
+extern bool async_share_out_receive(cap_handle_t *, size_t *, unsigned int *);
+extern int async_share_out_finalize(cap_handle_t, void **);
 
 /*
@@ -421,7 +423,7 @@
 extern aid_t async_data_read(async_exch_t *, void *, size_t, ipc_call_t *);
 extern int async_data_read_start(async_exch_t *, void *, size_t);
-extern bool async_data_read_receive(ipc_callid_t *, size_t *);
-extern bool async_data_read_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
-extern int async_data_read_finalize(ipc_callid_t, const void *, size_t);
+extern bool async_data_read_receive(cap_handle_t *, size_t *);
+extern bool async_data_read_receive_call(cap_handle_t *, ipc_call_t *, size_t *);
+extern int async_data_read_finalize(cap_handle_t, const void *, size_t);
 
 extern int async_data_read_forward_fast(async_exch_t *, sysarg_t, sysarg_t,
@@ -460,11 +462,11 @@
 
 extern int async_data_write_start(async_exch_t *, const void *, size_t);
-extern bool async_data_write_receive(ipc_callid_t *, size_t *);
-extern bool async_data_write_receive_call(ipc_callid_t *, ipc_call_t *, size_t *);
-extern int async_data_write_finalize(ipc_callid_t, void *, size_t);
+extern bool async_data_write_receive(cap_handle_t *, size_t *);
+extern bool async_data_write_receive_call(cap_handle_t *, ipc_call_t *, size_t *);
+extern int async_data_write_finalize(cap_handle_t, void *, size_t);
 
 extern int async_data_write_accept(void **, const bool, const size_t,
     const size_t, const size_t, size_t *);
-extern void async_data_write_void(sysarg_t);
+extern void async_data_write_void(int);
 
 extern int async_data_write_forward_fast(async_exch_t *, sysarg_t, sysarg_t,
@@ -476,7 +478,7 @@
 extern int async_state_change_start(async_exch_t *, sysarg_t, sysarg_t,
     sysarg_t, async_exch_t *);
-extern bool async_state_change_receive(ipc_callid_t *, sysarg_t *, sysarg_t *,
+extern bool async_state_change_receive(cap_handle_t *, sysarg_t *, sysarg_t *,
     sysarg_t *);
-extern int async_state_change_finalize(ipc_callid_t, async_exch_t *);
+extern int async_state_change_finalize(cap_handle_t, async_exch_t *);
 
 extern void *async_remote_state_acquire(async_sess_t *);
Index: uspace/lib/c/include/bd.h
===================================================================
--- uspace/lib/c/include/bd.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/bd.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -30,5 +30,5 @@
  * @{
  */
-/** @file
+/** @file Block device client interface
  */
 
Index: uspace/lib/c/include/device/hw_res.h
===================================================================
--- uspace/lib/c/include/device/hw_res.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/device/hw_res.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -123,5 +123,5 @@
 extern int hw_res_dma_channel_setup(async_sess_t *, unsigned int, uint32_t,
     uint32_t, uint8_t);
-extern int hw_res_dma_channel_remain(async_sess_t *, unsigned);
+extern int hw_res_dma_channel_remain(async_sess_t *, unsigned, size_t *);
 
 #endif
Index: uspace/lib/c/include/elf/elf_mod.h
===================================================================
--- uspace/lib/c/include/elf/elf_mod.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/elf/elf_mod.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -53,4 +53,5 @@
 #define EE_LOADER		5	/* The image is actually a program loader. */
 #define EE_IRRECOVERABLE	6
+#define EE_IO			7	/* Could not read file. */
 
 typedef enum {
Index: uspace/lib/c/include/errno.h
===================================================================
--- uspace/lib/c/include/errno.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/errno.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,39 +36,10 @@
 #define LIBC_ERRNO_H_
 
+#include <_bits/errno.h>
 #include <abi/errno.h>
 
 #define errno  (*(__errno()))
 
-extern int *__errno(void) __attribute__((const));
-
-#define EMFILE        (-18)
-#define ENAMETOOLONG  (-256)
-#define EISDIR        (-257)
-#define ENOTDIR       (-258)
-#define ENOSPC        (-259)
-#define ENOTEMPTY     (-261)
-#define EBADF         (-262)
-#define EDOM          (-263)
-#define ERANGE        (-264)
-#define EXDEV         (-265)
-#define EIO           (-266)
-#define EMLINK        (-267)
-#define ENXIO         (-268)
-#define ENOFS         (-269)
-
-/** Bad checksum. */
-#define EBADCHECKSUM  (-300)
-
-/** USB: stalled operation. */
-#define ESTALL (-301)
-
-/** Empty resource (no data). */
-#define EEMPTY (-302)
-
-/** Negative acknowledgment. */
-#define ENAK (-303)
-
-/** The requested operation was not performed. Try again later. */
-#define EAGAIN  (-11002)
+extern errno_t *__errno(void) __attribute__((const));
 
 #endif
Index: uspace/lib/c/include/fibril.h
===================================================================
--- uspace/lib/c/include/fibril.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/fibril.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -102,7 +102,4 @@
 extern void fibril_remove_manager(void);
 extern fid_t fibril_get_id(void);
-extern void fibril_inc_sercount(void);
-extern void fibril_dec_sercount(void);
-extern int fibril_get_sercount(void);
 
 static inline int fibril_yield(void)
Index: uspace/lib/c/include/fibril_synch.h
===================================================================
--- uspace/lib/c/include/fibril_synch.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/fibril_synch.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -173,6 +173,4 @@
 extern fibril_timer_state_t fibril_timer_clear(fibril_timer_t *);
 extern fibril_timer_state_t fibril_timer_clear_locked(fibril_timer_t *);
-extern void fibril_usleep(useconds_t);
-extern void fibril_sleep(unsigned int);
 
 #endif
Index: uspace/lib/c/include/futex.h
===================================================================
--- uspace/lib/c/include/futex.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/futex.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,4 +37,5 @@
 
 #include <atomic.h>
+#include <errno.h>
 #include <libc.h>
 
@@ -107,9 +108,9 @@
  * @param futex Futex.
  *
- * @return Non-zero if the futex was acquired.
- * @return Zero if the futex was not acquired.
+ * @return true if the futex was acquired.
+ * @return false if the futex was not acquired.
  *
  */
-static inline int futex_trydown(futex_t *futex)
+static inline bool futex_trydown(futex_t *futex)
 {
 	return cas(&futex->val, 1, 0);
@@ -121,6 +122,6 @@
  *
  * @return ENOENT if there is no such virtual address.
- * @return Zero in the uncontended case.
- * @return Otherwise one of ESYNCH_OK_ATOMIC or ESYNCH_OK_BLOCKED.
+ * @return EOK on success.
+ * @return Error code from <errno.h> otherwise.
  *
  */
@@ -128,7 +129,7 @@
 {
 	if ((atomic_signed_t) atomic_predec(&futex->val) < 0)
-		return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->val.count);
+		return (int) __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->val.count);
 	
-	return 0;
+	return EOK;
 }
 
@@ -138,5 +139,6 @@
  *
  * @return ENOENT if there is no such virtual address.
- * @return Zero in the uncontended case.
+ * @return EOK on success.
+ * @return Error code from <errno.h> otherwise.
  *
  */
@@ -144,7 +146,7 @@
 {
 	if ((atomic_signed_t) atomic_postinc(&futex->val) < 0)
-		return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->val.count);
+		return (int) __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->val.count);
 	
-	return 0;
+	return EOK;
 }
 
Index: uspace/lib/c/include/ieee80211/ieee80211.h
===================================================================
--- uspace/lib/c/include/ieee80211/ieee80211.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ieee80211/ieee80211.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,5 +38,4 @@
 #define LIBC_IEEE80211_H_
 
-#include <malloc.h>
 #include <adt/list.h>
 #include <nic/nic.h>
Index: uspace/lib/c/include/io/chardev.h
===================================================================
--- uspace/lib/c/include/io/chardev.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/io/chardev.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,5 @@
 /*
  * Copyright (c) 2011 Jan Vesely
+ * Copyright (c) 2017 Jiri Svoboda
  * All rights reserved.
  *
@@ -33,9 +34,15 @@
 #define LIBC_IO_CHARDEV_H_
 
-#include <types/common.h>
 #include <async.h>
+#include <stddef.h>
 
-ssize_t chardev_read(async_exch_t *, void *, size_t);
-ssize_t chardev_write(async_exch_t *, const void *, size_t);
+typedef struct {
+	async_sess_t *sess;
+} chardev_t;
+
+extern int chardev_open(async_sess_t *, chardev_t **);
+extern void chardev_close(chardev_t *);
+extern int chardev_read(chardev_t *, void *, size_t, size_t *);
+extern int chardev_write(chardev_t *, const void *, size_t, size_t *);
 
 #endif
Index: uspace/lib/c/include/io/chardev_srv.h
===================================================================
--- uspace/lib/c/include/io/chardev_srv.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/io/chardev_srv.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -59,6 +59,7 @@
 	int (*open)(chardev_srvs_t *, chardev_srv_t *);
 	int (*close)(chardev_srv_t *);
-	int (*read)(chardev_srv_t *, void *, size_t);
-	int (*write)(chardev_srv_t *, const void *, size_t);
+	int (*read)(chardev_srv_t *, void *, size_t, size_t *);
+	int (*write)(chardev_srv_t *, const void *, size_t, size_t *);
+	void (*def_handler)(chardev_srv_t *, ipc_callid_t, ipc_call_t *);
 };
 
Index: uspace/lib/c/include/io/con_srv.h
===================================================================
--- uspace/lib/c/include/io/con_srv.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/io/con_srv.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -69,6 +69,6 @@
 	int (*open)(con_srvs_t *, con_srv_t *);
 	int (*close)(con_srv_t *);
-	int (*read)(con_srv_t *, void *, size_t);
-	int (*write)(con_srv_t *, void *, size_t);
+	int (*read)(con_srv_t *, void *, size_t, size_t *);
+	int (*write)(con_srv_t *, void *, size_t, size_t *);
 	void (*sync)(con_srv_t *);
 	void (*clear)(con_srv_t *);
Index: uspace/lib/c/include/io/klog.h
===================================================================
--- uspace/lib/c/include/io/klog.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/io/klog.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,20 +44,15 @@
 #include <abi/log.h>
 
-extern size_t klog_write(log_level_t, const void *, size_t);
-extern int klog_read(void *, size_t);
+extern int klog_write(log_level_t, const void *, size_t);
+extern int klog_read(void *, size_t, size_t *);
 
 #define KLOG_PRINTF(lvl, fmt, ...) ({ \
-	char *_fmt = str_dup(fmt); \
-	size_t _fmtsize = str_size(_fmt); \
-	if (_fmtsize > 0 && _fmt[_fmtsize - 1] == '\n') \
-		_fmt[_fmtsize - 1] = 0; \
 	char *_s; \
-	int _c = asprintf(&_s, _fmt, ##__VA_ARGS__); \
-	free(_fmt); \
-	if (_c >= 0) { \
-		_c = klog_write((lvl), _s, str_size(_s)); \
+	int _rc = ENOMEM; \
+	if (asprintf(&_s, fmt, ##__VA_ARGS__) >= 0) { \
+		_rc = klog_write((lvl), _s, str_size(_s)); \
 		free(_s); \
 	}; \
-	(_c >= 0); \
+	(_rc != EOK); \
 })
 
Index: uspace/lib/c/include/io/serial.h
===================================================================
--- uspace/lib/c/include/io/serial.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
+++ uspace/lib/c/include/io/serial.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * 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_IO_SERIAL_H_
+#define LIBC_IO_SERIAL_H_
+
+#include <async.h>
+#include <ipc/serial_ctl.h>
+
+typedef struct {
+	async_sess_t *sess;
+} serial_t;
+
+extern int serial_open(async_sess_t *, serial_t **);
+extern void serial_close(serial_t *);
+extern int serial_set_comm_props(serial_t *, unsigned, serial_parity_t,
+    unsigned, unsigned);
+extern int serial_get_comm_props(serial_t *, unsigned *, serial_parity_t *,
+    unsigned *, unsigned *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/include/io/table.h
===================================================================
--- uspace/lib/c/include/io/table.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/io/table.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,4 +40,5 @@
 #include <stddef.h>
 #include <stdio.h>
+#include <errno.h>
 
 /** Table metrics */
Index: uspace/lib/c/include/ipc/char.h
===================================================================
--- uspace/lib/c/include/ipc/char.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,52 +1,0 @@
-/*
- * Copyright (c) 2009 Jiri Svoboda
- * 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 libcipc
- * @{
- */
-/** @file
- * @brief Character device interface.
- */
-
-#ifndef LIBC_IPC_CHAR_H_
-#define LIBC_IPC_CHAR_H_
-
-#include <ipc/common.h>
-
-typedef enum {
-	CHAR_WRITE_BYTE = IPC_FIRST_USER_METHOD
-} char_request_t;
-
-typedef enum {
-	CHAR_NOTIF_BYTE = IPC_FIRST_USER_METHOD
-} char_notif_t;
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/include/ipc/chardev.h
===================================================================
--- uspace/lib/c/include/ipc/chardev.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/chardev.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,6 +41,10 @@
 typedef enum {
 	CHARDEV_READ = IPC_FIRST_USER_METHOD,
-	CHARDEV_WRITE
+	CHARDEV_WRITE,
 } chardev_request_t;
+
+enum {
+	CHARDEV_LIMIT = CHARDEV_WRITE + 1
+};
 
 #endif
Index: uspace/lib/c/include/ipc/common.h
===================================================================
--- uspace/lib/c/include/ipc/common.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/common.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,6 +40,9 @@
 #include <abi/proc/task.h>
 #include <futex.h>
+#include <abi/cap.h>
 
 #define IPC_FLAG_BLOCKING  0x01
+
+struct async_call;
 
 typedef struct {
@@ -47,7 +50,10 @@
 	task_id_t in_task_id;
 	sysarg_t in_phone_hash;
+	unsigned flags;
+	struct async_call *label;
+	cap_handle_t cap_handle;
 } ipc_call_t;
 
-typedef sysarg_t ipc_callid_t;
+typedef cap_handle_t ipc_callid_t;
 
 extern futex_t async_futex;
Index: uspace/lib/c/include/ipc/dev_iface.h
===================================================================
--- uspace/lib/c/include/ipc/dev_iface.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/dev_iface.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -30,5 +30,5 @@
 #define LIBC_IPC_DEV_IFACE_H_
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <types/common.h>
 
Index: uspace/lib/c/include/ipc/devman.h
===================================================================
--- uspace/lib/c/include/ipc/devman.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/devman.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,6 +36,6 @@
 #include <ipc/common.h>
 #include <adt/list.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 
 #define DEVMAN_NAME_MAXLEN  256
Index: uspace/lib/c/include/ipc/ipc.h
===================================================================
--- uspace/lib/c/include/ipc/ipc.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/ipc.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,8 +44,9 @@
 #include <abi/synch.h>
 #include <abi/proc/task.h>
+#include <abi/cap.h>
 
 typedef void (*ipc_async_callback_t)(void *, int, ipc_call_t *);
 
-extern ipc_callid_t ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
+extern int ipc_wait_cycle(ipc_call_t *, sysarg_t, unsigned int);
 extern void ipc_poke(void);
 
@@ -53,6 +54,6 @@
 	ipc_wait_for_call_timeout(data, SYNCH_NO_TIMEOUT);
 
-extern ipc_callid_t ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
-extern ipc_callid_t ipc_trywait_for_call(ipc_call_t *);
+extern int ipc_wait_for_call_timeout(ipc_call_t *, sysarg_t);
+extern int ipc_trywait_for_call(ipc_call_t *);
 
 /*
@@ -63,20 +64,21 @@
  */
 
-#define ipc_answer_0(callid, retval) \
-	ipc_answer_fast((callid), (retval), 0, 0, 0, 0)
-#define ipc_answer_1(callid, retval, arg1) \
-	ipc_answer_fast((callid), (retval), (arg1), 0, 0, 0)
-#define ipc_answer_2(callid, retval, arg1, arg2) \
-	ipc_answer_fast((callid), (retval), (arg1), (arg2), 0, 0)
-#define ipc_answer_3(callid, retval, arg1, arg2, arg3) \
-	ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), 0)
-#define ipc_answer_4(callid, retval, arg1, arg2, arg3, arg4) \
-	ipc_answer_fast((callid), (retval), (arg1), (arg2), (arg3), (arg4))
-#define ipc_answer_5(callid, retval, arg1, arg2, arg3, arg4, arg5) \
-	ipc_answer_slow((callid), (retval), (arg1), (arg2), (arg3), (arg4), (arg5))
+#define ipc_answer_0(chandle, retval) \
+	ipc_answer_fast((chandle), (retval), 0, 0, 0, 0)
+#define ipc_answer_1(chandle, retval, arg1) \
+	ipc_answer_fast((chandle), (retval), (arg1), 0, 0, 0)
+#define ipc_answer_2(chandle, retval, arg1, arg2) \
+	ipc_answer_fast((chandle), (retval), (arg1), (arg2), 0, 0)
+#define ipc_answer_3(chandle, retval, arg1, arg2, arg3) \
+	ipc_answer_fast((chandle), (retval), (arg1), (arg2), (arg3), 0)
+#define ipc_answer_4(chandle, retval, arg1, arg2, arg3, arg4) \
+	ipc_answer_fast((chandle), (retval), (arg1), (arg2), (arg3), (arg4))
+#define ipc_answer_5(chandle, retval, arg1, arg2, arg3, arg4, arg5) \
+	ipc_answer_slow((chandle), (retval), (arg1), (arg2), (arg3), (arg4), \
+	    (arg5))
 
-extern sysarg_t ipc_answer_fast(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
+extern int ipc_answer_fast(cap_handle_t, int, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t);
-extern sysarg_t ipc_answer_slow(ipc_callid_t, sysarg_t, sysarg_t, sysarg_t,
+extern int ipc_answer_slow(cap_handle_t, int, sysarg_t, sysarg_t,
     sysarg_t, sysarg_t, sysarg_t);
 
@@ -88,38 +90,37 @@
  */
 
-#define ipc_call_async_0(phoneid, method, private, callback) \
-	ipc_call_async_fast((phoneid), (method), 0, 0, 0, 0, (private), \
+#define ipc_call_async_0(phandle, method, private, callback) \
+	ipc_call_async_fast((phandle), (method), 0, 0, 0, (private), (callback))
+#define ipc_call_async_1(phandle, method, arg1, private, callback) \
+	ipc_call_async_fast((phandle), (method), (arg1), 0, 0, (private), \
 	    (callback))
-#define ipc_call_async_1(phoneid, method, arg1, private, callback) \
-	ipc_call_async_fast((phoneid), (method), (arg1), 0, 0, 0, (private), \
-	    (callback))
-#define ipc_call_async_2(phoneid, method, arg1, arg2, private, callback) \
-	ipc_call_async_fast((phoneid), (method), (arg1), (arg2), 0, 0, \
+#define ipc_call_async_2(phandle, method, arg1, arg2, private, callback) \
+	ipc_call_async_fast((phandle), (method), (arg1), (arg2), 0, \
 	    (private), (callback))
-#define ipc_call_async_3(phoneid, method, arg1, arg2, arg3, private, callback) \
-	ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), 0, \
+#define ipc_call_async_3(phandle, method, arg1, arg2, arg3, private, callback) \
+	ipc_call_async_fast((phandle), (method), (arg1), (arg2), (arg3), \
 	    (private), (callback))
-#define ipc_call_async_4(phoneid, method, arg1, arg2, arg3, arg4, private, \
+#define ipc_call_async_4(phandle, method, arg1, arg2, arg3, arg4, private, \
     callback) \
-	ipc_call_async_fast((phoneid), (method), (arg1), (arg2), (arg3), \
-	    (arg4), (private), (callback))
-#define ipc_call_async_5(phoneid, method, arg1, arg2, arg3, arg4, arg5, \
+	ipc_call_async_slow((phandle), (method), (arg1), (arg2), (arg3), \
+	    (arg4), 0, (private), (callback))
+#define ipc_call_async_5(phandle, method, arg1, arg2, arg3, arg4, arg5, \
     private, callback) \
-	ipc_call_async_slow((phoneid), (method), (arg1), (arg2), (arg3), \
+	ipc_call_async_slow((phandle), (method), (arg1), (arg2), (arg3), \
 	    (arg4), (arg5), (private), (callback))
 
-extern void ipc_call_async_fast(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
+extern void ipc_call_async_fast(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
     sysarg_t, void *, ipc_async_callback_t);
-extern void ipc_call_async_slow(int, sysarg_t, sysarg_t, sysarg_t, sysarg_t,
-    sysarg_t, sysarg_t, void *, ipc_async_callback_t);
+extern void ipc_call_async_slow(cap_handle_t, sysarg_t, sysarg_t, sysarg_t,
+    sysarg_t, sysarg_t, sysarg_t, void *, ipc_async_callback_t);
 
-extern int ipc_hangup(int);
+extern int ipc_hangup(cap_handle_t);
 
-extern int ipc_forward_fast(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
-    unsigned int);
-extern int ipc_forward_slow(ipc_callid_t, int, sysarg_t, sysarg_t, sysarg_t,
-    sysarg_t, sysarg_t, sysarg_t, unsigned int);
+extern int ipc_forward_fast(cap_handle_t, cap_handle_t, sysarg_t, sysarg_t,
+    sysarg_t, unsigned int);
+extern int ipc_forward_slow(cap_handle_t, cap_handle_t, sysarg_t, sysarg_t,
+    sysarg_t, sysarg_t, sysarg_t, sysarg_t, unsigned int);
 
-extern int ipc_connect_kbox(task_id_t);
+extern int ipc_connect_kbox(task_id_t, cap_handle_t *);
 
 #endif
Index: uspace/lib/c/include/ipc/irq.h
===================================================================
--- uspace/lib/c/include/ipc/irq.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/irq.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,7 +38,8 @@
 #include <types/common.h>
 #include <abi/ddi/irq.h>
+#include <abi/cap.h>
 
-extern int ipc_irq_subscribe(int, sysarg_t, const irq_code_t *);
-extern int ipc_irq_unsubscribe(int);
+extern int ipc_irq_subscribe(int, sysarg_t, const irq_code_t *, cap_handle_t *);
+extern int ipc_irq_unsubscribe(cap_handle_t);
 
 #endif
Index: uspace/lib/c/include/ipc/serial_ctl.h
===================================================================
--- uspace/lib/c/include/ipc/serial_ctl.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/serial_ctl.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -30,5 +30,5 @@
 #define LIBC_IPC_SERIAL_CTL_H_
 
-#include <ipc/dev_iface.h>
+#include <ipc/chardev.h>
 
 /** IPC methods for getting/setting serial communication properties
@@ -41,5 +41,5 @@
  */
 typedef enum {
-	SERIAL_GET_COM_PROPS = DEV_FIRST_CUSTOM_METHOD,
+	SERIAL_GET_COM_PROPS = CHARDEV_LIMIT,
 	SERIAL_SET_COM_PROPS
 } serial_ctl_t;
Index: uspace/lib/c/include/ipc/services.h
===================================================================
--- uspace/lib/c/include/ipc/services.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/services.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -49,4 +49,7 @@
 } service_t;
 
+#define SERVICE_NAME_CHARDEV_TEST_SMALLX "chardev-test/smallx"
+#define SERVICE_NAME_CHARDEV_TEST_LARGEX "chardev-test/largex"
+#define SERVICE_NAME_CHARDEV_TEST_PARTIALX "chardev-test/partialx"
 #define SERVICE_NAME_CLIPBOARD "clipboard"
 #define SERVICE_NAME_CORECFG  "corecfg"
Index: uspace/lib/c/include/ipc/tcp.h
===================================================================
--- uspace/lib/c/include/ipc/tcp.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/tcp.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2015 Jiri Svobda
+ * Copyright (c) 2015 Jiri Svoboda
  * All rights reserved.
  *
Index: uspace/lib/c/include/ipc/udp.h
===================================================================
--- uspace/lib/c/include/ipc/udp.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/ipc/udp.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2015 Jiri Svobda
+ * Copyright (c) 2015 Jiri Svoboda
  * All rights reserved.
  *
Index: uspace/lib/c/include/str_error.h
===================================================================
--- uspace/lib/c/include/str_error.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/str_error.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,8 @@
 #define LIBC_STRERROR_H_
 
-const char *str_error(const int);
+#include <errno.h>
+
+const char *str_error(errno_t);
+const char *str_error_name(errno_t);
 
 #endif
Index: uspace/lib/c/include/sys/time.h
===================================================================
--- uspace/lib/c/include/sys/time.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/sys/time.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -93,6 +93,6 @@
 extern int time_local2str(const time_t, char *);
 extern double difftime(time_t, time_t);
-extern size_t strftime(char *restrict, size_t, const char *restrict,
-    const struct tm *restrict);
+extern size_t strftime(char *__restrict__, size_t, const char *__restrict__,
+    const struct tm *__restrict__);
 
 #endif
Index: uspace/lib/c/include/types/common.h
===================================================================
--- uspace/lib/c/include/types/common.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/types/common.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -45,4 +45,5 @@
 
 #include <_bits/all.h>
+#include <_bits/errno.h>
 
 #endif
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/include/vfs/vfs.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -85,5 +85,5 @@
 
 extern char *vfs_absolutize(const char *, size_t *);
-extern int vfs_clone(int, int, bool);
+extern int vfs_clone(int, int, bool, int *);
 extern int vfs_cwd_get(char *path, size_t);
 extern int vfs_cwd_set(const char *path);
@@ -95,6 +95,6 @@
 extern int vfs_link(int, const char *, vfs_file_kind_t, int *);
 extern int vfs_link_path(const char *, vfs_file_kind_t, int *);
-extern int vfs_lookup(const char *, int);
-extern int vfs_lookup_open(const char *, int, int);
+extern int vfs_lookup(const char *, int, int *);
+extern int vfs_lookup_open(const char *, int, int, int *);
 extern int vfs_mount_path(const char *, const char *, const char *,
     const char *, unsigned int, unsigned int);
@@ -104,11 +104,11 @@
 extern int vfs_pass_handle(async_exch_t *, int, async_exch_t *);
 extern int vfs_put(int);
-extern ssize_t vfs_read(int, aoff64_t *, void *, size_t);
+extern int vfs_read(int, aoff64_t *, void *, size_t, size_t *);
 extern int vfs_read_short(int, aoff64_t, void *, size_t, ssize_t *);
-extern int vfs_receive_handle(bool);
+extern int vfs_receive_handle(bool, int *);
 extern int vfs_rename_path(const char *, const char *);
 extern int vfs_resize(int, aoff64_t);
 extern int vfs_root(void);
-extern void vfs_root_set(int);
+extern int vfs_root_set(int);
 extern int vfs_stat(int, struct stat *);
 extern int vfs_stat_path(const char *, struct stat *);
@@ -120,6 +120,6 @@
 extern int vfs_unmount(int);
 extern int vfs_unmount_path(const char *);
-extern int vfs_walk(int, const char *, int);
-extern ssize_t vfs_write(int, aoff64_t *, const void *, size_t);
+extern int vfs_walk(int, const char *, int, int *);
+extern int vfs_write(int, aoff64_t *, const void *, size_t, size_t *);
 extern int vfs_write_short(int, aoff64_t, const void *, size_t, ssize_t *);
 
Index: uspace/lib/c/test/adt/circ_buf.c
===================================================================
--- uspace/lib/c/test/adt/circ_buf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
+++ uspace/lib/c/test/adt/circ_buf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -0,0 +1,81 @@
+/*
+ * Copyright (c) 2017 Jiri Svoboda
+ * 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.
+ */
+
+#include <adt/circ_buf.h>
+#include <pcut/pcut.h>
+
+PCUT_INIT
+
+PCUT_TEST_SUITE(circ_buf);
+
+enum {
+	buffer_size = 16
+};
+
+static int buffer[buffer_size];
+
+/** Basic insertion/deletion test.
+ *
+ * Test initialization, emptiness, pushing buffer until it is full,
+ * then emptying it again.
+ */
+PCUT_TEST(push_pop)
+{
+	circ_buf_t cbuf;
+	int i;
+	int j;
+	int rc;
+
+	circ_buf_init(&cbuf, buffer, buffer_size, sizeof(int));
+
+	for (i = 0; i < buffer_size; i++) {
+		PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nfree(&cbuf));
+		PCUT_ASSERT_INT_EQUALS(i, circ_buf_nused(&cbuf));
+		rc = circ_buf_push(&cbuf, &i);
+		PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+	}
+
+	rc = circ_buf_push(&cbuf, &i);
+	PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
+
+	for (i = 0; i < buffer_size; i++) {
+		PCUT_ASSERT_INT_EQUALS(i, circ_buf_nfree(&cbuf));
+		PCUT_ASSERT_INT_EQUALS(buffer_size - i, circ_buf_nused(&cbuf));
+		rc = circ_buf_pop(&cbuf, &j);
+		PCUT_ASSERT_ERRNO_VAL(EOK, rc);
+		PCUT_ASSERT_INT_EQUALS(i, j);
+	}
+
+	PCUT_ASSERT_INT_EQUALS(buffer_size, circ_buf_nfree(&cbuf));
+	PCUT_ASSERT_INT_EQUALS(0, circ_buf_nused(&cbuf));
+
+	rc = circ_buf_pop(&cbuf, &j);
+	PCUT_ASSERT_ERRNO_VAL(EAGAIN, rc);
+}
+
+PCUT_EXPORT(circ_buf);
Index: uspace/lib/c/test/fibril/timer.c
===================================================================
--- uspace/lib/c/test/fibril/timer.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/test/fibril/timer.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -27,4 +27,5 @@
  */
 
+#include <async.h>
 #include <fibril_synch.h>
 #include <pcut/pcut.h>
@@ -77,5 +78,5 @@
 
 	fibril_timer_set_locked(t, 100 * 1000 * 1000, test_timeout_fn, &cnt);
-	fibril_usleep(1000);
+	async_usleep(1000);
 	fts = fibril_timer_clear_locked(t);
 	PCUT_ASSERT_INT_EQUALS(fts_active, fts);
@@ -100,5 +101,5 @@
 	cnt = 0;
 	fibril_timer_set(t, 100 * 1000 * 1000, test_timeout_fn, &cnt);
-	fibril_usleep(1000);
+	async_usleep(1000);
 	fts = fibril_timer_clear(t);
 	PCUT_ASSERT_INT_EQUALS(fts_active, fts);
@@ -126,5 +127,5 @@
 	fibril_mutex_unlock(&lock);
 
-	fibril_usleep(1000);
+	async_usleep(1000);
 
 	fibril_mutex_lock(&lock);
Index: uspace/lib/c/test/main.c
===================================================================
--- uspace/lib/c/test/main.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/c/test/main.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -32,4 +32,5 @@
 PCUT_INIT
 
+PCUT_IMPORT(circ_buf);
 PCUT_IMPORT(fibril_timer);
 PCUT_IMPORT(odict);
Index: uspace/lib/clui/nchoice.c
===================================================================
--- uspace/lib/clui/nchoice.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/clui/nchoice.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -131,4 +131,5 @@
 	int i;
 	int rc;
+	int ret;
 	char *str;
 	unsigned long c;
@@ -151,6 +152,6 @@
 
 	if (def_i > 0) {
-		rc = asprintf(&istr, "%d", def_i);
-		if (rc < 0)
+		ret = asprintf(&istr, "%d", def_i);
+		if (ret < 0)
 			return ENOMEM;
 	} else {
Index: uspace/lib/clui/tinput.h
===================================================================
--- uspace/lib/clui/tinput.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/clui/tinput.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -61,5 +61,5 @@
  * @param state		Output, pointer to a client state object.
  *
- * @return		EOK on success, negative error code on failure.
+ * @return		EOK on success, error code on failure.
  */
 typedef int (*tinput_compl_init_fn)(wchar_t *text, size_t pos, size_t *cstart,
@@ -76,5 +76,5 @@
  * @param compl		Output, the completion text, ownership retained.
  *
- * @return		EOK on success, negative error code on failure.
+ * @return		EOK on success, error code on failure.
  */
 typedef int (*tinput_compl_get_next_fn)(void *state, char **compl);
Index: uspace/lib/compress/gzip.c
===================================================================
--- uspace/lib/compress/gzip.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/compress/gzip.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -31,6 +31,6 @@
 #include <errno.h>
 #include <mem.h>
-#include <malloc.h>
 #include <byteorder.h>
+#include <stdlib.h>
 #include "gzip.h"
 #include "inflate.h"
Index: uspace/lib/compress/inflate.c
===================================================================
--- uspace/lib/compress/inflate.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/compress/inflate.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -637,5 +637,5 @@
 	
 	uint16_t last;
-	int ret = 0;
+	int ret = EOK;
 	
 	do {
Index: uspace/lib/draw/codec/tga.gz.c
===================================================================
--- uspace/lib/draw/codec/tga.gz.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/codec/tga.gz.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,5 @@
 #include <errno.h>
 #include <gzip.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include "tga.gz.h"
 #include "tga.h"
Index: uspace/lib/draw/cursor.c
===================================================================
--- uspace/lib/draw/cursor.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/cursor.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,5 +34,5 @@
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "cursor.h"
Index: uspace/lib/draw/cursor/embedded.c
===================================================================
--- uspace/lib/draw/cursor/embedded.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/cursor/embedded.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,5 +37,5 @@
 #include <stddef.h>
 #include <stdint.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "../gfx/cursor-11x18.h"
Index: uspace/lib/draw/drawctx.c
===================================================================
--- uspace/lib/draw/drawctx.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/drawctx.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,5 @@
 #include <assert.h>
 #include <adt/list.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "drawctx.h"
Index: uspace/lib/draw/font.c
===================================================================
--- uspace/lib/draw/font.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/font.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,6 +35,6 @@
  */
 
-#include <malloc.h>
 #include <errno.h>
+#include <stdlib.h>
 #include <str.h>
 
Index: uspace/lib/draw/font/bitmap_backend.c
===================================================================
--- uspace/lib/draw/font/bitmap_backend.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/font/bitmap_backend.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,6 +35,6 @@
  */
 
-#include <malloc.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include "../font.h"
Index: uspace/lib/draw/font/embedded.c
===================================================================
--- uspace/lib/draw/font/embedded.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/font/embedded.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,6 +36,6 @@
 
 #include <stdint.h>
-#include <malloc.h>
 #include <errno.h>
+#include <stdlib.h>
 
 #include "../gfx/font-8x16.h"
Index: uspace/lib/draw/font/pcf.c
===================================================================
--- uspace/lib/draw/font/pcf.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/font/pcf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,4 @@
 #include <stddef.h>
 #include <stdint.h>
-#include <malloc.h>
 #include <errno.h>
 #include <byteorder.h>
@@ -42,4 +41,5 @@
 #include <align.h>
 #include <offset.h>
+#include <stdlib.h>
 
 #include "pcf.h"
@@ -268,6 +268,5 @@
 	    (glyph_id * sizeof(uint32_t));
 	
-	rc = fseek(data->file, offset, SEEK_SET);
-	if (rc != 0)
+	if (fseek(data->file, offset, SEEK_SET) < 0)
 		return errno;
 	
@@ -284,6 +283,5 @@
 	    + bitmap_offset;
 	
-	rc = fseek(data->file, offset, SEEK_SET);
-	if (rc != 0)
+	if (fseek(data->file, offset, SEEK_SET) < 0)
 		return errno;
 	
Index: uspace/lib/draw/path.c
===================================================================
--- uspace/lib/draw/path.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/path.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,5 +35,5 @@
 
 #include <assert.h>
-#include <malloc.h>
+#include <stdlib.h>
 
 #include "path.h"
Index: uspace/lib/draw/surface.c
===================================================================
--- uspace/lib/draw/surface.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/draw/surface.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,8 +35,8 @@
  */
 
-#include <malloc.h>
 #include <mem.h>
 #include <as.h>
 #include <assert.h>
+#include <stdlib.h>
 #include "surface.h"
 
Index: uspace/lib/drv/Makefile
===================================================================
--- uspace/lib/drv/Makefile	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/Makefile	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -43,5 +43,4 @@
 	generic/remote_hw_res.c \
 	generic/remote_pio_window.c \
-	generic/remote_char_dev.c \
 	generic/remote_nic.c \
 	generic/remote_ieee80211.c \
Index: uspace/lib/drv/generic/dev_iface.c
===================================================================
--- uspace/lib/drv/generic/dev_iface.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/dev_iface.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,5 +42,4 @@
 #include "remote_hw_res.h"
 #include "remote_pio_window.h"
-#include "remote_char_dev.h"
 #include "remote_clock_dev.h"
 #include "remote_led_dev.h"
@@ -63,5 +62,4 @@
 		[HW_RES_DEV_IFACE] = &remote_hw_res_iface,
 		[PIO_WINDOW_DEV_IFACE] = &remote_pio_window_iface,
-		[CHAR_DEV_IFACE] = &remote_char_dev_iface,
 		[NIC_DEV_IFACE] = &remote_nic_iface,
 		[IEEE80211_DEV_IFACE] = &remote_ieee80211_iface,
Index: uspace/lib/drv/generic/driver.c
===================================================================
--- uspace/lib/drv/generic/driver.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/driver.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -204,5 +204,5 @@
 	
 	dev_del_ref(dev);
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -237,5 +237,5 @@
 	
 	dev_del_ref(dev);
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -272,5 +272,5 @@
 	fun_del_ref(fun);
 	
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -305,5 +305,5 @@
 		rc = ENOTSUP;
 	
-	async_answer_0(iid, (sysarg_t) rc);
+	async_answer_0(iid, rc);
 }
 
@@ -822,5 +822,5 @@
  * @param fun Function to bind
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  *
  */
@@ -850,5 +850,5 @@
  * @param fun Function to unbind
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  *
  */
@@ -871,5 +871,5 @@
  * @param fun Function to online
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  *
  */
@@ -889,5 +889,5 @@
  * @param fun Function to offline
  *
- * @return EOK on success or negative error code
+ * @return EOK on success or an error code
  *
  */
Index: uspace/lib/drv/generic/interrupt.c
===================================================================
--- uspace/lib/drv/generic/interrupt.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/interrupt.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,11 +44,12 @@
 
 int register_interrupt_handler(ddf_dev_t *dev, int irq,
-    interrupt_handler_t *handler, const irq_code_t *irq_code)
+    interrupt_handler_t *handler, const irq_code_t *irq_code,
+    cap_handle_t *handle)
 {
 	return async_irq_subscribe(irq, (async_notification_handler_t) handler,
-	    dev, irq_code);
+	    dev, irq_code, handle);
 }
 
-int unregister_interrupt_handler(ddf_dev_t *dev, int cap)
+int unregister_interrupt_handler(ddf_dev_t *dev, cap_handle_t cap)
 {
 	return async_irq_unsubscribe(cap);
Index: uspace/lib/drv/generic/private/remote_char_dev.h
===================================================================
--- uspace/lib/drv/generic/private/remote_char_dev.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,44 +1,0 @@
-/*
- * Copyright (c) 2010 Lenka Trochtova
- * 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 libdrv
- * @{
- */
-/** @file
- */
-
-#ifndef LIBDRV_REMOTE_CHAR_DEV_H_
-#define LIBDRV_REMOTE_CHAR_DEV_H_
-
-extern remote_iface_t remote_char_dev_iface;
-
-#endif
-
-/**
- * @}
- */
Index: uspace/lib/drv/generic/remote_ahci.c
===================================================================
--- uspace/lib/drv/generic/remote_ahci.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_ahci.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -95,5 +95,5 @@
 	async_data_read_start(exch, sata_dev_name, sata_dev_name_length);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(req, &rc);
 	
@@ -155,5 +155,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(req, &rc);
 	
@@ -175,5 +175,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t rc;
+	int rc;
 	async_wait_for(req, &rc);
 	
Index: uspace/lib/drv/generic/remote_audio_pcm.c
===================================================================
--- uspace/lib/drv/generic/remote_audio_pcm.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_audio_pcm.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -221,18 +221,15 @@
  * @param sess Audio device session.
  * @param cap  Audio device capability.
- * @param val  Place to store queried value.
- *
- * @return Error code.
- */
-int audio_pcm_query_cap(audio_pcm_sess_t *sess, audio_cap_t cap)
-{
-	async_exch_t *exch = async_exchange_begin(sess);
-	sysarg_t value = 0;
+ * @param[out] val  Place to store queried value.
+ *
+ * @return Error code.
+ */
+int audio_pcm_query_cap(audio_pcm_sess_t *sess, audio_cap_t cap, sysarg_t *value)
+{
+	async_exch_t *exch = async_exchange_begin(sess);
 	const int ret = async_req_2_1(exch,
 	    DEV_IFACE_ID(AUDIO_PCM_BUFFER_IFACE), IPC_M_AUDIO_PCM_QUERY_CAPS,
-	    cap, &value);
-	async_exchange_end(exch);
-	if (ret == EOK)
-		return value;
+	    cap, value);
+	async_exchange_end(exch);
 	return ret;
 }
Index: uspace/lib/drv/generic/remote_battery_dev.c
===================================================================
--- uspace/lib/drv/generic/remote_battery_dev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_battery_dev.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -45,5 +45,5 @@
  * @param status   Current status of the battery
  *
- * @return         EOK on success or a negative error code
+ * @return         EOK on success or an error code
  */
 int
@@ -70,5 +70,5 @@
  * @param level    Battery charge level (0 - 100)
  *
- * @return         EOK on success or a negative error code
+ * @return         EOK on success or an error code
  */
 int
Index: uspace/lib/drv/generic/remote_char_dev.c
===================================================================
--- uspace/lib/drv/generic/remote_char_dev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,246 +1,0 @@
-/*
- * Copyright (c) 2010 Lenka Trochtova
- * 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 libdrv
- * @{
- */
-/** @file
- */
-
-#include <async.h>
-#include <errno.h>
-#include <macros.h>
-
-#include "ops/char_dev.h"
-#include "char_dev_iface.h"
-#include "ddf/driver.h"
-
-#define MAX_CHAR_RW_COUNT 256
-
-/** Read to or write from device.
- *
- * Helper function to read to or write from a device
- * using its character interface.
- *
- * @param sess Session to the device.
- * @param buf  Buffer for the data read from or written to the device.
- * @param size Maximum size of data (in bytes) to be read or written.
- * @param read Read from the device if true, write to it otherwise.
- *
- * @return Non-negative number of bytes actually read from or
- *         written to the device on success, negative error number
- *         otherwise.
- *
- */
-static ssize_t char_dev_rw(async_sess_t *sess, void *buf, size_t size, bool read)
-{
-	ipc_call_t answer;
-	aid_t req;
-	int ret;
-	
-	async_exch_t *exch = async_exchange_begin(sess);
-	
-	if (read) {
-		req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE),
-		    CHAR_DEV_READ, &answer);
-		ret = async_data_read_start(exch, buf, size);
-	} else {
-		req = async_send_1(exch, DEV_IFACE_ID(CHAR_DEV_IFACE),
-		    CHAR_DEV_WRITE, &answer);
-		ret = async_data_write_start(exch, buf, size);
-	}
-	
-	async_exchange_end(exch);
-	
-	sysarg_t rc;
-	if (ret != EOK) {
-		async_wait_for(req, &rc);
-		if (rc == EOK)
-			return (ssize_t) ret;
-		
-		return (ssize_t) rc;
-	}
-	
-	async_wait_for(req, &rc);
-	
-	ret = (int) rc;
-	if (ret != EOK)
-		return (ssize_t) ret;
-	
-	return (ssize_t) IPC_GET_ARG1(answer);
-}
-
-/** Read from character device.
- *
- * @param sess Session to the device.
- * @param buf  Output buffer for the data read from the device.
- * @param size Maximum size (in bytes) of the data to be read.
- *
- * @return Non-negative number of bytes actually read from the
- *         device on success, negative error number otherwise.
- *
- */
-ssize_t char_dev_read(async_sess_t *sess, void *buf, size_t size)
-{
-	return char_dev_rw(sess, buf, size, true);
-}
-
-/** Write to character device.
- *
- * @param sess Session to the device.
- * @param buf  Input buffer containg the data to be written to the
- *             device.
- * @param size Maximum size (in bytes) of the data to be written.
- *
- * @return Non-negative number of bytes actually written to the
- *         device on success, negative error number otherwise.
- *
- */
-ssize_t char_dev_write(async_sess_t *sess, void *buf, size_t size)
-{
-	return char_dev_rw(sess, buf, size, false);
-}
-
-static void remote_char_read(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-static void remote_char_write(ddf_fun_t *, void *, ipc_callid_t, ipc_call_t *);
-
-/** Remote character interface operations. */
-static const remote_iface_func_ptr_t remote_char_dev_iface_ops[] = {
-	[CHAR_DEV_READ] = remote_char_read,
-	[CHAR_DEV_WRITE] = remote_char_write
-};
-
-/** Remote character interface structure.
- *
- * Interface for processing request from remote clients addressed to the
- * character interface.
- */
-const remote_iface_t remote_char_dev_iface = {
-	.method_count = ARRAY_SIZE(remote_char_dev_iface_ops),
-	.methods = remote_char_dev_iface_ops
-};
-
-/** Process the read request from the remote client.
- *
- * Receive the read request's parameters from the remote client and pass them
- * to the local interface. Return the result of the operation processed by the
- * local interface to the remote client.
- *
- * @param fun		The function from which the data are read.
- * @param ops		The local ops structure.
- */
-static void
-remote_char_read(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
-    ipc_call_t *call)
-{
-	char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
-	ipc_callid_t cid;
-	
-	size_t len;
-	if (!async_data_read_receive(&cid, &len)) {
-		/* TODO handle protocol error. */
-		async_answer_0(callid, EINVAL);
-		return;
-	}
-	
-	if (!char_dev_ops->read) {
-		async_data_read_finalize(cid, NULL, 0);
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-	
-	if (len > MAX_CHAR_RW_COUNT)
-		len = MAX_CHAR_RW_COUNT;
-	
-	char buf[MAX_CHAR_RW_COUNT];
-	int ret = (*char_dev_ops->read)(fun, buf, len);
-	
-	if (ret < 0) {
-		/* Some error occured. */
-		async_data_read_finalize(cid, buf, 0);
-		async_answer_0(callid, ret);
-		return;
-	}
-	
-	/* The operation was successful, return the number of data read. */
-	async_data_read_finalize(cid, buf, ret);
-	async_answer_1(callid, EOK, ret);
-}
-
-/** Process the write request from the remote client.
- *
- * Receive the write request's parameters from the remote client and pass them
- * to the local interface. Return the result of the operation processed by the
- * local interface to the remote client.
- *
- * @param fun		The function to which the data are written.
- * @param ops		The local ops structure.
- */
-static void
-remote_char_write(ddf_fun_t *fun, void *ops, ipc_callid_t callid,
-    ipc_call_t *call)
-{
-	char_dev_ops_t *char_dev_ops = (char_dev_ops_t *) ops;
-	ipc_callid_t cid;
-	size_t len;
-	
-	if (!async_data_write_receive(&cid, &len)) {
-		/* TODO handle protocol error. */
-		async_answer_0(callid, EINVAL);
-		return;
-	}
-	
-	if (!char_dev_ops->write) {
-		async_data_write_finalize(cid, NULL, 0);
-		async_answer_0(callid, ENOTSUP);
-		return;
-	}
-	
-	if (len > MAX_CHAR_RW_COUNT)
-		len = MAX_CHAR_RW_COUNT;
-	
-	char buf[MAX_CHAR_RW_COUNT];
-	
-	async_data_write_finalize(cid, buf, len);
-	
-	int ret = (*char_dev_ops->write)(fun, buf, len);
-	if (ret < 0) {
-		/* Some error occured. */
-		async_answer_0(callid, ret);
-	} else {
-		/*
-		 * The operation was successful, return the number of data
-		 * written.
-		 */
-		async_answer_1(callid, EOK, ret);
-	}
-}
-
-/**
- * @}
- */
Index: uspace/lib/drv/generic/remote_ieee80211.c
===================================================================
--- uspace/lib/drv/generic/remote_ieee80211.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_ieee80211.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -59,5 +59,5 @@
  *
  * @return EOK If the operation was successfully completed,
- *         negative error code otherwise.
+ *         error code otherwise.
  *
  */
@@ -75,5 +75,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(aid, &res);
 	
@@ -123,5 +123,5 @@
  *
  * @return EOK If the operation was successfully completed,
- *         negative error code otherwise.
+ *         error code otherwise.
  *
  */
@@ -130,5 +130,5 @@
 	assert(ssid_start);
 	
-	sysarg_t rc_orig;
+	int rc_orig;
 	
 	async_exch_t *exch = async_exchange_begin(dev_sess);
@@ -137,5 +137,5 @@
 	    IEEE80211_CONNECT, NULL);
 	
-	sysarg_t rc = async_data_write_start(exch, ssid_start,
+	int rc = async_data_write_start(exch, ssid_start,
 	    str_size(ssid_start) + 1);
 	if (rc != EOK) {
@@ -190,5 +190,5 @@
  *
  * @return EOK If the operation was successfully completed,
- *         negative error code otherwise.
+ *         error code otherwise.
  *
  */
Index: uspace/lib/drv/generic/remote_nic.c
===================================================================
--- uspace/lib/drv/generic/remote_nic.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_nic.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -105,5 +105,5 @@
 	aid_t req = async_send_1(exch, DEV_IFACE_ID(NIC_DEV_IFACE),
 	    NIC_SEND_MESSAGE, &answer);
-	sysarg_t retval = async_data_write_start(exch, data, size);
+	int retval = async_data_write_start(exch, data, size);
 	
 	async_exchange_end(exch);
@@ -131,5 +131,5 @@
 	ipc_call_t answer;
 	int rc;
-	sysarg_t retval;
+	int retval;
 	
 	async_exch_t *exch = async_exchange_begin(dev_sess);
@@ -147,5 +147,5 @@
 	
 	async_wait_for(req, &retval);
-	return (int) retval;
+	return retval;
 }
 
@@ -210,5 +210,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(aid, &res);
 	
@@ -216,5 +216,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -237,5 +237,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(aid, &res);
 	
@@ -243,5 +243,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -295,5 +295,5 @@
 	async_exchange_end(exch);
 
-	sysarg_t res;
+	int res;
 	async_wait_for(aid, &res);
 	
@@ -301,5 +301,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -629,5 +629,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(message_id, &res);
 	
@@ -635,5 +635,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -717,5 +717,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(message_id, &res);
 	
@@ -723,5 +723,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -878,5 +878,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(message_id, &res);
 	
@@ -884,5 +884,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -938,5 +938,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(message_id, &res);
 	
@@ -944,5 +944,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
@@ -997,5 +997,5 @@
 	    NIC_WOL_VIRTUE_ADD, (sysarg_t) type, send_data, &result);
 	
-	sysarg_t res;
+	int res;
 	if (send_data) {
 		int rc = async_data_write_start(exch, data, length);
@@ -1011,5 +1011,5 @@
 	
 	*id = IPC_GET_ARG1(result);
-	return (int) res;
+	return res;
 }
 
@@ -1311,5 +1311,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t res;
+	int res;
 	async_wait_for(message_id, &res);
 	
@@ -1317,5 +1317,5 @@
 		return rc;
 	
-	return (int) res;
+	return res;
 }
 
Index: uspace/lib/drv/generic/remote_usbhc.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_usbhc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -135,5 +135,5 @@
 
 	/* Wait for the answer. */
-	sysarg_t opening_request_rc;
+	int opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
 
@@ -172,5 +172,5 @@
 
 	/* Wait for the answer. */
-	sysarg_t opening_request_rc;
+	int opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
 
@@ -208,6 +208,6 @@
 
 	/* Wait for the answer. */
-	sysarg_t data_request_rc;
-	sysarg_t opening_request_rc;
+	int data_request_rc;
+	int opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
@@ -256,5 +256,5 @@
 
 	/* Wait for the answer. */
-	sysarg_t opening_request_rc;
+	int opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
 
Index: uspace/lib/drv/generic/remote_usbhid.c
===================================================================
--- uspace/lib/drv/generic/remote_usbhid.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/generic/remote_usbhid.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -94,5 +94,5 @@
  * @param dev_sess Session to DDF device providing USB HID interface.
  *
- * @return Number of usages returned or negative error code.
+ * @return Number of usages returned or an error code.
  *
  */
@@ -174,6 +174,6 @@
 	}
 	
-	sysarg_t data_request_rc;
-	sysarg_t opening_request_rc;
+	int data_request_rc;
+	int opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
@@ -259,6 +259,6 @@
 	}
 	
-	sysarg_t data_request_rc;
-	sysarg_t opening_request_rc;
+	int data_request_rc;
+	int opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
Index: uspace/lib/drv/include/audio_pcm_iface.h
===================================================================
--- uspace/lib/drv/include/audio_pcm_iface.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/include/audio_pcm_iface.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -83,5 +83,5 @@
 int audio_pcm_test_format(audio_pcm_sess_t *, unsigned *, unsigned *,
     pcm_sample_format_t *);
-int audio_pcm_query_cap(audio_pcm_sess_t *, audio_cap_t);
+int audio_pcm_query_cap(audio_pcm_sess_t *, audio_cap_t, sysarg_t *);
 int audio_pcm_register_event_callback(audio_pcm_sess_t *,
     async_port_handler_t, void *);
Index: uspace/lib/drv/include/char_dev_iface.h
===================================================================
--- uspace/lib/drv/include/char_dev_iface.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2010 Lenka Trochtova
- * 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 LIBDRV_CHAR_DEV_IFACE_H_
-#define LIBDRV_CHAR_DEV_IFACE_H_
-
-#include <async.h>
-
-typedef enum {
-	CHAR_DEV_READ = 0,
-	CHAR_DEV_WRITE
-} char_dev_method_t;
-
-extern ssize_t char_dev_read(async_sess_t *, void *, size_t);
-extern ssize_t char_dev_write(async_sess_t *, void *, size_t);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/drv/include/ddf/interrupt.h
===================================================================
--- uspace/lib/drv/include/ddf/interrupt.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/include/ddf/interrupt.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,9 +48,9 @@
  */
 
-typedef void interrupt_handler_t(ipc_callid_t, ipc_call_t *, ddf_dev_t *);
+typedef void interrupt_handler_t(ipc_call_t *, ddf_dev_t *);
 
 extern int register_interrupt_handler(ddf_dev_t *, int, interrupt_handler_t *,
-    const irq_code_t *);
-extern int unregister_interrupt_handler(ddf_dev_t *, int);
+    const irq_code_t *, cap_handle_t *);
+extern int unregister_interrupt_handler(ddf_dev_t *, cap_handle_t);
 
 #endif
Index: uspace/lib/drv/include/ops/char_dev.h
===================================================================
--- uspace/lib/drv/include/ops/char_dev.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,49 +1,0 @@
-/*
- * Copyright (c) 2010 Lenka Trochtova
- * 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 libdrv
- * @{
- */
-/** @file
- */
-
-#ifndef LIBDRV_OPS_CHAR_DEV_H_
-#define LIBDRV_OPS_CHAR_DEV_H_
-
-#include "../ddf/driver.h"
-
-typedef struct {
-	int (*read)(ddf_fun_t *, char *, size_t);
-	int (*write)(ddf_fun_t *, char *, size_t);
-} char_dev_ops_t;
-
-#endif
-
-/**
- * @}
- */
Index: uspace/lib/drv/include/ops/ieee80211.h
===================================================================
--- uspace/lib/drv/include/ops/ieee80211.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/drv/include/ops/ieee80211.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,5 +48,5 @@
 	 * @param now     Whether to initiate scan immediately.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -59,5 +59,5 @@
 	 * @param password Network password (empty string if not needed).
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -68,5 +68,5 @@
 	 * @param fun IEEE 802.11 function.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
Index: uspace/lib/ext4/include/ext4/types.h
===================================================================
--- uspace/lib/ext4/include/ext4/types.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/include/ext4/types.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -476,5 +476,4 @@
 } ext4_directory_dx_block_t;
 
-#define EXT4_ERR_BAD_DX_DIR       (-75000)
 #define EXT4_DIRECTORY_HTREE_EOF  UINT32_C(0x7fffffff)
 
Index: uspace/lib/ext4/src/directory.c
===================================================================
--- uspace/lib/ext4/src/directory.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/src/directory.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,6 +38,6 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 #include <str.h>
 #include "ext4/directory.h"
Index: uspace/lib/ext4/src/extent.c
===================================================================
--- uspace/lib/ext4/src/extent.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/src/extent.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,6 +37,6 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 #include "ext4/balloc.h"
 #include "ext4/extent.h"
Index: uspace/lib/ext4/src/filesystem.c
===================================================================
--- uspace/lib/ext4/src/filesystem.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/src/filesystem.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -161,5 +161,5 @@
  * @param service_id Block device to probe
  *
- * @return EOK or negative error code.
+ * @return EOK or an error code.
  *
  */
@@ -252,5 +252,5 @@
  * @param fs Filesystem to be destroyed
  *
- * @return EOK or negative error code. On error the state of the file
+ * @return EOK or an error code. On error the state of the file
  *         system is unchanged.
  *
Index: uspace/lib/ext4/src/ops.c
===================================================================
--- uspace/lib/ext4/src/ops.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/src/ops.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,6 +42,6 @@
 #include <libfs.h>
 #include <macros.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 #include <str.h>
 #include <ipc/loc.h>
Index: uspace/lib/ext4/src/superblock.c
===================================================================
--- uspace/lib/ext4/src/superblock.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ext4/src/superblock.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,6 +40,6 @@
 #include <byteorder.h>
 #include <errno.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 #include "ext4/superblock.h"
 
Index: uspace/lib/fmtutil/fmtutil.c
===================================================================
--- uspace/lib/fmtutil/fmtutil.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/fmtutil/fmtutil.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -29,6 +29,6 @@
 #include <io/console.h>
 #include <errno.h>
-#include <malloc.h>
 #include <fmtutil.h>
+#include <stdlib.h>
 
 typedef struct {
Index: uspace/lib/fmtutil/fmtutil.h
===================================================================
--- uspace/lib/fmtutil/fmtutil.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/fmtutil/fmtutil.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,5 +42,5 @@
  * @param data user data
  * 
- * @returns EOK on success or error code on failure
+ * @returns EOK on success or an error code on failure
  */
 typedef int (*line_consumer_fn)(wchar_t *, size_t, bool, void *);
Index: uspace/lib/fs/libfs.c
===================================================================
--- uspace/lib/fs/libfs.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/fs/libfs.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -656,5 +656,5 @@
 		if (rc == EOK) {
 			aoff64_t size = ops->size_get(cur);
-			async_answer_5(rid, fs_handle, service_id,
+			async_answer_5(rid, EOK, fs_handle,
 			    ops->index_get(cur),
 			    (ops->is_directory(cur) << 16) | last,
@@ -699,5 +699,5 @@
 out1:
 	if (!cur) {
-		async_answer_5(rid, fs_handle, service_id, ops->index_get(par),
+		async_answer_5(rid, EOK, fs_handle, ops->index_get(par),
 		    (ops->is_directory(par) << 16) | last_next,
 		    LOWER32(ops->size_get(par)), UPPER32(ops->size_get(par)));
@@ -705,5 +705,5 @@
 	}
 	
-	async_answer_5(rid, fs_handle, service_id, ops->index_get(cur),
+	async_answer_5(rid, EOK, fs_handle, ops->index_get(cur),
 	    (ops->is_directory(cur) << 16) | last, LOWER32(ops->size_get(cur)),
 	    UPPER32(ops->size_get(cur)));
Index: uspace/lib/graph/graph.c
===================================================================
--- uspace/lib/graph/graph.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/graph/graph.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,6 +38,6 @@
 #include <inttypes.h>
 #include <stdio.h>
-#include <malloc.h>
 #include <as.h>
+#include <stdlib.h>
 #include "graph.h"
 
Index: uspace/lib/gui/button.c
===================================================================
--- uspace/lib/gui/button.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/button.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,5 +35,5 @@
 
 #include <str.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <drawctx.h>
 #include <surface.h>
Index: uspace/lib/gui/canvas.c
===================================================================
--- uspace/lib/gui/canvas.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/canvas.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,5 +34,5 @@
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <transform.h>
 #include <source.h>
Index: uspace/lib/gui/connection.c
===================================================================
--- uspace/lib/gui/connection.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/connection.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,5 +35,5 @@
 
 #include <mem.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <adt/list.h>
 #include <adt/prodcons.h>
Index: uspace/lib/gui/grid.c
===================================================================
--- uspace/lib/gui/grid.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/grid.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,5 +37,5 @@
 #include <assert.h>
 #include <mem.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <surface.h>
 #include "window.h"
Index: uspace/lib/gui/label.c
===================================================================
--- uspace/lib/gui/label.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/label.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,6 +35,6 @@
 
 #include <str.h>
-#include <malloc.h>
 #include <drawctx.h>
+#include <stdlib.h>
 #include <surface.h>
 #include <font/embedded.h>
Index: uspace/lib/gui/minimal.c
===================================================================
--- uspace/lib/gui/minimal.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/minimal.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,5 +34,5 @@
  */
 
-#include <malloc.h>
+#include <stdlib.h>
 #include <surface.h>
 
Index: uspace/lib/gui/terminal.c
===================================================================
--- uspace/lib/gui/terminal.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/terminal.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,5 +35,5 @@
 
 #include <errno.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <io/chargrid.h>
 #include <surface.h>
@@ -64,6 +64,6 @@
 static int term_open(con_srvs_t *, con_srv_t *);
 static int term_close(con_srv_t *);
-static int term_read(con_srv_t *, void *, size_t);
-static int term_write(con_srv_t *, void *, size_t);
+static int term_read(con_srv_t *, void *, size_t, size_t *);
+static int term_write(con_srv_t *, void *, size_t, size_t *);
 static void term_sync(con_srv_t *);
 static void term_clear(con_srv_t *);
@@ -386,5 +386,5 @@
 }
 
-static int term_read(con_srv_t *srv, void *buf, size_t size)
+static int term_read(con_srv_t *srv, void *buf, size_t size, size_t *nread)
 {
 	terminal_t *term = srv_to_terminal(srv);
@@ -431,5 +431,6 @@
 	}
 	
-	return size;
+	*nread = size;
+	return EOK;
 }
 
@@ -462,5 +463,5 @@
 }
 
-static int term_write(con_srv_t *srv, void *data, size_t size)
+static int term_write(con_srv_t *srv, void *data, size_t size, size_t *nwritten)
 {
 	terminal_t *term = srv_to_terminal(srv);
@@ -470,5 +471,6 @@
 		term_write_char(term, str_decode(data, &off, size));
 	
-	return size;
+	*nwritten = size;
+	return EOK;
 }
 
Index: uspace/lib/gui/window.c
===================================================================
--- uspace/lib/gui/window.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/gui/window.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,5 @@
 
 #include <as.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <str.h>
 
Index: uspace/lib/hound/include/hound/protocol.h
===================================================================
--- uspace/lib/hound/include/hound/protocol.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/hound/include/hound/protocol.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -58,19 +58,9 @@
 typedef intptr_t hound_context_id_t;
 
-/**
- * Check context id for errors.
- * @param id Context id
- * @return Error code.
- */
-static inline int hound_context_id_err(hound_context_id_t id)
-{
-	return id > 0 ? EOK : (id == 0 ? ENOENT : id);
-}
-
 hound_sess_t *hound_service_connect(const char *service);
 void hound_service_disconnect(hound_sess_t *sess);
 
-hound_context_id_t hound_service_register_context(hound_sess_t *sess,
-    const char *name, bool record);
+int hound_service_register_context(hound_sess_t *sess,
+    const char *name, bool record, hound_context_id_t *id);
 int hound_service_unregister_context(hound_sess_t *sess, hound_context_id_t id);
 
Index: uspace/lib/hound/src/client.c
===================================================================
--- uspace/lib/hound/src/client.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/hound/src/client.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -123,7 +123,8 @@
 			return NULL;
 		}
-		new_context->id = hound_service_register_context(
-		    new_context->session, new_context->name, record);
-		if (hound_context_id_err(new_context->id) != EOK) {
+		int rc = hound_service_register_context(
+		    new_context->session, new_context->name, record,
+		    &new_context->id);
+		if (rc != EOK) {
 			hound_service_disconnect(new_context->session);
 			free(new_context->name);
Index: uspace/lib/hound/src/protocol.c
===================================================================
--- uspace/lib/hound/src/protocol.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/hound/src/protocol.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -115,8 +115,11 @@
  * @param name Valid string identifier
  * @param record True if the application context wishes to receive data.
- * @return Valid ID on success, Error code on failure.
- */
-hound_context_id_t hound_service_register_context(hound_sess_t *sess,
-    const char *name, bool record)
+ *
+ * @param[out] id  Return context ID.
+ *
+ * @return EOK on success, Error code on failure.
+ */
+int hound_service_register_context(hound_sess_t *sess,
+    const char *name, bool record, hound_context_id_t *id)
 {
 	assert(sess);
@@ -134,8 +137,12 @@
 
 	if (ret == EOK)
-		async_wait_for(mid, (sysarg_t *)&ret);
+		async_wait_for(mid, &ret);
 
 	async_exchange_end(exch);
-	return ret == EOK ? (hound_context_id_t)IPC_GET_ARG1(call) : ret;
+	if (ret == EOK) {
+		*id = (hound_context_id_t)IPC_GET_ARG1(call);
+	}
+
+	return ret;
 }
 
@@ -182,5 +189,5 @@
 	ipc_call_t res_call;
 	aid_t mid = async_send_3(exch, IPC_M_HOUND_GET_LIST, flags, *count,
-	    (bool)connection, &res_call);
+	    connection != NULL, &res_call);
 
 	int ret = EOK;
@@ -190,5 +197,5 @@
 
 	if (ret == EOK)
-		async_wait_for(mid, (sysarg_t*)&ret);
+		async_wait_for(mid, &ret);
 
 	if (ret != EOK) {
@@ -257,5 +264,5 @@
 	if (ret == EOK)
 		ret = async_data_write_start(exch, sink, str_size(sink));
-	async_wait_for(id, (sysarg_t*)&ret);
+	async_wait_for(id, &ret);
 	async_exchange_end(exch);
 	return ret;
@@ -283,5 +290,5 @@
 	if (ret == EOK)
 		ret = async_data_write_start(exch, sink, str_size(sink));
-	async_wait_for(id, (sysarg_t*)&ret);
+	async_wait_for(id, &ret);
 	async_exchange_end(exch);
 	return ENOTSUP;
Index: uspace/lib/http/include/http/errno.h
===================================================================
--- uspace/lib/http/include/http/errno.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,48 +1,0 @@
-/*
- * Copyright (c) 2013 Martin Sucha
- * 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 http
- * @{
- */
-/**
- * @file
- */
-
-#ifndef HTTP_ERRNO_H_
-#define HTTP_ERRNO_H_
-
-#include <errno.h>
-
-#define HTTP_EMULTIPLE_HEADERS -20001
-#define HTTP_EMISSING_HEADER -20002
-#define HTTP_EPARSE -20003
-
-#endif
-
-/** @}
- */
Index: uspace/lib/http/include/http/receive-buffer.h
===================================================================
--- uspace/lib/http/include/http/receive-buffer.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/include/http/receive-buffer.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -46,7 +46,8 @@
  * @param buf buffer to store the data
  * @param buf_size buffer size
- * @return number of bytes received or negative error code
+ * @param nrecv number of bytes actually received
+ * @return EOK on success or an error code
  */
-typedef ssize_t (*receive_func_t)(void *, void *, size_t);
+typedef int (*receive_func_t)(void *, void *, size_t, size_t *);
 
 typedef struct {
@@ -81,10 +82,10 @@
     receive_buffer_mark_t *, char **);
 extern int recv_char(receive_buffer_t *, char *, bool);
-extern ssize_t recv_buffer(receive_buffer_t *, char *, size_t);
-extern ssize_t recv_discard(receive_buffer_t *, char);
-extern ssize_t recv_discard_str(receive_buffer_t *, const char *);
-extern ssize_t recv_while(receive_buffer_t *, char_class_func_t);
-extern ssize_t recv_eol(receive_buffer_t *);
-extern ssize_t recv_line(receive_buffer_t *, char *, size_t);
+extern int recv_buffer(receive_buffer_t *, char *, size_t, size_t *);
+extern int recv_discard(receive_buffer_t *, char, size_t *);
+extern int recv_discard_str(receive_buffer_t *, const char *, size_t *);
+extern int recv_while(receive_buffer_t *, char_class_func_t);
+extern int recv_eol(receive_buffer_t *, size_t *);
+extern int recv_line(receive_buffer_t *, char *, size_t, size_t *);
 
 #endif
Index: uspace/lib/http/src/headers.c
===================================================================
--- uspace/lib/http/src/headers.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/src/headers.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,4 +34,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -41,5 +42,4 @@
 #include <http/http.h>
 #include <http/ctype.h>
-#include <http/errno.h>
 
 #define HTTP_HEADER_LINE "%s: %s\r\n"
@@ -146,6 +146,7 @@
 			continue;
 		
-		rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'));
-		if (rc < 0)
+		size_t nrecv;
+		rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nrecv);
+		if (rc != EOK)
 			return rc;
 		
Index: uspace/lib/http/src/http.c
===================================================================
--- uspace/lib/http/src/http.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/src/http.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -47,15 +47,10 @@
 #include <http/receive-buffer.h>
 
-static ssize_t http_receive(void *client_data, void *buf, size_t buf_size)
+static int http_receive(void *client_data, void *buf, size_t buf_size,
+    size_t *nrecv)
 {
 	http_t *http = client_data;
-	size_t nrecv;
-	int rc;
 
-	rc = tcp_conn_recv_wait(http->conn, buf, buf_size, &nrecv);
-	if (rc != EOK)
-		return rc;
-
-	return nrecv;
+	return tcp_conn_recv_wait(http->conn, buf, buf_size, nrecv);
 }
 
Index: uspace/lib/http/src/receive-buffer.c
===================================================================
--- uspace/lib/http/src/receive-buffer.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/src/receive-buffer.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -61,7 +61,9 @@
 }
 
-static ssize_t dummy_receive(void *unused, void *buf, size_t buf_size)
-{
-	return 0;
+static int dummy_receive(void *unused, void *buf, size_t buf_size,
+    size_t *nrecv)
+{
+	*nrecv = 0;
+	return EOK;
 }
 
@@ -167,9 +169,10 @@
 		}
 		
-		ssize_t rc = rb->receive(rb->client_data, rb->buffer + rb->in, free);
-		if (rc <= 0)
+		size_t nrecv;
+		int rc = rb->receive(rb->client_data, rb->buffer + rb->in, free, &nrecv);
+		if (rc != EOK)
 			return rc;
 		
-		rb->in = rc;
+		rb->in = nrecv;
 	}
 	
@@ -180,21 +183,24 @@
 }
 
-ssize_t recv_buffer(receive_buffer_t *rb, char *buf, size_t buf_size)
-{
-	/* Flush any buffered data*/
+int recv_buffer(receive_buffer_t *rb, char *buf, size_t buf_size,
+    size_t *nrecv)
+{
+	/* Flush any buffered data */
 	if (rb->out != rb->in) {
 		size_t size = min(rb->in - rb->out, buf_size);
 		memcpy(buf, rb->buffer + rb->out, size);
 		rb->out += size;
-		return size;
-	}
-	
-	return rb->receive(rb->client_data, buf, buf_size);
+		*nrecv = size;
+		return EOK;
+	}
+	
+	return rb->receive(rb->client_data, buf, buf_size, nrecv);
 }
 
 /** Receive a character and if it is c, discard it from input buffer
- * @return number of characters discarded (0 or 1) or negative error code
- */
-ssize_t recv_discard(receive_buffer_t *rb, char discard)
+ * @param ndisc Place to store number of characters discarded
+ * @return EOK or an error code
+ */
+int recv_discard(receive_buffer_t *rb, char discard, size_t *ndisc)
 {
 	char c = 0;
@@ -202,34 +208,39 @@
 	if (rc != EOK)
 		return rc;
-	if (c != discard)
-		return 0;
+	if (c != discard) {
+		*ndisc = 0;
+		return EOK;
+	}
 	rc = recv_char(rb, &c, true);
 	if (rc != EOK)
 		return rc;
-	return 1;
+	*ndisc = 1;
+	return EOK;
 }
 
 /** Receive a prefix of constant string discard and return number of bytes read
- * @return number of characters discarded or negative error code
- */
-ssize_t recv_discard_str(receive_buffer_t *rb, const char *discard)
+ * @param ndisc Place to store number of characters discarded
+ * @return EOK or an error code
+ */
+int recv_discard_str(receive_buffer_t *rb, const char *discard, size_t *ndisc)
 {
 	size_t discarded = 0;
 	while (*discard) {
-		ssize_t rc = recv_discard(rb, *discard);
-		if (rc < 0)
-			return rc;
-		if (rc == 0)
+		size_t nd;
+		int rc = recv_discard(rb, *discard, &nd);
+		if (rc != EOK)
+			return rc;
+		if (nd == 0)
 			break;
-		discarded++;
+		discarded += nd;
 		discard++;
 	}
-	return discarded;
-}
-
-ssize_t recv_while(receive_buffer_t *rb, char_class_func_t class)
-{
-	size_t received = 0;
-	
+
+	*ndisc = discarded;
+	return EOK;
+}
+
+int recv_while(receive_buffer_t *rb, char_class_func_t class)
+{
 	while (true) {
 		char c = 0;
@@ -244,17 +255,16 @@
 		if (rc != EOK)
 			return rc;
-		
-		received++;
-	}
-	
-	return received;
+	}
+	
+	return EOK;
 }
 
 /** Receive an end of line, either CR, LF, CRLF or LFCR
  *
- * @return number of bytes read (0 if no newline is present in the stream)
- *         or negative error code
- */
-ssize_t recv_eol(receive_buffer_t *rb)
+ * @param nrecv Place to store number of bytes received (zero if
+ *              no newline is present in the stream)
+ * @return EOK on success or an error code
+ */
+int recv_eol(receive_buffer_t *rb, size_t *nrecv)
 {
 	char c = 0;
@@ -263,6 +273,8 @@
 		return rc;
 	
-	if (c != '\r' && c != '\n')
-		return 0;
+	if (c != '\r' && c != '\n') {
+		*nrecv = 0;
+		return EOK;
+	}
 	
 	rc = recv_char(rb, &c, true);
@@ -270,15 +282,18 @@
 		return rc;
 	
-	ssize_t rc2 = recv_discard(rb, (c == '\r' ? '\n' : '\r'));
-	if (rc2 < 0)
-		return rc2;
-	
-	return 1 + rc2;
+	size_t nr;
+	rc = recv_discard(rb, (c == '\r' ? '\n' : '\r'), &nr);
+	if (rc != EOK)
+		return rc;
+	
+	*nrecv = 1 + nr;
+	return EOK;
 }
 
 /* Receive a single line */
-ssize_t recv_line(receive_buffer_t *rb, char *line, size_t size)
+int recv_line(receive_buffer_t *rb, char *line, size_t size, size_t *nrecv)
 {
 	size_t written = 0;
+	size_t nr;
 	
 	while (written < size) {
@@ -288,12 +303,19 @@
 			return rc;
 		if (c == '\n') {
-			recv_discard(rb, '\r');
+			rc = recv_discard(rb, '\r', &nr);
+			if (rc != EOK)
+				return rc;
+
 			line[written++] = 0;
-			return written;
+			*nrecv = written;
+			return EOK;
 		}
 		else if (c == '\r') {
-			recv_discard(rb, '\n');
+			rc = recv_discard(rb, '\n', &nr);
+			if (rc != EOK)
+				return rc;
 			line[written++] = 0;
-			return written;
+			*nrecv = written;
+			return EOK;
 		}
 		line[written++] = c;
Index: uspace/lib/http/src/request.c
===================================================================
--- uspace/lib/http/src/request.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/src/request.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -96,5 +96,5 @@
 	ssize_t meth_size = http_encode_method(NULL, 0, req->method, req->path);
 	if (meth_size < 0)
-		return meth_size;
+		return EINVAL;
 	size_t size = meth_size;
 	
@@ -102,5 +102,5 @@
 		ssize_t header_size = http_header_encode(header, NULL, 0);
 		if (header_size < 0)
-			return header_size;
+			return EINVAL;
 		size += header_size;
 	}
@@ -116,5 +116,5 @@
 	if (written < 0) {
 		free(buf);
-		return written;
+		return EINVAL;
 	}
 	pos += written;
@@ -125,5 +125,5 @@
 		if (written < 0) {
 			free(buf);
-			return written;
+			return EINVAL;
 		}
 		pos += written;
Index: uspace/lib/http/src/response.c
===================================================================
--- uspace/lib/http/src/response.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/http/src/response.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,4 +34,5 @@
  */
 
+#include <errno.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -40,5 +41,4 @@
 
 #include <http/http.h>
-#include <http/errno.h>
 
 static bool is_digit(char c)
@@ -54,5 +54,5 @@
 	recv_mark(rb, &start);
 	int rc = recv_while(rb, is_digit);
-	if (rc < 0) {
+	if (rc != EOK) {
 		recv_unmark(rb, &start);
 		return rc;
@@ -96,8 +96,9 @@
 static int expect(receive_buffer_t *rb, const char *expect)
 {
-	int rc = recv_discard_str(rb, expect);
-	if (rc < 0)
-		return rc;
-	if ((size_t) rc < str_length(expect))
+	size_t ndisc;
+	int rc = recv_discard_str(rb, expect, &ndisc);
+	if (rc != EOK)
+		return rc;
+	if (ndisc < str_length(expect))
 		return HTTP_EPARSE;
 	return EOK;
@@ -148,5 +149,5 @@
 	
 	rc = recv_while(rb, is_not_newline);
-	if (rc < 0) {
+	if (rc != EOK) {
 		recv_unmark(rb, &msg_start);
 		return rc;
@@ -168,8 +169,9 @@
 	recv_unmark(rb, &msg_end);
 	
-	rc = recv_eol(rb);
-	if (rc == 0)
+	size_t nrecv;
+	rc = recv_eol(rb, &nrecv);
+	if (rc == EOK && nrecv == 0)
 		rc = HTTP_EPARSE;
-	if (rc < 0) {
+	if (rc != EOK) {
 		free(message);
 		return rc;
@@ -204,8 +206,9 @@
 		goto error;
 	
-	rc = recv_eol(rb);
-	if (rc == 0)
+	size_t nrecv;
+	rc = recv_eol(rb, &nrecv);
+	if (rc == EOK && nrecv == 0)
 		rc = HTTP_EPARSE;
-	if (rc < 0)
+	if (rc != EOK)
 		goto error;
 	
Index: uspace/lib/ieee80211/include/ieee80211.h
===================================================================
--- uspace/lib/ieee80211/include/ieee80211.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ieee80211/include/ieee80211.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -103,5 +103,5 @@
 	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -115,5 +115,5 @@
 	 * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -129,5 +129,5 @@
 	 * @param buffer_size   Size of buffer.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -139,5 +139,5 @@
 	 * @param freq          New device operating frequency.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -149,5 +149,5 @@
 	 * @param connected     True if connected to new BSSID, otherwise false.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
@@ -161,5 +161,5 @@
 	 *                      false to remove it.
 	 *
-	 * @return EOK if succeed, negative error code otherwise.
+	 * @return EOK if succeed, error code otherwise.
 	 *
 	 */
Index: uspace/lib/ieee80211/src/ieee80211.c
===================================================================
--- uspace/lib/ieee80211/src/ieee80211.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ieee80211/src/ieee80211.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -514,5 +514,5 @@
  * @param fun NIC function.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -728,5 +728,5 @@
  * @param ddf_dev       Pointer to backing DDF device structure.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -768,5 +768,5 @@
  *                        interface operations.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -847,5 +847,5 @@
  * @param ssid          Probing SSID or NULL if broadcast.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -914,5 +914,5 @@
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -964,5 +964,5 @@
  *                      or NULL for open networks.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1054,5 +1054,5 @@
  * @param ieee80211_dev Pointer to IEEE 802.11 device structure.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1238,5 +1238,5 @@
  * @param mgmt_header   Pointer to start of management frame header.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1324,5 +1324,5 @@
  * @param mgmt_header   Pointer to start of management frame header.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1353,5 +1353,5 @@
  * @param mgmt_header   Pointer to start of management frame header.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1629,5 +1629,5 @@
  * @param buffer_size   Size of buffer.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
@@ -1693,5 +1693,5 @@
  * @param buffer_size   Size of buffer.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
Index: uspace/lib/ieee80211/src/ieee80211_impl.c
===================================================================
--- uspace/lib/ieee80211/src/ieee80211_impl.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/ieee80211/src/ieee80211_impl.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -113,5 +113,5 @@
  * @param clear         Whether to clear current scan results.
  *
- * @return EOK if succeed, negative error code otherwise.
+ * @return EOK if succeed, error code otherwise.
  *
  */
Index: uspace/lib/nic/include/nic.h
===================================================================
--- uspace/lib/nic/include/nic.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/include/nic.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -87,5 +87,5 @@
 /**
  * The handler for transitions between driver states.
- * If the handler returns negative error code, the transition between
+ * If the handler returns error code, the transition between
  * states is canceled (the state is not changed).
  *
@@ -93,5 +93,5 @@
  *
  * @return EOK	If everything is all right.
- * @return negative error code on error.
+ * @return error code on error.
  */
 typedef int (*state_change_handler)(nic_t *);
Index: uspace/lib/nic/include/nic_addr_db.h
===================================================================
--- uspace/lib/nic/include/nic_addr_db.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/include/nic_addr_db.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -60,5 +60,5 @@
 extern int nic_addr_db_insert(nic_addr_db_t *db, const uint8_t *addr);
 extern int nic_addr_db_remove(nic_addr_db_t *db, const uint8_t *addr);
-extern int nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr);
+extern bool nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr);
 extern void nic_addr_db_foreach(const nic_addr_db_t *db,
 	void (*func)(const uint8_t *, void *), void *arg);
Index: uspace/lib/nic/include/nic_rx_control.h
===================================================================
--- uspace/lib/nic/include/nic_rx_control.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/include/nic_rx_control.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -118,5 +118,5 @@
 extern int nic_rxc_set_addr(nic_rxc_t *rxc,
 	const nic_address_t *prev_addr, const nic_address_t *curr_addr);
-extern int nic_rxc_check(const nic_rxc_t *rxc,
+extern bool nic_rxc_check(const nic_rxc_t *rxc,
 	const void *data, size_t size, nic_frame_type_t *frame_type);
 extern void nic_rxc_hw_filtering(nic_rxc_t *rxc,
Index: uspace/lib/nic/src/nic_addr_db.c
===================================================================
--- uspace/lib/nic/src/nic_addr_db.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/src/nic_addr_db.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -223,5 +223,5 @@
  * @return true if the address is in the db, false otherwise
  */
-int nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr)
+bool nic_addr_db_contains(const nic_addr_db_t *db, const uint8_t *addr)
 {
 	assert(db && addr);
Index: uspace/lib/nic/src/nic_driver.c
===================================================================
--- uspace/lib/nic/src/nic_driver.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/src/nic_driver.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -241,5 +241,5 @@
  * @param[out]	resources	Parsed lists of resources.
  *
- * @return EOK or negative error code
+ * @return EOK or an error code
  */
 int nic_get_resources(nic_t *nic_data, hw_res_list_parsed_t *resources)
@@ -521,5 +521,5 @@
 	fibril_rwlock_read_lock(&nic_data->rxc_lock);
 	nic_frame_type_t frame_type;
-	int check = nic_rxc_check(&nic_data->rx_control, frame->data,
+	bool check = nic_rxc_check(&nic_data->rx_control, frame->data,
 	    frame->size, &frame_type);
 	fibril_rwlock_read_unlock(&nic_data->rxc_lock);
@@ -1092,5 +1092,5 @@
 		fibril_rwlock_read_unlock(&nic->main_lock);
 	}
-	return 0;
+	return EOK;
 }
 
Index: uspace/lib/nic/src/nic_ev.c
===================================================================
--- uspace/lib/nic/src/nic_ev.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/src/nic_ev.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,5 +48,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, NIC_EV_ADDR_CHANGED, &answer);
-	sysarg_t retval = async_data_write_start(exch, addr,
+	int retval = async_data_write_start(exch, addr,
 	    sizeof(nic_address_t));
 
@@ -81,5 +81,5 @@
 	ipc_call_t answer;
 	aid_t req = async_send_0(exch, NIC_EV_RECEIVED, &answer);
-	sysarg_t retval = async_data_write_start(exch, data, size);
+	int retval = async_data_write_start(exch, data, size);
 
 	async_exchange_end(exch);
Index: uspace/lib/nic/src/nic_impl.c
===================================================================
--- uspace/lib/nic/src/nic_impl.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/src/nic_impl.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -189,5 +189,5 @@
  * @param	fun
  *
- * @return EOK		On success, or negative error code.
+ * @return EOK		On success, or an error code.
  */
 int nic_callback_create_impl(ddf_fun_t *fun)
Index: uspace/lib/nic/src/nic_rx_control.c
===================================================================
--- uspace/lib/nic/src/nic_rx_control.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/nic/src/nic_rx_control.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -394,5 +394,5 @@
  * @return True if the frame passes, false if it does not
  */
-int nic_rxc_check(const nic_rxc_t *rxc, const void *data, size_t size,
+bool nic_rxc_check(const nic_rxc_t *rxc, const void *data, size_t size,
 	nic_frame_type_t *frame_type)
 {
Index: uspace/lib/pcut/helenos.mak
===================================================================
--- uspace/lib/pcut/helenos.mak	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/helenos.mak	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,3 +39,4 @@
 
 EXTRA_CFLAGS = -D__helenos__
+
 LIBRARY = libpcut
Index: uspace/lib/pcut/include/pcut/pcut.h
===================================================================
--- uspace/lib/pcut/include/pcut/pcut.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/include/pcut/pcut.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,3 +36,17 @@
 #include <pcut/tests.h>
 
+
+/** PCUT outcome: test passed. */
+#define PCUT_OUTCOME_PASS 0
+
+/** PCUT outcome: test failed. */
+#define PCUT_OUTCOME_FAIL 1
+
+/** PCUT outcome: test failed unexpectedly. */
+#define PCUT_OUTCOME_INTERNAL_ERROR 2
+
+/** PCUT outcome: invalid invocation of the final program. */
+#define PCUT_OUTCOME_BAD_INVOCATION 3
+
+
 #endif
Index: uspace/lib/pcut/src/assert.c
===================================================================
--- uspace/lib/pcut/src/assert.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/assert.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -35,6 +35,10 @@
  */
 
-/** We need _BSD_SOURCE because of vsnprintf() when compiling under C89. */
+/*
+ * We need _BSD_SOURCE because of vsnprintf() when compiling under C89.
+ * In newer versions of features.h, _DEFAULT_SOURCE must be defined as well.
+ */
 #define _BSD_SOURCE
+#define _DEFAULT_SOURCE
 
 #include "internal.h"
Index: uspace/lib/pcut/src/internal.h
===================================================================
--- uspace/lib/pcut/src/internal.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/internal.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -79,14 +79,4 @@
 #define PCUT_RUN_MODE_SINGLE 2
 
-/** Test outcome: test passed. */
-#define TEST_OUTCOME_PASS 1
-
-/** Test outcome: test failed. */
-#define TEST_OUTCOME_FAIL 2
-
-/** Test outcome: test failed unexpectedly. */
-#define TEST_OUTCOME_ERROR 3
-
-
 /*
  * Use sprintf_s in Windows but only with Microsoft compiler.
@@ -109,5 +99,5 @@
 int pcut_is_arg_with_number(const char *arg, const char *opt, int *value);
 
-void pcut_run_test_forking(const char *self_path, pcut_item_t *test);
+int pcut_run_test_forking(const char *self_path, pcut_item_t *test);
 int pcut_run_test_forked(pcut_item_t *test);
 int pcut_run_test_single(pcut_item_t *test);
Index: uspace/lib/pcut/src/main.c
===================================================================
--- uspace/lib/pcut/src/main.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/main.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -90,8 +90,11 @@
  * @param last Pointer to first item after this suite is stored here.
  * @param prog_path Path to the current binary (used in forked mode).
- */
-static void run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) {
+ * @return Error code.
+ */
+static int run_suite(pcut_item_t *suite, pcut_item_t **last, const char *prog_path) {
 	int is_first_test = 1;
 	int total_count = 0;
+	int ret_code = PCUT_OUTCOME_PASS;
+	int ret_code_tmp;
 
 	pcut_item_t *it = pcut_get_real_next(suite);
@@ -114,8 +117,19 @@
 
 		if (pcut_run_mode == PCUT_RUN_MODE_FORKING) {
-			pcut_run_test_forking(prog_path, it);
+			ret_code_tmp = pcut_run_test_forking(prog_path, it);
 		} else {
-			pcut_run_test_single(it);
-		}
+			ret_code_tmp = pcut_run_test_single(it);
+		}
+
+		/*
+		 * Override final return code in case of failure.
+		 *
+		 * In this case we suppress any special error codes as
+		 * to the outside, there was a failure.
+		 */
+		if (ret_code_tmp != PCUT_OUTCOME_PASS) {
+			ret_code = PCUT_OUTCOME_FAIL;
+		}
+
 		total_count++;
 	}
@@ -130,4 +144,6 @@
 		*last = it;
 	}
+
+	return ret_code;
 }
 
@@ -181,4 +197,6 @@
 	int run_only_test = -1;
 
+	int rc, rc_tmp;
+
 	if (main_extras == NULL) {
 		main_extras = empty_main_extra;
@@ -203,5 +221,5 @@
 			if (pcut_str_equals(argv[i], "-l")) {
 				pcut_print_tests(items);
-				return 0;
+				return PCUT_OUTCOME_PASS;
 			}
 			if (pcut_str_equals(argv[i], "-x")) {
@@ -229,5 +247,5 @@
 	if ((run_only_suite >= 0) && (run_only_test >= 0)) {
 		printf("Specify either -s or -t!\n");
-		return 1;
+		return PCUT_OUTCOME_BAD_INVOCATION;
 	}
 
@@ -236,25 +254,24 @@
 		if (suite == NULL) {
 			printf("Suite not found, aborting!\n");
-			return 2;
+			return PCUT_OUTCOME_BAD_INVOCATION;
 		}
 		if (suite->kind != PCUT_KIND_TESTSUITE) {
 			printf("Invalid suite id!\n");
-			return 3;
+			return PCUT_OUTCOME_BAD_INVOCATION;
 		}
 
 		run_suite(suite, NULL, argv[0]);
-		return 0;
+		return PCUT_OUTCOME_PASS;
 	}
 
 	if (run_only_test > 0) {
-		int rc;
 		pcut_item_t *test = pcut_find_by_id(items, run_only_test);
 		if (test == NULL) {
 			printf("Test not found, aborting!\n");
-			return 2;
+			return PCUT_OUTCOME_BAD_INVOCATION;
 		}
 		if (test->kind != PCUT_KIND_TEST) {
 			printf("Invalid test id!\n");
-			return 3;
+			return PCUT_OUTCOME_BAD_INVOCATION;
 		}
 
@@ -271,9 +288,14 @@
 	pcut_report_init(items);
 
+	rc = PCUT_OUTCOME_PASS;
+
 	it = items;
 	while (it != NULL) {
 		if (it->kind == PCUT_KIND_TESTSUITE) {
 			pcut_item_t *tmp;
-			run_suite(it, &tmp, argv[0]);
+			rc_tmp = run_suite(it, &tmp, argv[0]);
+			if (rc_tmp != PCUT_OUTCOME_PASS) {
+				rc = rc_tmp;
+			}
 			it = tmp;
 		} else {
@@ -284,4 +306,4 @@
 	pcut_report_done();
 
-	return 0;
-}
+	return rc;
+}
Index: uspace/lib/pcut/src/os/generic.c
===================================================================
--- uspace/lib/pcut/src/os/generic.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/os/generic.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -34,4 +34,5 @@
 #include <stdlib.h>
 #include <stdio.h>
+#include <sys/types.h>
 #include <errno.h>
 #include <assert.h>
@@ -94,9 +95,9 @@
 static int convert_wait_status_to_outcome(int status) {
 	if (status < 0) {
-		return TEST_OUTCOME_ERROR;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	} else if (status == 0) {
-		return TEST_OUTCOME_PASS;
+		return PCUT_OUTCOME_PASS;
 	} else {
-		return TEST_OUTCOME_FAIL;
+		return PCUT_OUTCOME_FAIL;
 	}
 }
@@ -107,6 +108,6 @@
  * @param test Test to be run.
  */
-void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
-	int rc;
+int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
+	int rc, outcome;
 	FILE *tempfile;
 	char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
@@ -126,17 +127,19 @@
 	PCUT_DEBUG("system() returned 0x%04X", rc);
 
-	rc = convert_wait_status_to_outcome(rc);
+	outcome = convert_wait_status_to_outcome(rc);
 
 	tempfile = fopen(tempfile_name, "rb");
 	if (tempfile == NULL) {
 		pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to open temporary file.", NULL, NULL);
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
 	fread(extra_output_buffer, 1, OUTPUT_BUFFER_SIZE, tempfile);
 	fclose(tempfile);
-	unlink(tempfile_name);
+	remove(tempfile_name);
 
-	pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+	pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+
+	return outcome;
 }
 
Index: uspace/lib/pcut/src/os/helenos.c
===================================================================
--- uspace/lib/pcut/src/os/helenos.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/os/helenos.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -154,13 +154,14 @@
  * @param test Test to be run.
  */
-void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
+int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
 	before_test_start(test);
 
 	char tempfile_name[PCUT_TEMP_FILENAME_BUFFER_SIZE];
 	snprintf(tempfile_name, PCUT_TEMP_FILENAME_BUFFER_SIZE - 1, "pcut_%lld.tmp", (unsigned long long) task_get_id());
-	int tempfile = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE);
-	if (tempfile < 0) {
-		pcut_report_test_done(test, TEST_OUTCOME_ERROR, "Failed to create temporary file.", NULL, NULL);
-		return;
+	int tempfile;
+	int rc = vfs_lookup_open(tempfile_name, WALK_REGULAR | WALK_MAY_CREATE, MODE_READ | MODE_WRITE, &tempfile);
+	if (rc != EOK) {
+		pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, "Failed to create temporary file.", NULL, NULL);
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -174,11 +175,11 @@
 	};
 
-	int status = TEST_OUTCOME_PASS;
+	int status = PCUT_OUTCOME_PASS;
 
 	task_wait_t test_task_wait;
-	int rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments,
+	rc = task_spawnvf(&test_task_id, &test_task_wait, self_path, arguments,
 	    fileno(stdin), tempfile, tempfile);
 	if (rc != EOK) {
-		status = TEST_OUTCOME_ERROR;
+		status = PCUT_OUTCOME_INTERNAL_ERROR;
 		goto leave_close_tempfile;
 	}
@@ -198,11 +199,11 @@
 	rc = task_wait(&test_task_wait, &task_exit, &task_retval);
 	if (rc != EOK) {
-		status = TEST_OUTCOME_ERROR;
+		status = PCUT_OUTCOME_INTERNAL_ERROR;
 		goto leave_close_tempfile;
 	}
 	if (task_exit == TASK_EXIT_UNEXPECTED) {
-		status = TEST_OUTCOME_ERROR;
+		status = PCUT_OUTCOME_INTERNAL_ERROR;
 	} else {
-		status = task_retval == 0 ? TEST_OUTCOME_PASS : TEST_OUTCOME_FAIL;
+		status = task_retval == 0 ? PCUT_OUTCOME_PASS : PCUT_OUTCOME_FAIL;
 	}
 
@@ -213,5 +214,6 @@
 
 	aoff64_t pos = 0;
-	vfs_read(tempfile, &pos, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+	size_t nread;
+	vfs_read(tempfile, &pos, extra_output_buffer, OUTPUT_BUFFER_SIZE, &nread);
 
 leave_close_tempfile:
@@ -220,4 +222,6 @@
 
 	pcut_report_test_done_unparsed(test, status, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+
+	return status;
 }
 
Index: uspace/lib/pcut/src/os/unix.c
===================================================================
--- uspace/lib/pcut/src/os/unix.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/os/unix.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,7 +36,11 @@
 /** We need _BSD_SOURCE because of snprintf() when compiling under C89. */
 #define _BSD_SOURCE
+
+/** Newer versions of features.h needs _DEFAULT_SOURCE. */
+#define _DEFAULT_SOURCE
+
 #include <stdlib.h>
 #include <unistd.h>
-#include <stddef.h>
+#include <sys/types.h>
 #include <signal.h>
 #include <errno.h>
@@ -120,12 +124,12 @@
 	if (WIFEXITED(status)) {
 		if (WEXITSTATUS(status) != 0) {
-			return TEST_OUTCOME_FAIL;
+			return PCUT_OUTCOME_FAIL;
 		} else {
-			return TEST_OUTCOME_PASS;
+			return PCUT_OUTCOME_PASS;
 		}
 	}
 
 	if (WIFSIGNALED(status)) {
-		return TEST_OUTCOME_ERROR;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -138,7 +142,7 @@
  * @param test Test to be run.
  */
-void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
+int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
 	int link_stdout[2], link_stderr[2];
-	int rc, status;
+	int rc, status, outcome;
 	size_t stderr_size;
 
@@ -152,6 +156,6 @@
 		snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
 				"pipe() failed: %s.", strerror(rc));
-		pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);
-		return;
+		pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL);
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	rc = pipe(link_stderr);
@@ -159,6 +163,6 @@
 		snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
 				"pipe() failed: %s.", strerror(rc));
-		pcut_report_test_done(test, TEST_OUTCOME_ERROR, error_message_buffer, NULL, NULL);
-		return;
+		pcut_report_test_done(test, PCUT_OUTCOME_INTERNAL_ERROR, error_message_buffer, NULL, NULL);
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -167,5 +171,5 @@
 		snprintf(error_message_buffer, OUTPUT_BUFFER_SIZE - 1,
 			"fork() failed: %s.", strerror(rc));
-		rc = TEST_OUTCOME_ERROR;
+		outcome = PCUT_OUTCOME_INTERNAL_ERROR;
 		goto leave_close_pipes;
 	}
@@ -178,7 +182,7 @@
 		close(link_stderr[0]);
 
-		rc = pcut_run_test_forked(test);
-
-		exit(rc);
+		outcome = pcut_run_test_forked(test);
+
+		exit(outcome);
 	}
 
@@ -195,5 +199,5 @@
 	alarm(0);
 
-	rc = convert_wait_status_to_outcome(status);
+	outcome = convert_wait_status_to_outcome(status);
 
 	goto leave_close_parent_pipe;
@@ -206,5 +210,7 @@
 	close(link_stderr[0]);
 
-	pcut_report_test_done_unparsed(test, rc, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+	pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+
+	return outcome;
 }
 
Index: uspace/lib/pcut/src/os/windows.c
===================================================================
--- uspace/lib/pcut/src/os/windows.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/os/windows.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -144,5 +144,5 @@
  * @param test Test to be run.
  */
-void pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
+int pcut_run_test_forking(const char *self_path, pcut_item_t *test) {
 	/* TODO: clean-up if something goes wrong "in the middle" */
 	BOOL okay = FALSE;
@@ -173,10 +173,10 @@
 	if (!okay) {
 		report_func_fail(test, "CreatePipe(/* stdout */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	okay = SetHandleInformation(link_stdout[0], HANDLE_FLAG_INHERIT, 0);
 	if (!okay) {
 		report_func_fail(test, "SetHandleInformation(/* stdout */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -185,10 +185,10 @@
 	if (!okay) {
 		report_func_fail(test, "CreatePipe(/* stderr */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	okay = SetHandleInformation(link_stderr[0], HANDLE_FLAG_INHERIT, 0);
 	if (!okay) {
 		report_func_fail(test, "SetHandleInformation(/* stderr */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -197,10 +197,10 @@
 	if (!okay) {
 		report_func_fail(test, "CreatePipe(/* stdin */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	okay = SetHandleInformation(link_stdin[1], HANDLE_FLAG_INHERIT, 0);
 	if (!okay) {
 		report_func_fail(test, "SetHandleInformation(/* stdin */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -224,5 +224,5 @@
 	if (!okay) {
 		report_func_fail(test, "CreateProcess()");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -236,15 +236,15 @@
 	if (!okay) {
 		report_func_fail(test, "CloseHandle(/* stdout */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	okay = CloseHandle(link_stderr[1]);
 	if (!okay) {
 		report_func_fail(test, "CloseHandle(/* stderr */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 	okay = CloseHandle(link_stdin[0]);
 	if (!okay) {
 		report_func_fail(test, "CloseHandle(/* stdin */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -267,5 +267,5 @@
 	if (test_output_thread_reader == NULL) {
 		report_func_fail(test, "CreateThread(/* read test stdout */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -281,5 +281,5 @@
 		if (!okay) {
 			report_func_fail(test, "TerminateProcess(/* PROCESS_INFORMATION.hProcess */)");
-			return;
+			return PCUT_ERROR_INTERNAL_FAILURE;
 		}
 		rc = WaitForSingleObject(process_info.hProcess, INFINITE);
@@ -287,5 +287,5 @@
 	if (rc != WAIT_OBJECT_0) {
 		report_func_fail(test, "WaitForSingleObject(/* PROCESS_INFORMATION.hProcess */)");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -294,13 +294,13 @@
 	if (!okay) {
 		report_func_fail(test, "GetExitCodeProcess()");
-		return;
+		return PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
 	if (rc == 0) {
-		outcome = TEST_OUTCOME_PASS;
+		outcome = PCUT_OUTCOME_PASS;
 	} else if ((rc > 0) && (rc < 10) && !timed_out) {
-		outcome = TEST_OUTCOME_FAIL;
+		outcome = PCUT_OUTCOME_FAIL;
 	} else {
-		outcome = TEST_OUTCOME_ERROR;
+		outcome = PCUT_OUTCOME_INTERNAL_ERROR;
 	}
 
@@ -309,8 +309,10 @@
 	if (rc != WAIT_OBJECT_0) {
 		report_func_fail(test, "WaitForSingleObject(/* stdout reader thread */)");
-		return;
+		return PCUT_ERROR_INTERNAL_FAILURE;
 	}
 
 	pcut_report_test_done_unparsed(test, outcome, extra_output_buffer, OUTPUT_BUFFER_SIZE);
+
+	return outcome;
 }
 
Index: uspace/lib/pcut/src/print.c
===================================================================
--- uspace/lib/pcut/src/print.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/print.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -81,4 +81,8 @@
 			printf("    Test `%s' [%d]\n", it->name, it->id);
 			break;
+		case PCUT_KIND_SETUP:
+		case PCUT_KIND_TEARDOWN:
+			/* Fall-through, do nothing. */
+			break;
 		default:
 			assert(0 && "unreachable case in item-kind switch");
Index: uspace/lib/pcut/src/report/tap.c
===================================================================
--- uspace/lib/pcut/src/report/tap.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/report/tap.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,4 +42,7 @@
 static int test_counter;
 
+/** Counter of all failures. */
+static int failed_test_counter;
+
 /** Counter for tests in a current suite. */
 static int tests_in_suite;
@@ -55,4 +58,5 @@
 	int tests_total = pcut_count_tests(all_items);
 	test_counter = 0;
+	failed_test_counter = 0;
 
 	printf("1..%d\n", tests_total);
@@ -75,6 +79,11 @@
  */
 static void tap_suite_done(pcut_item_t *suite) {
-	printf("#> Finished suite %s (failed %d of %d).\n",
-			suite->name, failed_tests_in_suite, tests_in_suite);
+	if (failed_tests_in_suite == 0) {
+		printf("#> Finished suite %s (passed).\n",
+				suite->name);
+	} else {
+		printf("#> Finished suite %s (failed %d of %d).\n",
+				suite->name, failed_tests_in_suite, tests_in_suite);
+	}
 }
 
@@ -129,23 +138,21 @@
 	const char *fail_error_str = NULL;
 
-	if (outcome != TEST_OUTCOME_PASS) {
+	if (outcome != PCUT_OUTCOME_PASS) {
 		failed_tests_in_suite++;
+		failed_test_counter++;
 	}
 
 	switch (outcome) {
-	case TEST_OUTCOME_PASS:
+	case PCUT_OUTCOME_PASS:
 		status_str = "ok";
 		fail_error_str = "";
 		break;
-	case TEST_OUTCOME_FAIL:
+	case PCUT_OUTCOME_FAIL:
 		status_str = "not ok";
 		fail_error_str = " failed";
 		break;
-	case TEST_OUTCOME_ERROR:
+	default:
 		status_str = "not ok";
 		fail_error_str = " aborted";
-		break;
-	default:
-		/* Shall not get here. */
 		break;
 	}
@@ -160,4 +167,9 @@
 /** Report testing done. */
 static void tap_done(void) {
+	if (failed_test_counter == 0) {
+		printf("#> Done: all tests passed.\n");
+	} else {
+		printf("#> Done: %d of %d tests failed.\n", failed_test_counter, test_counter);
+	}
 }
 
Index: uspace/lib/pcut/src/report/xml.c
===================================================================
--- uspace/lib/pcut/src/report/xml.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/report/xml.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -135,20 +135,17 @@
 	const char *status_str = NULL;
 
-	if (outcome != TEST_OUTCOME_PASS) {
+	if (outcome != PCUT_OUTCOME_PASS) {
 		failed_tests_in_suite++;
 	}
 
 	switch (outcome) {
-	case TEST_OUTCOME_PASS:
+	case PCUT_OUTCOME_PASS:
 		status_str = "pass";
 		break;
-	case TEST_OUTCOME_FAIL:
+	case PCUT_OUTCOME_FAIL:
 		status_str = "fail";
 		break;
-	case TEST_OUTCOME_ERROR:
+	default:
 		status_str = "error";
-		break;
-	default:
-		/* Shall not get here. */
 		break;
 	}
Index: uspace/lib/pcut/src/run.c
===================================================================
--- uspace/lib/pcut/src/run.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/src/run.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -73,9 +73,8 @@
 static int default_suite_initialized = 0;
 
-static void init_default_suite_when_needed(void)
-{
-	if (default_suite_initialized)
+static void init_default_suite_when_needed() {
+	if (default_suite_initialized) {
 		return;
-	
+	}
 	default_suite.id = -1;
 	default_suite.kind = PCUT_KIND_TESTSUITE;
@@ -92,13 +91,11 @@
  * @return Always a valid test suite item.
  */
-static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it)
-{
+static pcut_item_t *pcut_find_parent_suite(pcut_item_t *it) {
 	while (it != NULL) {
-		if (it->kind == PCUT_KIND_TESTSUITE)
+		if (it->kind == PCUT_KIND_TESTSUITE) {
 			return it;
-		
+		}
 		it = it->previous;
 	}
-	
 	init_default_suite_when_needed();
 	return &default_suite;
@@ -109,8 +106,8 @@
  * @param func Function to run (can be NULL).
  */
-static void run_setup_teardown(pcut_setup_func_t func)
-{
-	if (func != NULL)
+static void run_setup_teardown(pcut_setup_func_t func) {
+	if (func != NULL) {
 		func();
+	}
 }
 
@@ -122,11 +119,11 @@
  * @param outcome Outcome of the current test.
  */
-static void leave_test(int outcome)
-{
+static void leave_test(int outcome) {
 	PCUT_DEBUG("leave_test(outcome=%d), will_exit=%s", outcome,
-	    leave_means_exit ? "yes" : "no");
-	if (leave_means_exit)
+		leave_means_exit ? "yes" : "no");
+	if (leave_means_exit) {
 		exit(outcome);
-	
+	}
+
 #ifndef PCUT_NO_LONG_JUMP
 	longjmp(start_test_jump, 1);
@@ -141,8 +138,6 @@
  * @param message Message describing the failure.
  */
-void pcut_failed_assertion(const char *message)
-{
+void pcut_failed_assertion(const char *message) {
 	static const char *prev_message = NULL;
-	
 	/*
 	 * The assertion failed. We need to abort the current test,
@@ -150,27 +145,28 @@
 	 * include running the tear-down routine.
 	 */
-	if (print_test_error)
+	if (print_test_error) {
 		pcut_print_fail_message(message);
-	
+	}
+
 	if (execute_teardown_on_failure) {
 		execute_teardown_on_failure = 0;
 		prev_message = message;
 		run_setup_teardown(current_suite->teardown_func);
-		
+
 		/* Tear-down was okay. */
 		if (report_test_result) {
-			pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,
+			pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL,
 				message, NULL, NULL);
 		}
 	} else {
 		if (report_test_result) {
-			pcut_report_test_done(current_test, TEST_OUTCOME_FAIL,
+			pcut_report_test_done(current_test, PCUT_OUTCOME_FAIL,
 				prev_message, message, NULL);
 		}
 	}
-	
+
 	prev_message = NULL;
-	
-	leave_test(TEST_OUTCOME_FAIL); /* No return. */
+
+	leave_test(PCUT_OUTCOME_FAIL); /* No return. */
 }
 
@@ -180,6 +176,5 @@
  * @return Error status (zero means success).
  */
-static int run_test(pcut_item_t *test)
-{
+static int run_test(pcut_item_t *test) {
 	/*
 	 * Set here as the returning point in case of test failure.
@@ -187,19 +182,20 @@
 	 * test execution.
 	 */
-	
 #ifndef PCUT_NO_LONG_JUMP
 	int test_finished = setjmp(start_test_jump);
-	if (test_finished)
-		return 1;
+	if (test_finished) {
+		return PCUT_OUTCOME_FAIL;
+	}
 #endif
-	
-	if (report_test_result)
+
+	if (report_test_result) {
 		pcut_report_test_start(test);
-	
+	}
+
 	current_suite = pcut_find_parent_suite(test);
 	current_test = test;
-	
+
 	pcut_hook_before_test(test);
-	
+
 	/*
 	 * If anything goes wrong, execute the tear-down function
@@ -207,10 +203,10 @@
 	 */
 	execute_teardown_on_failure = 1;
-	
+
 	/*
 	 * Run the set-up function.
 	 */
 	run_setup_teardown(current_suite->setup_func);
-	
+
 	/*
 	 * The setup function was performed, it is time to run
@@ -218,5 +214,5 @@
 	 */
 	test->test_func();
-	
+
 	/*
 	 * Finally, run the tear-down function. We need to clear
@@ -225,14 +221,15 @@
 	execute_teardown_on_failure = 0;
 	run_setup_teardown(current_suite->teardown_func);
-	
+
 	/*
 	 * If we got here, it means everything went well with
 	 * this test.
 	 */
-	if (report_test_result)
-		pcut_report_test_done(current_test, TEST_OUTCOME_PASS,
-		    NULL, NULL, NULL);
-	
-	return 0;
+	if (report_test_result) {
+		pcut_report_test_done(current_test, PCUT_OUTCOME_PASS,
+			NULL, NULL, NULL);
+	}
+
+	return PCUT_OUTCOME_PASS;
 }
 
@@ -245,15 +242,16 @@
  * @return Error status (zero means success).
  */
-int pcut_run_test_forked(pcut_item_t *test)
-{
+int pcut_run_test_forked(pcut_item_t *test) {
+	int rc;
+
 	report_test_result = 0;
 	print_test_error = 1;
 	leave_means_exit = 1;
-	
-	int rc = run_test(test);
-	
+
+	rc = run_test(test);
+
 	current_test = NULL;
 	current_suite = NULL;
-	
+
 	return rc;
 }
@@ -267,15 +265,16 @@
  * @return Error status (zero means success).
  */
-int pcut_run_test_single(pcut_item_t *test)
-{
+int pcut_run_test_single(pcut_item_t *test) {
+	int rc;
+
 	report_test_result = 1;
 	print_test_error = 0;
 	leave_means_exit = 0;
-	
-	int rc = run_test(test);
-	
+
+	rc = run_test(test);
+
 	current_test = NULL;
 	current_suite = NULL;
-	
+
 	return rc;
 }
@@ -286,16 +285,16 @@
  * @return Timeout in seconds.
  */
-int pcut_get_test_timeout(pcut_item_t *test)
-{
+int pcut_get_test_timeout(pcut_item_t *test) {
 	int timeout = PCUT_DEFAULT_TEST_TIMEOUT;
 	pcut_extra_t *extras = test->extras;
-	
+
+
 	while (extras->type != PCUT_EXTRA_LAST) {
-		if (extras->type == PCUT_EXTRA_TIMEOUT)
+		if (extras->type == PCUT_EXTRA_TIMEOUT) {
 			timeout = extras->timeout;
-		
+		}
 		extras++;
 	}
-	
+
 	return timeout;
 }
Index: uspace/lib/pcut/tests/abort.expected
===================================================================
--- uspace/lib/pcut/tests/abort.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/abort.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -3,2 +3,3 @@
 not ok 1 access_null_pointer aborted
 #> Finished suite Default (failed 1 of 1).
+#> Done: 1 of 1 tests failed.
Index: uspace/lib/pcut/tests/asserts.expected
===================================================================
--- uspace/lib/pcut/tests/asserts.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/asserts.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -18,2 +18,3 @@
 # error: asserts.c:72: Expected false but got <42>
 #> Finished suite Default (failed 7 of 9).
+#> Done: 7 of 9 tests failed.
Index: uspace/lib/pcut/tests/beforeafter.c
===================================================================
--- uspace/lib/pcut/tests/beforeafter.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/beforeafter.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -28,4 +28,5 @@
 
 #define _BSD_SOURCE
+#define _DEFAULT_SOURCE
 
 #include <pcut/pcut.h>
Index: uspace/lib/pcut/tests/beforeafter.expected
===================================================================
--- uspace/lib/pcut/tests/beforeafter.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/beforeafter.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -2,6 +2,7 @@
 #> Starting suite suite_with_setup_and_teardown.
 ok 1 test_with_setup_and_teardown
-#> Finished suite suite_with_setup_and_teardown (failed 0 of 1).
+#> Finished suite suite_with_setup_and_teardown (passed).
 #> Starting suite another_without_setup.
 ok 2 test_without_any_setup_or_teardown
-#> Finished suite another_without_setup (failed 0 of 1).
+#> Finished suite another_without_setup (passed).
+#> Done: all tests passed.
Index: uspace/lib/pcut/tests/errno.expected
===================================================================
--- uspace/lib/pcut/tests/errno.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/errno.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -6,2 +6,3 @@
 # error: errno.c:54: Expected error 0 (EOK, *****) but got error ***** (*****)
 #> Finished suite Default (failed 2 of 2).
+#> Done: 2 of 2 tests failed.
Index: uspace/lib/pcut/tests/inithook.expected
===================================================================
--- uspace/lib/pcut/tests/inithook.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/inithook.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -3,3 +3,4 @@
 ok 1 check_init_counter
 ok 2 check_init_counter_2
-#> Finished suite Default (failed 0 of 2).
+#> Finished suite Default (passed).
+#> Done: all tests passed.
Index: uspace/lib/pcut/tests/manytests.expected
===================================================================
--- uspace/lib/pcut/tests/manytests.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/manytests.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -81,3 +81,4 @@
 ok 79 my_test_079
 ok 80 my_test_080
-#> Finished suite Default (failed 0 of 80).
+#> Finished suite Default (passed).
+#> Done: all tests passed.
Index: uspace/lib/pcut/tests/multisuite.expected
===================================================================
--- uspace/lib/pcut/tests/multisuite.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/multisuite.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -11,2 +11,3 @@
 ok 4 test_same_numbers
 #> Finished suite intmin (failed 1 of 2).
+#> Done: 3 of 4 tests failed.
Index: uspace/lib/pcut/tests/preinithook.expected
===================================================================
--- uspace/lib/pcut/tests/preinithook.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/preinithook.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -3,3 +3,4 @@
 ok 1 check_init_counter
 ok 2 check_init_counter_2
-#> Finished suite Default (failed 0 of 2).
+#> Finished suite Default (passed).
+#> Done: all tests passed.
Index: uspace/lib/pcut/tests/printing.expected
===================================================================
--- uspace/lib/pcut/tests/printing.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/printing.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -9,2 +9,3 @@
 # stdio: Printed from a test to stdout!
 #> Finished suite Default (failed 1 of 3).
+#> Done: 1 of 3 tests failed.
Index: uspace/lib/pcut/tests/simple.expected
===================================================================
--- uspace/lib/pcut/tests/simple.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/simple.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -8,2 +8,3 @@
 # error: simple.c:46: Expected <abc> but got <abd> ("abc" != "XXXabd" + 3)
 #> Finished suite Default (failed 3 of 3).
+#> Done: 3 of 3 tests failed.
Index: uspace/lib/pcut/tests/skip.expected
===================================================================
--- uspace/lib/pcut/tests/skip.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/skip.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -3,3 +3,4 @@
 ok 1 normal_test
 ok 2 again_normal_test
-#> Finished suite Default (failed 0 of 2).
+#> Finished suite Default (passed).
+#> Done: all tests passed.
Index: uspace/lib/pcut/tests/suites.expected
===================================================================
--- uspace/lib/pcut/tests/suites.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/suites.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -10,2 +10,3 @@
 # error: suites.c:49: Expected <5> but got <654> (5 != intmin(654, 5))
 #> Finished suite intmin (failed 1 of 1).
+#> Done: 3 of 3 tests failed.
Index: uspace/lib/pcut/tests/teardown.expected
===================================================================
--- uspace/lib/pcut/tests/teardown.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/teardown.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -21,2 +21,3 @@
 # stdio: This is failing teardown-function.
 #> Finished suite with_failing_teardown (failed 3 of 3).
+#> Done: 4 of 5 tests failed.
Index: uspace/lib/pcut/tests/teardownaborts.expected
===================================================================
--- uspace/lib/pcut/tests/teardownaborts.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/teardownaborts.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -5,2 +5,3 @@
 # stdio: Tear-down will cause null pointer access...
 #> Finished suite Default (failed 1 of 1).
+#> Done: 1 of 1 tests failed.
Index: uspace/lib/pcut/tests/timeout.c
===================================================================
--- uspace/lib/pcut/tests/timeout.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/timeout.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -29,10 +29,13 @@
 #include <pcut/pcut.h>
 
+#ifdef __helenos__
+#include <thread.h>
+#else
 #ifdef __unix
-// FIXME
-#include <thread.h>
+#include <unistd.h>
 #endif
 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
 #include <windows.h>
+#endif
 #endif
 
@@ -41,10 +44,13 @@
 
 static void my_sleep(int sec) {
+#ifdef __helenos__
+	thread_sleep(sec);
+#else
 #ifdef __unix
-// FIXME
-	thread_sleep(sec);
+	sleep(sec);
 #endif
 #if defined(__WIN64) || defined(__WIN32) || defined(_WIN32)
 	Sleep(1000 * sec);
+#endif
 #endif
 }
Index: uspace/lib/pcut/tests/timeout.expected
===================================================================
--- uspace/lib/pcut/tests/timeout.expected	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/timeout.expected	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -7,2 +7,3 @@
 # stdio: Text after the sleep.
 #> Finished suite Default (failed 1 of 2).
+#> Done: 1 of 2 tests failed.
Index: uspace/lib/pcut/tests/xmlreport.c
===================================================================
--- uspace/lib/pcut/tests/xmlreport.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/pcut/tests/xmlreport.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -30,4 +30,6 @@
 #include "tested.h"
 
+#include <pcut/pcut.h>
+#include "tested.h"
 
 PCUT_INIT
Index: uspace/lib/posix/Makefile
===================================================================
--- uspace/lib/posix/Makefile	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/Makefile	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -63,5 +63,4 @@
 	source/ctype.c \
 	source/dlfcn.c \
-	source/errno.c \
 	source/fcntl.c \
 	source/fnmatch.c \
Index: uspace/lib/posix/include/posix/errno.h
===================================================================
--- uspace/lib/posix/include/posix/errno.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,326 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * 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 libposix
- * @{
- */
-/** @file System error numbers.
- */
-
-#ifndef POSIX_ERRNO_H_
-#define POSIX_ERRNO_H_
-
-#include "libc/errno.h"
-
-/* IMPORTANT:
- * Since libc uses negative errorcodes, some sort of conversion is necessary to
- * keep POSIX programs and libraries from breaking. This file maps POSIX error
- * codes to absolute values of corresponding libc codes where available, and
- * assigns new code where there is no prior definition in libc.
- *
- * A new errno variable is defined. When accessed, the function first looks at
- * libc errno and iff it is != 0, sets the POSIX errno to absolute value of
- * libc errno. Given that no library function sets errno to 0 and that all
- * POSIX libraries will be used solely by POSIX programs (thus, there only needs
- * to be one way correspondence between errno and posix_errno), this approach
- * should work as expected in most cases and does not require any wrappers for
- * libc routines that would just change errno values.
- *
- * There is no conditioning by LIBPOSIX_INTERNAL for redefinitions of macros.
- * If there is a need to check errno for a value not defined by POSIX, it's
- * necessary to compare errno against abs(ECODE), because there is no
- * redefinition for such error codes.
- *
- * XXX: maybe all HOS error codes should be redefined
- *
- * NOTE: This redefinition is slightly POSIX incompatible, since the
- *  specification requires the macro values to be usable in preprocessing
- *  directives. I don't think that's very important, though.
- */
-
-#undef errno
-#define errno (*__posix_errno())
-
-extern int *__posix_errno(void);
-
-#define __TOP_ERRNO (-EAGAIN)
-
-enum {
-	POSIX_E2BIG = __TOP_ERRNO + 1,
-	POSIX_EACCES = __TOP_ERRNO + 2,
-	POSIX_EADDRNOTAVAIL = -EADDRNOTAVAIL,
-	POSIX_EAGAIN = -EAGAIN,
-	POSIX_EALREADY = __TOP_ERRNO + 3,
-	POSIX_EBADF = -EBADF,
-	POSIX_EBADMSG = __TOP_ERRNO + 4,
-	POSIX_EBUSY = -EBUSY,
-	POSIX_ECANCELED = __TOP_ERRNO + 5,
-	POSIX_ECHILD = __TOP_ERRNO + 6,
-	POSIX_ECONNABORTED = __TOP_ERRNO + 7,
-	POSIX_ECONNREFUSED = __TOP_ERRNO + 8,
-	POSIX_ECONNRESET = __TOP_ERRNO + 9,
-	POSIX_EDEADLK = __TOP_ERRNO + 10,
-	POSIX_EDOM = __TOP_ERRNO + 11,
-	POSIX_EDQUOT = __TOP_ERRNO + 12,
-	POSIX_EEXIST = -EEXIST,
-	POSIX_EFAULT = __TOP_ERRNO + 13,
-	POSIX_EFBIG = __TOP_ERRNO + 14,
-	POSIX_EHOSTUNREACH = __TOP_ERRNO + 15,
-	POSIX_EIDRM = __TOP_ERRNO + 16,
-	POSIX_EILSEQ = __TOP_ERRNO + 17,
-	POSIX_EINTR = -EINTR,
-	POSIX_EINVAL = -EINVAL,
-	POSIX_EIO = -EIO,
-	POSIX_EISCONN = __TOP_ERRNO + 18,
-	POSIX_EISDIR = -EISDIR,
-	POSIX_ELOOP = __TOP_ERRNO + 19,
-	POSIX_EMFILE = -EMFILE,
-	POSIX_EMLINK = -EMLINK,
-	POSIX_EMSGSIZE = __TOP_ERRNO + 20,
-	POSIX_EMULTIHOP = __TOP_ERRNO + 21,
-	POSIX_ENAMETOOLONG = -ENAMETOOLONG,
-	POSIX_ENETDOWN = __TOP_ERRNO + 22,
-	POSIX_ENETRESET = __TOP_ERRNO + 23,
-	POSIX_ENETUNREACH = __TOP_ERRNO + 24,
-	POSIX_ENFILE = __TOP_ERRNO + 25,
-	POSIX_ENOBUFS = __TOP_ERRNO + 26,
-	POSIX_ENODEV = __TOP_ERRNO + 27,
-	POSIX_ENOENT = -ENOENT,
-	POSIX_ENOEXEC = __TOP_ERRNO + 28,
-	POSIX_ENOLCK = __TOP_ERRNO + 29,
-	POSIX_ENOLINK = __TOP_ERRNO + 30,
-	POSIX_ENOMEM = -ENOMEM,
-	POSIX_ENOMSG = __TOP_ERRNO + 31,
-	POSIX_ENOPROTOOPT = __TOP_ERRNO + 32,
-	POSIX_ENOSPC = -ENOSPC,
-	POSIX_ENOSR = __TOP_ERRNO + 33,
-	POSIX_ENOSTR = __TOP_ERRNO + 34,
-	POSIX_ENOSYS = __TOP_ERRNO + 35,
-	POSIX_ENOTDIR = -ENOTDIR,
-	POSIX_ENOTEMPTY = -ENOTEMPTY,
-	POSIX_ENOTRECOVERABLE = __TOP_ERRNO + 36,
-	POSIX_ENOTSUP = -ENOTSUP,
-	POSIX_ENOTTY = __TOP_ERRNO + 37,
-	POSIX_ENXIO = __TOP_ERRNO + 38,
-	POSIX_EOPNOTSUPP = __TOP_ERRNO + 39,
-	POSIX_EOVERFLOW = -EOVERFLOW,
-	POSIX_EOWNERDEAD = __TOP_ERRNO + 40,
-	POSIX_EPERM = -EPERM,
-	POSIX_EPIPE = __TOP_ERRNO + 41,
-	POSIX_EPROTO = __TOP_ERRNO + 42,
-	POSIX_EPROTOTYPE = __TOP_ERRNO + 43,
-	POSIX_ERANGE = -ERANGE,
-	POSIX_EROFS = __TOP_ERRNO + 44,
-	POSIX_ESPIPE = __TOP_ERRNO + 45,
-	POSIX_ESRCH = __TOP_ERRNO + 46,
-	POSIX_ESTALE = __TOP_ERRNO + 47,
-	POSIX_ETIME = __TOP_ERRNO + 48,
-	POSIX_ETIMEDOUT = __TOP_ERRNO + 49,
-	POSIX_ETXTBSY = __TOP_ERRNO + 50,
-	POSIX_EWOULDBLOCK = __TOP_ERRNO + 51,
-	POSIX_EXDEV = -EXDEV,
-	POSIX_EINPROGRESS = __TOP_ERRNO + 52,
-	POSIX_ENOTSOCK = __TOP_ERRNO + 53,
-	POSIX_EDESTADDRREQ = __TOP_ERRNO + 54,
-	POSIX_EPROTONOSUPPORT = __TOP_ERRNO + 55,
-	POSIX_EAFNOSUPPORT = __TOP_ERRNO + 56,
-	POSIX_EADDRINUSE = __TOP_ERRNO + 57,
-	POSIX_ENOTCONN = __TOP_ERRNO + 58,
-	POSIX_ENODATA = __TOP_ERRNO + 59,
-};
-
-#undef __TOP_ERRNO
-
-#undef E2BIG
-#undef EACCES
-#undef EADDRINUSE
-#undef EADDRNOTAVAIL
-#undef EAFNOSUPPORT
-#undef EAGAIN
-#undef EALREADY
-#undef EBADF
-#undef EBADMSG
-#undef EBUSY
-#undef ECANCELED
-#undef ECHILD
-#undef ECONNABORTED
-#undef ECONNREFUSED
-#undef ECONNRESET
-#undef EDEADLK
-#undef EDESTADDRREQ
-#undef EDOM
-#undef EDQUOT
-#undef EEXIST
-#undef EFAULT
-#undef EFBIG
-#undef EHOSTUNREACH
-#undef EIDRM
-#undef EILSEQ
-#undef EINPROGRESS
-#undef EINTR
-#undef EINVAL
-#undef EIO
-#undef EISCONN
-#undef EISDIR
-#undef ELOOP
-#undef EMFILE
-#undef EMLINK
-#undef EMSGSIZE
-#undef EMULTIHOP
-#undef ENAMETOOLONG
-#undef ENETDOWN
-#undef ENETRESET
-#undef ENETUNREACH
-#undef ENFILE
-#undef ENOBUFS
-#undef ENODATA
-#undef ENODEV
-#undef ENOENT
-#undef ENOEXEC
-#undef ENOLCK
-#undef ENOLINK
-#undef ENOMEM
-#undef ENOMSG
-#undef ENOPROTOOPT
-#undef ENOSPC
-#undef ENOSR
-#undef ENOSTR
-#undef ENOSYS
-#undef ENOTCONN
-#undef ENOTDIR
-#undef ENOTEMPTY
-#undef ENOTRECOVERABLE
-#undef ENOTSOCK
-#undef ENOTSUP
-#undef ENOTTY
-#undef ENXIO
-#undef EOPNOTSUPP
-#undef EOVERFLOW
-#undef EOWNERDEAD
-#undef EPERM
-#undef EPIPE
-#undef EPROTO
-#undef EPROTONOSUPPORT
-#undef EPROTOTYPE
-#undef ERANGE
-#undef EROFS
-#undef ESPIPE
-#undef ESRCH
-#undef ESTALE
-#undef ETIME
-#undef ETIMEDOUT
-#undef ETXTBSY
-#undef EWOULDBLOCK
-#undef EXDEV
-
-#define E2BIG POSIX_E2BIG
-#define EACCES POSIX_EACCES
-#define EADDRINUSE POSIX_EADDRINUSE
-#define EADDRNOTAVAIL POSIX_EADDRNOTAVAIL
-#define EAFNOSUPPORT POSIX_EAFNOSUPPORT
-#define EAGAIN POSIX_EAGAIN
-#define EALREADY POSIX_EALREADY
-#define EBADF POSIX_EBADF
-#define EBADMSG POSIX_EBADMSG
-#define EBUSY POSIX_EBUSY
-#define ECANCELED POSIX_ECANCELED
-#define ECHILD POSIX_ECHILD
-#define ECONNABORTED POSIX_ECONNABORTED
-#define ECONNREFUSED POSIX_ECONNREFUSED
-#define ECONNRESET POSIX_ECONNRESET
-#define EDEADLK POSIX_EDEADLK
-#define EDESTADDRREQ POSIX_EDESTADDRREQ
-#define EDOM POSIX_EDOM
-#define EDQUOT POSIX_EDQUOT
-#define EEXIST POSIX_EEXIST
-#define EFAULT POSIX_EFAULT
-#define EFBIG POSIX_EFBIG
-#define EHOSTUNREACH POSIX_EHOSTUNREACH
-#define EIDRM POSIX_EIDRM
-#define EILSEQ POSIX_EILSEQ
-#define EINPROGRESS POSIX_EINPROGRESS
-#define EINTR POSIX_EINTR
-#define EINVAL POSIX_EINVAL
-#define EIO POSIX_EIO
-#define EISCONN POSIX_EISCONN
-#define EISDIR POSIX_EISDIR
-#define ELOOP POSIX_ELOOP
-#define EMFILE POSIX_EMFILE
-#define EMLINK POSIX_EMLINK
-#define EMSGSIZE POSIX_EMSGSIZE
-#define EMULTIHOP POSIX_EMULTIHOP
-#define ENAMETOOLONG POSIX_ENAMETOOLONG
-#define ENETDOWN POSIX_ENETDOWN
-#define ENETRESET POSIX_ENETRESET
-#define ENETUNREACH POSIX_ENETUNREACH
-#define ENFILE POSIX_ENFILE
-#define ENOBUFS POSIX_ENOBUFS
-#define ENODATA POSIX_ENODATA
-#define ENODEV POSIX_ENODEV
-#define ENOENT POSIX_ENOENT
-#define ENOEXEC POSIX_ENOEXEC
-#define ENOLCK POSIX_ENOLCK
-#define ENOLINK POSIX_ENOLINK
-#define ENOMEM POSIX_ENOMEM
-#define ENOMSG POSIX_ENOMSG
-#define ENOPROTOOPT POSIX_ENOPROTOOPT
-#define ENOSPC POSIX_ENOSPC
-#define ENOSR POSIX_ENOSR
-#define ENOSTR POSIX_ENOSTR
-#define ENOSYS POSIX_ENOSYS
-#define ENOTCONN POSIX_ENOTCONN
-#define ENOTDIR POSIX_ENOTDIR
-#define ENOTEMPTY POSIX_ENOTEMPTY
-#define ENOTRECOVERABLE POSIX_ENOTRECOVERABLE
-#define ENOTSOCK POSIX_ENOTSOCK
-#define ENOTSUP POSIX_ENOTSUP
-#define ENOTTY POSIX_ENOTTY
-#define ENXIO POSIX_ENXIO
-#define EOPNOTSUPP POSIX_EOPNOTSUPP
-#define EOVERFLOW POSIX_EOVERFLOW
-#define EOWNERDEAD POSIX_EOWNERDEAD
-#define EPERM POSIX_EPERM
-#define EPIPE POSIX_EPIPE
-#define EPROTO POSIX_EPROTO
-#define EPROTONOSUPPORT POSIX_EPROTONOSUPPORT
-#define EPROTOTYPE POSIX_EPROTOTYPE
-#define ERANGE POSIX_ERANGE
-#define EROFS POSIX_EROFS
-#define ESPIPE POSIX_ESPIPE
-#define ESRCH POSIX_ESRCH
-#define ESTALE POSIX_ESTALE
-#define ETIME POSIX_ETIME
-#define ETIMEDOUT POSIX_ETIMEDOUT
-#define ETXTBSY POSIX_ETXTBSY
-#define EWOULDBLOCK POSIX_EWOULDBLOCK
-#define EXDEV POSIX_EXDEV
-
-#endif /* POSIX_ERRNO_H_ */
-
-/** @}
- */
Index: uspace/lib/posix/include/posix/fcntl.h
===================================================================
--- uspace/lib/posix/include/posix/fcntl.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/fcntl.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,5 +41,4 @@
 
 #include "sys/types.h"
-#include "errno.h"
 
 #undef O_CREAT
Index: uspace/lib/posix/include/posix/inttypes.h
===================================================================
--- uspace/lib/posix/include/posix/inttypes.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/inttypes.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -43,8 +43,8 @@
 #include "libc/inttypes.h"
 
-extern intmax_t __POSIX_DEF__(strtoimax)(const char *restrict nptr,
-    char **restrict endptr, int base);
-extern uintmax_t __POSIX_DEF__(strtoumax)(const char *restrict nptr,
-    char **restrict endptr, int base);
+extern intmax_t __POSIX_DEF__(strtoimax)(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
+extern uintmax_t __POSIX_DEF__(strtoumax)(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
 
 
Index: uspace/lib/posix/include/posix/pthread.h
===================================================================
--- uspace/lib/posix/include/posix/pthread.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/pthread.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -80,6 +80,6 @@
 extern int pthread_attr_destroy(pthread_attr_t *);
 
-extern int pthread_mutex_init(pthread_mutex_t *restrict,
-    const pthread_mutexattr_t *restrict);
+extern int pthread_mutex_init(pthread_mutex_t *__restrict__,
+    const pthread_mutexattr_t *__restrict__);
 extern int pthread_mutex_destroy(pthread_mutex_t *);
 extern int pthread_mutex_lock(pthread_mutex_t *);
@@ -89,17 +89,17 @@
 extern int pthread_mutexattr_init(pthread_mutexattr_t *);
 extern int pthread_mutexattr_destroy(pthread_mutexattr_t *);
-extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict,
-    int *restrict);
+extern int pthread_mutexattr_gettype(const pthread_mutexattr_t *__restrict__,
+    int *__restrict__);
 extern int pthread_mutexattr_settype(pthread_mutexattr_t *, int);
 
-extern int pthread_cond_init(pthread_cond_t *restrict,
-    const pthread_condattr_t *restrict);
+extern int pthread_cond_init(pthread_cond_t *__restrict__,
+    const pthread_condattr_t *__restrict__);
 extern int pthread_cond_destroy(pthread_cond_t *);
 extern int pthread_cond_broadcast(pthread_cond_t *);
 extern int pthread_cond_signal(pthread_cond_t *);
-extern int pthread_cond_timedwait(pthread_cond_t *restrict,
-    pthread_mutex_t *restrict, const struct __POSIX_DEF__(timespec) *restrict);
-extern int pthread_cond_wait(pthread_cond_t *restrict,
-    pthread_mutex_t *restrict);
+extern int pthread_cond_timedwait(pthread_cond_t *__restrict__,
+    pthread_mutex_t *__restrict__, const struct __POSIX_DEF__(timespec) *__restrict__);
+extern int pthread_cond_wait(pthread_cond_t *__restrict__,
+    pthread_mutex_t *__restrict__);
 
 extern int pthread_condattr_destroy(pthread_condattr_t *);
Index: uspace/lib/posix/include/posix/signal.h
===================================================================
--- uspace/lib/posix/include/posix/signal.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/signal.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -229,6 +229,6 @@
 };
 
-extern int __POSIX_DEF__(sigaction)(int sig, const struct __POSIX_DEF__(sigaction) *restrict act,
-    struct __POSIX_DEF__(sigaction) *restrict oact);
+extern int __POSIX_DEF__(sigaction)(int sig, const struct __POSIX_DEF__(sigaction) *__restrict__ act,
+    struct __POSIX_DEF__(sigaction) *__restrict__ oact);
 
 extern void (*__POSIX_DEF__(signal)(int sig, void (*func)(int)))(int);
@@ -246,8 +246,8 @@
 extern int __POSIX_DEF__(sigismember)(const __POSIX_DEF__(sigset_t) *set, int signo);
 
-extern int __POSIX_DEF__(thread_sigmask)(int how, const __POSIX_DEF__(sigset_t) *restrict set,
-    __POSIX_DEF__(sigset_t) *restrict oset);
-extern int __POSIX_DEF__(sigprocmask)(int how, const __POSIX_DEF__(sigset_t) *restrict set,
-    __POSIX_DEF__(sigset_t) *restrict oset);
+extern int __POSIX_DEF__(thread_sigmask)(int how, const __POSIX_DEF__(sigset_t) *__restrict__ set,
+    __POSIX_DEF__(sigset_t) *__restrict__ oset);
+extern int __POSIX_DEF__(sigprocmask)(int how, const __POSIX_DEF__(sigset_t) *__restrict__ set,
+    __POSIX_DEF__(sigset_t) *__restrict__ oset);
 
 
Index: uspace/lib/posix/include/posix/stdio.h
===================================================================
--- uspace/lib/posix/include/posix/stdio.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/stdio.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -143,16 +143,16 @@
 #undef putc
 #define putc fputc
-extern int __POSIX_DEF__(fputs)(const char *restrict s, FILE *restrict stream);
+extern int __POSIX_DEF__(fputs)(const char *__restrict__ s, FILE *__restrict__ stream);
 #undef getc
 #define getc fgetc
 extern int __POSIX_DEF__(ungetc)(int c, FILE *stream);
-extern ssize_t __POSIX_DEF__(getdelim)(char **restrict lineptr, size_t *restrict n,
-    int delimiter, FILE *restrict stream);
-extern ssize_t __POSIX_DEF__(getline)(char **restrict lineptr, size_t *restrict n,
-    FILE *restrict stream);
+extern ssize_t __POSIX_DEF__(getdelim)(char **__restrict__ lineptr, size_t *__restrict__ n,
+    int delimiter, FILE *__restrict__ stream);
+extern ssize_t __POSIX_DEF__(getline)(char **__restrict__ lineptr, size_t *__restrict__ n,
+    FILE *__restrict__ stream);
 
 /* Opening Streams */
-extern FILE *__POSIX_DEF__(freopen)(const char *restrict filename,
-    const char *restrict mode, FILE *restrict stream);
+extern FILE *__POSIX_DEF__(freopen)(const char *__restrict__ filename,
+    const char *__restrict__ mode, FILE *__restrict__ stream);
 
 /* Error Messages */
@@ -165,5 +165,5 @@
 
 extern int __POSIX_DEF__(fsetpos)(FILE *stream, const __POSIX_DEF__(fpos_t) *pos);
-extern int __POSIX_DEF__(fgetpos)(FILE *restrict stream, __POSIX_DEF__(fpos_t) *restrict pos);
+extern int __POSIX_DEF__(fgetpos)(FILE *__restrict__ stream, __POSIX_DEF__(fpos_t) *__restrict__ pos);
 extern int __POSIX_DEF__(fseek)(FILE *stream, long offset, int whence);
 extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
@@ -175,22 +175,22 @@
 
 /* Formatted Output */
-extern int __POSIX_DEF__(dprintf)(int fildes, const char *restrict format, ...)
+extern int __POSIX_DEF__(dprintf)(int fildes, const char *__restrict__ format, ...)
     PRINTF_ATTRIBUTE(2, 3);
-extern int __POSIX_DEF__(vdprintf)(int fildes, const char *restrict format, va_list ap);
-extern int __POSIX_DEF__(sprintf)(char *restrict s, const char *restrict format, ...)
+extern int __POSIX_DEF__(vdprintf)(int fildes, const char *__restrict__ format, va_list ap);
+extern int __POSIX_DEF__(sprintf)(char *__restrict__ s, const char *__restrict__ format, ...)
     PRINTF_ATTRIBUTE(2, 3);
-extern int __POSIX_DEF__(vsprintf)(char *restrict s, const char *restrict format, va_list ap);
+extern int __POSIX_DEF__(vsprintf)(char *__restrict__ s, const char *__restrict__ format, va_list ap);
 
 /* Formatted Input */
 extern int __POSIX_DEF__(fscanf)(
-    FILE *restrict stream, const char *restrict format, ...);
+    FILE *__restrict__ stream, const char *__restrict__ format, ...);
 extern int __POSIX_DEF__(vfscanf)(
-    FILE *restrict stream, const char *restrict format, va_list arg);
-extern int __POSIX_DEF__(scanf)(const char *restrict format, ...);
-extern int __POSIX_DEF__(vscanf)(const char *restrict format, va_list arg);
+    FILE *__restrict__ stream, const char *__restrict__ format, va_list arg);
+extern int __POSIX_DEF__(scanf)(const char *__restrict__ format, ...);
+extern int __POSIX_DEF__(vscanf)(const char *__restrict__ format, va_list arg);
 extern int __POSIX_DEF__(sscanf)(
-    const char *restrict s, const char *restrict format, ...);
+    const char *__restrict__ s, const char *__restrict__ format, ...);
 extern int __POSIX_DEF__(vsscanf)(
-    const char *restrict s, const char *restrict format, va_list arg);
+    const char *__restrict__ s, const char *__restrict__ format, va_list arg);
 
 /* File Locking */
Index: uspace/lib/posix/include/posix/stdlib.h
===================================================================
--- uspace/lib/posix/include/posix/stdlib.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/stdlib.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -92,11 +92,11 @@
 
 /* Symbolic Links */
-extern char *__POSIX_DEF__(realpath)(const char *restrict name, char *restrict resolved);
+extern char *__POSIX_DEF__(realpath)(const char *__restrict__ name, char *__restrict__ resolved);
 
 /* Floating Point Conversion */
 extern double __POSIX_DEF__(atof)(const char *nptr);
-extern float __POSIX_DEF__(strtof)(const char *restrict nptr, char **restrict endptr);
-extern double __POSIX_DEF__(strtod)(const char *restrict nptr, char **restrict endptr);
-extern long double __POSIX_DEF__(strtold)(const char *restrict nptr, char **restrict endptr);
+extern float __POSIX_DEF__(strtof)(const char *__restrict__ nptr, char **__restrict__ endptr);
+extern double __POSIX_DEF__(strtod)(const char *__restrict__ nptr, char **__restrict__ endptr);
+extern long double __POSIX_DEF__(strtold)(const char *__restrict__ nptr, char **__restrict__ endptr);
 
 /* Integer Conversion */
@@ -104,12 +104,12 @@
 extern long int __POSIX_DEF__(atol)(const char *nptr);
 extern long long int __POSIX_DEF__(atoll)(const char *nptr);
-extern long int __POSIX_DEF__(strtol)(const char *restrict nptr,
-    char **restrict endptr, int base);
-extern long long int __POSIX_DEF__(strtoll)(const char *restrict nptr,
-    char **restrict endptr, int base);
-extern unsigned long int __POSIX_DEF__(strtoul)(const char *restrict nptr,
-    char **restrict endptr, int base);
+extern long int __POSIX_DEF__(strtol)(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
+extern long long int __POSIX_DEF__(strtoll)(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
+extern unsigned long int __POSIX_DEF__(strtoul)(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
 extern unsigned long long int __POSIX_DEF__(strtoull)(
-    const char *restrict nptr, char **restrict endptr, int base);
+    const char *__restrict__ nptr, char **__restrict__ endptr, int base);
 
 /* Memory Allocation */
Index: uspace/lib/posix/include/posix/string.h
===================================================================
--- uspace/lib/posix/include/posix/string.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/string.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -48,5 +48,5 @@
  * int      strcoll_l(const char *, const char *, locale_t);
  * char    *strerror_l(int, locale_t);
- * size_t   strxfrm_l(char *restrict, const char *restrict, size_t, locale_t);
+ * size_t   strxfrm_l(char *__restrict__, const char *__restrict__, size_t, locale_t);
  */
 
@@ -74,11 +74,11 @@
 
 /* Copying and Concatenation */
-extern char *__POSIX_DEF__(strcpy)(char *restrict dest, const char *restrict src);
-extern char *__POSIX_DEF__(strncpy)(char *restrict dest, const char *restrict src, size_t n);
-extern char *__POSIX_DEF__(stpcpy)(char *restrict dest, const char *restrict src);
-extern char *__POSIX_DEF__(stpncpy)(char *restrict dest, const char *restrict src, size_t n);
-extern char *__POSIX_DEF__(strcat)(char *restrict dest, const char *restrict src);
-extern char *__POSIX_DEF__(strncat)(char *restrict dest, const char *restrict src, size_t n);
-extern void *__POSIX_DEF__(memccpy)(void *restrict dest, const void *restrict src, int c, size_t n);
+extern char *__POSIX_DEF__(strcpy)(char *__restrict__ dest, const char *__restrict__ src);
+extern char *__POSIX_DEF__(strncpy)(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern char *__POSIX_DEF__(stpcpy)(char *__restrict__ dest, const char *__restrict__ src);
+extern char *__POSIX_DEF__(stpncpy)(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern char *__POSIX_DEF__(strcat)(char *__restrict__ dest, const char *__restrict__ src);
+extern char *__POSIX_DEF__(strncat)(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern void *__POSIX_DEF__(memccpy)(void *__restrict__ dest, const void *__restrict__ src, int c, size_t n);
 extern char *__POSIX_DEF__(strdup)(const char *s);
 extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
@@ -106,5 +106,5 @@
 /* Collation Functions */
 extern int __POSIX_DEF__(strcoll)(const char *s1, const char *s2);
-extern size_t __POSIX_DEF__(strxfrm)(char *restrict s1, const char *restrict s2, size_t n);
+extern size_t __POSIX_DEF__(strxfrm)(char *__restrict__ s1, const char *__restrict__ s2, size_t n);
 
 /* Error Messages */
Index: uspace/lib/posix/include/posix/sys/stat.h
===================================================================
--- uspace/lib/posix/include/posix/sys/stat.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/sys/stat.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -129,6 +129,6 @@
 
 extern int __POSIX_DEF__(fstat)(int fd, struct __POSIX_DEF__(stat) *st);
-extern int __POSIX_DEF__(lstat)(const char *restrict path, struct __POSIX_DEF__(stat) *restrict st);
-extern int __POSIX_DEF__(stat)(const char *restrict path, struct __POSIX_DEF__(stat) *restrict st);
+extern int __POSIX_DEF__(lstat)(const char *__restrict__ path, struct __POSIX_DEF__(stat) *__restrict__ st);
+extern int __POSIX_DEF__(stat)(const char *__restrict__ path, struct __POSIX_DEF__(stat) *__restrict__ st);
 extern int __POSIX_DEF__(chmod)(const char *path, __POSIX_DEF__(mode_t) mode);
 extern __POSIX_DEF__(mode_t) __POSIX_DEF__(umask)(__POSIX_DEF__(mode_t) mask);
Index: uspace/lib/posix/include/posix/time.h
===================================================================
--- uspace/lib/posix/include/posix/time.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/include/posix/time.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -89,15 +89,15 @@
 
 /* Broken-down Time */
-extern struct tm *__POSIX_DEF__(gmtime_r)(const time_t *restrict timer,
-    struct tm *restrict result);
-extern struct tm *__POSIX_DEF__(gmtime)(const time_t *restrict timep);
-extern struct tm *__POSIX_DEF__(localtime_r)(const time_t *restrict timer,
-    struct tm *restrict result);
-extern struct tm *__POSIX_DEF__(localtime)(const time_t *restrict timep);
+extern struct tm *__POSIX_DEF__(gmtime_r)(const time_t *__restrict__ timer,
+    struct tm *__restrict__ result);
+extern struct tm *__POSIX_DEF__(gmtime)(const time_t *__restrict__ timep);
+extern struct tm *__POSIX_DEF__(localtime_r)(const time_t *__restrict__ timer,
+    struct tm *__restrict__ result);
+extern struct tm *__POSIX_DEF__(localtime)(const time_t *__restrict__ timep);
 
 /* Formatting Calendar Time */
-extern char *__POSIX_DEF__(asctime_r)(const struct tm *restrict timeptr,
-    char *restrict buf);
-extern char *__POSIX_DEF__(asctime)(const struct tm *restrict timeptr);
+extern char *__POSIX_DEF__(asctime_r)(const struct tm *__restrict__ timeptr,
+    char *__restrict__ buf);
+extern char *__POSIX_DEF__(asctime)(const struct tm *__restrict__ timeptr);
 extern char *__POSIX_DEF__(ctime_r)(const time_t *timer, char *buf);
 extern char *__POSIX_DEF__(ctime)(const time_t *timer);
Index: uspace/lib/posix/source/errno.c
===================================================================
--- uspace/lib/posix/source/errno.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ 	(revision )
@@ -1,54 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * 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 libposix
- * @{
- */
-/** @file System error numbers.
- */
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/errno.h"
-
-#include "posix/stdlib.h"
-#include "libc/fibril.h"
-
-static fibril_local int _posix_errno;
-
-int *__posix_errno(void)
-{
-	if (*__errno() != 0) {
-		_posix_errno = posix_abs(*__errno());
-		*__errno() = 0;
-	}
-	return &_posix_errno;
-}
-
-/** @}
- */
Index: uspace/lib/posix/source/fcntl.c
===================================================================
--- uspace/lib/posix/source/fcntl.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/fcntl.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,6 @@
 
 #include "libc/vfs/vfs.h"
-#include "posix/errno.h"
+
+#include <errno.h>
 
 /**
@@ -103,5 +104,4 @@
 int posix_open(const char *pathname, int posix_flags, ...)
 {
-	int rc;
 	posix_mode_t posix_mode = 0;
 	if (posix_flags & O_CREAT) {
@@ -135,10 +135,10 @@
 	    ((posix_flags & O_APPEND) ? MODE_APPEND : 0);
 
-	int file = rcerrno(vfs_lookup, pathname, flags);
-	if (file < 0)
+	int file;
+
+	if (failed(vfs_lookup(pathname, flags, &file)))
 		return -1;
 
-	rc = rcerrno(vfs_open, file, mode);
-	if (rc != EOK) {
+	if (failed(vfs_open(file, mode))) {
 		vfs_put(file);
 		return -1;
@@ -147,6 +147,5 @@
 	if (posix_flags & O_TRUNC) {
 		if (posix_flags & (O_RDWR | O_WRONLY)) {
-			rc = rcerrno(vfs_resize, file, 0);
-			if (rc != EOK) {
+			if (failed(vfs_resize(file, 0))) {
 				vfs_put(file);
 				return -1;
Index: uspace/lib/posix/source/internal/common.h
===================================================================
--- uspace/lib/posix/source/internal/common.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/internal/common.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -50,20 +50,14 @@
 	} while (0)
 
-/* Convert negative errno to positive errno */
-#define negerrno(func, ...) ({ \
-	int rc = func(__VA_ARGS__); \
-	if (rc < 0) { \
-		errno = -errno; \
-	} \
-	rc; \
-})
-
-/* Convert error code to positive errno and -1 return value */
-#define rcerrno(func, ...) ({ \
-	int rc = func(__VA_ARGS__); \
-	if (rc < 0) \
-		errno = -rc; \
-	rc; \
-})
+/* Checks if the value is a failing error code.
+ * If so, writes the error code to errno and returns true.
+ */
+static inline bool failed(int rc) {
+	if (rc != EOK) {
+		errno = rc;
+		return true;
+	}
+	return false;
+}
 
 extern aoff64_t posix_pos[MAX_OPEN_FILES];
Index: uspace/lib/posix/source/locale.c
===================================================================
--- uspace/lib/posix/source/locale.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/locale.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,6 @@
 #include "posix/locale.h"
 
-#include "posix/errno.h"
+#include <errno.h>
+
 #include "posix/limits.h"
 #include "posix/string.h"
Index: uspace/lib/posix/source/pthread/keys.c
===================================================================
--- uspace/lib/posix/source/pthread/keys.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/pthread/keys.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -38,5 +38,5 @@
 #include "posix/stdlib.h"
 #include "posix/pthread.h"
-#include "errno.h"
+#include <errno.h>
 #include "../internal/common.h"
 
Index: uspace/lib/posix/source/pthread/mutex.c
===================================================================
--- uspace/lib/posix/source/pthread/mutex.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/pthread/mutex.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,5 +37,5 @@
 
 #include "posix/pthread.h"
-#include "errno.h"
+#include <errno.h>
 #include "../internal/common.h"
 
Index: uspace/lib/posix/source/pwd.c
===================================================================
--- uspace/lib/posix/source/pwd.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/pwd.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -39,5 +39,5 @@
 #include "posix/pwd.h"
 #include "posix/string.h"
-#include "posix/errno.h"
+#include <errno.h>
 #include "posix/assert.h"
 
Index: uspace/lib/posix/source/signal.c
===================================================================
--- uspace/lib/posix/source/signal.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/signal.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,5 +41,6 @@
 #include "posix/stdlib.h"
 #include "posix/string.h"
-#include "posix/errno.h"
+
+#include <errno.h>
 
 #include "libc/fibril_synch.h"
Index: uspace/lib/posix/source/stdio.c
===================================================================
--- uspace/lib/posix/source/stdio.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/stdio.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,5 +41,7 @@
 
 #include "posix/assert.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/stdlib.h"
 #include "posix/string.h"
@@ -313,5 +315,5 @@
 int posix_fflush(FILE *stream)
 {
-	return negerrno(fflush, stream);
+	return fflush(stream);
 }
 
@@ -343,7 +345,7 @@
 {
 	const int fildes = *(int *) fd;
-	ssize_t wr = vfs_write(fildes, &posix_pos[fildes], str, size);
-	if (wr < 0)
-		return wr;
+	size_t wr;
+	if (failed(vfs_write(fildes, &posix_pos[fildes], str, size, &wr)))
+		return -1;
 	return str_nlength(str, wr);
 }
@@ -371,5 +373,6 @@
 		
 		const int fildes = *(int *) fd;
-		if (vfs_write(fildes, &posix_pos[fildes], buf, sz) < 0)
+		size_t nwr;
+		if (vfs_write(fildes, &posix_pos[fildes], buf, sz, &nwr) != EOK)
 			break;
 		
@@ -574,5 +577,5 @@
 int posix_remove(const char *path)
 {
-	if (rcerrno(vfs_unlink_path, path) != EOK)
+	if (failed(vfs_unlink_path(path)))
 		return -1;
 	else
@@ -589,6 +592,5 @@
 int posix_rename(const char *old, const char *new)
 {
-	int rc = rcerrno(vfs_rename_path, old, new);
-	if (rc != EOK)
+	if (failed(vfs_rename_path(old, new)))
 		return -1;
 	else
@@ -662,5 +664,5 @@
 		
 		int orig_errno = errno;
-		errno = 0;
+		errno = EOK;
 		/* Check if the file exists. */
 		if (posix_access(result, F_OK) == -1) {
Index: uspace/lib/posix/source/stdio/scanf.c
===================================================================
--- uspace/lib/posix/source/stdio/scanf.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/stdio/scanf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -37,5 +37,6 @@
 
 #include "posix/assert.h"
-#include "posix/errno.h"
+
+#include <errno.h>
 
 #include "posix/stdio.h"
Index: uspace/lib/posix/source/stdlib.c
===================================================================
--- uspace/lib/posix/source/stdlib.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/stdlib.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,6 @@
 #include "posix/stdlib.h"
 
-#include "posix/errno.h"
+#include <errno.h>
+
 #include "posix/fcntl.h"
 #include "posix/limits.h"
Index: uspace/lib/posix/source/stdlib/strtol.c
===================================================================
--- uspace/lib/posix/source/stdlib/strtol.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/stdlib/strtol.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,7 @@
 
 #include "posix/ctype.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/inttypes.h"
 #include "posix/limits.h"
Index: uspace/lib/posix/source/stdlib/strtold.c
===================================================================
--- uspace/lib/posix/source/stdlib/strtold.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/stdlib/strtold.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -44,5 +44,7 @@
 #include "posix/stdint.h"
 #include "posix/strings.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/limits.h"
 
Index: uspace/lib/posix/source/string.c
===================================================================
--- uspace/lib/posix/source/string.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/string.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,5 +41,7 @@
 
 #include "posix/assert.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/limits.h"
 #include "posix/stdlib.h"
@@ -615,89 +617,6 @@
 char *posix_strerror(int errnum)
 {
-	static const char *error_msgs[] = {
-		[E2BIG] = "[E2BIG] Argument list too long",
-		[EACCES] = "[EACCES] Permission denied",
-		[EADDRINUSE] = "[EADDRINUSE] Address in use",
-		[EADDRNOTAVAIL] = "[EADDRNOTAVAIL] Address not available",
-		[EAFNOSUPPORT] = "[EAFNOSUPPORT] Address family not supported",
-		[EAGAIN] = "[EAGAIN] Resource unavailable, try again",
-		[EALREADY] = "[EALREADY] Connection already in progress",
-		[EBADF] = "[EBADF] Bad file descriptor",
-		[EBADMSG] = "[EBADMSG] Bad message",
-		[EBUSY] = "[EBUSY] Device or resource busy",
-		[ECANCELED] = "[ECANCELED] Operation canceled",
-		[ECHILD] = "[ECHILD] No child processes",
-		[ECONNABORTED] = "[ECONNABORTED] Connection aborted",
-		[ECONNREFUSED] = "[ECONNREFUSED] Connection refused",
-		[ECONNRESET] = "[ECONNRESET] Connection reset",
-		[EDEADLK] = "[EDEADLK] Resource deadlock would occur",
-		[EDESTADDRREQ] = "[EDESTADDRREQ] Destination address required",
-		[EDOM] = "[EDOM] Mathematics argument out of domain of function",
-		[EDQUOT] = "[EDQUOT] Reserved",
-		[EEXIST] = "[EEXIST] File exists",
-		[EFAULT] = "[EFAULT] Bad address",
-		[EFBIG] = "[EFBIG] File too large",
-		[EHOSTUNREACH] = "[EHOSTUNREACH] Host is unreachable",
-		[EIDRM] = "[EIDRM] Identifier removed",
-		[EILSEQ] = "[EILSEQ] Illegal byte sequence",
-		[EINPROGRESS] = "[EINPROGRESS] Operation in progress",
-		[EINTR] = "[EINTR] Interrupted function",
-		[EINVAL] = "[EINVAL] Invalid argument",
-		[EIO] = "[EIO] I/O error",
-		[EISCONN] = "[EISCONN] Socket is connected",
-		[EISDIR] = "[EISDIR] Is a directory",
-		[ELOOP] = "[ELOOP] Too many levels of symbolic links",
-		[EMFILE] = "[EMFILE] File descriptor value too large",
-		[EMLINK] = "[EMLINK] Too many links",
-		[EMSGSIZE] = "[EMSGSIZE] Message too large",
-		[EMULTIHOP] = "[EMULTIHOP] Reserved",
-		[ENAMETOOLONG] = "[ENAMETOOLONG] Filename too long",
-		[ENETDOWN] = "[ENETDOWN] Network is down",
-		[ENETRESET] = "[ENETRESET] Connection aborted by network",
-		[ENETUNREACH] = "[ENETUNREACH] Network unreachable",
-		[ENFILE] = "[ENFILE] Too many files open in system",
-		[ENOBUFS] = "[ENOBUFS] No buffer space available",
-		[ENODATA] = "[ENODATA] No message is available on the STREAM head read queue",
-		[ENODEV] = "[ENODEV] No such device",
-		[ENOENT] = "[ENOENT] No such file or directory",
-		[ENOEXEC] = "[ENOEXEC] Executable file format error",
-		[ENOLCK] = "[ENOLCK] No locks available",
-		[ENOLINK] = "[ENOLINK] Reserved",
-		[ENOMEM] = "[ENOMEM] Not enough space",
-		[ENOMSG] = "[ENOMSG] No message of the desired type",
-		[ENOPROTOOPT] = "[ENOPROTOOPT] Protocol not available",
-		[ENOSPC] = "[ENOSPC] No space left on device",
-		[ENOSR] = "[ENOSR] No STREAM resources.",
-		[ENOSTR] = "[ENOSTR] Not a STREAM",
-		[ENOSYS] = "[ENOSYS] Function not supported",
-		[ENOTCONN] = "[ENOTCONN] The socket is not connected",
-		[ENOTDIR] = "[ENOTDIR] Not a directory",
-		[ENOTEMPTY] = "[ENOTEMPTY] Directory not empty",
-		[ENOTRECOVERABLE] = "[ENOTRECOVERABLE] State not recoverable",
-		[ENOTSOCK] = "[ENOTSOCK] Not a socket",
-		[ENOTSUP] = "[ENOTSUP] Not supported",
-		[ENOTTY] = "[ENOTTY] Inappropriate I/O control operation",
-		[ENXIO] = "[ENXIO] No such device or address",
-		[EOPNOTSUPP] = "[EOPNOTSUPP] Operation not supported",
-		[EOVERFLOW] = "[EOVERFLOW] Value too large to be stored in data type",
-		[EOWNERDEAD] = "[EOWNERDEAD] Previous owned died",
-		[EPERM] = "[EPERM] Operation not permitted",
-		[EPIPE] = "[EPIPE] Broken pipe",
-		[EPROTO] = "[EPROTO] Protocol error",
-		[EPROTONOSUPPORT] = "[EPROTONOSUPPORT] Protocol not supported",
-		[EPROTOTYPE] = "[EPROTOTYPE] Protocol wrong type for socket",
-		[ERANGE] = "[ERANGE] Result too large",
-		[EROFS] = "[EROFS] Read-only file system",
-		[ESPIPE] = "[ESPIPE] Invalid seek",
-		[ESRCH] = "[ESRCH] No such process",
-		[ESTALE] = "[ESTALE] Reserved",
-		[ETIME] = "[ETIME] Stream ioctl() timeout",
-		[ETIMEDOUT] = "[ETIMEDOUT] Connection timed out",
-		[ETXTBSY] = "[ETXTBSY] Text file busy",
-		[EWOULDBLOCK] = "[EWOULDBLOCK] Operation would block",
-		[EXDEV] = "[EXDEV] Cross-device link",
-	};
-
-	return (char *) error_msgs[posix_abs(errnum)];
+	// FIXME: move strerror() and strerror_r() to libc.
+	return (char *) str_error(errnum);
 }
 
@@ -722,5 +641,5 @@
 	}
 
-	return 0;
+	return EOK;
 }
 
Index: uspace/lib/posix/source/sys/mman.c
===================================================================
--- uspace/lib/posix/source/sys/mman.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/sys/mman.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -59,5 +59,10 @@
 int posix_munmap(void *start, size_t length)
 {
-	return as_area_destroy(start);
+	int rc = as_area_destroy(start);
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	return 0;
 }
 
Index: uspace/lib/posix/source/sys/stat.c
===================================================================
--- uspace/lib/posix/source/sys/stat.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/sys/stat.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,5 +41,5 @@
 #include "libc/vfs/vfs.h"
 
-#include "posix/errno.h"
+#include <errno.h>
 #include "libc/mem.h"
 
@@ -89,6 +89,5 @@
 {
 	struct stat hst;
-	int rc = rcerrno(vfs_stat, fd, &hst);
-	if (rc < 0)
+	if (failed(vfs_stat(fd, &hst)))
 		return -1;
 	return stat_to_posix(st, &hst);
@@ -118,6 +117,5 @@
 {
 	struct stat hst;
-	int rc = rcerrno(vfs_stat_path, path, &hst);
-	if (rc < 0)
+	if (failed(vfs_stat_path(path, &hst)))
 		return -1;
 	return stat_to_posix(st, &hst);
@@ -159,6 +157,5 @@
 int posix_mkdir(const char *path, posix_mode_t mode)
 {
-	int rc = rcerrno(vfs_link_path, path, KIND_DIRECTORY, NULL);
-	if (rc != EOK)
+	if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL)))
 		return -1;
 	else
Index: uspace/lib/posix/source/sys/wait.c
===================================================================
--- uspace/lib/posix/source/sys/wait.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/sys/wait.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -42,5 +42,7 @@
 #include "libc/task.h"
 #include "posix/assert.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/limits.h"
 #include "posix/signal.h"
@@ -100,9 +102,6 @@
 	int retval;
 	
-	int rc = task_wait_task_id((task_id_t) pid, &texit, &retval);
-	
-	if (rc < 0) {
+	if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) {
 		/* Unable to retrieve status. */
-		errno = -rc;
 		return (posix_pid_t) -1;
 	}
Index: uspace/lib/posix/source/time.c
===================================================================
--- uspace/lib/posix/source/time.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/time.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -41,9 +41,11 @@
 
 #include "posix/ctype.h"
-#include "posix/errno.h"
+
+#include <errno.h>
+
 #include "posix/signal.h"
 #include "posix/assert.h"
 
-#include "libc/fibril_synch.h"
+#include "libc/async.h"
 #include "libc/malloc.h"
 #include "libc/task.h"
@@ -100,7 +102,5 @@
     struct tm *restrict result)
 {
-	int rc = time_utc2tm(*timer, result);
-	if (rc != EOK) {
-		errno = rc;
+	if (failed(time_utc2tm(*timer, result))) {
 		return NULL;
 	}
@@ -197,7 +197,5 @@
 char *posix_ctime_r(const time_t *timer, char *buf)
 {
-	int r = time_local2str(*timer, buf);
-	if (r != EOK) {
-		errno = r;
+	if (failed(time_local2str(*timer, buf))) {
 		return NULL;
 	}
@@ -314,8 +312,8 @@
 			// TODO: interruptible sleep
 			if (rqtp->tv_sec != 0) {
-				fibril_sleep(rqtp->tv_sec);
+				async_sleep(rqtp->tv_sec);
 			}
 			if (rqtp->tv_nsec != 0) {
-				fibril_usleep(rqtp->tv_nsec / 1000);
+				async_usleep(rqtp->tv_nsec / 1000);
 			}
 			return 0;
Index: uspace/lib/posix/source/unistd.c
===================================================================
--- uspace/lib/posix/source/unistd.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/source/unistd.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -40,5 +40,6 @@
 #include "posix/unistd.h"
 
-#include "posix/errno.h"
+#include <errno.h>
+
 #include "posix/string.h"
 #include "posix/fcntl.h"
@@ -52,4 +53,5 @@
 #include <libarch/config.h>
 
+// FIXME: replace with a hash table
 aoff64_t posix_pos[MAX_OPEN_FILES];
 
@@ -126,6 +128,5 @@
 char *posix_getcwd(char *buf, size_t size)
 {
-	int rc = rcerrno(vfs_cwd_get, buf, size);
-	if (rc != EOK) 
+	if (failed(vfs_cwd_get(buf, size))) 
 		return NULL;
 	return buf;
@@ -139,6 +140,5 @@
 int posix_chdir(const char *path)
 {
-	int rc = rcerrno(vfs_cwd_set, path);
-	if (rc != EOK)
+	if (failed(vfs_cwd_set(path)))
 		return -1;
 	return 0;
@@ -196,6 +196,5 @@
 {
 	posix_pos[fildes] = 0;
-	int rc = rcerrno(vfs_put, fildes);
-	if (rc != EOK)
+	if (failed(vfs_put(fildes)))
 		return -1;
 	else
@@ -213,8 +212,8 @@
 ssize_t posix_read(int fildes, void *buf, size_t nbyte)
 {
-	ssize_t size = rcerrno(vfs_read, fildes, &posix_pos[fildes], buf, nbyte);
-	if (size < 0)
-		return -1;
-	return size;
+	size_t nread;
+	if (failed(vfs_read(fildes, &posix_pos[fildes], buf, nbyte, &nread)))
+		return -1;
+	return (ssize_t) nread;
 }
 
@@ -229,8 +228,8 @@
 ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
 {
-	ssize_t size = rcerrno(vfs_write, fildes, &posix_pos[fildes], buf, nbyte);
-	if (size < 0)
-		return -1;
-	return size;
+	size_t nwr;
+	if (failed(vfs_write(fildes, &posix_pos[fildes], buf, nbyte, &nwr)))
+		return -1;
+	return nwr;
 }
 
@@ -247,5 +246,4 @@
 {
 	struct stat st;
-	int rc;
 
 	switch (whence) {
@@ -257,6 +255,5 @@
 		break;
 	case SEEK_END:
-		rc = rcerrno(vfs_stat, fildes, &st);
-		if (rc != EOK)
+		if (failed(vfs_stat(fildes, &st)))
 			return -1;
 		posix_pos[fildes] = st.size + offset;
@@ -279,5 +276,5 @@
 int posix_fsync(int fildes)
 {
-	if (rcerrno(vfs_sync, fildes) != EOK)
+	if (failed(vfs_sync(fildes)))
 		return -1;
 	else
@@ -294,5 +291,5 @@
 int posix_ftruncate(int fildes, posix_off_t length)
 {
-	if (rcerrno(vfs_resize, fildes, (aoff64_t) length) != EOK)
+	if (failed(vfs_resize(fildes, (aoff64_t) length)))
 		return -1;
 	else
@@ -308,5 +305,5 @@
 int posix_rmdir(const char *path)
 {
-	if (rcerrno(vfs_unlink_path, path) != EOK)
+	if (failed(vfs_unlink_path(path)))
 		return -1;
 	else
@@ -322,5 +319,5 @@
 int posix_unlink(const char *path)
 {
-	if (rcerrno(vfs_unlink_path, path) != EOK)
+	if (failed(vfs_unlink_path(path)))
 		return -1;
 	else
@@ -349,5 +346,9 @@
 int posix_dup2(int fildes, int fildes2)
 {
-	return negerrno(vfs_clone, fildes, fildes2, false);
+	int file;
+	if (failed(vfs_clone(fildes, fildes2, false, &file))) {
+		return -1;
+	}
+	return file;
 }
 
Index: uspace/lib/posix/test/scanf.c
===================================================================
--- uspace/lib/posix/test/scanf.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/posix/test/scanf.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -30,5 +30,6 @@
 #define __POSIX_DEF__(x) posix_##x
 
-#include "posix/errno.h"
+#include <errno.h>
+
 #include "posix/stdio.h"
 
Index: uspace/lib/trackmod/protracker.c
===================================================================
--- uspace/lib/trackmod/protracker.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/trackmod/protracker.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -302,6 +302,5 @@
 		memcpy(&mod15, &mod31, sizeof(protracker_15smp_t));
 
-		rc = fseek(f, sizeof(protracker_15smp_t), SEEK_SET);
-		if (rc != 0) {
+		if (fseek(f, sizeof(protracker_15smp_t), SEEK_SET) < 0) {
 			printf("Error seeking.\n");
 			rc = EIO;
Index: uspace/lib/trackmod/xm.c
===================================================================
--- uspace/lib/trackmod/xm.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/trackmod/xm.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -174,4 +174,5 @@
 	long seek_amount;
 	int rc;
+	int ret;
 
 	module->pattern = calloc(sizeof(trackmod_pattern_t), module->patterns);
@@ -182,6 +183,6 @@
 
 	for (i = 0; i < module->patterns; i++) {
-		rc = fread(&pattern, 1, sizeof(xm_pattern_t), f);
-		if (rc != sizeof(xm_pattern_t)) {
+		ret = fread(&pattern, 1, sizeof(xm_pattern_t), f);
+		if (ret != sizeof(xm_pattern_t)) {
 			rc = EIO;
 			goto error;
@@ -297,4 +298,5 @@
 	long pos;
 	int rc;
+	int ret;
 
 	module->instrs = uint16_t_le2host(xm_hdr->instruments);
@@ -305,6 +307,6 @@
 	for (i = 0; i < module->instrs; i++) {
 		pos = ftell(f);
-		rc = fread(&instr, 1, sizeof(xm_instr_t), f);
-		if (rc != sizeof(xm_instr_t)) {
+		ret = fread(&instr, 1, sizeof(xm_instr_t), f);
+		if (ret != sizeof(xm_instr_t)) {
 			rc = EIO;
 			goto error;
@@ -315,6 +317,6 @@
 
 		if (samples > 0) {
-			rc = fread(&instrx, 1, sizeof(xm_instr_ext_t), f);
-			if (rc != sizeof(xm_instr_ext_t)) {
+			ret = fread(&instrx, 1, sizeof(xm_instr_ext_t), f);
+			if (ret != sizeof(xm_instr_ext_t)) {
 				rc = EIO;
 				goto error;
@@ -346,6 +348,6 @@
 			pos = ftell(f);
 
-			rc = fread(&smp, 1, sizeof(xm_smp_t), f);
-			if (rc != sizeof(xm_smp_t)) {
+			ret = fread(&smp, 1, sizeof(xm_smp_t), f);
+			if (ret != sizeof(xm_smp_t)) {
 				rc = EIO;
 				goto error;
Index: uspace/lib/usbdev/src/recognise.c
===================================================================
--- uspace/lib/usbdev/src/recognise.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbdev/src/recognise.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -88,10 +88,12 @@
 		char *str = NULL; \
 		int __rc = asprintf(&str, format, ##__VA_ARGS__); \
-		if (__rc > 0) { \
-			__rc = usb_add_match_id((match_ids), (score), str); \
-		} \
-		if (__rc != EOK) { \
-			free(str); \
-			return __rc; \
+		if (__rc >= 0) { \
+			int __rc = usb_add_match_id((match_ids), (score), str); \
+			if (__rc != EOK) { \
+				free(str); \
+				return __rc; \
+			} \
+		} else { \
+			return ENOMEM; \
 		} \
 	} while (0)
Index: uspace/lib/usbhid/src/hiddescriptor.c
===================================================================
--- uspace/lib/usbhid/src/hiddescriptor.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbhid/src/hiddescriptor.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,8 +36,8 @@
 #include <errno.h>
 #include <stdio.h>
-#include <malloc.h>
 #include <mem.h>
 #include <usb/debug.h>
 #include <assert.h>
+#include <stdlib.h>
 
 
@@ -75,4 +75,5 @@
 #define USB_HID_RESET_OFFSET	3
 
+#define USB_HID_INVALID                 -98
 /** Unknown tag was founded in report descriptor data*/
 #define USB_HID_UNKNOWN_TAG		-99
@@ -103,5 +104,5 @@
 		
 		if(usb_hid_report_compare_usage_path(path, cmp_path,
-					USB_HID_PATH_COMPARE_STRICT) == EOK){
+					USB_HID_PATH_COMPARE_STRICT) == 0){
 			break;
 		}
@@ -539,5 +540,5 @@
 
 		if((ret=usb_hid_report_parse_main_tag(tag, data, item_size,
-			report_item, usage_path)) == EOK) {
+			report_item, usage_path)) == 0) {
 
 			return USB_HID_NEW_REPORT_ITEM;
@@ -570,5 +571,5 @@
  * @param Length of data buffer
  * @param Current state table
- * @return Error code
+ * @return 0 or USB_HID_ code
  */
 
@@ -585,5 +586,5 @@
 	case USB_HID_REPORT_TAG_FEATURE:
 		report_item->item_flags = *data;			
-		return EOK;			
+		return 0;			
 		break;
 			
@@ -625,5 +626,5 @@
 	}
 
-	return EOK;
+	return 0;
 }
 
@@ -635,5 +636,5 @@
  * @param Length of data buffer
  * @param Current state table
- * @return Error code
+ * @return 0 or USB_HID_ code
  */
 int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 
@@ -711,5 +712,5 @@
 	}
 
-	return EOK;
+	return 0;
 }
 
@@ -721,5 +722,5 @@
  * @param Length of data buffer
  * @param Current state table
- * @return Error code
+ * @return 0 or USB_HID_ code
  */
 int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
@@ -777,5 +778,5 @@
 			    USB_HID_EXTENDED_USAGE_PAGE(
 			    usb_hid_report_tag_data_uint32(data, item_size))) {
-				return EINVAL;
+				return USB_HID_INVALID;
 			}
 			
@@ -848,5 +849,5 @@
 	}
 	
-	return EOK;
+	return 0;
 }
 
Index: uspace/lib/usbhid/src/hidparser.c
===================================================================
--- uspace/lib/usbhid/src/hidparser.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbhid/src/hidparser.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,5 +36,5 @@
 #include <errno.h>
 #include <stdio.h>
-#include <malloc.h>
+#include <stdlib.h>
 #include <mem.h>
 #include <usb/debug.h>
@@ -518,5 +518,5 @@
 
 			if (usb_hid_report_compare_usage_path(
-			    field->collection_path, path, flags) == EOK) {
+			    field->collection_path, path, flags) == 0) {
 				usb_hid_report_remove_last_item(
 				    field->collection_path);
Index: uspace/lib/usbhid/src/hidpath.c
===================================================================
--- uspace/lib/usbhid/src/hidpath.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbhid/src/hidpath.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -36,6 +36,6 @@
 #include <errno.h>
 #include <stdio.h>
-#include <malloc.h>
 #include <mem.h>
+#include <stdlib.h>
 #include <usb/debug.h>
 #include <assert.h>
@@ -191,5 +191,5 @@
  * @param flags       Flags determining the mode of comparison
  *
- * @return EOK if both paths are identical, non zero number otherwise
+ * @return 0 if both paths are identical, non zero number otherwise
  *
  */
@@ -213,5 +213,5 @@
 	// Empty path match all others
 	if (path->depth == 0) {
-		return EOK;
+		return 0;
 	}
 	
@@ -239,7 +239,7 @@
 					if (USB_HID_SAME_USAGE(report_item->usage,
 					    path_item->usage))
-						return EOK;
+						return 0;
 				} else {
-					return EOK;
+					return 0;
 				}
 			}
@@ -285,5 +285,5 @@
 		    ((report_link == &report_path->items.head) &&
 		    (path_link == &path->items.head))) {
-			return EOK;
+			return 0;
 		} else {
 			return 1;
@@ -297,5 +297,5 @@
 		
 		if (list_empty(&path->items)) {
-			return EOK;
+			return 0;
 		}
 		
@@ -320,5 +320,5 @@
 		
 		if (path_link == &path->items.head) {
-			return EOK;
+			return 0;
 		} else {
 			return 1;
@@ -327,5 +327,5 @@
 	
 	default:
-		return EINVAL;
+		return -1;
 	}
 }
Index: uspace/lib/usbhost/include/usb/host/hcd.h
===================================================================
--- uspace/lib/usbhost/include/usb/host/hcd.h	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbhost/include/usb/host/hcd.h	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -77,5 +77,5 @@
 
 	/** Generate IRQ code to handle interrupts. */
-	int (*irq_code_gen)(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *);
+	int (*irq_code_gen)(irq_code_t *, hc_device_t *, const hw_res_list_parsed_t *, int *);
 
 	/** Claim device from BIOS. */
Index: uspace/lib/usbhost/src/hcd.c
===================================================================
--- uspace/lib/usbhost/src/hcd.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbhost/src/hcd.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -95,5 +95,5 @@
  * lookup.
  */
-static void irq_handler(ipc_callid_t iid, ipc_call_t *call, ddf_dev_t *dev)
+static void irq_handler(ipc_call_t *call, ddf_dev_t *dev)
 {
 	assert(dev);
@@ -162,6 +162,8 @@
 		return ENOTSUP;
 
-	const int irq = hc_driver->irq_code_gen(&irq_code, hcd, hw_res);
-	if (irq < 0) {
+	int irq;
+	int ret;
+	ret = hc_driver->irq_code_gen(&irq_code, hcd, hw_res, &irq);
+	if (ret != EOK) {
 		usb_log_error("Failed to generate IRQ code: %s.",
 		    str_error(irq));
@@ -170,7 +172,8 @@
 
 	/* Register handler to avoid interrupt lockup */
-	const int irq_cap = register_interrupt_handler(hcd->ddf_dev, irq, irq_handler, &irq_code);
+	int irq_cap;
+	ret = register_interrupt_handler(hcd->ddf_dev, irq, irq_handler, &irq_code, &irq_cap);
 	irq_code_clean(&irq_code);
-	if (irq_cap < 0) {
+	if (ret != EOK) {
 		usb_log_error("Failed to register interrupt handler: %s.",
 		    str_error(irq_cap));
@@ -179,5 +182,5 @@
 
 	/* Enable interrupts */
-	int ret = hcd_ddf_enable_interrupt(hcd, irq);
+	ret = hcd_ddf_enable_interrupt(hcd, irq);
 	if (ret != EOK) {
 		usb_log_error("Failed to enable interrupts: %s.",
Index: uspace/lib/usbvirt/src/ipc_hc.c
===================================================================
--- uspace/lib/usbvirt/src/ipc_hc.c	(revision 1bab1c8792534785c46d223f7930181efe68225a)
+++ uspace/lib/usbvirt/src/ipc_hc.c	(revision 132ab5d1e75253f9bae910b2748a4c13efe7e71f)
@@ -95,6 +95,6 @@
 	}
 	
-	sysarg_t data_request_rc;
-	sysarg_t opening_request_rc;
+	int data_request_rc;
+	int opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
@@ -168,5 +168,5 @@
 	async_exchange_end(exch);
 	
-	sysarg_t opening_request_rc;
+	int opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
 	
@@ -230,6 +230,6 @@
 	}
 	
-	sysarg_t data_request_rc;
-	sysarg_t opening_request_rc;
+	int data_request_rc;
+	int opening_request_rc;
 	async_wait_for(data_request, &data_request_rc);
 	async_wait_for(opening_request, &opening_request_rc);
@@ -305,5 +305,5 @@
 	}
 	
-	sysarg_t opening_request_rc;
+	int opening_request_rc;
 	async_wait_for(opening_request, &opening_request_rc);
 	
