Index: uspace/lib/libblock/libblock.c
===================================================================
--- uspace/lib/libblock/libblock.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libblock/libblock.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -47,5 +47,5 @@
 #include <as.h>
 #include <assert.h>
-#include <fibril_sync.h>
+#include <fibril_synch.h>
 #include <adt/list.h>
 #include <adt/hash_table.h>
Index: uspace/lib/libblock/libblock.h
===================================================================
--- uspace/lib/libblock/libblock.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libblock/libblock.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -36,9 +36,9 @@
 
 #ifndef LIBBLOCK_LIBBLOCK_H_
-#define	LIBBLOCK_LIBBLOCK_H_ 
+#define LIBBLOCK_LIBBLOCK_H_
 
 #include <stdint.h>
 #include "../../srv/vfs/vfs.h"
-#include <fibril_sync.h>
+#include <fibril_synch.h>
 #include <adt/hash_table.h>
 #include <adt/list.h>
Index: uspace/lib/libc/Makefile.build
===================================================================
--- uspace/lib/libc/Makefile.build	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/Makefile.build	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -50,4 +50,5 @@
 	generic/as.c \
 	generic/cap.c \
+	generic/clipboard.c \
 	generic/devmap.c \
 	generic/event.c \
@@ -56,5 +57,5 @@
 	generic/string.c \
 	generic/fibril.c \
-	generic/fibril_sync.c \
+	generic/fibril_synch.c \
 	generic/pcb.c \
 	generic/smc.c \
Index: uspace/lib/libc/arch/amd64/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/amd64/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/amd64/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -37,4 +37,8 @@
 #ifndef LIBC_amd64_ATOMIC_H_
 #define LIBC_amd64_ATOMIC_H_
+
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 
 static inline void atomic_inc(atomic_t *val) {
Index: uspace/lib/libc/arch/arm32/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/arm32/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/arm32/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -37,4 +37,50 @@
 #define LIBC_arm32_ATOMIC_H_
 
+#define LIBC_ARCH_ATOMIC_H_
+#define CAS 
+
+#include <atomicdflt.h>
+#include <bool.h>
+#include <sys/types.h>
+
+extern uintptr_t *ras_page;
+
+static inline bool cas(atomic_t *val, long ov, long nv)
+{
+	long ret = 0;
+
+	/*
+	 * The following instructions between labels 1 and 2 constitute a
+	 * Restartable Atomic Seqeunce. Should the sequence be non-atomic,
+	 * the kernel will restart it.
+	 */
+	asm volatile (
+		"1:\n"
+		"	adr %[ret], 1b\n"
+		"	str %[ret], %[rp0]\n"
+		"	adr %[ret], 2f\n"
+		"	str %[ret], %[rp1]\n"
+		"	ldr %[ret], %[addr]\n"
+		"	cmp %[ret], %[ov]\n"
+		"	streq %[nv], %[addr]\n"
+		"2:\n"
+		"	moveq %[ret], #1\n"
+		"	movne %[ret], #0\n"
+		: [ret] "+&r" (ret),
+		  [rp0] "=m" (ras_page[0]),
+		  [rp1] "=m" (ras_page[1]),
+		  [addr] "+m" (val->count)
+		: [ov] "r" (ov),
+		  [nv] "r" (nv)
+		: "memory"
+	);
+
+	ras_page[0] = 0;
+	asm volatile ("" ::: "memory");	
+	ras_page[1] = 0xffffffff;
+
+	return (bool) ret;
+}
+
 /** Atomic addition.
  *
@@ -46,20 +92,31 @@
 static inline long atomic_add(atomic_t *val, int i)
 {
-	int ret;
-	volatile long * mem = &(val->count);
+	long ret = 0;
 
+	/*
+	 * The following instructions between labels 1 and 2 constitute a
+	 * Restartable Atomic Seqeunce. Should the sequence be non-atomic,
+	 * the kernel will restart it.
+	 */
 	asm volatile (
-	"1:\n"
-		"ldr r2, [%1]\n"
-		"add r3, r2, %2\n"
-		"str r3, %0\n"
-		"swp r3, r3, [%1]\n"
-		"cmp r3, r2\n"
-		"bne 1b\n"
+		"1:\n"
+		"	adr %[ret], 1b\n"
+		"	str %[ret], %[rp0]\n"
+		"	adr %[ret], 2f\n"
+		"	str %[ret], %[rp1]\n"
+		"	ldr %[ret], %[addr]\n"
+		"	add %[ret], %[ret], %[imm]\n"
+		"	str %[ret], %[addr]\n"
+		"2:\n"
+		: [ret] "+&r" (ret),
+		  [rp0] "=m" (ras_page[0]),
+		  [rp1] "=m" (ras_page[1]),
+		  [addr] "+m" (val->count)
+		: [imm] "r" (i)
+	);
 
-		: "=m" (ret)
-		: "r" (mem), "r" (i)
-		: "r3", "r2"
-	);
+	ras_page[0] = 0;
+	asm volatile ("" ::: "memory");	
+	ras_page[1] = 0xffffffff;
 
 	return ret;
Index: uspace/lib/libc/arch/arm32/src/entry.s
===================================================================
--- uspace/lib/libc/arch/arm32/src/entry.s	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/arm32/src/entry.s	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -36,6 +36,11 @@
 #
 # r1 contains the PCB pointer
+# r2 contains the RAS page address
 #
 __entry:
+	# Store the RAS page address into the ras_page variable
+	ldr r0, =ras_page
+	str r2, [r0]
+
 	# Pass pcb_ptr to __main as the first argument (in r0)
 	mov r0, r1
@@ -43,2 +48,9 @@
 
 	bl __exit
+
+.data
+
+.global ras_page
+ras_page:
+	.long 0
+
Index: uspace/lib/libc/arch/arm32/src/syscall.c
===================================================================
--- uspace/lib/libc/arch/arm32/src/syscall.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/arm32/src/syscall.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -60,6 +60,7 @@
 	register sysarg_t __arm_reg_r5 asm("r5") = p6;
 	register sysarg_t __arm_reg_r6 asm("r6") = id;
-
-	asm volatile ( "swi"
+	
+	asm volatile (
+		"swi 0"
 		: "=r" (__arm_reg_r0)
 		: "r" (__arm_reg_r0),
@@ -71,5 +72,5 @@
 		  "r" (__arm_reg_r6)
 	);
-
+	
 	return __arm_reg_r0;
 }
Index: uspace/lib/libc/arch/ia32/Makefile.inc
===================================================================
--- uspace/lib/libc/arch/ia32/Makefile.inc	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/ia32/Makefile.inc	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -39,4 +39,5 @@
 	arch/$(UARCH)/src/setjmp.S
 
+GCC_CFLAGS += -march=pentium
 LFLAGS += -N
 
Index: uspace/lib/libc/arch/ia32/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/ia32/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/ia32/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -35,4 +35,8 @@
 #ifndef LIBC_ia32_ATOMIC_H_
 #define LIBC_ia32_ATOMIC_H_
+
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 
 static inline void atomic_inc(atomic_t *val) {
Index: uspace/lib/libc/arch/ia64/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/ia64/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/ia64/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -35,4 +35,8 @@
 #ifndef LIBC_ia64_ATOMIC_H_
 #define LIBC_ia64_ATOMIC_H_
+
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 
 static inline void atomic_inc(atomic_t *val)
Index: uspace/lib/libc/arch/mips32/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/mips32/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/mips32/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -36,4 +36,8 @@
 #ifndef LIBC_mips32_ATOMIC_H_
 #define LIBC_mips32_ATOMIC_H_
+
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 
 #define atomic_inc(x)	((void) atomic_add(x, 1))
Index: uspace/lib/libc/arch/ppc32/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/ppc32/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/ppc32/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -35,4 +35,8 @@
 #ifndef LIBC_ppc32_ATOMIC_H_
 #define LIBC_ppc32_ATOMIC_H_
+
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 
 static inline void atomic_inc(atomic_t *val)
Index: uspace/lib/libc/arch/sparc64/include/atomic.h
===================================================================
--- uspace/lib/libc/arch/sparc64/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/arch/sparc64/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -36,4 +36,7 @@
 #define LIBC_sparc64_ATOMIC_H_
 
+#define LIBC_ARCH_ATOMIC_H_
+
+#include <atomicdflt.h>
 #include <sys/types.h>
 
Index: uspace/lib/libc/generic/clipboard.c
===================================================================
--- uspace/lib/libc/generic/clipboard.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/generic/clipboard.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,185 @@
+/*
+ * 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 libc
+ * @{
+ */
+/** @file
+ * @brief System clipboard API.
+ *
+ * The clipboard data is managed by the clipboard service and it is shared by
+ * the entire system.
+ *
+ */
+
+#include <clipboard.h>
+#include <ipc/services.h>
+#include <ipc/clipboard.h>
+#include <async.h>
+#include <string.h>
+#include <errno.h>
+#include <malloc.h>
+
+static int clip_phone = -1;
+
+/** Connect to clipboard server
+ *
+ */
+static void clip_connect(void)
+{
+	while (clip_phone < 0)
+		clip_phone = ipc_connect_me_to_blocking(PHONE_NS, SERVICE_CLIPBOARD, 0, 0);
+}
+
+/** Copy string to clipboard.
+ *
+ * Sets the clipboard contents to @a str. Passing an empty string or NULL
+ * makes the clipboard empty.
+ *
+ * @param str String to put to clipboard or NULL.
+ *
+ * @return Zero on success or negative error code.
+ *
+ */
+int clipboard_put_str(const char *str)
+{
+	size_t size = str_size(str);
+	
+	if (size == 0) {
+		async_serialize_start();
+		clip_connect();
+		
+		ipcarg_t rc = async_req_1_0(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_NONE);
+		
+		async_serialize_end();
+		
+		return (int) rc;
+	} else {
+		async_serialize_start();
+		clip_connect();
+		
+		aid_t req = async_send_1(clip_phone, CLIPBOARD_PUT_DATA, CLIPBOARD_TAG_BLOB, NULL);
+		ipcarg_t rc = async_data_write_start(clip_phone, (void *) str, size);
+		if (rc != EOK) {
+			ipcarg_t rc_orig;
+			async_wait_for(req, &rc_orig);
+			async_serialize_end();
+			if (rc_orig == EOK)
+				return (int) rc;
+			else
+				return (int) rc_orig;
+		}
+		
+		async_wait_for(req, &rc);
+		async_serialize_end();
+		
+		return (int) rc;
+	}
+}
+
+/** Get a copy of clipboard contents.
+ *
+ * Returns a new string that can be deallocated with free().
+ *
+ * @param str Here pointer to the newly allocated string is stored.
+ *
+ * @return Zero on success or negative error code.
+ *
+ */
+int clipboard_get_str(char **str)
+{
+	/* Loop until clipboard read succesful */
+	while (true) {
+		async_serialize_start();
+		clip_connect();
+		
+		ipcarg_t size;
+		ipcarg_t tag;
+		ipcarg_t rc = async_req_0_2(clip_phone, CLIPBOARD_CONTENT, &size, &tag);
+		
+		async_serialize_end();
+		
+		if (rc != EOK)
+			return (int) rc;
+		
+		char *sbuf;
+		
+		switch (tag) {
+		case CLIPBOARD_TAG_NONE:
+			sbuf = malloc(1);
+			if (sbuf == NULL)
+				return ENOMEM;
+			
+			sbuf[0] = 0;
+			*str = sbuf;
+			return EOK;
+		case CLIPBOARD_TAG_BLOB:
+			sbuf = malloc(size + 1);
+			if (sbuf == NULL)
+				return ENOMEM;
+			
+			async_serialize_start();
+			
+			aid_t req = async_send_1(clip_phone, CLIPBOARD_GET_DATA, tag, NULL);
+			rc = async_data_read_start(clip_phone, (void *) sbuf, size);
+			if (rc == EOVERFLOW) {
+				/*
+				 * The data in the clipboard has changed since
+				 * the last call of CLIPBOARD_CONTENT
+				 */
+				async_serialize_end();
+				break;
+			}
+			
+			if (rc != EOK) {
+				ipcarg_t rc_orig;
+				async_wait_for(req, &rc_orig);
+				async_serialize_end();
+				if (rc_orig == EOK)
+					return (int) rc;
+				else
+					return (int) rc_orig;
+			}
+			
+			async_wait_for(req, &rc);
+			async_serialize_end();
+			
+			if (rc == EOK) {
+				sbuf[size] = 0;
+				*str = sbuf;
+			}
+			
+			return rc;
+		default:
+			return EINVAL;
+		}
+	}
+}
+
+/** @}
+ */
Index: uspace/lib/libc/generic/fibril_sync.c
===================================================================
--- uspace/lib/libc/generic/fibril_sync.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ 	(revision )
@@ -1,308 +1,0 @@
-/*
- * Copyright (c) 2009 Jakub Jermar 
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <fibril_sync.h>
-#include <fibril.h>
-#include <async.h>
-#include <async_priv.h>
-#include <adt/list.h>
-#include <futex.h>
-#include <sys/time.h>
-#include <errno.h>
-#include <assert.h>
-
-static void optimize_execution_power(void)
-{
-	/*
-	 * When waking up a worker fibril previously blocked in fibril
-	 * synchronization, chances are that there is an idle manager fibril
-	 * waiting for IPC, that could start executing the awakened worker
-	 * fibril right away. We try to detect this and bring the manager
-	 * fibril back to fruitful work.
-	 */
-	if (atomic_get(&threads_in_ipc_wait) > 0)
-		ipc_poke();
-}
-
-void fibril_mutex_initialize(fibril_mutex_t *fm)
-{
-	fm->counter = 1;
-	list_initialize(&fm->waiters);
-}
-
-void fibril_mutex_lock(fibril_mutex_t *fm)
-{
-	futex_down(&async_futex);
-	if (fm->counter-- <= 0) {
-		awaiter_t wdata;
-
-		wdata.fid = fibril_get_id();
-		wdata.active = false;
-		wdata.wu_event.inlist = true;
-		link_initialize(&wdata.wu_event.link);
-		list_append(&wdata.wu_event.link, &fm->waiters);
-		fibril_switch(FIBRIL_TO_MANAGER);
-	} else {
-		futex_up(&async_futex);
-	}
-}
-
-bool fibril_mutex_trylock(fibril_mutex_t *fm)
-{
-	bool locked = false;
-	
-	futex_down(&async_futex);
-	if (fm->counter > 0) {
-		fm->counter--;
-		locked = true;
-	}
-	futex_up(&async_futex);
-	
-	return locked;
-}
-
-static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm)
-{
-	assert(fm->counter <= 0);
-	if (fm->counter++ < 0) {
-		link_t *tmp;
-		awaiter_t *wdp;
-	
-		assert(!list_empty(&fm->waiters));
-		tmp = fm->waiters.next;
-		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
-		wdp->active = true;
-		wdp->wu_event.inlist = false;
-		list_remove(&wdp->wu_event.link);
-		fibril_add_ready(wdp->fid);
-		optimize_execution_power();
-	}
-}
-
-void fibril_mutex_unlock(fibril_mutex_t *fm)
-{
-	futex_down(&async_futex);
-	_fibril_mutex_unlock_unsafe(fm);
-	futex_up(&async_futex);
-}
-
-void fibril_rwlock_initialize(fibril_rwlock_t *frw)
-{
-	frw->writers = 0;
-	frw->readers = 0;
-	list_initialize(&frw->waiters);
-}
-
-void fibril_rwlock_read_lock(fibril_rwlock_t *frw)
-{
-	futex_down(&async_futex);
-	if (frw->writers) {
-		fibril_t *f = (fibril_t *) fibril_get_id();
-		awaiter_t wdata;
-
-		wdata.fid = (fid_t) f;
-		wdata.active = false;
-		wdata.wu_event.inlist = true;
-		link_initialize(&wdata.wu_event.link);
-		f->flags &= ~FIBRIL_WRITER;
-		list_append(&wdata.wu_event.link, &frw->waiters);
-		fibril_switch(FIBRIL_TO_MANAGER);
-	} else {
-		frw->readers++;
-		futex_up(&async_futex);
-	}
-}
-
-void fibril_rwlock_write_lock(fibril_rwlock_t *frw)
-{
-	futex_down(&async_futex);
-	if (frw->writers || frw->readers) {
-		fibril_t *f = (fibril_t *) fibril_get_id();
-		awaiter_t wdata;
-
-		wdata.fid = (fid_t) f;
-		wdata.active = false;
-		wdata.wu_event.inlist = true;
-		link_initialize(&wdata.wu_event.link);
-		f->flags |= FIBRIL_WRITER;
-		list_append(&wdata.wu_event.link, &frw->waiters);
-		fibril_switch(FIBRIL_TO_MANAGER);
-	} else {
-		frw->writers++;
-		futex_up(&async_futex);
-	}
-}
-
-static void _fibril_rwlock_common_unlock(fibril_rwlock_t *frw)
-{
-	futex_down(&async_futex);
-	assert(frw->readers || (frw->writers == 1));
-	if (frw->readers) {
-		if (--frw->readers)
-			goto out;
-	} else {
-		frw->writers--;
-	}
-	
-	assert(!frw->readers && !frw->writers);
-	
-	while (!list_empty(&frw->waiters)) {
-		link_t *tmp = frw->waiters.next;
-		awaiter_t *wdp;
-		fibril_t *f;
-		
-		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
-		f = (fibril_t *) wdp->fid;
-		
-		if (f->flags & FIBRIL_WRITER) {
-			if (frw->readers)
-				break;
-			wdp->active = true;
-			wdp->wu_event.inlist = false;
-			list_remove(&wdp->wu_event.link);
-			fibril_add_ready(wdp->fid);
-			frw->writers++;
-			optimize_execution_power();
-			break;
-		} else {
-			wdp->active = true;
-			wdp->wu_event.inlist = false;
-			list_remove(&wdp->wu_event.link);
-			fibril_add_ready(wdp->fid);
-			frw->readers++;
-			optimize_execution_power();
-		}
-	}
-out:
-	futex_up(&async_futex);
-}
-
-void fibril_rwlock_read_unlock(fibril_rwlock_t *frw)
-{
-	_fibril_rwlock_common_unlock(frw);
-}
-
-void fibril_rwlock_write_unlock(fibril_rwlock_t *frw)
-{
-	_fibril_rwlock_common_unlock(frw);
-}
-
-void fibril_condvar_initialize(fibril_condvar_t *fcv)
-{
-	list_initialize(&fcv->waiters);
-}
-
-int
-fibril_condvar_wait_timeout(fibril_condvar_t *fcv, fibril_mutex_t *fm,
-    suseconds_t timeout)
-{
-	awaiter_t wdata;
-
-	if (timeout < 0)
-		return ETIMEOUT;
-
-	wdata.fid = fibril_get_id();
-	wdata.active = false;
-	
-	wdata.to_event.inlist = timeout > 0;
-	wdata.to_event.occurred = false;
-	link_initialize(&wdata.to_event.link);
-
-	wdata.wu_event.inlist = true;
-	link_initialize(&wdata.wu_event.link);
-
-	futex_down(&async_futex);
-	if (timeout) {
-		gettimeofday(&wdata.to_event.expires, NULL);
-		tv_add(&wdata.to_event.expires, timeout);
-		async_insert_timeout(&wdata);
-	}
-	list_append(&wdata.wu_event.link, &fcv->waiters);
-	_fibril_mutex_unlock_unsafe(fm);
-	fibril_switch(FIBRIL_TO_MANAGER);
-	fibril_mutex_lock(fm);
-
-	/* async_futex not held after fibril_switch() */
-	futex_down(&async_futex);
-	if (wdata.to_event.inlist)
-		list_remove(&wdata.to_event.link);
-	if (wdata.wu_event.inlist)
-		list_remove(&wdata.wu_event.link);
-	futex_up(&async_futex);
-	
-	return wdata.to_event.occurred ? ETIMEOUT : EOK;
-}
-
-void fibril_condvar_wait(fibril_condvar_t *fcv, fibril_mutex_t *fm)
-{
-	int rc;
-
-	rc = fibril_condvar_wait_timeout(fcv, fm, 0);
-	assert(rc == EOK);
-}
-
-static void _fibril_condvar_wakeup_common(fibril_condvar_t *fcv, bool once)
-{
-	link_t *tmp;
-	awaiter_t *wdp;
-
-	futex_down(&async_futex);
-	while (!list_empty(&fcv->waiters)) {
-		tmp = fcv->waiters.next;
-		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
-		list_remove(&wdp->wu_event.link);
-		wdp->wu_event.inlist = false;
-		if (!wdp->active) {
-			wdp->active = true;
-			fibril_add_ready(wdp->fid);
-			optimize_execution_power();
-			if (once)
-				break;
-		}
-	}
-	futex_up(&async_futex);
-}
-
-void fibril_condvar_signal(fibril_condvar_t *fcv)
-{
-	_fibril_condvar_wakeup_common(fcv, true);
-}
-
-void fibril_condvar_broadcast(fibril_condvar_t *fcv)
-{
-	_fibril_condvar_wakeup_common(fcv, false);
-}
-
-/** @}
- */
Index: uspace/lib/libc/generic/fibril_synch.c
===================================================================
--- uspace/lib/libc/generic/fibril_synch.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/generic/fibril_synch.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,308 @@
+/*
+ * Copyright (c) 2009 Jakub Jermar 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <fibril_synch.h>
+#include <fibril.h>
+#include <async.h>
+#include <async_priv.h>
+#include <adt/list.h>
+#include <futex.h>
+#include <sys/time.h>
+#include <errno.h>
+#include <assert.h>
+
+static void optimize_execution_power(void)
+{
+	/*
+	 * When waking up a worker fibril previously blocked in fibril
+	 * synchronization, chances are that there is an idle manager fibril
+	 * waiting for IPC, that could start executing the awakened worker
+	 * fibril right away. We try to detect this and bring the manager
+	 * fibril back to fruitful work.
+	 */
+	if (atomic_get(&threads_in_ipc_wait) > 0)
+		ipc_poke();
+}
+
+void fibril_mutex_initialize(fibril_mutex_t *fm)
+{
+	fm->counter = 1;
+	list_initialize(&fm->waiters);
+}
+
+void fibril_mutex_lock(fibril_mutex_t *fm)
+{
+	futex_down(&async_futex);
+	if (fm->counter-- <= 0) {
+		awaiter_t wdata;
+
+		wdata.fid = fibril_get_id();
+		wdata.active = false;
+		wdata.wu_event.inlist = true;
+		link_initialize(&wdata.wu_event.link);
+		list_append(&wdata.wu_event.link, &fm->waiters);
+		fibril_switch(FIBRIL_TO_MANAGER);
+	} else {
+		futex_up(&async_futex);
+	}
+}
+
+bool fibril_mutex_trylock(fibril_mutex_t *fm)
+{
+	bool locked = false;
+	
+	futex_down(&async_futex);
+	if (fm->counter > 0) {
+		fm->counter--;
+		locked = true;
+	}
+	futex_up(&async_futex);
+	
+	return locked;
+}
+
+static void _fibril_mutex_unlock_unsafe(fibril_mutex_t *fm)
+{
+	assert(fm->counter <= 0);
+	if (fm->counter++ < 0) {
+		link_t *tmp;
+		awaiter_t *wdp;
+	
+		assert(!list_empty(&fm->waiters));
+		tmp = fm->waiters.next;
+		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
+		wdp->active = true;
+		wdp->wu_event.inlist = false;
+		list_remove(&wdp->wu_event.link);
+		fibril_add_ready(wdp->fid);
+		optimize_execution_power();
+	}
+}
+
+void fibril_mutex_unlock(fibril_mutex_t *fm)
+{
+	futex_down(&async_futex);
+	_fibril_mutex_unlock_unsafe(fm);
+	futex_up(&async_futex);
+}
+
+void fibril_rwlock_initialize(fibril_rwlock_t *frw)
+{
+	frw->writers = 0;
+	frw->readers = 0;
+	list_initialize(&frw->waiters);
+}
+
+void fibril_rwlock_read_lock(fibril_rwlock_t *frw)
+{
+	futex_down(&async_futex);
+	if (frw->writers) {
+		fibril_t *f = (fibril_t *) fibril_get_id();
+		awaiter_t wdata;
+
+		wdata.fid = (fid_t) f;
+		wdata.active = false;
+		wdata.wu_event.inlist = true;
+		link_initialize(&wdata.wu_event.link);
+		f->flags &= ~FIBRIL_WRITER;
+		list_append(&wdata.wu_event.link, &frw->waiters);
+		fibril_switch(FIBRIL_TO_MANAGER);
+	} else {
+		frw->readers++;
+		futex_up(&async_futex);
+	}
+}
+
+void fibril_rwlock_write_lock(fibril_rwlock_t *frw)
+{
+	futex_down(&async_futex);
+	if (frw->writers || frw->readers) {
+		fibril_t *f = (fibril_t *) fibril_get_id();
+		awaiter_t wdata;
+
+		wdata.fid = (fid_t) f;
+		wdata.active = false;
+		wdata.wu_event.inlist = true;
+		link_initialize(&wdata.wu_event.link);
+		f->flags |= FIBRIL_WRITER;
+		list_append(&wdata.wu_event.link, &frw->waiters);
+		fibril_switch(FIBRIL_TO_MANAGER);
+	} else {
+		frw->writers++;
+		futex_up(&async_futex);
+	}
+}
+
+static void _fibril_rwlock_common_unlock(fibril_rwlock_t *frw)
+{
+	futex_down(&async_futex);
+	assert(frw->readers || (frw->writers == 1));
+	if (frw->readers) {
+		if (--frw->readers)
+			goto out;
+	} else {
+		frw->writers--;
+	}
+	
+	assert(!frw->readers && !frw->writers);
+	
+	while (!list_empty(&frw->waiters)) {
+		link_t *tmp = frw->waiters.next;
+		awaiter_t *wdp;
+		fibril_t *f;
+		
+		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
+		f = (fibril_t *) wdp->fid;
+		
+		if (f->flags & FIBRIL_WRITER) {
+			if (frw->readers)
+				break;
+			wdp->active = true;
+			wdp->wu_event.inlist = false;
+			list_remove(&wdp->wu_event.link);
+			fibril_add_ready(wdp->fid);
+			frw->writers++;
+			optimize_execution_power();
+			break;
+		} else {
+			wdp->active = true;
+			wdp->wu_event.inlist = false;
+			list_remove(&wdp->wu_event.link);
+			fibril_add_ready(wdp->fid);
+			frw->readers++;
+			optimize_execution_power();
+		}
+	}
+out:
+	futex_up(&async_futex);
+}
+
+void fibril_rwlock_read_unlock(fibril_rwlock_t *frw)
+{
+	_fibril_rwlock_common_unlock(frw);
+}
+
+void fibril_rwlock_write_unlock(fibril_rwlock_t *frw)
+{
+	_fibril_rwlock_common_unlock(frw);
+}
+
+void fibril_condvar_initialize(fibril_condvar_t *fcv)
+{
+	list_initialize(&fcv->waiters);
+}
+
+int
+fibril_condvar_wait_timeout(fibril_condvar_t *fcv, fibril_mutex_t *fm,
+    suseconds_t timeout)
+{
+	awaiter_t wdata;
+
+	if (timeout < 0)
+		return ETIMEOUT;
+
+	wdata.fid = fibril_get_id();
+	wdata.active = false;
+	
+	wdata.to_event.inlist = timeout > 0;
+	wdata.to_event.occurred = false;
+	link_initialize(&wdata.to_event.link);
+
+	wdata.wu_event.inlist = true;
+	link_initialize(&wdata.wu_event.link);
+
+	futex_down(&async_futex);
+	if (timeout) {
+		gettimeofday(&wdata.to_event.expires, NULL);
+		tv_add(&wdata.to_event.expires, timeout);
+		async_insert_timeout(&wdata);
+	}
+	list_append(&wdata.wu_event.link, &fcv->waiters);
+	_fibril_mutex_unlock_unsafe(fm);
+	fibril_switch(FIBRIL_TO_MANAGER);
+	fibril_mutex_lock(fm);
+
+	/* async_futex not held after fibril_switch() */
+	futex_down(&async_futex);
+	if (wdata.to_event.inlist)
+		list_remove(&wdata.to_event.link);
+	if (wdata.wu_event.inlist)
+		list_remove(&wdata.wu_event.link);
+	futex_up(&async_futex);
+	
+	return wdata.to_event.occurred ? ETIMEOUT : EOK;
+}
+
+void fibril_condvar_wait(fibril_condvar_t *fcv, fibril_mutex_t *fm)
+{
+	int rc;
+
+	rc = fibril_condvar_wait_timeout(fcv, fm, 0);
+	assert(rc == EOK);
+}
+
+static void _fibril_condvar_wakeup_common(fibril_condvar_t *fcv, bool once)
+{
+	link_t *tmp;
+	awaiter_t *wdp;
+
+	futex_down(&async_futex);
+	while (!list_empty(&fcv->waiters)) {
+		tmp = fcv->waiters.next;
+		wdp = list_get_instance(tmp, awaiter_t, wu_event.link);
+		list_remove(&wdp->wu_event.link);
+		wdp->wu_event.inlist = false;
+		if (!wdp->active) {
+			wdp->active = true;
+			fibril_add_ready(wdp->fid);
+			optimize_execution_power();
+			if (once)
+				break;
+		}
+	}
+	futex_up(&async_futex);
+}
+
+void fibril_condvar_signal(fibril_condvar_t *fcv)
+{
+	_fibril_condvar_wakeup_common(fcv, true);
+}
+
+void fibril_condvar_broadcast(fibril_condvar_t *fcv)
+{
+	_fibril_condvar_wakeup_common(fcv, false);
+}
+
+/** @}
+ */
Index: uspace/lib/libc/generic/futex.c
===================================================================
--- uspace/lib/libc/generic/futex.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/generic/futex.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -36,49 +36,5 @@
 #include <atomic.h>
 #include <libc.h>
-#include <stdio.h>
 #include <sys/types.h>
-#include <kernel/synch/synch.h>
-
-/*
- * Note about race conditions.
- * Because of non-atomic nature of operations performed sequentially on the
- * futex counter and the futex wait queue, there is a race condition:
- *
- * (wq->missed_wakeups == 1) && (futex->count = 1)
- *
- * Scenario 1 (wait queue timeout vs. futex_up()):
- * 1. assume wq->missed_wakeups == 0 && futex->count == -1
- *    (ie. thread A sleeping, thread B in the critical section)
- * 2. A receives timeout and gets removed from the wait queue
- * 3. B wants to leave the critical section and calls futex_up()
- * 4. B thus changes futex->count from -1 to 0
- * 5. B has to call SYS_FUTEX_WAKEUP syscall to wake up the sleeping thread
- * 6. B finds the wait queue empty and changes wq->missed_wakeups from 0 to 1
- * 7. A fixes futex->count (i.e. the number of waiting threads) by changing it
- *    from 0 to 1
- *
- * Scenario 2 (conditional down operation vs. futex_up)
- * 1. assume wq->missed_wakeups == 0 && futex->count == 0
- *    (i.e. thread A is in the critical section)
- * 2. thread B performs futex_trydown() operation and changes futex->count from
- *    0 to -1
- *    B is now obliged to call SYS_FUTEX_SLEEP syscall
- * 3. A wants to leave the critical section and does futex_up()
- * 4. A thus changes futex->count from -1 to 0 and must call SYS_FUTEX_WAKEUP
- *    syscall
- * 5. B finds the wait queue empty and immediatelly aborts the conditional sleep
- * 6. No thread is queueing in the wait queue so wq->missed_wakeups changes from
- *    0 to 1
- * 6. B fixes futex->count (i.e. the number of waiting threads) by changing it
- *    from 0 to 1
- *
- * Both scenarios allow two threads to be in the critical section
- * simultaneously. One without kernel intervention and the other through
- * wq->missed_wakeups being 1.
- *
- * To mitigate this problem, futex_down_timeout() detects that the syscall
- * didn't sleep in the wait queue, fixes the futex counter and RETRIES the
- * whole operation again.
- */
 
 /** Initialize futex counter.
@@ -92,81 +48,28 @@
 }
 
-int futex_down(futex_t *futex)
-{
-	return futex_down_timeout(futex, SYNCH_NO_TIMEOUT, SYNCH_FLAGS_NONE);
-}
-
-int futex_trydown(futex_t *futex)
-{
-	return futex_down_timeout(futex, SYNCH_NO_TIMEOUT,
-	    SYNCH_FLAGS_NON_BLOCKING);
-}
-
 /** Try to down the futex.
  *
  * @param futex		Futex.
- * @param usec		Microseconds to wait. Zero value means sleep without
- * 			timeout.
- * @param flags		Select mode of operation. See comment for
- * 			waitq_sleep_timeout(). 
+ * @return		Non-zero if the futex was acquired.
+ * @return		Zero if the futex was not acquired.
+ */
+int futex_trydown(futex_t *futex)
+{
+	return cas(futex, 1, 0);
+}
+
+/** Down the futex.
  *
- * @return		ENOENT if there is no such virtual address. One of
- * 			ESYNCH_OK_ATOMIC and ESYNCH_OK_BLOCKED on success or
- * 			ESYNCH_TIMEOUT if the lock was not acquired because of
- * 			a timeout or ESYNCH_WOULD_BLOCK if the operation could
- * 			not be carried out atomically (if requested so).
+ * @param futex		Futex.
+ * @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.
  */
-int futex_down_timeout(futex_t *futex, uint32_t usec, int flags)
+int futex_down(futex_t *futex)
 {
-	int rc;
-	
-	while (atomic_predec(futex) < 0) {
-		rc = __SYSCALL3(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count,
-		    (sysarg_t) usec, (sysarg_t) flags);
-		
-		switch (rc) {
-		case ESYNCH_OK_ATOMIC:
-			/*
-			 * Because of a race condition between timeout and
-			 * futex_up() and between conditional
-			 * futex_down_timeout() and futex_up(), we have to give
-			 * up and try again in this special case.
-			 */
-			atomic_inc(futex);
-			break;
+	if (atomic_predec(futex) < 0)
+		return __SYSCALL1(SYS_FUTEX_SLEEP, (sysarg_t) &futex->count);
 
-		case ESYNCH_TIMEOUT:
-			atomic_inc(futex);
-			return ESYNCH_TIMEOUT;
-			break;
-
-		case ESYNCH_WOULD_BLOCK:
-			/*
-			 * The conditional down operation should be implemented
-			 * this way. The userspace-only variant tends to
-			 * accumulate missed wakeups in the kernel futex wait
-			 * queue.
-			 */
-			atomic_inc(futex);
-			return ESYNCH_WOULD_BLOCK;
-			break;
-
-		case ESYNCH_OK_BLOCKED:
-			/*
-			 * Enter the critical section.
-			 * The futex counter has already been incremented for
-			 * us.
-			 */
-			return ESYNCH_OK_BLOCKED;
-			break;
-		default:
-			return rc;
-		}
-	}
-
-	/*
-	 * Enter the critical section.
-	 */
-	return ESYNCH_OK_ATOMIC;
+	return 0;
 }
 
@@ -174,14 +77,10 @@
  *
  * @param futex		Futex.
- *
- * @return		ENOENT if there is no such virtual address. Otherwise
- * 			zero.
+ * @return		ENOENT if there is no such virtual address.
+ * @return		Zero in the uncontended case.
  */
 int futex_up(futex_t *futex)
 {
-	long val;
-	
-	val = atomic_postinc(futex);
-	if (val < 0)
+	if (atomic_postinc(futex) < 0)
 		return __SYSCALL1(SYS_FUTEX_WAKEUP, (sysarg_t) &futex->count);
 		
Index: uspace/lib/libc/generic/io/console.c
===================================================================
--- uspace/lib/libc/generic/io/console.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/generic/io/console.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -94,4 +94,17 @@
 }
 
+int console_get_pos(int phone, int *col, int *row)
+{
+	ipcarg_t col_v;
+	ipcarg_t row_v;
+	int rc;
+
+	rc = async_req_0_2(phone, CONSOLE_GET_POS, &col_v, &row_v);
+
+	*col = (int) col_v;
+	*row = (int) row_v;
+	return rc;
+}
+
 void console_goto(int phone, int col, int row)
 {
Index: uspace/lib/libc/generic/io/io.c
===================================================================
--- uspace/lib/libc/generic/io/io.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/generic/io/io.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -341,9 +341,14 @@
 size_t fread(void *buf, size_t size, size_t nmemb, FILE *stream)
 {
-	size_t left = size * nmemb;
-	size_t done = 0;
-	
+	size_t left, done;
+
+	if (size == 0 || nmemb == 0)
+		return 0;
+
 	/* Make sure no data is pending write. */
 	_fflushbuf(stream);
+
+	left = size * nmemb;
+	done = 0;
 	
 	while ((left > 0) && (!stream->error) && (!stream->eof)) {
@@ -365,7 +370,13 @@
 static size_t _fwrite(const void *buf, size_t size, size_t nmemb, FILE *stream)
 {
-	size_t left = size * nmemb;
-	size_t done = 0;
-	
+	size_t left;
+	size_t done;
+
+	if (size == 0 || nmemb == 0)
+		return 0;
+
+	left = size * nmemb;
+	done = 0;
+
 	while ((left > 0) && (!stream->error)) {
 		ssize_t wr;
@@ -421,5 +432,8 @@
 	uint8_t b;
 	bool need_flush;
-	
+
+	if (size == 0 || nmemb == 0)
+		return 0;
+
 	/* If not buffered stream, write out directly. */
 	if (stream->btype == _IONBF) {
@@ -480,5 +494,5 @@
 	
 	if (chr_encode(c, buf, &sz, STR_BOUNDS(1)) == EOK) {
-		size_t wr = fwrite(buf, sz, 1, stream);
+		size_t wr = fwrite(buf, 1, sz, stream);
 		
 		if (wr < sz)
Index: uspace/lib/libc/generic/string.c
===================================================================
--- uspace/lib/libc/generic/string.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/generic/string.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -471,5 +471,5 @@
  * null-terminated and containing only complete characters.
  *
- * @param dst   Destination buffer.
+ * @param dest   Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
@@ -505,5 +505,5 @@
  * have to be null-terminated.
  *
- * @param dst   Destination buffer.
+ * @param dest   Destination buffer.
  * @param count Size of the destination buffer (must be > 0).
  * @param src   Source string.
@@ -537,5 +537,5 @@
  * null-terminated and containing only complete characters.
  *
- * @param dst   Destination buffer.
+ * @param dest   Destination buffer.
  * @param count Size of the destination buffer.
  * @param src   Source string.
@@ -549,36 +549,113 @@
 }
 
-/** Copy NULL-terminated wide string to string
- *
- * Copy source wide string @a src to destination buffer @a dst.
- * No more than @a size bytes are written. NULL-terminator is always
- * written after the last succesfully copied character (i.e. if the
- * destination buffer is has at least 1 byte, it will be always
- * NULL-terminated).
- *
- * @param src   Source wide string.
- * @param dst   Destination buffer.
- * @param count Size of the destination buffer.
- *
- */
-void wstr_nstr(char *dst, const wchar_t *src, size_t size)
-{
-	/* No space for the NULL-terminator in the buffer */
-	if (size == 0)
-		return;
-	
+/** Convert wide string to string.
+ *
+ * Convert wide string @a src to string. The output is written to the buffer
+ * specified by @a dest and @a size. @a size must be non-zero and the string
+ * written will always be well-formed.
+ *
+ * @param dest	Destination buffer.
+ * @param size	Size of the destination buffer.
+ * @param src	Source wide string.
+ */
+void wstr_to_str(char *dest, size_t size, const wchar_t *src)
+{
 	wchar_t ch;
-	size_t src_idx = 0;
-	size_t dst_off = 0;
-	
+	size_t src_idx;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	
+	src_idx = 0;
+	dest_off = 0;
+
 	while ((ch = src[src_idx++]) != 0) {
-		if (chr_encode(ch, dst, &dst_off, size) != EOK)
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
 			break;
 	}
-	
-	if (dst_off >= size)
-		dst[size - 1] = 0;
-	else
-		dst[dst_off] = 0;
+
+	dest[dest_off] = '\0';
+}
+
+/** Convert wide string to new string.
+ *
+ * Convert wide string @a src to string. Space for the new string is allocated
+ * on the heap.
+ *
+ * @param src	Source wide string.
+ * @return	New string.
+ */
+char *wstr_to_astr(const wchar_t *src)
+{
+	char dbuf[STR_BOUNDS(1)];
+	char *str;
+	wchar_t ch;
+
+	size_t src_idx;
+	size_t dest_off;
+	size_t dest_size;
+
+	/* Compute size of encoded string. */
+
+	src_idx = 0;
+	dest_size = 0;
+
+	while ((ch = src[src_idx++]) != 0) {
+		dest_off = 0;
+		if (chr_encode(ch, dbuf, &dest_off, STR_BOUNDS(1)) != EOK)
+			break;
+		dest_size += dest_off;
+	}
+
+	str = malloc(dest_size + 1);
+	if (str == NULL)
+		return NULL;
+
+	/* Encode string. */
+
+	src_idx = 0;
+	dest_off = 0;
+
+	while ((ch = src[src_idx++]) != 0) {
+		if (chr_encode(ch, str, &dest_off, dest_size) != EOK)
+			break;
+	}
+
+	str[dest_size] = '\0';
+	return str;
+}
+
+
+/** Convert string to wide string.
+ *
+ * Convert string @a src to wide string. The output is written to the
+ * buffer specified by @a dest and @a dlen. @a dlen must be non-zero
+ * and the wide string written will always be null-terminated.
+ *
+ * @param dest	Destination buffer.
+ * @param dlen	Length of destination buffer (number of wchars).
+ * @param src	Source string.
+ */
+void str_to_wstr(wchar_t *dest, size_t dlen, const char *src)
+{
+	size_t offset;
+	size_t di;
+	wchar_t c;
+
+	assert(dlen > 0);
+
+	offset = 0;
+	di = 0;
+
+	do {
+		if (di >= dlen - 1)
+			break;
+
+		c = str_decode(src, &offset, STR_NO_LIMIT);
+		dest[di++] = c;
+	} while (c != '\0');
+
+	dest[dlen - 1] = '\0';
 }
 
Index: uspace/lib/libc/generic/time.c
===================================================================
--- uspace/lib/libc/generic/time.c	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/generic/time.c	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -31,5 +31,5 @@
  */
 /** @file
- */ 
+ */
 
 #include <sys/time.h>
@@ -40,7 +40,7 @@
 #include <unistd.h>
 #include <atomic.h>
-#include <futex.h>
 #include <sysinfo.h>
 #include <ipc/services.h>
+#include <libc.h>
 
 #include <sysinfo.h>
@@ -189,27 +189,20 @@
 
 /** Wait unconditionally for specified number of microseconds */
-int usleep(unsigned long usec)
-{
-	atomic_t futex = FUTEX_INITIALIZER;
-
-	futex_initialize(&futex, 0);
-	futex_down_timeout(&futex, usec, 0);
+int usleep(useconds_t usec)
+{
+	(void) __SYSCALL1(SYS_THREAD_USLEEP, usec);
 	return 0;
 }
 
 /** Wait unconditionally for specified number of seconds */
-unsigned int sleep(unsigned int seconds)
-{
-	atomic_t futex = FUTEX_INITIALIZER;
-
-	futex_initialize(&futex, 0);
-	
+unsigned int sleep(unsigned int sec)
+{
 	/* Sleep in 1000 second steps to support
 	   full argument range */
-	while (seconds > 0) {
-		unsigned int period = (seconds > 1000) ? 1000 : seconds;
+	while (sec > 0) {
+		unsigned int period = (sec > 1000) ? 1000 : sec;
 	
-		futex_down_timeout(&futex, period * 1000000, 0);
-		seconds -= period;
+		usleep(period * 1000000);
+		sec -= period;
 	}
 	return 0;
Index: uspace/lib/libc/include/atomic.h
===================================================================
--- uspace/lib/libc/include/atomic.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/atomic.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -1,4 +1,4 @@
 /*
- * Copyright (c) 2006 Jakub Jermar
+ * Copyright (c) 2009 Jakub Jermar
  * All rights reserved.
  *
@@ -36,19 +36,5 @@
 #define LIBC_ATOMIC_H_
 
-typedef struct atomic {
-	volatile long count;
-} atomic_t;
-
 #include <libarch/atomic.h>
-
-static inline void atomic_set(atomic_t *val, long i)
-{
-        val->count = i;
-}
-
-static inline long atomic_get(atomic_t *val)
-{
-        return val->count;
-}
 
 #endif
Index: uspace/lib/libc/include/atomicdflt.h
===================================================================
--- uspace/lib/libc/include/atomicdflt.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/include/atomicdflt.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2006 Jakub Jermar
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_ATOMICDFLT_H_
+#define LIBC_ATOMICDFLT_H_
+
+#ifndef LIBC_ARCH_ATOMIC_H_
+#error This file cannot be included directly, include atomic.h instead.
+#endif
+
+#include <bool.h>
+
+typedef struct atomic {
+	volatile long count;
+} atomic_t;
+
+static inline void atomic_set(atomic_t *val, long i)
+{
+        val->count = i;
+}
+
+static inline long atomic_get(atomic_t *val)
+{
+        return val->count;
+}
+
+#ifndef CAS 
+static inline bool cas(atomic_t *val, long ov, long nv)
+{
+	return __sync_bool_compare_and_swap(&val->count, ov, nv);
+}
+#endif
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/clipboard.h
===================================================================
--- uspace/lib/libc/include/clipboard.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/include/clipboard.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,44 @@
+/*
+ * 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_CLIPBOARD_H_
+#define LIBC_CLIPBOARD_H_
+
+extern int clipboard_put_str(const char *);
+extern int clipboard_get_str(char **);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/fibril_sync.h
===================================================================
--- uspace/lib/libc/include/fibril_sync.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ 	(revision )
@@ -1,107 +1,0 @@
-/*
- * Copyright (c) 2009 Jakub Jermar 
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#ifndef LIBC_FIBRIL_SYNC_H_
-#define LIBC_FIBRIL_SYNC_H_
-
-#include <async.h>
-#include <fibril.h>
-#include <adt/list.h>
-#include <libarch/tls.h>
-#include <sys/time.h>
-
-typedef struct {
-	int counter;
-	link_t waiters;
-} fibril_mutex_t;
-
-#define FIBRIL_MUTEX_INITIALIZE(name) \
-	fibril_mutex_t name = {	\
-		.counter = 1, \
-		.waiters = { \
-			.prev = &name.waiters, \
-			.next = &name.waiters, \
-		} \
-	}
-
-typedef struct {
-	unsigned writers;
-	unsigned readers;
-	link_t waiters;
-} fibril_rwlock_t;
-
-#define FIBRIL_RWLOCK_INITIALIZE(name) \
-	fibril_rwlock_t name = { \
-		.readers = 0, \
-		.writers = 0, \
-		.waiters = { \
-			.prev = &name.waiters, \
-			.next = &name.waiters, \
-		} \
-	}
-
-typedef struct {
-	link_t waiters;
-} fibril_condvar_t;
-
-#define FIBRIL_CONDVAR_INITIALIZE(name) \
-	fibril_condvar_t name = { \
-		.waiters = { \
-			.next = &name.waiters, \
-			.prev = &name.waiters, \
-		} \
-	}
-
-extern void fibril_mutex_initialize(fibril_mutex_t *);
-extern void fibril_mutex_lock(fibril_mutex_t *);
-extern bool fibril_mutex_trylock(fibril_mutex_t *);
-extern void fibril_mutex_unlock(fibril_mutex_t *);
-
-extern void fibril_rwlock_initialize(fibril_rwlock_t *);
-extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
-extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
-extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
-extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
-
-extern void fibril_condvar_initialize(fibril_condvar_t *);
-extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
-    suseconds_t);
-extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
-extern void fibril_condvar_signal(fibril_condvar_t *);
-extern void fibril_condvar_broadcast(fibril_condvar_t *);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/libc/include/fibril_synch.h
===================================================================
--- uspace/lib/libc/include/fibril_synch.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/include/fibril_synch.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,107 @@
+/*
+ * Copyright (c) 2009 Jakub Jermar 
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_FIBRIL_SYNCH_H_
+#define LIBC_FIBRIL_SYNCH_H_
+
+#include <async.h>
+#include <fibril.h>
+#include <adt/list.h>
+#include <libarch/tls.h>
+#include <sys/time.h>
+
+typedef struct {
+	int counter;
+	link_t waiters;
+} fibril_mutex_t;
+
+#define FIBRIL_MUTEX_INITIALIZE(name) \
+	fibril_mutex_t name = {	\
+		.counter = 1, \
+		.waiters = { \
+			.prev = &name.waiters, \
+			.next = &name.waiters, \
+		} \
+	}
+
+typedef struct {
+	unsigned writers;
+	unsigned readers;
+	link_t waiters;
+} fibril_rwlock_t;
+
+#define FIBRIL_RWLOCK_INITIALIZE(name) \
+	fibril_rwlock_t name = { \
+		.readers = 0, \
+		.writers = 0, \
+		.waiters = { \
+			.prev = &name.waiters, \
+			.next = &name.waiters, \
+		} \
+	}
+
+typedef struct {
+	link_t waiters;
+} fibril_condvar_t;
+
+#define FIBRIL_CONDVAR_INITIALIZE(name) \
+	fibril_condvar_t name = { \
+		.waiters = { \
+			.next = &name.waiters, \
+			.prev = &name.waiters, \
+		} \
+	}
+
+extern void fibril_mutex_initialize(fibril_mutex_t *);
+extern void fibril_mutex_lock(fibril_mutex_t *);
+extern bool fibril_mutex_trylock(fibril_mutex_t *);
+extern void fibril_mutex_unlock(fibril_mutex_t *);
+
+extern void fibril_rwlock_initialize(fibril_rwlock_t *);
+extern void fibril_rwlock_read_lock(fibril_rwlock_t *);
+extern void fibril_rwlock_write_lock(fibril_rwlock_t *);
+extern void fibril_rwlock_read_unlock(fibril_rwlock_t *);
+extern void fibril_rwlock_write_unlock(fibril_rwlock_t *);
+
+extern void fibril_condvar_initialize(fibril_condvar_t *);
+extern int fibril_condvar_wait_timeout(fibril_condvar_t *, fibril_mutex_t *,
+    suseconds_t);
+extern void fibril_condvar_wait(fibril_condvar_t *, fibril_mutex_t *);
+extern void fibril_condvar_signal(fibril_condvar_t *);
+extern void fibril_condvar_broadcast(fibril_condvar_t *);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/futex.h
===================================================================
--- uspace/lib/libc/include/futex.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/futex.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -46,5 +46,4 @@
 extern int futex_down(futex_t *futex);
 extern int futex_trydown(futex_t *futex);
-extern int futex_down_timeout(futex_t *futex, uint32_t usec, int flags);
 extern int futex_up(futex_t *futex);
 
Index: uspace/lib/libc/include/io/console.h
===================================================================
--- uspace/lib/libc/include/io/console.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/io/console.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -69,4 +69,5 @@
 
 extern int console_get_size(int phone, int *cols, int *rows);
+extern int console_get_pos(int phone, int *col, int *row);
 extern void console_goto(int phone, int col, int row);
 
Index: uspace/lib/libc/include/ipc/clipboard.h
===================================================================
--- uspace/lib/libc/include/ipc/clipboard.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
+++ uspace/lib/libc/include/ipc/clipboard.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -0,0 +1,54 @@
+/*
+ * Copyright (c) 2009 Martin Decky
+ * 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
+ */
+
+#ifndef LIBC_IPC_CLIPBOARD_H_
+#define LIBC_IPC_CLIPBOARD_H_
+
+#include <ipc/ipc.h>
+
+typedef enum {
+	CLIPBOARD_PUT_DATA = IPC_FIRST_USER_METHOD,
+	CLIPBOARD_GET_DATA,
+	CLIPBOARD_CONTENT
+} clipboard_request_t;
+
+typedef enum {
+	CLIPBOARD_TAG_NONE,
+	CLIPBOARD_TAG_BLOB
+} clipboard_tag_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/libc/include/ipc/console.h
===================================================================
--- uspace/lib/libc/include/ipc/console.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/ipc/console.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -43,4 +43,5 @@
 	CONSOLE_GET_COLOR_CAP,
 	CONSOLE_GET_EVENT,
+	CONSOLE_GET_POS,
 	CONSOLE_GOTO,
 	CONSOLE_CLEAR,
Index: uspace/lib/libc/include/ipc/services.h
===================================================================
--- uspace/lib/libc/include/ipc/services.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/ipc/services.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -47,5 +47,6 @@
 	SERVICE_DEVMAP,
 	SERVICE_FHC,
-	SERVICE_OBIO
+	SERVICE_OBIO,
+	SERVICE_CLIPBOARD
 } services_t;
 
Index: uspace/lib/libc/include/string.h
===================================================================
--- uspace/lib/libc/include/string.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/string.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -73,5 +73,7 @@
 extern void str_append(char *dest, size_t size, const char *src);
 
-extern void wstr_nstr(char *dst, const wchar_t *src, size_t size);
+extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
+extern char *wstr_to_astr(const wchar_t *src);
+extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
 
 extern char *str_chr(const char *str, wchar_t ch);
Index: uspace/lib/libc/include/unistd.h
===================================================================
--- uspace/lib/libc/include/unistd.h	(revision 58d5803d422309587aa1e5c37ec90f119d64af5d)
+++ uspace/lib/libc/include/unistd.h	(revision 387416b0bf7b246ca6a9df2aea472d75776a5b48)
@@ -51,4 +51,6 @@
 #endif
 
+typedef uint32_t useconds_t;
+
 extern int dup2(int oldfd, int newfd);
 
@@ -68,6 +70,6 @@
 
 extern void _exit(int status) __attribute__ ((noreturn));
-extern int usleep(unsigned long usec);
-extern unsigned int sleep(unsigned int seconds);
+extern int usleep(useconds_t uses);
+extern unsigned int sleep(unsigned int se);
 
 #endif
