Index: .travis.yml
===================================================================
--- .travis.yml	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ .travis.yml	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -1,35 +1,62 @@
+#
+# Travis CI configuration notes
+# -----------------------------
+#
+# * HelenOS is always built for all architectures
+#   * that is done using matrix environmental variables
+#   * the list of architectures has to be kept manually in sync with
+#     HelenOS.config
+#   * the actual architecture is specified via H_ARCH variable
+#
+# * ported software is built when H_HARBOURS is set to true for given
+#   configuration
+#   * building ported software takes a lot of time, it is thus impossible
+#     to build for all architectures
+#   * some ports are known to fail for certain architectures: because that
+#     would make the whole build failing, we currently build only for ia32
+#     that seems to be in the best condition with respect to ported software
+#   * list of harbours is also maintained manually, look for a variable
+#     H_DEFAULT_HARBOURS_LIST to allow overriding from within this file
+#
+# * since the setup is rather complicated we use a dedicated shell script to
+#   run the actual build process and installation of the cross-compiler
+#   toolchain
+#
+# * if you have enabled Travis in your feature branch you may want to change
+#   some of the settings to better suite your needs
+#   * reduce number of built architectures (probably not needed)
+#   * built ported software for a different architecture
+#     * specify H_HARBOURS=true
+#     * optionally specify H_HARBOUR_LIST="..." to a list of harbours to be
+#       built
+#     * optionally specify H_HARBOURS_REPOSITORY="..." to point to your repo
+#       with HARBOUR files
+#
+
 language: c
-
+sudo: required
 env:
   global:
     - CROSS_PREFIX=/usr/local/cross-static/
   matrix:
-    - HELENOS_ARCH=amd64 HELENOS_TARGET=amd64-unknown-elf HELENOS_OUTPUT=image.iso
-    - HELENOS_ARCH=arm32/beagleboardxm HELENOS_TARGET=arm-linux-gnueabi HELENOS_OUTPUT=uImage.bin
-    - HELENOS_ARCH=arm32/beaglebone HELENOS_TARGET=arm-linux-gnueabi HELENOS_OUTPUT=uImage.bin
-    - HELENOS_ARCH=arm32/gta02 HELENOS_TARGET=arm-linux-gnueabi HELENOS_OUTPUT=uImage.bin
-    - HELENOS_ARCH=arm32/integratorcp HELENOS_TARGET=arm-linux-gnueabi HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=arm32/raspberrypi HELENOS_TARGET=arm-linux-gnueabi HELENOS_OUTPUT=uImage.bin
-    - HELENOS_ARCH=ia32 HELENOS_TARGET=i686-pc-linux-gnu HELENOS_OUTPUT=image.iso
-    - HELENOS_ARCH=ia64/i460GX HELENOS_TARGET=ia64-pc-linux-gnu HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=ia64/ski HELENOS_TARGET=ia64-pc-linux-gnu HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=mips32/malta-be HELENOS_TARGET=mips-linux-gnu HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=mips32/malta-le HELENOS_TARGET=mipsel-linux-gnu HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=mips32/msim HELENOS_TARGET=mipsel-linux-gnu HELENOS_OUTPUT=image.boot
-    - HELENOS_ARCH=ppc32 HELENOS_TARGET=ppc-linux-gnu HELENOS_OUTPUT=image.iso
-    - HELENOS_ARCH=sparc64/niagara HELENOS_TARGET=sparc64-linux-gnu HELENOS_OUTPUT=image.iso
-    - HELENOS_ARCH=sparc64/ultra HELENOS_TARGET=sparc64-linux-gnu HELENOS_OUTPUT=image.iso
-
+    - H_ARCH=amd64
+    - H_ARCH=arm32/beagleboardxm
+    - H_ARCH=arm32/beaglebone
+    - H_ARCH=arm32/gta02
+    - H_ARCH=arm32/integratorcp
+    - H_ARCH=arm32/raspberrypi
+    - H_ARCH=ia32 H_HARBOURS=true
+    - H_ARCH=ia64/i460GX
+    - H_ARCH=ia64/ski
+    - H_ARCH=mips32/malta-be
+    - H_ARCH=mips32/malta-le
+    - H_ARCH=mips32/msim
+    - H_ARCH=ppc32
+    - H_ARCH=sparc64/niagara
+    - H_ARCH=sparc64/ultra
 before_install:
- - sudo apt-get -qq update
- - sudo apt-get install -y genisoimage 
- - wget http://ci.helenos.org/download/helenos-cross-$HELENOS_TARGET.static.tar.xz -O /tmp/cross-$HELENOS_TARGET.static.tar.xz
- - sudo mkdir -p /usr/local/cross-static/
- - sudo tar -xJ -C /usr/local/cross-static/ -f /tmp/cross-$HELENOS_TARGET.static.tar.xz
-
+ - ./tools/travis.sh install
 script:
- - make PROFILE=$HELENOS_ARCH HANDS_OFF=y
- - test -s $HELENOS_OUTPUT
-
+ - ./tools/travis.sh run
 os:
-- linux
+ - linux
Index: Makefile
===================================================================
--- Makefile	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ Makefile	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -79,4 +79,7 @@
 	tools/ccheck.sh
 
+ccheck-fix: $(CCHECK)
+	tools/ccheck.sh --fix
+
 $(CCHECK):
 	cd tools && ./build-ccheck.sh
Index: abi/include/abi/ipc/methods.h
===================================================================
--- abi/include/abi/ipc/methods.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ abi/include/abi/ipc/methods.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -108,5 +108,5 @@
 	 *
 	 * - ARG1 - source user page address
-	 */ 
+	 */
 	IPC_M_PAGE_IN,
 
Index: abi/include/abi/proc/uarg.h
===================================================================
--- abi/include/abi/proc/uarg.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ abi/include/abi/proc/uarg.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,5 +44,5 @@
 	size_t uspace_stack_size;
 	
-	void (* uspace_thread_function)(void *);
+	void (*uspace_thread_function)(void *);
 	void *uspace_thread_arg;
 	
Index: boot/arch/arm32/include/arch/arch.h
===================================================================
--- boot/arch/arm32/include/arch/arch.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/arch/arm32/include/arch/arch.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -55,15 +55,15 @@
 
 #ifdef MACHINE_beagleboardxm
-	#define PA_OFFSET 0
+#define PA_OFFSET 0
 #elif defined MACHINE_beaglebone
-	#define PA_OFFSET 0
+#define PA_OFFSET 0
 #else
-	#define PA_OFFSET 0x80000000
+#define PA_OFFSET 0x80000000
 #endif
 
 #ifndef __ASM__
-	#define PA2KA(addr)  (((uintptr_t) (addr)) + PA_OFFSET)
+#define PA2KA(addr)  (((uintptr_t) (addr)) + PA_OFFSET)
 #else
-	#define PA2KA(addr)  ((addr) + PA_OFFSET)
+#define PA2KA(addr)  ((addr) + PA_OFFSET)
 #endif
 
Index: boot/arch/mips32/include/arch/arch.h
===================================================================
--- boot/arch/mips32/include/arch/arch.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/arch/mips32/include/arch/arch.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -56,11 +56,11 @@
 
 #ifndef __ASM__
-	#define PA2KA(addr)    (((uintptr_t) (addr)) + 0x80000000)
-	#define PA2KSEG(addr)  (((uintptr_t) (addr)) + 0xa0000000)
-	#define KA2PA(addr)    (((uintptr_t) (addr)) - 0x80000000)
-	#define KSEG2PA(addr)  (((uintptr_t) (addr)) - 0xa0000000)
+#define PA2KA(addr)    (((uintptr_t) (addr)) + 0x80000000)
+#define PA2KSEG(addr)  (((uintptr_t) (addr)) + 0xa0000000)
+#define KA2PA(addr)    (((uintptr_t) (addr)) - 0x80000000)
+#define KSEG2PA(addr)  (((uintptr_t) (addr)) - 0xa0000000)
 #else
-	#define PA2KA(addr)    ((addr) + 0x80000000)
-	#define KSEG2PA(addr)  ((addr) - 0xa0000000)
+#define PA2KA(addr)    ((addr) + 0x80000000)
+#define KSEG2PA(addr)  ((addr) - 0xa0000000)
 #endif
 
Index: boot/arch/ppc32/include/arch/arch.h
===================================================================
--- boot/arch/ppc32/include/arch/arch.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/arch/ppc32/include/arch/arch.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,7 +38,7 @@
 
 #ifndef __ASM__
-	#define PA2KA(addr)  (((uintptr_t) (addr)) + 0x80000000)
+#define PA2KA(addr)  (((uintptr_t) (addr)) + 0x80000000)
 #else
-	#define PA2KA(addr)  ((addr) + 0x80000000)
+#define PA2KA(addr)  ((addr) + 0x80000000)
 #endif
 
Index: boot/arch/riscv64/include/arch/mm.h
===================================================================
--- boot/arch/riscv64/include/arch/mm.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/arch/riscv64/include/arch/mm.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,9 +34,9 @@
 
 #ifndef __ASM__
-	#define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
-	#define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
+#define KA2PA(x)  (((uintptr_t) (x)) - UINT64_C(0xffff800000000000))
+#define PA2KA(x)  (((uintptr_t) (x)) + UINT64_C(0xffff800000000000))
 #else
-	#define KA2PA(x)  ((x) - 0xffff800000000000)
-	#define PA2KA(x)  ((x) + 0xffff800000000000)
+#define KA2PA(x)  ((x) - 0xffff800000000000)
+#define PA2KA(x)  ((x) + 0xffff800000000000)
 #endif
 
Index: boot/generic/include/printf.h
===================================================================
--- boot/generic/include/printf.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/generic/include/printf.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 extern int puts(const char *);
 extern int printf(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 extern int vprintf(const char *, va_list);
 
Index: boot/generic/include/printf_verify.h
===================================================================
--- boot/generic/include/printf_verify.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ boot/generic/include/printf_verify.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -33,14 +33,14 @@
 #define BOOT_PRINTF_VERIFY_H_
 
-#ifndef NVERIFY_PRINTF
+#ifndef _HELENOS_NVERIFY_PRINTF
 
-#define PRINTF_ATTRIBUTE(start, end) \
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(gnu_printf, start, end)))
 
-#else /* NVERIFY_PRINTF */
+#else /* _HELENOS_NVERIFY_PRINTF */
 
-#define PRINTF_ATTRIBUTE(start, end)
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end)
 
-#endif /* NVERIFY_PRINTF */
+#endif /* _HELENOS_NVERIFY_PRINTF */
 
 #endif
Index: contrib/arch/uspace/srv/vfs/vfs.bp
===================================================================
--- contrib/arch/uspace/srv/vfs/vfs.bp	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ contrib/arch/uspace/srv/vfs/vfs.bp	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -129,9 +129,9 @@
 	?fstat {
 		tentative {
-			?ipc_m_data_read /* struct stat */ {
+			?ipc_m_data_read /* vfs_stat_t */ {
 				alternative (fs; tmpfs; fat; devfs) {
 					[fnc.vfs_grab_phone] ;
 					!fs.stat {
-						!fs.ipc_m_data_read /* forward struct stat */
+						!fs.ipc_m_data_read /* forward vfs_stat_t */
 					} ;
 					[fnc.vfs_release_phone]
@@ -144,10 +144,10 @@
 		?ipc_m_data_write /* path */ ;
 		tentative {
-			?ipc_m_data_read /* struct stat */ {
+			?ipc_m_data_read /* vfs_stat_t */ {
 				alternative (fs; tmpfs; fat; devfs) {
 					[fnc.vfs_lookup_internal] ;
 					tentative {
 						!fs.stat {
-							!fs.ipc_m_data_read /* forward struct stat */
+							!fs.ipc_m_data_read /* forward vfs_stat_t */
 						}
 					}
Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/Makefile	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -90,5 +90,5 @@
 
 COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc \
+	-ffreestanding -nostdlib -nostdinc \
 	-fexec-charset=UTF-8 -finput-charset=UTF-8 -fno-common \
 	-fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
@@ -208,5 +208,5 @@
 	generic/src/mm/backend_user.c \
 	generic/src/mm/slab.c \
-	generic/src/lib/func.c \
+	generic/src/lib/halt.c \
 	generic/src/lib/mem.c \
 	generic/src/lib/memfnc.c \
Index: kernel/arch/abs32le/src/abs32le.c
===================================================================
--- kernel/arch/abs32le/src/abs32le.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/abs32le/src/abs32le.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,5 +38,5 @@
 #include <arch/asm.h>
 
-#include <func.h>
+#include <halt.h>
 #include <config.h>
 #include <console/console.h>
Index: kernel/arch/abs32le/src/mm/page.c
===================================================================
--- kernel/arch/abs32le/src/mm/page.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/abs32le/src/mm/page.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 #include <align.h>
 #include <config.h>
-#include <func.h>
+#include <halt.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
Index: kernel/arch/amd64/Makefile.inc
===================================================================
--- kernel/arch/amd64/Makefile.inc	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/amd64/Makefile.inc	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -32,5 +32,5 @@
 
 FPU_NO_CFLAGS = -mno-sse -mno-sse2
-COMMON_CFLAGS += -m64 -mcmodel=$(MEMORY_MODEL) -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
+COMMON_CFLAGS += -mcmodel=$(MEMORY_MODEL) -mno-red-zone -fno-unwind-tables -fno-omit-frame-pointer
 
 BITS = 64
Index: kernel/arch/amd64/include/arch/interrupt.h
===================================================================
--- kernel/arch/amd64/include/arch/interrupt.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/amd64/include/arch/interrupt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -83,7 +83,7 @@
 #define VECTOR_SMP_CALL_IPI       (IVT_FREEBASE + 3)
 
-extern void (* disable_irqs_function)(uint16_t);
-extern void (* enable_irqs_function)(uint16_t);
-extern void (* eoi_function)(void);
+extern void (*disable_irqs_function)(uint16_t);
+extern void (*enable_irqs_function)(uint16_t);
+extern void (*eoi_function)(void);
 extern const char *irqs_info;
 
Index: kernel/arch/amd64/src/interrupt.c
===================================================================
--- kernel/arch/amd64/src/interrupt.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/amd64/src/interrupt.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,5 +39,5 @@
 #include <panic.h>
 #include <arch/drivers/i8259.h>
-#include <func.h>
+#include <halt.h>
 #include <cpu.h>
 #include <arch/asm.h>
Index: kernel/arch/arm32/include/arch/elf.h
===================================================================
--- kernel/arch/arm32/include/arch/elf.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/arm32/include/arch/elf.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,7 +40,7 @@
 
 #ifdef __BE__
-	#define ELF_DATA_ENCODING  ELFDATA2MSB
+#define ELF_DATA_ENCODING  ELFDATA2MSB
 #else
-	#define ELF_DATA_ENCODING  ELFDATA2LSB
+#define ELF_DATA_ENCODING  ELFDATA2LSB
 #endif
 
Index: kernel/arch/arm32/include/arch/exception.h
===================================================================
--- kernel/arch/arm32/include/arch/exception.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/arm32/include/arch/exception.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,7 +45,7 @@
 
 #ifdef HIGH_EXCEPTION_VECTORS
-	#define EXC_BASE_ADDRESS  0xffff0000
+#define EXC_BASE_ADDRESS  0xffff0000
 #else
-	#define EXC_BASE_ADDRESS  0x0
+#define EXC_BASE_ADDRESS  0x0
 #endif
 
Index: kernel/arch/arm32/include/arch/mach/integratorcp/integratorcp.h
===================================================================
--- kernel/arch/arm32/include/arch/mach/integratorcp/integratorcp.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/arm32/include/arch/mach/integratorcp/integratorcp.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -77,22 +77,22 @@
 
 typedef struct {
-        uintptr_t uart;
-        uintptr_t kbd_ctrl;
-        uintptr_t kbd_stat;
-        uintptr_t kbd_data;
-        uintptr_t kbd_intstat;
-        uintptr_t rtc;
-        uintptr_t rtc1_load;
-        uintptr_t rtc1_read;
-        uintptr_t rtc1_ctl;
-        uintptr_t rtc1_intrclr;
-        uintptr_t rtc1_intrstat;
-        uintptr_t rtc1_bgload;
-        uintptr_t irqc;
-        uintptr_t irqc_mask;
-        uintptr_t irqc_unmask;
-        uintptr_t vga;
-        uintptr_t cmcr;
-        uintptr_t sdramcr;
+	uintptr_t uart;
+	uintptr_t kbd_ctrl;
+	uintptr_t kbd_stat;
+	uintptr_t kbd_data;
+	uintptr_t kbd_intstat;
+	uintptr_t rtc;
+	uintptr_t rtc1_load;
+	uintptr_t rtc1_read;
+	uintptr_t rtc1_ctl;
+	uintptr_t rtc1_intrclr;
+	uintptr_t rtc1_intrstat;
+	uintptr_t rtc1_bgload;
+	uintptr_t irqc;
+	uintptr_t irqc_mask;
+	uintptr_t irqc_unmask;
+	uintptr_t vga;
+	uintptr_t cmcr;
+	uintptr_t sdramcr;
 } icp_hw_map_t;
 
Index: kernel/arch/arm32/include/arch/machine_func.h
===================================================================
--- kernel/arch/arm32/include/arch/machine_func.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/arm32/include/arch/machine_func.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -108,5 +108,5 @@
 extern size_t machine_get_irq_count(void);
 
-extern const char * machine_get_platform_name(void);
+extern const char *machine_get_platform_name(void);
 
 #endif
Index: kernel/arch/arm32/include/arch/types.h
===================================================================
--- kernel/arch/arm32/include/arch/types.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/arm32/include/arch/types.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,7 +38,7 @@
 
 #ifndef DOXYGEN
-	#define ATTRIBUTE_PACKED __attribute__((packed))
+#define ATTRIBUTE_PACKED __attribute__((packed))
 #else
-	#define ATTRIBUTE_PACKED
+#define ATTRIBUTE_PACKED
 #endif
 
Index: kernel/arch/ia32/Makefile.inc
===================================================================
--- kernel/arch/ia32/Makefile.inc	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/Makefile.inc	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,5 +34,5 @@
 ENDIANESS = LE
 
-COMMON_CFLAGS += -m32 -fno-omit-frame-pointer
+COMMON_CFLAGS += -fno-omit-frame-pointer
 
 ## Accepted CPUs
Index: kernel/arch/ia32/include/arch/interrupt.h
===================================================================
--- kernel/arch/ia32/include/arch/interrupt.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/include/arch/interrupt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -85,7 +85,7 @@
 #define VECTOR_SMP_CALL_IPI       (IVT_FREEBASE + 3)
 
-extern void (* disable_irqs_function)(uint16_t);
-extern void (* enable_irqs_function)(uint16_t);
-extern void (* eoi_function)(void);
+extern void (*disable_irqs_function)(uint16_t);
+extern void (*enable_irqs_function)(uint16_t);
+extern void (*eoi_function)(void);
 extern const char *irqs_info;
 
Index: kernel/arch/ia32/include/arch/smp/smp.h
===================================================================
--- kernel/arch/ia32/include/arch/smp/smp.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/include/arch/smp/smp.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 struct smp_config_operations {
 	/** Check whether a processor is enabled. */
-	bool (* cpu_enabled)(size_t);
+	bool (*cpu_enabled)(size_t);
 	
 	/** Check whether a processor is BSP. */
Index: kernel/arch/ia32/src/interrupt.c
===================================================================
--- kernel/arch/ia32/src/interrupt.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/src/interrupt.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,5 +40,5 @@
 #include <panic.h>
 #include <arch/drivers/i8259.h>
-#include <func.h>
+#include <halt.h>
 #include <cpu.h>
 #include <arch/asm.h>
Index: kernel/arch/ia32/src/mm/page.c
===================================================================
--- kernel/arch/ia32/src/mm/page.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/src/mm/page.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 #include <align.h>
 #include <config.h>
-#include <func.h>
+#include <halt.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
Index: kernel/arch/ia32/src/smp/mps.c
===================================================================
--- kernel/arch/ia32/src/smp/mps.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/src/smp/mps.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 #include <arch/smp/smp.h>
 #include <assert.h>
-#include <func.h>
+#include <halt.h>
 #include <typedefs.h>
 #include <cpu.h>
Index: kernel/arch/ia32/src/smp/smp.c
===================================================================
--- kernel/arch/ia32/src/smp/smp.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/ia32/src/smp/smp.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,5 +45,5 @@
 #include <synch/waitq.h>
 #include <arch/pm.h>
-#include <func.h>
+#include <halt.h>
 #include <panic.h>
 #include <arch/asm.h>
Index: kernel/arch/mips32/include/arch/elf.h
===================================================================
--- kernel/arch/mips32/include/arch/elf.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/mips32/include/arch/elf.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,7 +39,7 @@
 
 #ifdef __BE__
-	#define ELF_DATA_ENCODING  ELFDATA2MSB
+#define ELF_DATA_ENCODING  ELFDATA2MSB
 #else
-	#define ELF_DATA_ENCODING  ELFDATA2LSB
+#define ELF_DATA_ENCODING  ELFDATA2LSB
 #endif
 
Index: kernel/arch/mips32/src/debugger.c
===================================================================
--- kernel/arch/mips32/src/debugger.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/mips32/src/debugger.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 #include <arch.h>
 #include <arch/cp0.h>
-#include <func.h>
+#include <halt.h>
 #include <symtab.h>
 
Index: kernel/arch/mips32/src/exception.c
===================================================================
--- kernel/arch/mips32/src/exception.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/mips32/src/exception.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,5 +43,5 @@
 #include <print.h>
 #include <interrupt.h>
-#include <func.h>
+#include <halt.h>
 #include <ddi/irq.h>
 #include <arch/debugger.h>
Index: kernel/arch/riscv64/src/mm/page.c
===================================================================
--- kernel/arch/riscv64/src/mm/page.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/riscv64/src/mm/page.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 #include <align.h>
 #include <config.h>
-#include <func.h>
+#include <halt.h>
 #include <arch/interrupt.h>
 #include <arch/asm.h>
Index: kernel/arch/riscv64/src/riscv64.c
===================================================================
--- kernel/arch/riscv64/src/riscv64.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/riscv64/src/riscv64.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,5 +40,5 @@
 #include <arch/drivers/ucb.h>
 
-#include <func.h>
+#include <halt.h>
 #include <config.h>
 #include <errno.h>
Index: kernel/arch/sparc64/include/arch/drivers/pci.h
===================================================================
--- kernel/arch/sparc64/include/arch/drivers/pci.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/sparc64/include/arch/drivers/pci.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,6 +52,6 @@
 
 struct pci_operations {
-	void (* enable_interrupt)(pci_t *, int);
-	void (* clear_interrupt)(pci_t *, int);
+	void (*enable_interrupt)(pci_t *, int);
+	void (*clear_interrupt)(pci_t *, int);
 };
 
Index: kernel/arch/sparc64/include/arch/mm/cache_spec.h
===================================================================
--- kernel/arch/sparc64/include/arch/mm/cache_spec.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/sparc64/include/arch/mm/cache_spec.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,7 +47,7 @@
 
 #if defined (US)
-	#define DCACHE_SIZE  (16 * 1024)
+#define DCACHE_SIZE  (16 * 1024)
 #elif defined (US3)
-	#define DCACHE_SIZE  (64 * 1024)
+#define DCACHE_SIZE  (64 * 1024)
 #endif
 
Index: kernel/arch/sparc64/include/arch/sun4v/md.h
===================================================================
--- kernel/arch/sparc64/include/arch/sun4v/md.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/sparc64/include/arch/sun4v/md.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -54,7 +54,7 @@
 const char *md_get_node_name(md_node_t node);
 bool md_get_integer_property(md_node_t node, const char *key,
-	uint64_t *result);
+    uint64_t *result);
 bool md_get_string_property(md_node_t node, const char *key,
-	const char **result);
+    const char **result);
 bool md_next_node(md_node_t *node, const char *name);
 void md_init(void);
Index: kernel/arch/sparc64/src/smp/sun4v/smp.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,5 +43,5 @@
 #include <config.h>
 #include <macros.h>
-#include <func.h>
+#include <halt.h>
 #include <stdbool.h>
 #include <stddef.h>
Index: kernel/arch/sparc64/src/sun4v/md.c
===================================================================
--- kernel/arch/sparc64/src/sun4v/md.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/arch/sparc64/src/sun4v/md.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,5 +35,5 @@
 #include <debug.h>
 #include <panic.h>
-#include <func.h>
+#include <halt.h>
 #include <log.h>
 #include <str.h>
Index: kernel/doc/doxygroups.h
===================================================================
--- kernel/doc/doxygroups.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/doc/doxygroups.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -117,5 +117,5 @@
 	 * @ingroup mm
 	 * @endcond
-	 */	 
+	 */
 	
 	/**
@@ -193,5 +193,5 @@
 	 * @ingroup ddi
 	 * @endcond
-	 */	 
+	 */
 
  	/**
@@ -257,5 +257,5 @@
 	 * @ingroup debug
 	 * @endcond
-	 */	 
+	 */
 
 	/**
@@ -321,5 +321,5 @@
 	 * @ingroup interrupt
 	 * @endcond
-	 */	 
+	 */
 
 	/**
@@ -389,5 +389,5 @@
 	 * @ingroup others
 	 * @endcond
-	 */	 
+	 */
 
 	/**
Index: kernel/genarch/include/genarch/ofw/ofw_tree.h
===================================================================
--- kernel/genarch/include/genarch/ofw/ofw_tree.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/genarch/include/genarch/ofw/ofw_tree.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -65,5 +65,5 @@
 
 /* Walker for visiting OpenFirmware device tree nodes. */
-typedef bool (* ofw_tree_walker_t)(ofw_tree_node_t *, void *);
+typedef bool (*ofw_tree_walker_t)(ofw_tree_node_t *, void *);
 
 extern void ofw_tree_init(ofw_tree_node_t *);
Index: kernel/genarch/src/ofw/upa.c
===================================================================
--- kernel/genarch/src/ofw/upa.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/genarch/src/ofw/upa.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,5 +38,5 @@
 #include <genarch/ofw/ofw_tree.h>
 #include <genarch/ofw/upa.h>
-#include <func.h>
+#include <halt.h>
 #include <panic.h>
 #include <macros.h>
Index: kernel/generic/include/adt/bitmap.h
===================================================================
--- kernel/generic/include/adt/bitmap.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/adt/bitmap.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,4 +38,5 @@
 #include <stddef.h>
 #include <stdbool.h>
+#include <stdint.h>
 
 #define BITMAP_ELEMENT   8
Index: kernel/generic/include/adt/hash_table.h
===================================================================
--- kernel/generic/include/adt/hash_table.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/adt/hash_table.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -84,6 +84,6 @@
 	member_to_inst((item), type, member)
 
-extern bool hash_table_create(hash_table_t *, size_t, size_t, 
-	hash_table_ops_t *);
+extern bool hash_table_create(hash_table_t *, size_t, size_t,
+    hash_table_ops_t *);
 extern void hash_table_destroy(hash_table_t *);
 
@@ -98,6 +98,6 @@
 extern size_t hash_table_remove(hash_table_t *, void *);
 extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
-extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 
-	void *);
+extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *),
+    void *);
 
 
Index: kernel/generic/include/align.h
===================================================================
--- kernel/generic/include/align.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/align.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -58,5 +58,5 @@
  * @param s Address or size to be checked for alignment.
  * @param a Size of alignment, must be a power of 2.
- */ 
+ */
 #define IS_ALIGNED(s, a)	(ALIGN_UP((s), (a)) == (s))
 
Index: kernel/generic/include/arch.h
===================================================================
--- kernel/generic/include/arch.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/arch.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -80,9 +80,9 @@
 
 typedef struct {
-	void (* pre_mm_init)(void);
-	void (* post_mm_init)(void);
-	void (* post_cpu_init)(void);
-	void (* pre_smp_init)(void);
-	void (* post_smp_init)(void);
+	void (*pre_mm_init)(void);
+	void (*post_mm_init)(void);
+	void (*post_cpu_init)(void);
+	void (*pre_smp_init)(void);
+	void (*post_smp_init)(void);
 } arch_ops_t;
 
Index: rnel/generic/include/func.h
===================================================================
--- kernel/generic/include/func.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,47 +1,0 @@
-/*
- * Copyright (c) 2001-2004 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 generic
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_FUNC_H_
-#define KERN_FUNC_H_
-
-#include <atomic.h>
-
-extern atomic_t haltstate;
-
-extern void halt(void) __attribute__((noreturn));
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/gsort.h
===================================================================
--- kernel/generic/include/gsort.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/gsort.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,5 +39,5 @@
 #include <stddef.h>
 
-typedef int (* sort_cmp_t)(void *, void *, void *);
+typedef int (*sort_cmp_t)(void *, void *, void *);
 
 extern bool gsort(void *, size_t, size_t, sort_cmp_t, void *);
Index: kernel/generic/include/halt.h
===================================================================
--- kernel/generic/include/halt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ kernel/generic/include/halt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2001-2004 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 generic
+ * @{
+ */
+/** @file
+ */
+
+#ifndef KERN_HALT_H_
+#define KERN_HALT_H_
+
+#include <atomic.h>
+
+extern atomic_t haltstate;
+
+extern void halt(void) __attribute__((noreturn));
+
+#endif
+
+/** @}
+ */
Index: kernel/generic/include/interrupt.h
===================================================================
--- kernel/generic/include/interrupt.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/interrupt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -61,7 +61,7 @@
 
 extern void fault_from_uspace(istate_t *, const char *, ...)
-    PRINTF_ATTRIBUTE(2, 3);
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 extern void fault_if_from_uspace(istate_t *, const char *, ...)
-    PRINTF_ATTRIBUTE(2, 3);
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 extern istate_t *istate_get(thread_t *);
 extern iroutine_t exc_register(unsigned int, const char *, bool, iroutine_t);
Index: kernel/generic/include/ipc/sysipc_ops.h
===================================================================
--- kernel/generic/include/ipc/sysipc_ops.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/ipc/sysipc_ops.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -90,5 +90,5 @@
 	 * Invoked on:		all calls
 	 */
-	errno_t (* request_preprocess)(call_t *, phone_t *);
+	errno_t (*request_preprocess)(call_t *, phone_t *);
 
 	/**
@@ -101,6 +101,6 @@
 	 *			_ipc_answer_free_call()
 	 * Invoked on:		all forgotten calls
-	 */	
-	errno_t (* request_forget)(call_t *);
+	 */
+	errno_t (*request_forget)(call_t *);
 
 	/**
@@ -111,6 +111,6 @@
 	 * Races with:		request_forget()
 	 * Invoked on:		all calls delivered to the callee
-	 */	
-	int (* request_process)(call_t *, answerbox_t *);
+	 */
+	int (*request_process)(call_t *, answerbox_t *);
 
 	/**
@@ -123,5 +123,5 @@
 	 * Invoked on:		all forgotten calls
 	 */
-	errno_t (* answer_cleanup)(call_t *, ipc_data_t *);
+	errno_t (*answer_cleanup)(call_t *, ipc_data_t *);
 
 	/**
@@ -134,5 +134,5 @@
 	 * Invoked on:		all answered calls
 	 */
-	errno_t (* answer_preprocess)(call_t *, ipc_data_t *);
+	errno_t (*answer_preprocess)(call_t *, ipc_data_t *);
 
 	/**
@@ -144,5 +144,5 @@
 	 * Invoked on:		all answered calls
 	 */
-	errno_t (* answer_process)(call_t *);
+	errno_t (*answer_process)(call_t *);
 } sysipc_ops_t;
 
Index: kernel/generic/include/log.h
===================================================================
--- kernel/generic/include/log.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/log.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,7 +48,7 @@
 extern int log_vprintf(const char *, va_list);
 extern int log_printf(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 extern int log(log_facility_t, log_level_t, const char *, ...)
-    PRINTF_ATTRIBUTE(3, 4);
+    _HELENOS_PRINTF_ATTRIBUTE(3, 4);
 
 extern sys_errno_t sys_klog(sysarg_t, void *buf, size_t size,
Index: kernel/generic/include/mm/page.h
===================================================================
--- kernel/generic/include/mm/page.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/mm/page.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -46,9 +46,9 @@
 /** Operations to manipulate page mappings. */
 typedef struct {
-	void (* mapping_insert)(as_t *, uintptr_t, uintptr_t, unsigned int);
-	void (* mapping_remove)(as_t *, uintptr_t);
-	bool (* mapping_find)(as_t *, uintptr_t, bool, pte_t *);
-	void (* mapping_update)(as_t *, uintptr_t, bool, pte_t *);
-	void (* mapping_make_global)(uintptr_t, size_t);
+	void (*mapping_insert)(as_t *, uintptr_t, uintptr_t, unsigned int);
+	void (*mapping_remove)(as_t *, uintptr_t);
+	bool (*mapping_find)(as_t *, uintptr_t, bool, pte_t *);
+	void (*mapping_update)(as_t *, uintptr_t, bool, pte_t *);
+	void (*mapping_make_global)(uintptr_t, size_t);
 } page_mapping_operations_t;
 
Index: kernel/generic/include/panic.h
===================================================================
--- kernel/generic/include/panic.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/panic.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -66,5 +66,5 @@
 extern void panic_common(panic_category_t, struct istate *, int,
     uintptr_t, const char *, ...) __attribute__ ((noreturn))
-    PRINTF_ATTRIBUTE(5, 6);
+    _HELENOS_PRINTF_ATTRIBUTE(5, 6);
 
 #endif
Index: kernel/generic/include/print.h
===================================================================
--- kernel/generic/include/print.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/print.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,7 +44,7 @@
 extern int puts(const char *s);
 extern int printf(const char *fmt, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 extern int snprintf(char *str, size_t size, const char *fmt, ...)
-    PRINTF_ATTRIBUTE(3, 4);
+    _HELENOS_PRINTF_ATTRIBUTE(3, 4);
 
 extern int vprintf(const char *fmt, va_list ap);
Index: kernel/generic/include/printf/verify.h
===================================================================
--- kernel/generic/include/printf/verify.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/printf/verify.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,20 +36,20 @@
 #define KERN_PRINTF_VERIFY_H_
 
-#ifndef NVERIFY_PRINTF
+#ifndef _HELENOS_NVERIFY_PRINTF
 
 #ifdef __clang__
-#define PRINTF_ATTRIBUTE(start, end) \
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(__printf__, start, end)))
 #else
-#define PRINTF_ATTRIBUTE(start, end) \
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(gnu_printf, start, end)))
 #endif
 
 
-#else /* NVERIFY_PRINTF */
+#else /* _HELENOS_NVERIFY_PRINTF */
 
-#define PRINTF_ATTRIBUTE(start, end)
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end)
 
-#endif /* NVERIFY_PRINTF */
+#endif /* _HELENOS_NVERIFY_PRINTF */
 
 #endif
Index: kernel/generic/include/stacktrace.h
===================================================================
--- kernel/generic/include/stacktrace.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/stacktrace.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,8 +49,8 @@
 
 typedef struct {
-	bool (* stack_trace_context_validate)(stack_trace_context_t *);
-	bool (* frame_pointer_prev)(stack_trace_context_t *, uintptr_t *);
-	bool (* return_address_get)(stack_trace_context_t *, uintptr_t *);
-	bool (* symbol_resolve)(uintptr_t, const char **, uintptr_t *);
+	bool (*stack_trace_context_validate)(stack_trace_context_t *);
+	bool (*frame_pointer_prev)(stack_trace_context_t *, uintptr_t *);
+	bool (*return_address_get)(stack_trace_context_t *, uintptr_t *);
+	bool (*symbol_resolve)(uintptr_t, const char **, uintptr_t *);
 } stack_trace_ops_t;
 
Index: kernel/generic/include/symtab.h
===================================================================
--- kernel/generic/include/symtab.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/symtab.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,5 +40,5 @@
 
 extern void symtab_print_search(const char *);
-extern const char* symtab_hints_enum(const char *, const char **, void **);
+extern const char *symtab_hints_enum(const char *, const char **, void **);
 
 #endif
Index: kernel/generic/include/synch/condvar.h
===================================================================
--- kernel/generic/include/synch/condvar.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/synch/condvar.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -65,7 +65,7 @@
     int flags);
 extern errno_t _condvar_wait_timeout_spinlock_impl(condvar_t *cv, spinlock_t *lock,
-	uint32_t usec, int flags);
+    uint32_t usec, int flags);
 extern errno_t _condvar_wait_timeout_irq_spinlock(condvar_t *cv,
-	irq_spinlock_t *irq_lock, uint32_t usec, int flags);
+    irq_spinlock_t *irq_lock, uint32_t usec, int flags);
 
 
Index: kernel/generic/include/synch/workqueue.h
===================================================================
--- kernel/generic/include/synch/workqueue.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/synch/workqueue.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -64,5 +64,5 @@
 extern bool workq_global_enqueue(work_t *, work_func_t);
 
-extern struct work_queue * workq_create(const char *);
+extern struct work_queue *workq_create(const char *);
 extern void workq_destroy(struct work_queue *);
 extern bool workq_init(struct work_queue *, const char *);
Index: kernel/generic/include/typedefs.h
===================================================================
--- kernel/generic/include/typedefs.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/include/typedefs.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,5 +43,5 @@
 } atomic_t;
 
-typedef void (* function)(void);
+typedef void (*function)(void);
 
 typedef uint32_t container_id_t;
Index: kernel/generic/src/console/chardev.c
===================================================================
--- kernel/generic/src/console/chardev.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/console/chardev.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,5 +39,5 @@
 #include <synch/spinlock.h>
 #include <print.h>
-#include <func.h>
+#include <halt.h>
 #include <cpu.h>
 
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/console/cmd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,5 +52,5 @@
 #include <arch.h>
 #include <config.h>
-#include <func.h>
+#include <halt.h>
 #include <str.h>
 #include <macros.h>
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/console/kconsole.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,5 +52,5 @@
 #include <macros.h>
 #include <debug.h>
-#include <func.h>
+#include <halt.h>
 #include <str.h>
 #include <sysinfo/sysinfo.h>
Index: kernel/generic/src/debug/panic.c
===================================================================
--- kernel/generic/src/debug/panic.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/debug/panic.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,5 +36,5 @@
 #include <print.h>
 #include <stacktrace.h>
-#include <func.h>
+#include <halt.h>
 #include <typedefs.h>
 #include <mm/as.h>
Index: rnel/generic/src/lib/func.c
===================================================================
--- kernel/generic/src/lib/func.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,82 +1,0 @@
-/*
- * Copyright (c) 2001-2004 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 generic
- * @{
- */
-
-/**
- * @file
- * @brief Miscellaneous functions.
- */
-
-#include <func.h>
-#include <log.h>
-#include <cpu.h>
-#include <arch/asm.h>
-#include <arch.h>
-#include <console/kconsole.h>
-
-atomic_t haltstate = {0}; /**< Halt flag */
-
-
-/** Halt wrapper
- *
- * Set halt flag and halt the CPU.
- *
- */
-void halt(void)
-{
-#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
-	bool rundebugger = false;
-	
-	if (!atomic_get(&haltstate)) {
-		atomic_set(&haltstate, 1);
-		rundebugger = true;
-	}
-#else
-	atomic_set(&haltstate, 1);
-#endif
-	
-	interrupts_disable();
-	
-#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
-	if ((rundebugger) && (kconsole_check_poll()))
-		kconsole("panic", "\nLast resort kernel console ready.\n", false);
-#endif
-	
-	if (CPU)
-		log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
-	else
-		log(LF_OTHER, LVL_NOTE, "cpu: halted");
-	
-	cpu_halt();
-}
-
-/** @}
- */
Index: kernel/generic/src/lib/halt.c
===================================================================
--- kernel/generic/src/lib/halt.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ kernel/generic/src/lib/halt.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,82 @@
+/*
+ * Copyright (c) 2001-2004 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 generic
+ * @{
+ */
+
+/**
+ * @file
+ * @brief Halt function.
+ */
+
+#include <halt.h>
+#include <log.h>
+#include <cpu.h>
+#include <arch/asm.h>
+#include <arch.h>
+#include <console/kconsole.h>
+
+/** Halt flag */
+atomic_t haltstate = {0};
+
+/** Halt wrapper
+ *
+ * Set halt flag and halt the CPU.
+ *
+ */
+void halt(void)
+{
+#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
+	bool rundebugger = false;
+	
+	if (!atomic_get(&haltstate)) {
+		atomic_set(&haltstate, 1);
+		rundebugger = true;
+	}
+#else
+	atomic_set(&haltstate, 1);
+#endif
+	
+	interrupts_disable();
+	
+#if (defined(CONFIG_DEBUG)) && (defined(CONFIG_KCONSOLE))
+	if ((rundebugger) && (kconsole_check_poll()))
+		kconsole("panic", "\nLast resort kernel console ready.\n", false);
+#endif
+	
+	if (CPU)
+		log(LF_OTHER, LVL_NOTE, "cpu%u: halted", CPU->id);
+	else
+		log(LF_OTHER, LVL_NOTE, "cpu: halted");
+	
+	cpu_halt();
+}
+
+/** @}
+ */
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/main/kinit.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -51,5 +51,5 @@
 #include <proc/program.h>
 #include <panic.h>
-#include <func.h>
+#include <halt.h>
 #include <cpu.h>
 #include <arch/asm.h>
Index: kernel/generic/src/main/main.c
===================================================================
--- kernel/generic/src/main/main.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/main/main.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -67,4 +67,5 @@
 #include <align.h>
 #include <interrupt.h>
+#include <str.h>
 #include <mm/frame.h>
 #include <mm/page.h>
Index: kernel/generic/src/main/shutdown.c
===================================================================
--- kernel/generic/src/main/shutdown.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/main/shutdown.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,5 +38,5 @@
 #include <arch.h>
 #include <proc/task.h>
-#include <func.h>
+#include <halt.h>
 #include <print.h>
 #include <log.h>
Index: kernel/generic/src/proc/scheduler.c
===================================================================
--- kernel/generic/src/proc/scheduler.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/proc/scheduler.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -58,5 +58,5 @@
 #include <context.h>
 #include <fpu_context.h>
-#include <func.h>
+#include <halt.h>
 #include <arch.h>
 #include <adt/list.h>
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/proc/task.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -56,5 +56,5 @@
 #include <print.h>
 #include <errno.h>
-#include <func.h>
+#include <halt.h>
 #include <str.h>
 #include <syscall/copy.h>
Index: kernel/generic/src/time/clock.c
===================================================================
--- kernel/generic/src/time/clock.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/time/clock.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -46,5 +46,5 @@
 #include <synch/spinlock.h>
 #include <synch/waitq.h>
-#include <func.h>
+#include <halt.h>
 #include <proc/scheduler.h>
 #include <cpu.h>
Index: kernel/generic/src/time/timeout.c
===================================================================
--- kernel/generic/src/time/timeout.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/generic/src/time/timeout.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 #include <panic.h>
 #include <synch/spinlock.h>
-#include <func.h>
+#include <halt.h>
 #include <cpu.h>
 #include <arch/asm.h>
Index: kernel/test/print/print5.c
===================================================================
--- kernel/test/print/print5.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ kernel/test/print/print5.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,5 +37,5 @@
  *
  */
-#define NVERIFY_PRINTF
+#define _HELENOS_NVERIFY_PRINTF
 
 #include <print.h>
Index: tools/ccheck.sh
===================================================================
--- tools/ccheck.sh	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ tools/ccheck.sh	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -30,4 +30,10 @@
 ccheck=tools/sycek/ccheck
 
+if [ ."$1" == .--fix ] ; then
+	opt=--fix
+else
+	opt=
+fi
+
 srepcnt=0
 snorepcnt=0
@@ -37,5 +43,5 @@
 while read fname; do
 	outfile="$(mktemp)"
-	$ccheck $fname >"$outfile" 2>&1
+	$ccheck $opt $fname >"$outfile" 2>&1
 	rc=$?
 	if [ .$rc == .0 ]; then
Index: tools/travis.sh
===================================================================
--- tools/travis.sh	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ tools/travis.sh	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,213 @@
+#!/bin/sh
+
+#
+# Copyright (c) 2018 Vojtech Horky
+# 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.
+#
+
+#
+# This is wrapper script for testing build of HelenOS under Travis CI [1].
+#
+# You probably do not want to run this script directly. If you wish to test
+# that HelenOS builds for all architectures, consider using either check.sh
+# script or running our CI solution [2] (if you want to test ported software
+# too).
+#
+# [1] https://travis-ci.org/
+# [2] http://www.helenos.org/wiki/CI
+#
+
+H_ARCH_CONFIG_CROSS_TARGET=2
+H_ARCH_CONFIG_OUTPUT_FILENAME=3
+
+h_get_arch_config_space() {
+    cat <<'EOF_CONFIG_SPACE'
+amd64:amd64-unknown-elf:image.iso
+arm32/beagleboardxm:arm-linux-gnueabi:uImage.bin
+arm32/beaglebone:arm-linux-gnueabi:uImage.bin
+arm32/gta02:arm-linux-gnueabi:uImage.bin
+arm32/integratorcp:arm-linux-gnueabi:image.boot
+arm32/raspberrypi:arm-linux-gnueabi:uImage.bin
+ia32:i686-pc-linux-gnu:image.iso
+ia64/i460GX:ia64-pc-linux-gnu:image.boot
+ia64/ski:ia64-pc-linux-gnu:image.boot
+mips32/malta-be:mips-linux-gnu:image.boot
+mips32/malta-le:mipsel-linux-gnu:image.boot
+mips32/msim:mipsel-linux-gnu:image.boot
+ppc32:ppc-linux-gnu:image.iso
+sparc64/niagara:sparc64-linux-gnu:image.iso
+sparc64/ultra:sparc64-linux-gnu:image.iso
+EOF_CONFIG_SPACE
+}
+
+h_get_arch_config() {
+    h_get_arch_config_space | grep "^$H_ARCH:" | cut '-d:' -f "$1"
+}
+
+H_DEFAULT_HARBOURS_LIST="binutils fdlibm jainja libgmp libiconv msim pcc zlib libisl libmpfr libpng python2 libmpc gcc"
+
+
+
+#
+# main script starts here
+#
+
+# Check we are actually running inside Travis
+if [ -z "$TRAVIS" ]; then
+    echo "\$TRAVIS env not set. Are you running me inside Travis?" >&2
+    exit 5
+fi
+
+# Check HelenOS configuration was set-up
+if [ -z "$H_ARCH" ]; then
+    echo "\$H_ARCH env not set. Are you running me inside Travis?" >&2
+    exit 5
+fi
+
+# Check cross-compiler target
+H_CROSS_TARGET=`h_get_arch_config $H_ARCH_CONFIG_CROSS_TARGET`
+if [ -z "$H_CROSS_TARGET" ]; then
+    echo "No suitable cross-target found for '$H_ARCH.'" >&2
+    exit 1
+fi
+
+
+# Custom CROSS_PREFIX
+export CROSS_PREFIX=/usr/local/cross-static/
+
+# Default Harbours repository
+if [ -z "$H_HARBOURS_REPOSITORY" ]; then
+    H_HARBOURS_REPOSITORY="https://github.com/HelenOS/harbours.git"
+fi
+
+if [ "$1" = "help" ]; then
+    echo
+    echo "Following variables needs to be set prior running this script."
+    echo "Example settings follows:"
+    echo
+    echo "export H_ARCH=$H_ARCH"
+    echo "export TRAVIS_BUILD_ID=`date +%s`"
+    echo
+    echo "export H_HARBOURS=true"
+    echo "export H_HARBOUR_LIST=\"$H_DEFAULT_HARBOURS_LIST\""
+    echo
+    exit 0
+
+elif [ "$1" = "install" ]; then
+    set -x
+    
+    # Install dependencies
+    sudo apt-get -qq update || exit 1
+    sudo apt-get install -y genisoimage || exit 1
+
+    # Fetch and install cross-compiler
+    wget "http://ci.helenos.org/download/helenos-cross-$H_CROSS_TARGET.static.tar.xz" -O "/tmp/cross-$H_CROSS_TARGET.static.tar.xz" || exit 1
+    sudo mkdir -p "$CROSS_PREFIX" || exit 1
+    sudo tar -xJ -C "$CROSS_PREFIX" -f "/tmp/cross-$H_CROSS_TARGET.static.tar.xz" || exit 1
+    exit 0
+
+
+elif [ "$1" = "run" ]; then
+    set -x
+    
+    # Expected output filename (bootable image)
+    H_OUTPUT_FILENAME=`h_get_arch_config $H_ARCH_CONFIG_OUTPUT_FILENAME`
+    if [ -z "$H_OUTPUT_FILENAME" ]; then
+        echo "No suitable output image found for '$H_ARCH.'" >&2
+        exit 1
+    fi
+
+    # Build HARBOURs too?
+    H_HARBOURS=`echo "$H_HARBOURS" | grep -e '^true$' -e '^false$'`
+    if [ -z "$H_HARBOURS" ]; then
+        H_HARBOURS=false
+    fi
+    if [ -z "$H_HARBOUR_LIST" ]; then
+        H_HARBOUR_LIST="$H_DEFAULT_HARBOURS_LIST"
+    fi
+
+	
+    # Build it
+    make "PROFILE=$H_ARCH" HANDS_OFF=y || exit 1
+    test -s "$H_OUTPUT_FILENAME" || exit 1
+    
+    echo
+    echo "HelenOS for $H_ARCH built okay."
+    echo
+
+    # Build harbours
+    if $H_HARBOURS; then
+        echo
+        echo "Will try to build ported software for $H_ARCH."
+        echo "Repository used is $H_HARBOURS_REPOSITORY."
+        echo
+        
+        H_HELENOS_HOME=`pwd`
+        cd "$HOME" || exit 1
+        git clone --depth 10 "$H_HARBOURS_REPOSITORY" helenos-harbours || exit 1
+        mkdir "build-harbours-$TRAVIS_BUILD_ID" || exit 1
+        (
+            cd "build-harbours-$TRAVIS_BUILD_ID" || exit 1
+            mkdir build || exit 1
+            cd build
+
+            (
+                #[ "$H_ARCH" = "mips32/malta-be" ] && H_ARCH="mips32eb/malta-be"
+                echo "root = $H_HELENOS_HOME"
+                echo "arch =" `echo "$H_ARCH" | cut -d/ -f 1`
+                echo "machine =" `echo "$H_ARCH" | cut -d/ -f 2`
+            ) >hsct.conf || exit 1
+            
+            # "$HOME/helenos-harbours/hsct.sh" init "$H_HELENOS_HOME" "$H_ARCH" build >/dev/null 2>/dev/null || exit 1
+            
+            "$HOME/helenos-harbours/hsct.sh" update || exit 1
+
+            FAILED_HARBOURS=""    
+            for HARBOUR in $H_HARBOUR_LIST; do
+                "$HOME/helenos-harbours/hsct.sh" archive --no-deps "$HARBOUR" >"run-$HARBOUR.log" 2>&1
+                if [ $? -eq 0 ]; then
+                    tail -n 10 "run-$HARBOUR.log"
+                else
+                    FAILED_HARBOURS="$FAILED_HARBOURS $HARBOUR"
+                    cat build/$HARBOUR/*/config.log
+                    tail -n 100 "run-$HARBOUR.log"
+                fi
+                
+            done
+            
+            if [ -n "$FAILED_HARBOURS" ]; then
+                echo
+                echo "ERROR: following packages were not built:$FAILED_HARBOURS."
+                echo
+                exit 1
+            fi
+        ) || exit 1
+    fi
+else
+    echo "Invalid action specified." >&2
+    exit 5
+fi
+
Index: uspace/Makefile.common
===================================================================
--- uspace/Makefile.common	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/Makefile.common	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -175,6 +175,6 @@
 
 COMMON_CFLAGS = $(INCLUDES_FLAGS) -O$(OPTIMIZATION) -imacros $(CONFIG_HEADER) \
-	-ffreestanding -fno-builtin -nostdlib -nostdinc -fexec-charset=UTF-8 \
-	-finput-charset=UTF-8 -D__$(ENDIANESS)__ -fno-common \
+	-ffreestanding -nostdlib -nostdinc -fexec-charset=UTF-8 \
+	-finput-charset=UTF-8 -D__$(ENDIANESS)__ -D_HELENOS_SOURCE -fno-common \
 	-fdebug-prefix-map=$(realpath $(ROOT_PATH))=.
 
Index: uspace/app/bdsh/cmds/builtins/batch/batch.c
===================================================================
--- uspace/app/bdsh/cmds/builtins/batch/batch.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/builtins/batch/batch.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -32,4 +32,5 @@
 #include <stddef.h>
 #include <errno.h>
+#include <str.h>
 #include "config.h"
 #include "util.h"
Index: uspace/app/bdsh/cmds/modules/cat/cat.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cat/cat.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -215,5 +215,5 @@
 
 	if (tail != CAT_FULL_FILE) {
-		struct stat st;
+		vfs_stat_t st;
 
 		if (vfs_stat(fd, &st) != EOK) {
Index: uspace/app/bdsh/cmds/modules/cp/cp.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cp/cp.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/cp/cp.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -80,5 +80,5 @@
 static dentry_type_t get_type(const char *path)
 {
-	struct stat s;
+	vfs_stat_t s;
 
 	errno_t r = vfs_stat_path(path, &s);
@@ -340,6 +340,6 @@
 		 */
 		while ((dp = readdir(dir))) {
-			struct stat src_s;
-			struct stat dest_s;
+			vfs_stat_t src_s;
+			vfs_stat_t dest_s;
 
 			char src_dent[PATH_MAX];
@@ -392,5 +392,5 @@
 	char *buff = NULL;
 	aoff64_t posr = 0, posw = 0;
-	struct stat st;
+	vfs_stat_t st;
 
 	if (vb)
Index: uspace/app/bdsh/cmds/modules/ls/ls.h
===================================================================
--- uspace/app/bdsh/cmds/modules/ls/ls.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/ls/ls.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -23,5 +23,5 @@
 struct dir_elem_t {
 	char *name;
-	struct stat s;
+	vfs_stat_t s;
 };
 
Index: uspace/app/bdsh/cmds/modules/mount/mount.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mount/mount.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/mount/mount.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <getopt.h>
 #include <inttypes.h>
+#include <str.h>
 #include "config.h"
 #include "util.h"
Index: uspace/app/bdsh/cmds/modules/sleep/sleep.c
===================================================================
--- uspace/app/bdsh/cmds/modules/sleep/sleep.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/sleep/sleep.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -31,4 +31,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include "config.h"
 #include "util.h"
Index: uspace/app/bdsh/cmds/modules/touch/touch.c
===================================================================
--- uspace/app/bdsh/cmds/modules/touch/touch.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/cmds/modules/touch/touch.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -82,5 +82,5 @@
 	int longind;
 	bool no_create = false;
-	struct stat file_stat;
+	vfs_stat_t file_stat;
 	int fd = -1;
 	char *buff = NULL;
Index: uspace/app/bdsh/compl.c
===================================================================
--- uspace/app/bdsh/compl.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/compl.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,4 +34,5 @@
 #include <stdlib.h>
 #include <vfs/vfs.h>
+#include <str.h>
 
 #include "cmds/cmds.h"
@@ -68,7 +69,7 @@
 
 	/** Pointer inside list of directories */
-	const char **path;
+	const char *const *path;
 	/** If not @c NULL, should be freed in the end. */
-	const char **path_list;
+	char **path_list;
 	/** Current open directory */
 	DIR *dir;
@@ -218,5 +219,7 @@
 		cs->path_list[0] = dirname;
 		cs->path_list[1] = NULL;
-		cs->path = cs->path_list;
+		/* The second const ensures that we can't assign a const
+		 * string to the non-const array. */
+		cs->path = (const char *const *) cs->path_list;
 
 	} else if (cs->is_command) {
@@ -359,5 +362,5 @@
 				char *ent_path;
 				asprintf(&ent_path, "%s/%s", *cs->path, dent->d_name);
-				struct stat ent_stat;
+				vfs_stat_t ent_stat;
 				if (vfs_stat_path(ent_path, &ent_stat) != EOK) {
 					/* Error */
Index: uspace/app/bdsh/errors.h
===================================================================
--- uspace/app/bdsh/errors.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/errors.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,5 @@
 
 extern void cli_error(int, const char *, ...)
-    PRINTF_ATTRIBUTE(2, 3);
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 
 #endif
Index: uspace/app/bdsh/tok.h
===================================================================
--- uspace/app/bdsh/tok.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bdsh/tok.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 	size_t byte_length;
 	size_t char_length;
- 	token_type_t type;
+	token_type_t type;
 } token_t;
 
Index: uspace/app/blkdump/blkdump.c
===================================================================
--- uspace/app/blkdump/blkdump.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/blkdump/blkdump.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,4 +49,5 @@
 #include <inttypes.h>
 #include <errno.h>
+#include <str.h>
 
 #define NAME	"blkdump"
Index: uspace/app/bnchmark/bnchmark.c
===================================================================
--- uspace/app/bnchmark/bnchmark.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/bnchmark/bnchmark.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,4 +49,5 @@
 #include <time.h>
 #include <dirent.h>
+#include <str.h>
 
 #define NAME	"bnchmark"
Index: uspace/app/corecfg/corecfg.c
===================================================================
--- uspace/app/corecfg/corecfg.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/corecfg/corecfg.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,5 @@
 #include <errno.h>
 #include <stdio.h>
+#include <str.h>
 
 #define NAME "corecfg"
Index: uspace/app/date/date.c
===================================================================
--- uspace/app/date/date.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/date/date.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,5 @@
 #include <getopt.h>
 #include <ctype.h>
+#include <str.h>
 
 #define NAME   "date"
Index: uspace/app/devctl/devctl.c
===================================================================
--- uspace/app/devctl/devctl.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/devctl/devctl.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,4 +39,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/app/df/df.c
===================================================================
--- uspace/app/df/df.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/df/df.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -58,5 +58,5 @@
 static errno_t size_to_human_readable(uint64_t, size_t, char **);
 static void print_header(void);
-static errno_t print_statfs(struct statfs *, char *, char *);
+static errno_t print_statfs(vfs_statfs_t *, char *, char *);
 static void print_usage(void);
 
@@ -64,5 +64,5 @@
 {
 	int optres, errflg = 0;
-	struct statfs st;
+	vfs_statfs_t st;
 	errno_t rc;
 
@@ -147,5 +147,5 @@
 }
 
-static errno_t print_statfs(struct statfs *st, char *name, char *mountpoint)
+static errno_t print_statfs(vfs_statfs_t *st, char *name, char *mountpoint)
 {
 	uint64_t const used_blocks = st->f_blocks - st->f_bfree;
Index: uspace/app/dltest/dltest.c
===================================================================
--- uspace/app/dltest/dltest.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/dltest/dltest.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,4 +41,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 /** libdltest library handle */
Index: uspace/app/dnscfg/dnscfg.c
===================================================================
--- uspace/app/dnscfg/dnscfg.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/dnscfg/dnscfg.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,4 +43,5 @@
 #include <stdlib.h>
 #include <stdint.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/app/dnsres/dnsres.c
===================================================================
--- uspace/app/dnsres/dnsres.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/dnsres/dnsres.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,4 +38,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 #define NAME  "dnsres"
Index: uspace/app/edit/search_impl.h
===================================================================
--- uspace/app/edit/search_impl.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/edit/search_impl.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,5 +43,5 @@
 	/* Note: This structure is opaque for the user. */
 
-	const wchar_t *pattern;
+	wchar_t *pattern;
 	size_t pattern_length;
 	ssize_t *back_table;
Index: uspace/app/fdisk/fdisk.c
===================================================================
--- uspace/app/fdisk/fdisk.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/fdisk/fdisk.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <stdlib.h>
 #include <fdisk.h>
+#include <str.h>
 
 #define NO_LABEL_CAPTION "(No name)"
Index: uspace/app/fontviewer/fontviewer.c
===================================================================
--- uspace/app/fontviewer/fontviewer.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/fontviewer/fontviewer.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -139,5 +139,5 @@
 
 static int text(drawctx_t *, font_t *, source_t *, surface_coord_t x,
-    surface_coord_t , const char *, ...) PRINTF_ATTRIBUTE(6, 7);
+    surface_coord_t , const char *, ...) _HELENOS_PRINTF_ATTRIBUTE(6, 7);
 static int text(drawctx_t *drawctx, font_t *font, source_t *source,
     surface_coord_t x, surface_coord_t y, const char *fmt, ...)
Index: uspace/app/getterm/getterm.c
===================================================================
--- uspace/app/getterm/getterm.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/getterm/getterm.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <loc.h>
 #include <vfs/vfs.h>
+#include <str.h>
 #include "version.h"
 #include "welcome.h"
Index: uspace/app/inet/inet.c
===================================================================
--- uspace/app/inet/inet.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/inet/inet.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,4 +43,5 @@
 #include <stdlib.h>
 #include <stdint.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/init/init.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -152,5 +152,5 @@
 static errno_t srv_startl(const char *path, ...)
 {
-	struct stat s;
+	vfs_stat_t s;
 	if (vfs_stat_path(path, &s) != EOK) {
 		printf("%s: Unable to stat %s\n", NAME, path);
Index: uspace/app/kill/kill.c
===================================================================
--- uspace/app/kill/kill.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/kill/kill.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <stdio.h>
 #include <task.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/app/killall/killall.c
===================================================================
--- uspace/app/killall/killall.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/killall/killall.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,4 +40,5 @@
 #include <str_error.h>
 #include <stdlib.h>
+#include <str.h>
 
 #define NAME  "killall"
Index: uspace/app/mixerctl/mixerctl.c
===================================================================
--- uspace/app/mixerctl/mixerctl.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/mixerctl/mixerctl.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,5 @@
 static void print_levels(async_exch_t *exch)
 {
-	const char* name = NULL;
+	char* name = NULL;
 	unsigned count = 0;
 	errno_t ret = audio_mixer_get_info(exch, &name, &count);
@@ -59,5 +59,5 @@
 
 	for (unsigned i = 0; i < count; ++i) {
-		const char *name = NULL;
+		char *name = NULL;
 		unsigned levels = 0, current = 0;
 		errno_t ret =
Index: uspace/app/mkfat/mkfat.c
===================================================================
--- uspace/app/mkfat/mkfat.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/mkfat/mkfat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,4 +48,5 @@
 #include <inttypes.h>
 #include <errno.h>
+#include <str.h>
 #include "fat.h"
 #include "fat_dentry.h"
Index: uspace/app/netecho/comm.c
===================================================================
--- uspace/app/netecho/comm.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/netecho/comm.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,4 +44,5 @@
 #include <stdlib.h>
 #include <stdint.h>
+#include <str.h>
 #include <str_error.h>
 
Index: pace/app/netstart/self_test.c
===================================================================
--- uspace/app/netstart/self_test.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,334 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-/** @file
- * Networking self-tests implementation.
- *
- */
-
-#include <errno.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include <net_checksum.h>
-#include <adt/int_map.h>
-#include <adt/char_map.h>
-#include <adt/generic_char_map.h>
-#include <adt/measured_strings.h>
-#include <adt/dynamic_fifo.h>
-
-#include "self_test.h"
-
-/** Test the statement, compare the result and evaluate.
- *
- * @param[in] statement The statement to test.
- * @param[in] result    The expected result.
- *
- */
-#define TEST(statement, result) \
-	do { \
-		printf("\n\t%s == %s", #statement, #result); \
-		if ((statement) != (result)) { \
-			printf("\tfailed\n"); \
-			fprintf(stderr, "\nNetwork self-test failed\n"); \
-			return EINVAL; \
-		} else \
-			printf("\tOK"); \
-	} while (0)
-
-#define XMALLOC(var, type) \
-	do { \
-		(var) = (type *) malloc(sizeof(type)); \
-		if ((var) == NULL) { \
-			fprintf(stderr, "\nMemory allocation error\n"); \
-			return ENOMEM; \
-		} \
-	} while (0)
-
-GENERIC_CHAR_MAP_DECLARE(int_char_map, int);
-GENERIC_CHAR_MAP_IMPLEMENT(int_char_map, int);
-
-GENERIC_FIELD_DECLARE(int_field, int);
-GENERIC_FIELD_IMPLEMENT(int_field, int);
-
-INT_MAP_DECLARE(int_map, int);
-INT_MAP_IMPLEMENT(int_map, int);
-
-/** Self-test start function.
- *
- * Run all self-tests.
- *
- * @returns EOK on success.
- * @returns The first error occurred.
- *
- */
-errno_t self_test(void)
-{
-	printf("Running networking self-tests\n");
-	
-	printf("\nChar map test");
-	char_map_t cm;
-	
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	TEST(char_map_initialize(&cm), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_add(&cm, "bla", 0, 1), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 1);
-	TEST(char_map_add(&cm, "bla", 0, 10), EEXISTS);
-	TEST(char_map_update(&cm, "bla", 0, 2), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 2), EOK);
-	TEST(char_map_exclude(&cm, "bla", 0), 2);
-	TEST(char_map_exclude(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "ucho", 0), 2);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EOK);
-	TEST(char_map_find(&cm, "ucho", 0), 3);
-	TEST(char_map_add(&cm, "blabla", 0, 5), EOK);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "bla", 0, 6), EOK);
-	TEST(char_map_find(&cm, "bla", 0), 6);
-	TEST(char_map_exclude(&cm, "bla", 0), 6);
-	TEST(char_map_find(&cm, "bla", 0), CHAR_MAP_NULL);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "auto", 0, 7), EOK);
-	TEST(char_map_find(&cm, "auto", 0), 7);
-	TEST(char_map_add(&cm, "kara", 0, 8), EOK);
-	TEST(char_map_find(&cm, "kara", 0), 8);
-	TEST(char_map_add(&cm, "nic", 0, 9), EOK);
-	TEST(char_map_find(&cm, "nic", 0), 9);
-	TEST(char_map_find(&cm, "blabla", 0), 5);
-	TEST(char_map_add(&cm, "micnicnic", 5, 9), EOK);
-	TEST(char_map_find(&cm, "micni", 0), 9);
-	TEST(char_map_find(&cm, "micnicn", 5), 9);
-	TEST(char_map_add(&cm, "\x10\x0\x2\x2", 4, 15), EOK);
-	TEST(char_map_find(&cm, "\x10\x0\x2\x2", 4), 15);
-	
-	TEST((char_map_destroy(&cm), EOK), EOK);
-	TEST(char_map_update(&cm, "ucho", 0, 3), EINVAL);
-	
-	printf("\nCRC computation test");
-	uint32_t value;
-	
-	TEST(value = ~compute_crc32(~0, "123456789", 8 * 9), 0xcbf43926);
-	TEST(value = ~compute_crc32(~0, "1", 8), 0x83dcefb7);
-	TEST(value = ~compute_crc32(~0, "12", 8 * 2), 0x4f5344cd);
-	TEST(value = ~compute_crc32(~0, "123", 8 * 3), 0x884863d2);
-	TEST(value = ~compute_crc32(~0, "1234", 8 * 4), 0x9be3e0a3);
-	TEST(value = ~compute_crc32(~0, "12345678", 8 * 8), 0x9ae0daaf);
-	TEST(value = ~compute_crc32(~0, "ahoj pane", 8 * 9), 0x5fc3d706);
-	
-	printf("\nDynamic fifo test");
-	dyn_fifo_t fifo;
-	
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	TEST(dyn_fifo_initialize(&fifo, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 1);
-	TEST(dyn_fifo_pop(&fifo), ENOENT);
-	TEST(dyn_fifo_push(&fifo, 2, 1), EOK);
-	TEST(dyn_fifo_push(&fifo, 3, 1), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 3, 0), EOK);
-	TEST(dyn_fifo_pop(&fifo), 2);
-	TEST(dyn_fifo_pop(&fifo), 3);
-	TEST(dyn_fifo_push(&fifo, 4, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 5, 2), EOK);
-	TEST(dyn_fifo_push(&fifo, 6, 2), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 6, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 7, 5), EOK);
-	TEST(dyn_fifo_pop(&fifo), 4);
-	TEST(dyn_fifo_pop(&fifo), 5);
-	TEST(dyn_fifo_push(&fifo, 8, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 9, 5), EOK);
-	TEST(dyn_fifo_push(&fifo, 10, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 11, 6), EOK);
-	TEST(dyn_fifo_pop(&fifo), 6);
-	TEST(dyn_fifo_pop(&fifo), 7);
-	TEST(dyn_fifo_push(&fifo, 12, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 13, 6), EOK);
-	TEST(dyn_fifo_push(&fifo, 14, 6), ENOMEM);
-	TEST(dyn_fifo_push(&fifo, 14, 8), EOK);
-	TEST(dyn_fifo_pop(&fifo), 8);
-	TEST(dyn_fifo_pop(&fifo), 9);
-	TEST(dyn_fifo_pop(&fifo), 10);
-	TEST(dyn_fifo_pop(&fifo), 11);
-	TEST(dyn_fifo_pop(&fifo), 12);
-	TEST(dyn_fifo_pop(&fifo), 13);
-	TEST(dyn_fifo_pop(&fifo), 14);
-	TEST(dyn_fifo_destroy(&fifo), EOK);
-	TEST(dyn_fifo_push(&fifo, 1, 0), EINVAL);
-	
-	printf("\nGeneric char map test");
-	
-	int *x;
-	int *y;
-	int *z;
-	int *u;
-	int *v;
-	int *w;
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_char_map_t icm;
-	icm.magic = 0;
-	
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	TEST(int_char_map_initialize(&icm), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_add(&icm, "bla", 0, x), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), x);
-	TEST(int_char_map_add(&icm, "bla", 0, y), EEXISTS);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_add(&icm, "blabla", 0, v), EOK);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "bla", 0, w), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), w);
-	TEST((int_char_map_exclude(&icm, "bla", 0), EOK), EOK);
-	TEST(int_char_map_find(&icm, "bla", 0), NULL);
-	TEST(int_char_map_find(&icm, "blabla", 0), v);
-	TEST(int_char_map_add(&icm, "auto", 0, u), EOK);
-	TEST(int_char_map_find(&icm, "auto", 0), u);
-	TEST((int_char_map_destroy(&icm), EOK), EOK);
-	TEST(int_char_map_add(&icm, "ucho", 0, z), EINVAL);
-	
-	printf("\nGeneric field test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_field_t gf;
-	gf.magic = 0;
-	
-	TEST(int_field_add(&gf, x), EINVAL);
-	TEST(int_field_count(&gf), -1);
-	TEST(int_field_initialize(&gf), EOK);
-	TEST(int_field_count(&gf), 0);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_add(&gf, x), 0);
-	TEST(int_field_get_index(&gf, 0), x);
-	TEST((int_field_exclude_index(&gf, 0), EOK), EOK);
-	TEST(int_field_get_index(&gf, 0), NULL);
-	TEST(int_field_add(&gf, y), 1);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_add(&gf, z), 2);
-	TEST(int_field_get_index(&gf, 2), z);
-	TEST(int_field_get_index(&gf, 1), y);
-	TEST(int_field_count(&gf), 3);
-	TEST(int_field_add(&gf, u), 3);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_add(&gf, v), 4);
-	TEST(int_field_get_index(&gf, 4), v);
-	TEST(int_field_add(&gf, w), 5);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST(int_field_count(&gf), 6);
-	TEST((int_field_exclude_index(&gf, 1), EOK), EOK);
-	TEST(int_field_get_index(&gf, 1), NULL);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST((int_field_exclude_index(&gf, 7), EOK), EOK);
-	TEST(int_field_get_index(&gf, 3), u);
-	TEST(int_field_get_index(&gf, 5), w);
-	TEST((int_field_exclude_index(&gf, 4), EOK), EOK);
-	TEST(int_field_get_index(&gf, 4), NULL);
-	TEST((int_field_destroy(&gf), EOK), EOK);
-	TEST(int_field_count(&gf), -1);
-	
-	printf("\nInt map test");
-	
-	XMALLOC(x, int);
-	XMALLOC(y, int);
-	XMALLOC(z, int);
-	XMALLOC(u, int);
-	XMALLOC(v, int);
-	XMALLOC(w, int);
-	
-	int_map_t im;
-	im.magic = 0;
-	
-	TEST(int_map_add(&im, 1, x), EINVAL);
-	TEST(int_map_count(&im), -1);
-	TEST(int_map_initialize(&im), EOK);
-	TEST(int_map_count(&im), 0);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, x), 0);
-	TEST(int_map_find(&im, 1), x);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_add(&im, 1, y), 1);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_add(&im, 4, z), 2);
-	TEST(int_map_get_index(&im, 2), z);
-	TEST(int_map_find(&im, 4), z);
-	TEST(int_map_find(&im, 1), y);
-	TEST(int_map_count(&im), 3);
-	TEST(int_map_add(&im, 2, u), 3);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_add(&im, 3, v), 4);
-	TEST(int_map_find(&im, 3), v);
-	TEST(int_map_get_index(&im, 4), v);
-	TEST(int_map_add(&im, 6, w), 5);
-	TEST(int_map_find(&im, 6), w);
-	TEST(int_map_count(&im), 6);
-	TEST((int_map_exclude(&im, 1), EOK), EOK);
-	TEST(int_map_find(&im, 1), NULL);
-	TEST(int_map_find(&im, 2), u);
-	TEST((int_map_exclude(&im, 7), EOK), EOK);
-	TEST(int_map_find(&im, 2), u);
-	TEST(int_map_find(&im, 6), w);
-	TEST((int_map_exclude_index(&im, 4), EOK), EOK);
-	TEST(int_map_get_index(&im, 4), NULL);
-	TEST(int_map_find(&im, 3), NULL);
-	TEST((int_map_destroy(&im), EOK), EOK);
-	TEST(int_map_count(&im), -1);
-	
-	printf("\nMeasured strings test");
-	
-	measured_string_ref string =
-	    measured_string_create_bulk("I am a measured string!", 0);
-	printf("\n%x, %s at %x of %d\n", string, string->value, string->value,
-	    string->length);
-	
-	return EOK;
-}
-
-/** @}
- */
Index: pace/app/netstart/self_test.h
===================================================================
--- uspace/app/netstart/self_test.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,41 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 net
- * @{
- */
-
-#ifndef __SELF_TEST_H__
-#define __SELF_TEST_H__
-
-extern errno_t self_test(void);
-
-#endif
-
-/** @}
- */
Index: uspace/app/nic/nic.c
===================================================================
--- uspace/app/nic/nic.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/nic/nic.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,4 +40,5 @@
 #include <stdlib.h>
 #include <stddef.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/app/nterm/nterm.c
===================================================================
--- uspace/app/nterm/nterm.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/nterm/nterm.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <io/console.h>
 #include <stdio.h>
+#include <str.h>
 
 #include "conn.h"
Index: uspace/app/pkg/pkg.c
===================================================================
--- uspace/app/pkg/pkg.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/pkg/pkg.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,4 +39,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <str_error.h>
 #include <task.h>
Index: uspace/app/rcubench/rcubench.c
===================================================================
--- uspace/app/rcubench/rcubench.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/rcubench/rcubench.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <compiler/barrier.h>
 #include <futex.h>
+#include <str.h>
 
 #include <rcu.h>
Index: uspace/app/rcutest/rcutest.c
===================================================================
--- uspace/app/rcutest/rcutest.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/rcutest/rcutest.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,4 +48,5 @@
 #include <compiler/barrier.h>
 #include <futex.h>
+#include <str.h>
 
 #include <rcu.h>
Index: uspace/app/sportdmp/sportdmp.c
===================================================================
--- uspace/app/sportdmp/sportdmp.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/sportdmp/sportdmp.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -33,4 +33,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 #define BUF_SIZE 1
Index: uspace/app/sysinfo/sysinfo.c
===================================================================
--- uspace/app/sysinfo/sysinfo.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/sysinfo/sysinfo.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,4 +40,5 @@
 #include <sysinfo.h>
 #include <stdlib.h>
+#include <str.h>
 
 static void dump_bytes_hex(char *data, size_t size)
Index: uspace/app/sysinst/futil.c
===================================================================
--- uspace/app/sysinst/futil.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/sysinst/futil.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -108,5 +108,5 @@
 	DIR *dir;
 	struct dirent *de;
-	struct stat s;
+	vfs_stat_t s;
 	char *srcp, *destp;
 	errno_t rc;
@@ -165,5 +165,5 @@
 	size_t fsize;
 	char *data;
-	struct stat st;
+	vfs_stat_t st;
 
 	rc = vfs_lookup_open(srcp, WALK_REGULAR, MODE_READ, &sf);
Index: uspace/app/sysinst/sysinst.c
===================================================================
--- uspace/app/sysinst/sysinst.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/sysinst/sysinst.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <task.h>
 #include <vfs/vfs.h>
+#include <str.h>
 
 #include "futil.h"
Index: uspace/app/taskdump/elf_core.c
===================================================================
--- uspace/app/taskdump/elf_core.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/taskdump/elf_core.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -62,4 +62,5 @@
 #include <libarch/istate.h>
 #include <vfs/vfs.h>
+#include <str.h>
 
 #include "elf_core.h"
Index: uspace/app/taskdump/symtab.c
===================================================================
--- uspace/app/taskdump/symtab.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/taskdump/symtab.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,4 +41,5 @@
 #include <stddef.h>
 #include <errno.h>
+#include <str.h>
 #include <str_error.h>
 #include <vfs/vfs.h>
Index: uspace/app/taskdump/taskdump.c
===================================================================
--- uspace/app/taskdump/taskdump.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/taskdump/taskdump.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,4 +48,5 @@
 #include <macros.h>
 #include <assert.h>
+#include <str.h>
 
 #include <symtab.h>
Index: uspace/app/tester/print/print5.c
===================================================================
--- uspace/app/tester/print/print5.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/tester/print/print5.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,5 +37,5 @@
  *
  */
-#define NVERIFY_PRINTF
+#define _HELENOS_NVERIFY_PRINTF
 
 #include <stdio.h>
Index: uspace/app/testread/testread.c
===================================================================
--- uspace/app/testread/testread.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/testread/testread.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -58,4 +58,5 @@
 #include <time.h>
 #include <offset.h>
+#include <str.h>
 
 #define NAME	"testread"
Index: uspace/app/testwrit/testwrit.c
===================================================================
--- uspace/app/testwrit/testwrit.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/testwrit/testwrit.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -33,4 +33,5 @@
 #include <stdio.h>
 #include <stddef.h>
+#include <str.h>
 
 #define BUF_SIZE  1024
Index: uspace/app/tetris/tetris.c
===================================================================
--- uspace/app/tetris/tetris.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/tetris/tetris.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -156,7 +156,7 @@
 const struct shape *randshape(void)
 {
-	const struct shape *tmp = &shapes[random() % 7];
+	const struct shape *tmp = &shapes[rand() % 7];
 	int i;
-	int j = random() % 4;
+	int j = rand() % 4;
 	
 	for (i = 0; i < j; i++)
@@ -171,5 +171,5 @@
 	
 	gettimeofday(&tv, NULL);
-	srandom(tv.tv_sec + tv.tv_usec / 100000);
+	srand(tv.tv_sec + tv.tv_usec / 100000);
 }
 
Index: uspace/app/tmon/burst_tests.c
===================================================================
--- uspace/app/tmon/burst_tests.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/tmon/burst_tests.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <stdio.h>
 #include <errno.h>
+#include <str.h>
 #include <str_error.h>
 #include <getopt.h>
Index: uspace/app/tmon/main.c
===================================================================
--- uspace/app/tmon/main.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/tmon/main.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,6 @@
 
 #include <stdio.h>
+#include <stddef.h>
+#include <str.h>
 #include <macros.h>
 #include "commands.h"
Index: uspace/app/top/screen.c
===================================================================
--- uspace/app/top/screen.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/top/screen.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,4 +45,5 @@
 #include <inttypes.h>
 #include <macros.h>
+#include <str.h>
 #include "screen.h"
 #include "top.h"
Index: uspace/app/top/screen.h
===================================================================
--- uspace/app/top/screen.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/top/screen.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,5 +45,5 @@
 extern void print_data(data_t *);
 extern void show_warning(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 
 extern int tgetchar(unsigned int);
Index: uspace/app/top/top.c
===================================================================
--- uspace/app/top/top.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/top/top.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,4 +43,5 @@
 #include <errno.h>
 #include <gsort.h>
+#include <str.h>
 #include "screen.h"
 #include "top.h"
Index: uspace/app/usbinfo/list.c
===================================================================
--- uspace/app/usbinfo/list.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/usbinfo/list.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,4 +45,5 @@
 #include <loc.h>
 #include <usb_iface.h>
+#include <str.h>
 
 #include "usbinfo.h"
Index: uspace/app/viewer/viewer.c
===================================================================
--- uspace/app/viewer/viewer.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/viewer/viewer.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,4 +44,5 @@
 #include <codec/tga.h>
 #include <task.h>
+#include <str.h>
 
 #define NAME  "viewer"
@@ -114,5 +115,5 @@
 		return false;
 	
-	struct stat stat;
+	vfs_stat_t stat;
 	rc = vfs_stat(fd, &stat);
 	if (rc != EOK) {
Index: uspace/app/wavplay/dplay.c
===================================================================
--- uspace/app/wavplay/dplay.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/wavplay/dplay.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -353,5 +353,5 @@
 	}
 
-	const char* info = NULL;
+	char* info = NULL;
 	ret = audio_pcm_get_info_str(session, &info);
 	if (ret != EOK) {
Index: uspace/app/wavplay/drec.c
===================================================================
--- uspace/app/wavplay/drec.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/wavplay/drec.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <as.h>
 #include <inttypes.h>
+#include <str.h>
 
 #include "wave.h"
@@ -194,5 +195,5 @@
 	}
 
-	const char* info = NULL;
+	char* info = NULL;
 	ret = audio_pcm_get_info_str(session, &info);
 	if (ret != EOK) {
Index: uspace/app/wifi_supplicant/wifi_supplicant.c
===================================================================
--- uspace/app/wifi_supplicant/wifi_supplicant.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/app/wifi_supplicant/wifi_supplicant.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,4 +41,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <str_error.h>
 #include <loc.h>
Index: uspace/dist/src/c/demos/tetris/tetris.c
===================================================================
--- uspace/dist/src/c/demos/tetris/tetris.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/dist/src/c/demos/tetris/tetris.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -157,7 +157,7 @@
 const struct shape *randshape(void)
 {
-	const struct shape *tmp = &shapes[random() % 7];
+	const struct shape *tmp = &shapes[rand() % 7];
 	int i;
-	int j = random() % 4;
+	int j = rand() % 4;
 	
 	for (i = 0; i < j; i++)
@@ -172,5 +172,5 @@
 	
 	gettimeofday(&tv, NULL);
-	srandom(tv.tv_sec + tv.tv_usec / 100000);
+	srand(tv.tv_sec + tv.tv_usec / 100000);
 }
 
Index: uspace/dist/src/c/demos/top/screen.h
===================================================================
--- uspace/dist/src/c/demos/top/screen.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/dist/src/c/demos/top/screen.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,5 +45,5 @@
 extern void print_data(data_t *);
 extern void show_warning(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 
 extern errno_t tgetchar(unsigned int);
Index: uspace/drv/audio/hdaudio/spec/regs.h
===================================================================
--- uspace/drv/audio/hdaudio/spec/regs.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/audio/hdaudio/spec/regs.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -64,5 +64,5 @@
 	/** Buffer Descriptor List Pointer - Lower */
 	uint32_t bdpl;
-	/** Buffer Descriptor List Pointer - Upper */ 
+	/** Buffer Descriptor List Pointer - Upper */
 	uint32_t bdpu;
 } hda_sdesc_regs_t;
Index: uspace/drv/audio/sb16/dsp.h
===================================================================
--- uspace/drv/audio/sb16/dsp.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/audio/sb16/dsp.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -82,8 +82,8 @@
 errno_t sb_dsp_get_buffer_position(sb_dsp_t *dsp, size_t *size);
 errno_t sb_dsp_test_format(sb_dsp_t *dsp, unsigned *channels, unsigned *rate,
-  pcm_sample_format_t *format);
+    pcm_sample_format_t *format);
 errno_t sb_dsp_get_buffer(sb_dsp_t *dsp, void **buffer, size_t *size);
 errno_t sb_dsp_set_event_session(sb_dsp_t *dsp, async_sess_t *session);
-async_sess_t * sb_dsp_get_event_session(sb_dsp_t *dsp);
+async_sess_t *sb_dsp_get_event_session(sb_dsp_t *dsp);
 errno_t sb_dsp_release_buffer(sb_dsp_t *dsp);
 errno_t sb_dsp_start_playback(sb_dsp_t *dsp, unsigned frames,
Index: uspace/drv/audio/sb16/mixer.h
===================================================================
--- uspace/drv/audio/sb16/mixer.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/audio/sb16/mixer.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -50,5 +50,5 @@
 } sb_mixer_t;
 
-const char * sb_mixer_type_str(sb_mixer_type_t type);
+const char *sb_mixer_type_str(sb_mixer_type_t type);
 errno_t sb_mixer_init(sb_mixer_t *mixer, sb16_regs_t *regs, sb_mixer_type_t type);
 int sb_mixer_get_control_item_count(const sb_mixer_t *mixer);
Index: uspace/drv/bus/isa/isa.c
===================================================================
--- uspace/drv/bus/isa/isa.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/bus/isa/isa.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -279,5 +279,5 @@
 	errno_t rc;
 	size_t nread;
-	struct stat st;
+	vfs_stat_t st;
 
 	rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd);
Index: uspace/drv/bus/usb/vhc/hub/virthub.c
===================================================================
--- uspace/drv/bus/usb/vhc/hub/virthub.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/bus/usb/vhc/hub/virthub.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <ddf/driver.h>
 
@@ -155,14 +156,16 @@
 	dev->descriptors = &descriptors;
 	dev->address = 0;
-	dev->name = str_dup(name);
-	if (!dev->name)
+
+	char *n = str_dup(name);
+	if (!n)
 		return ENOMEM;
 
 	hub_t *hub = malloc(sizeof(hub_t));
 	if (hub == NULL) {
-		free(dev->name);
+		free(n);
 		return ENOMEM;
 	}
 
+	dev->name = n;
 	hub_init(hub);
 	dev->device_data = hub;
Index: uspace/drv/hid/atkbd/atkbd.h
===================================================================
--- uspace/drv/hid/atkbd/atkbd.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/hid/atkbd/atkbd.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,5 @@
 	chardev_t *chardev;
 	/** Callback connection to client */
-	async_sess_t *client_sess; 
+	async_sess_t *client_sess;
 	/** Fibril retrieving and parsing data */
 	fid_t polling_fibril;
Index: uspace/drv/platform/amdm37x/main.c
===================================================================
--- uspace/drv/platform/amdm37x/main.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/platform/amdm37x/main.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,6 @@
 typedef struct {
 	const char *name;
-	match_id_t match_id;
+	const char *id;
+	int score;
 	hw_resource_list_t hw_resources;
 } amdm37x_fun_t;
@@ -133,15 +134,18 @@
 {
 	.name = "ohci",
-	.match_id = { .id = "usb/host=ohci", .score = 90 },
+	.id = "usb/host=ohci",
+	.score = 90,
 	.hw_resources = { .resources = ohci_res, .count = ARRAY_SIZE(ohci_res) }
 },
 {
 	.name = "ehci",
-	.match_id = { .id = "usb/host=ehci", .score = 90 },
+	.id = "usb/host=ehci",
+	.score = 90,
 	.hw_resources = { .resources = ehci_res, .count = ARRAY_SIZE(ehci_res) }
 },
 {
 	.name = "fb",
-	.match_id = { .id = "amdm37x&dispc", .score = 90 },
+	.id = "amdm37x&dispc",
+	.score = 90,
 	.hw_resources = { .resources = disp_res, .count = ARRAY_SIZE(disp_res) }
 },
@@ -174,6 +178,5 @@
 	
 	/* Add match id */
-	errno_t ret = ddf_fun_add_match_id(fnode,
-	    fun->match_id.id, fun->match_id.score);
+	errno_t ret = ddf_fun_add_match_id(fnode, fun->id, fun->score);
 	if (ret != EOK) {
 		ddf_fun_destroy(fnode);
Index: uspace/drv/test/test1/test1.c
===================================================================
--- uspace/drv/test/test1/test1.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/test/test1/test1.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <ddf/driver.h>
 #include <ddf/log.h>
+#include <str.h>
 
 #include "test1.h"
Index: uspace/drv/test/test2/test2.c
===================================================================
--- uspace/drv/test/test2/test2.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/drv/test/test2/test2.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,4 +34,5 @@
 #include <stdio.h>
 #include <errno.h>
+#include <str.h>
 #include <str_error.h>
 #include <ddf/driver.h>
Index: uspace/lib/bithenge/include/bithenge/tree.h
===================================================================
--- uspace/lib/bithenge/include/bithenge/tree.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/bithenge/include/bithenge/tree.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,4 +39,5 @@
 
 #include <assert.h>
+#include <stdbool.h>
 #include "os.h"
 
Index: uspace/lib/bithenge/src/failure.c
===================================================================
--- uspace/lib/bithenge/src/failure.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/bithenge/src/failure.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -225,5 +225,5 @@
 }
 
-errno_t bithenge_failure_fstat(int fd, struct stat *buf)
+errno_t bithenge_failure_fstat(int fd, vfs_stat_t *buf)
 {
 	if (bithenge_should_fail()) {
Index: uspace/lib/bithenge/src/failure.h
===================================================================
--- uspace/lib/bithenge/src/failure.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/bithenge/src/failure.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,5 +52,5 @@
 char *bithenge_failure_str_ndup(const char *, size_t);
 errno_t bithenge_failure_open(const char *, int);
-errno_t bithenge_failure_fstat(int, struct stat *);
+errno_t bithenge_failure_fstat(int, vfs_stat_t *);
 
 #ifndef BITHENGE_FAILURE_DECLS_ONLY
Index: uspace/lib/bithenge/src/file.c
===================================================================
--- uspace/lib/bithenge/src/file.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/bithenge/src/file.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -102,5 +102,5 @@
 	assert(out);
 
-	struct stat stat;
+	vfs_stat_t stat;
 	errno_t rc = vfs_stat(fd, &stat);
 	if (rc != EOK) {
Index: uspace/lib/block/block.h
===================================================================
--- uspace/lib/block/block.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/block/block.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -85,5 +85,5 @@
 	/** Link for placing the block into the free block list. */
 	link_t free_link;
-	/** Link for placing the block into the block hash table. */ 
+	/** Link for placing the block into the block hash table. */
 	ht_link_t hash_link;
 	/** Buffer with the block data. */
Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/Makefile	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -85,4 +85,5 @@
 	generic/str.c \
 	generic/str_error.c \
+	generic/strtol.c \
 	generic/l18n/langs.c \
 	generic/fibril.c \
Index: uspace/lib/c/arch/ia32/include/libarch/syscall.h
===================================================================
--- uspace/lib/c/arch/ia32/include/libarch/syscall.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/arch/ia32/include/libarch/syscall.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,5 +48,5 @@
 #define __syscall6  __syscall_slow
 
-extern sysarg_t (* __syscall_fast_func)(const sysarg_t, const sysarg_t,
+extern sysarg_t (*__syscall_fast_func)(const sysarg_t, const sysarg_t,
     const sysarg_t, const sysarg_t, const sysarg_t, const sysarg_t,
     const syscall_t);
Index: uspace/lib/c/arch/ia32/src/rtld/reloc.c
===================================================================
--- uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/arch/ia32/src/rtld/reloc.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,4 +38,5 @@
 #include <stdlib.h>
 #include <inttypes.h>
+#include <str.h>
 
 #include <libarch/rtld/elf_dyn.h>
Index: uspace/lib/c/generic/getopt.c
===================================================================
--- uspace/lib/c/generic/getopt.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/getopt.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,5 @@
 int	optopt = '?';		/* character checked for validity */
 int	optreset;		/* reset getopt */
-const char *optarg;		/* argument associated with option */
+char	*optarg;		/* argument associated with option */
 
 
@@ -67,5 +67,5 @@
 #define INORDER (int)1
 
-#define	EMSG	""
+static char EMSG[] = "";
 
 static int getopt_internal(int, char **, const char *);
@@ -73,5 +73,5 @@
 static void permute_args(int, int, int, char **);
 
-static const char *place = EMSG; /* option letter processing */
+static char *place = EMSG; /* option letter processing */
 
 /* XXX: set optreset to 1 rather than these two */
@@ -336,5 +336,5 @@
 	if (retval == -2) {
 		char *current_argv;
-		const char *has_equal;
+		char *has_equal;
 		size_t current_argv_len;
 		int i, ambiguous, match;
Index: uspace/lib/c/generic/inet/addr.c
===================================================================
--- uspace/lib/c/generic/inet/addr.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/inet/addr.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <bitops.h>
 #include <inttypes.h>
+#include <str.h>
 
 #define INET_PREFIXSTRSIZE  5
Index: uspace/lib/c/generic/io/io.c
===================================================================
--- uspace/lib/c/generic/io/io.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/io/io.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -799,5 +799,5 @@
 }
 
-int fseek(FILE *stream, long offset, int whence)
+int fseek64(FILE *stream, off64_t offset, int whence)
 {
 	errno_t rc;
@@ -814,5 +814,5 @@
 	stream->ungetc_chars = 0;
 
-	struct stat st;
+	vfs_stat_t st;
 	switch (whence) {
 	case SEEK_SET:
@@ -837,10 +837,6 @@
 }
 
-long ftell(FILE *stream)
-{
-	/* The native position is too large for the C99-ish interface. */
-	if (stream->pos - stream->ungetc_chars > LONG_MAX)
-		return EOF;
-
+off64_t ftell64(FILE *stream)
+{
 	if (stream->error)
 		return EOF;
@@ -853,4 +849,20 @@
 
 	return stream->pos - stream->ungetc_chars;
+}
+
+int fseek(FILE *stream, long offset, int whence)
+{
+	return fseek64(stream, offset, whence);
+}
+
+long ftell(FILE *stream)
+{
+	off64_t off = ftell64(stream);
+
+	/* The native position is too large for the C99-ish interface. */
+	if (off > LONG_MAX)
+		return EOF;
+
+	return off;
 }
 
Index: uspace/lib/c/generic/io/log.c
===================================================================
--- uspace/lib/c/generic/io/log.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/io/log.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,4 +41,5 @@
 #include <io/log.h>
 #include <ipc/logger.h>
+#include <str.h>
 #include <ns.h>
 
Index: uspace/lib/c/generic/io/table.c
===================================================================
--- uspace/lib/c/generic/io/table.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/io/table.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,4 +40,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 static table_column_t *table_column_first(table_t *);
Index: uspace/lib/c/generic/malloc.c
===================================================================
--- uspace/lib/c/generic/malloc.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/malloc.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -33,6 +33,4 @@
 /** @file
  */
-
-#define _HELENOS_SOURCE
 
 #include <malloc.h>
@@ -876,6 +874,11 @@
  *
  */
-void *realloc(const void *addr, const size_t size)
-{
+void *realloc(void * const addr, const size_t size)
+{
+	if (size == 0) {
+		free(addr);
+		return NULL;
+	}
+
 	if (addr == NULL)
 		return malloc(size);
@@ -985,5 +988,5 @@
  *
  */
-void free(const void *addr)
+void free(void * const addr)
 {
 	if (addr == NULL)
Index: uspace/lib/c/generic/rtld/dynamic.c
===================================================================
--- uspace/lib/c/generic/rtld/dynamic.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/rtld/dynamic.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <stdio.h>
 #include <inttypes.h>
+#include <str.h>
 
 #include <rtld/elf_dyn.h>
Index: uspace/lib/c/generic/rtld/module.c
===================================================================
--- uspace/lib/c/generic/rtld/module.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/rtld/module.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,4 +41,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include <rtld/rtld.h>
Index: uspace/lib/c/generic/rtld/rtld.c
===================================================================
--- uspace/lib/c/generic/rtld/rtld.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/rtld/rtld.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,4 +40,5 @@
 #include <rtld/rtld_debug.h>
 #include <stdlib.h>
+#include <str.h>
 
 rtld_t *runtime_env;
Index: uspace/lib/c/generic/rtld/symbol.c
===================================================================
--- uspace/lib/c/generic/rtld/symbol.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/rtld/symbol.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include <elf/elf.h>
Index: uspace/lib/c/generic/stdlib.c
===================================================================
--- uspace/lib/c/generic/stdlib.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/stdlib.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,12 +35,12 @@
 #include <stdlib.h>
 
-static long glbl_seed = 1;
+static int glbl_seed = 1;
 
-long int random(void)
+int rand(void)
 {
 	return glbl_seed = ((1366 * glbl_seed + 150889) % RAND_MAX);
 }
 
-void srandom(unsigned int seed)
+void srand(unsigned int seed)
 {
 	glbl_seed = seed % RAND_MAX;
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/str.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -1273,128 +1273,4 @@
 }
 
-/** Convert string to a number.
- * Core of strtol and strtoul functions.
- *
- * @param nptr		Pointer to string.
- * @param endptr	If not NULL, function stores here pointer to the first
- * 			invalid character.
- * @param base		Zero or number between 2 and 36 inclusive.
- * @param sgn		It's set to 1 if minus found.
- * @return		Result of conversion.
- */
-static unsigned long
-_strtoul(const char *nptr, char **endptr, int base, char *sgn)
-{
-	unsigned char c;
-	unsigned long result = 0;
-	unsigned long a, b;
-	const char *str = nptr;
-	const char *tmpptr;
-	
-	while (isspace(*str))
-		str++;
-	
-	if (*str == '-') {
-		*sgn = 1;
-		++str;
-	} else if (*str == '+')
-		++str;
-	
-	if (base) {
-		if ((base == 1) || (base > 36)) {
-			/* FIXME: set errno to EINVAL */
-			return 0;
-		}
-		if ((base == 16) && (*str == '0') && ((str[1] == 'x') ||
-		    (str[1] == 'X'))) {
-			str += 2;
-		}
-	} else {
-		base = 10;
-		
-		if (*str == '0') {
-			base = 8;
-			if ((str[1] == 'X') || (str[1] == 'x'))  {
-				base = 16;
-				str += 2;
-			}
-		}
-	}
-	
-	tmpptr = str;
-
-	while (*str) {
-		c = *str;
-		c = (c >= 'a' ? c - 'a' + 10 : (c >= 'A' ? c - 'A' + 10 :
-		    (c <= '9' ? c - '0' : 0xff)));
-		if (c >= base) {
-			break;
-		}
-		
-		a = (result & 0xff) * base + c;
-		b = (result >> 8) * base + (a >> 8);
-		
-		if (b > (ULONG_MAX >> 8)) {
-			/* overflow */
-			/* FIXME: errno = ERANGE*/
-			return ULONG_MAX;
-		}
-	
-		result = (b << 8) + (a & 0xff);
-		++str;
-	}
-	
-	if (str == tmpptr) {
-		/*
-		 * No number was found => first invalid character is the first
-		 * character of the string.
-		 */
-		/* FIXME: set errno to EINVAL */
-		str = nptr;
-		result = 0;
-	}
-	
-	if (endptr)
-		*endptr = (char *) str;
-
-	if (nptr == str) {
-		/*FIXME: errno = EINVAL*/
-		return 0;
-	}
-
-	return result;
-}
-
-/** Convert initial part of string to long int according to given base.
- * The number may begin with an arbitrary number of whitespaces followed by
- * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
- * inserted and the number will be taken as hexadecimal one. If the base is 0
- * and the number begin with a zero, number will be taken as octal one (as with
- * base 8). Otherwise the base 0 is taken as decimal.
- *
- * @param nptr		Pointer to string.
- * @param endptr	If not NULL, function stores here pointer to the first
- * 			invalid character.
- * @param base		Zero or number between 2 and 36 inclusive.
- * @return		Result of conversion.
- */
-long int strtol(const char *nptr, char **endptr, int base)
-{
-	char sgn = 0;
-	unsigned long number = 0;
-	
-	number = _strtoul(nptr, endptr, base, &sgn);
-
-	if (number > LONG_MAX) {
-		if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) {
-			/* FIXME: set 0 to errno */
-			return number;
-		}
-		/* FIXME: set ERANGE to errno */
-		return (sgn ? LONG_MIN : LONG_MAX);
-	}
-	
-	return (sgn ? -number : number);
-}
 
 /** Duplicate string.
@@ -1457,27 +1333,4 @@
 	str_ncpy(dest, size + 1, src, size);
 	return dest;
-}
-
-/** Convert initial part of string to unsigned long according to given base.
- * The number may begin with an arbitrary number of whitespaces followed by
- * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
- * inserted and the number will be taken as hexadecimal one. If the base is 0
- * and the number begin with a zero, number will be taken as octal one (as with
- * base 8). Otherwise the base 0 is taken as decimal.
- *
- * @param nptr		Pointer to string.
- * @param endptr	If not NULL, function stores here pointer to the first
- * 			invalid character
- * @param base		Zero or number between 2 and 36 inclusive.
- * @return		Result of conversion.
- */
-unsigned long strtoul(const char *nptr, char **endptr, int base)
-{
-	char sgn = 0;
-	unsigned long number = 0;
-	
-	number = _strtoul(nptr, endptr, base, &sgn);
-
-	return (sgn ? -number : number);
 }
 
Index: uspace/lib/c/generic/strtol.c
===================================================================
--- uspace/lib/c/generic/strtol.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/c/generic/strtol.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,267 @@
+/*
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2008 Jiri Svoboda
+ * Copyright (c) 2011 Martin Sucha
+ * Copyright (c) 2011 Oleg Romanenko
+ * 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 libc
+ * @{
+ */
+/** @file
+ */
+
+#include <inttypes.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <ctype.h>
+#include <assert.h>
+
+// TODO: unit tests
+
+static inline int _digit_value(int c)
+{
+	if (isdigit(c)) {
+		return c - '0';
+	} else if (islower(c)) {
+		return c - 'a' + 10;
+	} else if (isupper(c)) {
+		return c - 'A' + 10;
+	}
+	return INT_MAX;
+}
+
+/* FIXME: workaround for GCC "optimizing" the overflow check
+ * into soft-emulated 128b multiplication using `__multi3`,
+ * which we don't currently implement.
+ */
+__attribute__((noinline)) static uintmax_t _max_value(int base)
+{
+	return UINTMAX_MAX / base;
+}
+
+static inline uintmax_t _strtoumax(
+    const char *restrict nptr, char **restrict endptr, int base,
+    bool *restrict sgn)
+{
+	assert(nptr != NULL);
+	assert(sgn != NULL);
+
+	/* Skip leading whitespace. */
+
+	while (isspace(*nptr)) {
+		nptr++;
+	}
+
+	/* Parse sign, if any. */
+
+	switch (*nptr) {
+	case '-':
+		*sgn = true;
+		nptr++;
+		break;
+	case '+':
+		nptr++;
+		break;
+	}
+
+	/* Figure out the base. */
+
+	if (base == 0) {
+		if (*nptr == '0') {
+			if (tolower(nptr[1]) == 'x') {
+				/* 0x... is hex. */
+				base = 16;
+				nptr += 2;
+			} else {
+				/* 0... is octal. */
+				base = 8;
+			}
+		} else {
+			/* Anything else is decimal by default. */
+			base = 10;
+		}
+	} else if (base == 16) {
+		/* Allow hex number to be prefixed with "0x". */
+		if (nptr[0] == '0' && tolower(nptr[1]) == 'x') {
+			nptr += 2;
+		}
+	} else if (base < 0 || base == 1 || base > 36) {
+		errno = EINVAL;
+		return 0;
+	}
+
+	/* Read the value. */
+
+	uintmax_t result = 0;
+	uintmax_t max = _max_value(base);
+	int digit;
+
+	while (digit = _digit_value(*nptr), digit < base) {
+
+		if (result > max ||
+		    __builtin_add_overflow(result * base, digit, &result)) {
+
+			errno = ERANGE;
+			result = UINTMAX_MAX;
+			break;
+		}
+
+		nptr++;
+	}
+
+	/* Set endptr. */
+
+	if (endptr != NULL) {
+		/* Move the pointer to the end of the number,
+		 * in case it isn't there already.
+		 */
+		while (_digit_value(*nptr) < base) {
+			nptr++;
+		}
+
+		*endptr = (char *) nptr;
+	}
+
+	return result;
+}
+
+static inline intmax_t _strtosigned(const char *nptr, char **endptr, int base,
+    intmax_t min, intmax_t max)
+{
+	bool sgn = false;
+	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn);
+
+	if (number > (uintmax_t) max) {
+		if (sgn && (number - 1 == (uintmax_t) max)) {
+			return min;
+		}
+
+		errno = ERANGE;
+		return (sgn ? min : max);
+	}
+
+	return (sgn ? -number : number);
+}
+
+static inline uintmax_t _strtounsigned(const char *nptr, char **endptr, int base,
+    uintmax_t max)
+{
+	bool sgn = false;
+	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn);
+
+	if (sgn) {
+		if (number == 0) {
+			return 0;
+		} else {
+			errno = ERANGE;
+			return max;
+		}
+	}
+
+	if (number > max) {
+		errno = ERANGE;
+		return max;
+	}
+
+	return number;
+}
+
+/** Convert initial part of string to long int according to given base.
+ * The number may begin with an arbitrary number of whitespaces followed by
+ * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
+ * inserted and the number will be taken as hexadecimal one. If the base is 0
+ * and the number begin with a zero, number will be taken as octal one (as with
+ * base 8). Otherwise the base 0 is taken as decimal.
+ *
+ * @param nptr		Pointer to string.
+ * @param[out] endptr	If not NULL, function stores here pointer to the first
+ * 			invalid character.
+ * @param base		Zero or number between 2 and 36 inclusive.
+ * @return		Result of conversion.
+ */
+long strtol(const char *nptr, char **endptr, int base)
+{
+	return _strtosigned(nptr, endptr, base, LONG_MIN, LONG_MAX);
+}
+
+/** Convert initial part of string to unsigned long according to given base.
+ * The number may begin with an arbitrary number of whitespaces followed by
+ * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
+ * inserted and the number will be taken as hexadecimal one. If the base is 0
+ * and the number begin with a zero, number will be taken as octal one (as with
+ * base 8). Otherwise the base 0 is taken as decimal.
+ *
+ * @param nptr		Pointer to string.
+ * @param[out] endptr	If not NULL, function stores here pointer to the first
+ * 			invalid character
+ * @param base		Zero or number between 2 and 36 inclusive.
+ * @return		Result of conversion.
+ */
+unsigned long strtoul(const char *nptr, char **endptr, int base)
+{
+	return _strtounsigned(nptr, endptr, base, ULONG_MAX);
+}
+
+long long strtoll(const char *nptr, char **endptr, int base)
+{
+	return _strtosigned(nptr, endptr, base, LLONG_MIN, LLONG_MAX);
+}
+
+unsigned long long strtoull(const char *nptr, char **endptr, int base)
+{
+	return _strtounsigned(nptr, endptr, base, ULLONG_MAX);
+}
+
+intmax_t strtoimax(const char *nptr, char **endptr, int base)
+{
+	return _strtosigned(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX);
+}
+
+uintmax_t strtoumax(const char *nptr, char **endptr, int base)
+{
+	return _strtounsigned(nptr, endptr, base, UINTMAX_MAX);
+}
+
+int atoi(const char *nptr)
+{
+	return (int)strtol(nptr, NULL, 10);
+}
+
+long atol(const char *nptr)
+{
+	return strtol(nptr, NULL, 10);
+}
+
+long long atoll(const char *nptr)
+{
+	return strtoll(nptr, NULL, 10);
+}
+
+/** @}
+ */
Index: uspace/lib/c/generic/uuid.c
===================================================================
--- uspace/lib/c/generic/uuid.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/uuid.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,8 +52,8 @@
 	/* XXX This is a rather poor way of generating random numbers */
 	gettimeofday(&tv, NULL);
-	srandom(tv.tv_sec ^ tv.tv_usec);
+	srand(tv.tv_sec ^ tv.tv_usec);
 
 	for (i = 0; i < uuid_bytes; i++)
-		uuid->b[i] = random();
+		uuid->b[i] = rand();
 
 	/* Version 4 UUID from random or pseudo-random numbers */
Index: uspace/lib/c/generic/vfs/mtab.c
===================================================================
--- uspace/lib/c/generic/vfs/mtab.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/vfs/mtab.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,6 +40,7 @@
 #include <errno.h>
 #include <assert.h>
+#include <str.h>
 
-static void process_mp(const char *path, struct stat *stat, list_t *mtab_list)
+static void process_mp(const char *path, vfs_stat_t *stat, list_t *mtab_list)
 {
 	mtab_ent_t *ent;
@@ -53,5 +54,5 @@
 	ent->service_id = stat->service_id;
 
-	struct statfs stfs;
+	vfs_statfs_t stfs;
 	if (vfs_statfs_path(path, &stfs) == EOK)
 		str_cpy(ent->fs_name, sizeof(ent->fs_name), stfs.fs_name);
@@ -74,5 +75,5 @@
 	while ((dirent = readdir(dir)) != NULL) {
 		char *child;
-		struct stat st;
+		vfs_stat_t st;
 		errno_t rc;
 		int ret;
@@ -122,5 +123,5 @@
 errno_t vfs_get_mtab_list(list_t *mtab_list)
 {
-	struct stat st;
+	vfs_stat_t st;
 
 	errno_t rc = vfs_stat_path("/", &st);
Index: uspace/lib/c/generic/vfs/vfs.c
===================================================================
--- uspace/lib/c/generic/vfs/vfs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/generic/vfs/vfs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -352,5 +352,5 @@
 async_sess_t *vfs_fd_session(int file, iface_t iface)
 {
-	struct stat stat;
+	vfs_stat_t stat;
 	errno_t rc = vfs_stat(file, &stat);
 	if (rc != EOK)
@@ -1052,5 +1052,5 @@
  * @return              EOK on success or an error code
  */
-errno_t vfs_stat(int file, struct stat *stat)
+errno_t vfs_stat(int file, vfs_stat_t *stat)
 {
 	errno_t rc;
@@ -1060,5 +1060,5 @@
 	
 	req = async_send_1(exch, VFS_IN_STAT, file, NULL);
-	rc = async_data_read_start(exch, (void *) stat, sizeof(struct stat));
+	rc = async_data_read_start(exch, (void *) stat, sizeof(vfs_stat_t));
 	if (rc != EOK) {
 		vfs_exchange_end(exch);
@@ -1086,5 +1086,5 @@
  * @return              EOK on success or an error code
  */
-errno_t vfs_stat_path(const char *path, struct stat *stat)
+errno_t vfs_stat_path(const char *path, vfs_stat_t *stat)
 {
 	int file;
@@ -1107,5 +1107,5 @@
  * @return              EOK on success or an error code
  */
-errno_t vfs_statfs(int file, struct statfs *st)
+errno_t vfs_statfs(int file, vfs_statfs_t *st)
 {
 	errno_t rc, ret;
@@ -1132,5 +1132,5 @@
  * @return              EOK on success or an error code
  */
-errno_t vfs_statfs_path(const char *path, struct statfs *st)
+errno_t vfs_statfs_path(const char *path, vfs_statfs_t *st)
 {
 	int file;
Index: uspace/lib/c/include/adt/hash_table.h
===================================================================
--- uspace/lib/c/include/adt/hash_table.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/adt/hash_table.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -84,6 +84,6 @@
 	member_to_inst((item), type, member)
 
-extern bool hash_table_create(hash_table_t *, size_t, size_t, 
-	hash_table_ops_t *);
+extern bool hash_table_create(hash_table_t *, size_t, size_t,
+    hash_table_ops_t *);
 extern void hash_table_destroy(hash_table_t *);
 
@@ -98,6 +98,6 @@
 extern size_t hash_table_remove(hash_table_t *, void *);
 extern void hash_table_remove_item(hash_table_t *, ht_link_t *);
-extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *), 
-	void *);
+extern void hash_table_apply(hash_table_t *, bool (*)(ht_link_t *, void *),
+    void *);
 
 
Index: uspace/lib/c/include/async.h
===================================================================
--- uspace/lib/c/include/async.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/async.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,5 +34,5 @@
 
 #if ((defined(LIBC_IPC_H_)) && (!defined(LIBC_ASYNC_C_)))
-	#error Do not intermix low-level IPC interface and async framework
+#error Do not intermix low-level IPC interface and async framework
 #endif
 
Index: uspace/lib/c/include/ctype.h
===================================================================
--- uspace/lib/c/include/ctype.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/ctype.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -61,4 +61,24 @@
 }
 
+static inline int isblank(int c)
+{
+	return c == ' ' || c == '\t';
+}
+
+static inline int iscntrl(int c)
+{
+	return (c >= 0 && c < 0x20) || c == 0x7E;
+}
+
+static inline int isprint(int c)
+{
+	return c >= 0 && c < 0x80 && !iscntrl(c);
+}
+
+static inline int isgraph(int c)
+{
+	return isprint(c) && c != ' ';
+}
+
 static inline int isspace(int c)
 {
@@ -75,4 +95,16 @@
 		return 0;
 	}
+}
+
+static inline int ispunct(int c)
+{
+	return !isspace(c) && !isalnum(c) && isprint(c);
+}
+
+static inline int isxdigit(int c)
+{
+	return isdigit(c) ||
+	    (c >= 'a' && c <= 'f') ||
+	    (c >= 'A' && c <= 'F');
 }
 
Index: uspace/lib/c/include/getopt.h
===================================================================
--- uspace/lib/c/include/getopt.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/getopt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -57,5 +57,5 @@
 
 /* HelenOS Port - These need to be exposed for legacy getopt() */
-extern const char *optarg;
+extern char *optarg;
 extern int optind, opterr, optopt;
 extern int optreset;
Index: uspace/lib/c/include/gsort.h
===================================================================
--- uspace/lib/c/include/gsort.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/gsort.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,5 +39,5 @@
 #include <stdbool.h>
 
-typedef int (* sort_cmp_t)(void *, void *, void *);
+typedef int (*sort_cmp_t)(void *, void *, void *);
 
 extern bool gsort(void *, size_t, size_t, sort_cmp_t, void *);
Index: uspace/lib/c/include/inttypes.h
===================================================================
--- uspace/lib/c/include/inttypes.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/inttypes.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,4 +38,11 @@
 #include <_bits/inttypes.h>
 
+#ifndef __HELENOS_DISABLE_INTMAX__
+intmax_t strtoimax(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
+uintmax_t strtoumax(const char *__restrict__ nptr,
+    char **__restrict__ endptr, int base);
+#endif
+
 #endif
 
Index: uspace/lib/c/include/io/kio.h
===================================================================
--- uspace/lib/c/include/io/kio.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/io/kio.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,4 +39,6 @@
 #include <stdarg.h>
 #include <io/verify.h>
+#include <_bits/errno.h>
+#include <_bits/size_t.h>
 
 extern errno_t kio_write(const void *, size_t, size_t *);
@@ -44,5 +46,5 @@
 extern void kio_command(const void *, size_t);
 extern int kio_printf(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 extern int kio_vprintf(const char *, va_list);
 
Index: uspace/lib/c/include/io/log.h
===================================================================
--- uspace/lib/c/include/io/log.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/io/log.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -60,5 +60,5 @@
 
 extern void log_msg(log_t, log_level_t, const char *, ...)
-    PRINTF_ATTRIBUTE(3, 4);
+    _HELENOS_PRINTF_ATTRIBUTE(3, 4);
 extern void log_msgv(log_t, log_level_t, const char *, va_list);
 
Index: uspace/lib/c/include/io/verify.h
===================================================================
--- uspace/lib/c/include/io/verify.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/io/verify.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,19 +36,19 @@
 #define LIBC_IO_VERIFY_H_
 
-#ifndef NVERIFY_PRINTF
+#ifndef _HELENOS_NVERIFY_PRINTF
 
 #ifdef __clang__
-#define PRINTF_ATTRIBUTE(start, end) \
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(__printf__, start, end)))
 #else
-#define PRINTF_ATTRIBUTE(start, end) \
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end) \
 	__attribute__((format(gnu_printf, start, end)))
 #endif
 
-#else /* NVERIFY_PRINTF */
+#else /* _HELENOS_NVERIFY_PRINTF */
 
-#define PRINTF_ATTRIBUTE(start, end)
+#define _HELENOS_PRINTF_ATTRIBUTE(start, end)
 
-#endif /* NVERIFY_PRINTF */
+#endif /* _HELENOS_NVERIFY_PRINTF */
 
 #endif
Index: uspace/lib/c/include/ipc/devman.h
===================================================================
--- uspace/lib/c/include/ipc/devman.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/ipc/devman.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -74,5 +74,5 @@
 	/** Id of device model.
 	 */
-	const char *id;
+	char *id;
 	/** Relevancy of device-to-driver match.
 	 * The higher is the product of scores specified for the device by the bus driver and by the leaf driver,
Index: uspace/lib/c/include/ipc/ipc.h
===================================================================
--- uspace/lib/c/include/ipc/ipc.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/ipc/ipc.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,5 +34,5 @@
 
 #if ((defined(LIBC_ASYNC_H_)) && (!defined(LIBC_ASYNC_C_)))
-	#error Do not intermix low-level IPC interface and async framework
+#error Do not intermix low-level IPC interface and async framework
 #endif
 
Index: uspace/lib/c/include/ipc/logger.h
===================================================================
--- uspace/lib/c/include/ipc/logger.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/ipc/logger.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -54,5 +54,5 @@
 	 * Returns: error code
 	 * Followed by: vfs_pass_handle() request.
-	 */ 
+	 */
 	LOGGER_CONTROL_SET_ROOT
 } logger_control_request_t;
Index: uspace/lib/c/include/malloc.h
===================================================================
--- uspace/lib/c/include/malloc.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/malloc.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -38,13 +38,13 @@
 #include <stddef.h>
 
-extern void *malloc(const size_t size)
+extern void *malloc(size_t size)
     __attribute__((malloc));
-extern void *calloc(const size_t nmemb, const size_t size)
+extern void *calloc(size_t nmemb, size_t size)
     __attribute__((malloc));
-extern void *memalign(const size_t align, const size_t size)
+extern void *memalign(size_t align, size_t size)
     __attribute__((malloc));
-extern void *realloc(const void *addr, const size_t size)
+extern void *realloc(void *addr, size_t size)
     __attribute__((warn_unused_result));
-extern void free(const void *addr);
+extern void free(void *addr);
 extern void *heap_check(void);
 
Index: uspace/lib/c/include/rtld/rtld_debug.h
===================================================================
--- uspace/lib/c/include/rtld/rtld_debug.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/rtld/rtld_debug.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,7 +42,7 @@
 
 #ifdef RTLD_DEBUG
-	#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
+#define DPRINTF(format, ...) printf(format, ##__VA_ARGS__)
 #else
-	#define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
+#define DPRINTF(format, ...) if (0) printf(format, ##__VA_ARGS__)
 #endif
 
Index: uspace/lib/c/include/stdio.h
===================================================================
--- uspace/lib/c/include/stdio.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/stdio.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,7 +37,7 @@
 
 #include <stdarg.h>
-#include <str.h>
 #include <io/verify.h>
-#include <abi/kio.h>
+#include <_bits/size_t.h>
+#include <_bits/wchar_t.h>
 
 #define EOF  (-1)
@@ -58,11 +58,76 @@
 #define BUFSIZ  4096
 
-#define DEBUG(fmt, ...) \
-	{ \
-		char _buf[256]; \
-		int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
-		if (_n > 0) \
-			(void) __SYSCALL3(SYS_KIO, KIO_WRITE, (sysarg_t) _buf, str_size(_buf)); \
-	}
+/** Forward declaration */
+struct _IO_FILE;
+typedef struct _IO_FILE FILE;
+
+extern FILE *stdin;
+extern FILE *stdout;
+extern FILE *stderr;
+
+/* Character and string input functions */
+extern int fgetc(FILE *);
+extern char *fgets(char *, int, FILE *);
+
+extern int getchar(void);
+
+/* Character and string output functions */
+extern int fputc(wchar_t, FILE *);
+extern int fputs(const char *, FILE *);
+
+extern int putchar(wchar_t);
+extern int puts(const char *);
+
+extern int ungetc(int, FILE *);
+
+/* Formatted string output functions */
+extern int fprintf(FILE *, const char*, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
+extern int vfprintf(FILE *, const char *, va_list);
+
+extern int printf(const char *, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
+extern int vprintf(const char *, va_list);
+
+extern int snprintf(char *, size_t , const char *, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(3, 4);
+extern int vasprintf(char **, const char *, va_list);
+extern int asprintf(char **, const char *, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
+extern int vsnprintf(char *, size_t, const char *, va_list);
+
+/* File stream functions */
+extern FILE *fopen(const char *, const char *);
+extern FILE *freopen(const char *, const char *, FILE *);
+extern int fclose(FILE *);
+
+extern size_t fread(void *, size_t, size_t, FILE *);
+extern size_t fwrite(const void *, size_t, size_t, FILE *);
+
+extern int fseek(FILE *, long, int);
+extern void rewind(FILE *);
+extern long ftell(FILE *);
+extern int feof(FILE *);
+
+extern int fflush(FILE *);
+extern int ferror(FILE *);
+extern void clearerr(FILE *);
+
+extern void setvbuf(FILE *, void *, int, size_t);
+extern void setbuf(FILE *, void *);
+
+/* Misc file functions */
+extern int rename(const char *, const char *);
+extern int remove(const char *);
+
+#ifndef _HELENOS_SOURCE
+#define _IONBF 0
+#define _IOLBF 1
+#define _IOFBF 2
+#endif
+
+#ifdef _HELENOS_SOURCE
+
+/* Nonstandard extensions. */
 
 enum _buffer_type {
@@ -86,73 +151,18 @@
 };
 
-/** Forward declaration */
-struct _IO_FILE;
-typedef struct _IO_FILE FILE;
-
-extern FILE *stdin;
-extern FILE *stdout;
-extern FILE *stderr;
-
-/* Character and string input functions */
-extern int fgetc(FILE *);
-extern char *fgets(char *, int, FILE *);
-
-extern int getchar(void);
+extern int vprintf_size(const char *, va_list);
+extern int printf_size(const char *, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(1, 2);
+extern FILE *fdopen(int, const char *);
+extern int fileno(FILE *);
 extern char *gets(char *, size_t);
 
-/* Character and string output functions */
-extern int fputc(wchar_t, FILE *);
-extern int fputs(const char *, FILE *);
+#include <offset.h>
 
-extern int putchar(wchar_t);
-extern int puts(const char *);
+extern int fseek64(FILE *, off64_t, int);
+extern off64_t ftell64(FILE *);
 
-extern int ungetc(int, FILE *);
+#endif
 
-/* Formatted string output functions */
-extern int fprintf(FILE *, const char*, ...)
-    PRINTF_ATTRIBUTE(2, 3);
-extern int vfprintf(FILE *, const char *, va_list);
-
-extern int printf(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
-extern int vprintf(const char *, va_list);
-
-extern int snprintf(char *, size_t , const char *, ...)
-    PRINTF_ATTRIBUTE(3, 4);
-extern int vasprintf(char **, const char *, va_list);
-extern int asprintf(char **, const char *, ...)
-    PRINTF_ATTRIBUTE(2, 3);
-extern int vsnprintf(char *, size_t, const char *, va_list);
-
-extern int printf_size(const char *, ...)
-    PRINTF_ATTRIBUTE(1, 2);
-extern int vprintf_size(const char *, va_list);
-
-/* File stream functions */
-extern FILE *fopen(const char *, const char *);
-extern FILE *fdopen(int, const char *);
-extern FILE *freopen(const char *, const char *, FILE *);
-extern int fclose(FILE *);
-
-extern size_t fread(void *, size_t, size_t, FILE *);
-extern size_t fwrite(const void *, size_t, size_t, FILE *);
-
-extern int fseek(FILE *, long, int);
-extern void rewind(FILE *);
-extern long ftell(FILE *);
-extern int feof(FILE *);
-extern int fileno(FILE *);
-
-extern int fflush(FILE *);
-extern int ferror(FILE *);
-extern void clearerr(FILE *);
-
-extern void setvbuf(FILE *, void *, int, size_t);
-extern void setbuf(FILE *, void *);
-
-/* Misc file functions */
-extern int rename(const char *, const char *);
-extern int remove(const char *);
 
 #endif
Index: uspace/lib/c/include/stdlib.h
===================================================================
--- uspace/lib/c/include/stdlib.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/stdlib.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,12 +42,18 @@
 #define RAND_MAX  714025
 
-#define rand()       random()
-#define srand(seed)  srandom(seed)
-
-extern long int random(void);
-extern void srandom(unsigned int seed);
+extern int rand(void);
+extern void srand(unsigned int seed);
 
 extern void abort(void) __attribute__((noreturn));
 extern void exit(int) __attribute__((noreturn));
+
+extern int atoi(const char *);
+extern long atol(const char *);
+extern long long atoll(const char *);
+
+extern long strtol(const char *__restrict__, char **__restrict__, int);
+extern long long strtoll(const char *__restrict__, char **__restrict__, int);
+extern unsigned long strtoul(const char *__restrict__, char **__restrict__, int);
+extern unsigned long long strtoull(const char *__restrict__, char **__restrict__, int);
 
 #endif
Index: uspace/lib/c/include/syscall.h
===================================================================
--- uspace/lib/c/include/syscall.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/syscall.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 
 #ifndef LIBARCH_SYSCALL_GENERIC
-	#error You cannot include this file directly
+#error You cannot include this file directly
 #endif
 
Index: uspace/lib/c/include/time.h
===================================================================
--- uspace/lib/c/include/time.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/time.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -31,5 +31,5 @@
  */
 /** @file
- */ 
+ */
 
 #ifndef LIBC_TIME_H_
Index: uspace/lib/c/include/udebug.h
===================================================================
--- uspace/lib/c/include/udebug.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/udebug.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -46,5 +46,5 @@
 extern errno_t udebug_end(async_sess_t *);
 extern errno_t udebug_set_evmask(async_sess_t *, udebug_evmask_t);
-extern errno_t udebug_thread_read(async_sess_t *, void *, size_t , size_t *,
+extern errno_t udebug_thread_read(async_sess_t *, void *, size_t, size_t *,
     size_t *);
 extern errno_t udebug_name_read(async_sess_t *, void *, size_t, size_t *,
Index: uspace/lib/c/include/vfs/inbox.h
===================================================================
--- uspace/lib/c/include/vfs/inbox.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/vfs/inbox.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -29,5 +29,5 @@
 /** @addtogroup libc 
  * @{
- */ 
+ */
 
 /**
Index: uspace/lib/c/include/vfs/vfs.h
===================================================================
--- uspace/lib/c/include/vfs/vfs.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/include/vfs/vfs.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -57,5 +57,5 @@
 
 
-struct stat {
+typedef struct {
 	fs_handle_t fs_handle;
 	service_id_t service_id;
@@ -66,12 +66,12 @@
 	aoff64_t size;
 	service_id_t service;
-};
+} vfs_stat_t;
 
-struct statfs { 
+typedef struct {
 	char fs_name[FS_NAME_MAXLEN + 1];
 	uint32_t f_bsize;    /* fundamental file system block size */
 	uint64_t f_blocks;   /* total data blocks in file system */
 	uint64_t f_bfree;    /* free blocks in fs */
-};
+} vfs_statfs_t;
 
 /** List of file system types */
@@ -111,8 +111,8 @@
 extern int vfs_root(void);
 extern errno_t vfs_root_set(int);
-extern errno_t vfs_stat(int, struct stat *);
-extern errno_t vfs_stat_path(const char *, struct stat *);
-extern errno_t vfs_statfs(int, struct statfs *);
-extern errno_t vfs_statfs_path(const char *, struct statfs *);
+extern errno_t vfs_stat(int, vfs_stat_t *);
+extern errno_t vfs_stat_path(const char *, vfs_stat_t *);
+extern errno_t vfs_statfs(int, vfs_statfs_t *);
+extern errno_t vfs_statfs_path(const char *, vfs_statfs_t *);
 extern errno_t vfs_sync(int);
 extern errno_t vfs_unlink(int, const char *, int);
Index: uspace/lib/c/test/sprintf.c
===================================================================
--- uspace/lib/c/test/sprintf.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/c/test/sprintf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -28,4 +28,5 @@
 
 #include <stdio.h>
+#include <str.h>
 #include <pcut/pcut.h>
 
Index: uspace/lib/draw/font/pcf.c
===================================================================
--- uspace/lib/draw/font/pcf.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/draw/font/pcf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <offset.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include "pcf.h"
Index: uspace/lib/draw/surface.h
===================================================================
--- uspace/lib/draw/surface.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/draw/surface.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -60,6 +60,6 @@
 extern void surface_get_damaged_region(surface_t *, surface_coord_t *, surface_coord_t *,
     surface_coord_t *, surface_coord_t *);
-extern void surface_add_damaged_region(surface_t *, surface_coord_t , surface_coord_t ,
-    surface_coord_t , surface_coord_t );
+extern void surface_add_damaged_region(surface_t *, surface_coord_t, surface_coord_t,
+    surface_coord_t, surface_coord_t);
 extern void surface_reset_damaged_region(surface_t *);
 
Index: uspace/lib/drv/generic/logbuf.c
===================================================================
--- uspace/lib/drv/generic/logbuf.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/generic/logbuf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,4 +35,5 @@
 #include <ddf/log.h>
 #include <assert.h>
+#include <str.h>
 
 /** Formatting string for printing number of not-printed items. */
Index: uspace/lib/drv/generic/private/driver.h
===================================================================
--- uspace/lib/drv/generic/private/driver.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/generic/private/driver.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -57,5 +57,5 @@
 	
 	/** Device name */
-	const char *name;
+	char *name;
 	
 	/** Driver-specific data associated with this device */
@@ -84,5 +84,5 @@
 	
 	/** Function name */
-	const char *name;
+	char *name;
 	
 	/** List of device ids for driver matching */
Index: uspace/lib/drv/generic/remote_ahci.c
===================================================================
--- uspace/lib/drv/generic/remote_ahci.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/generic/remote_ahci.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,4 +39,5 @@
 #include <stdio.h>
 #include <macros.h>
+#include <str.h>
 #include "ahci_iface.h"
 #include "ddf/driver.h"
Index: uspace/lib/drv/generic/remote_audio_mixer.c
===================================================================
--- uspace/lib/drv/generic/remote_audio_mixer.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/generic/remote_audio_mixer.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -94,5 +94,5 @@
  * @return Error code.
  */
-errno_t audio_mixer_get_info(async_exch_t *exch, const char **name, unsigned *items)
+errno_t audio_mixer_get_info(async_exch_t *exch, char **name, unsigned *items)
 {
 	if (!exch)
@@ -131,5 +131,5 @@
  */
 errno_t audio_mixer_get_item_info(async_exch_t *exch, unsigned item,
-    const char **name, unsigned *levels)
+    char **name, unsigned *levels)
 {
 	if (!exch)
Index: uspace/lib/drv/generic/remote_audio_pcm.c
===================================================================
--- uspace/lib/drv/generic/remote_audio_pcm.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/generic/remote_audio_pcm.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -184,5 +184,5 @@
  * @note Caller is responsible for freeing newly allocated memory.
  */
-errno_t audio_pcm_get_info_str(audio_pcm_sess_t *sess, const char **name)
+errno_t audio_pcm_get_info_str(audio_pcm_sess_t *sess, char **name)
 {
 	if (!name)
Index: uspace/lib/drv/include/ahci_iface.h
===================================================================
--- uspace/lib/drv/include/ahci_iface.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/ahci_iface.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,5 +41,5 @@
 #include <async.h>
 
-extern async_sess_t* ahci_get_sess(devman_handle_t, char **);
+extern async_sess_t *ahci_get_sess(devman_handle_t, char **);
 
 extern errno_t ahci_get_sata_device_name(async_sess_t *, size_t, char *);
Index: uspace/lib/drv/include/audio_mixer_iface.h
===================================================================
--- uspace/lib/drv/include/audio_mixer_iface.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/audio_mixer_iface.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,7 +43,7 @@
 #include "ddf/driver.h"
 
-errno_t audio_mixer_get_info(async_exch_t *, const char **, unsigned *);
+errno_t audio_mixer_get_info(async_exch_t *, char **, unsigned *);
 errno_t audio_mixer_get_item_info(async_exch_t *, unsigned,
-    const char **, unsigned *);
+    char **, unsigned *);
 errno_t audio_mixer_get_item_level(async_exch_t *, unsigned, unsigned *);
 errno_t audio_mixer_set_item_level(async_exch_t *, unsigned, unsigned);
Index: uspace/lib/drv/include/audio_pcm_iface.h
===================================================================
--- uspace/lib/drv/include/audio_pcm_iface.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/audio_pcm_iface.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -80,5 +80,5 @@
 void audio_pcm_close(audio_pcm_sess_t *);
 
-errno_t audio_pcm_get_info_str(audio_pcm_sess_t *, const char **);
+errno_t audio_pcm_get_info_str(audio_pcm_sess_t *, char **);
 errno_t audio_pcm_test_format(audio_pcm_sess_t *, unsigned *, unsigned *,
     pcm_sample_format_t *);
@@ -120,5 +120,5 @@
 	errno_t (*release_buffer)(ddf_fun_t *);
 	errno_t (*set_event_session)(ddf_fun_t *, async_sess_t *);
-	async_sess_t * (*get_event_session)(ddf_fun_t *);
+	async_sess_t *(*get_event_session)(ddf_fun_t *);
 	errno_t (*start_playback)(ddf_fun_t *, unsigned,
 	    unsigned, unsigned, pcm_sample_format_t);
Index: uspace/lib/drv/include/ddf/log.h
===================================================================
--- uspace/lib/drv/include/ddf/log.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/ddf/log.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,5 +39,5 @@
 extern errno_t ddf_log_init(const char *);
 extern void ddf_msg(log_level_t, const char *, ...)
-    PRINTF_ATTRIBUTE(2, 3);
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 
 extern void ddf_dump_buffer(char *, size_t, const void *, size_t, size_t,
Index: uspace/lib/drv/include/ops/nic.h
===================================================================
--- uspace/lib/drv/include/ops/nic.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/ops/nic.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -66,5 +66,5 @@
 	errno_t (*autoneg_restart)(ddf_fun_t *);
 	errno_t (*get_pause)(ddf_fun_t *, nic_result_t *, nic_result_t *,
-		uint16_t *);
+	    uint16_t *);
 	errno_t (*set_pause)(ddf_fun_t *, int, int, uint16_t);
 	
Index: uspace/lib/drv/include/ops/pio_window.h
===================================================================
--- uspace/lib/drv/include/ops/pio_window.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/ops/pio_window.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -40,5 +40,5 @@
 
 typedef struct {
-	pio_window_t *(* get_pio_window)(ddf_fun_t *);
+	pio_window_t *(*get_pio_window)(ddf_fun_t *);
 } pio_window_ops_t;
 
Index: uspace/lib/drv/include/usbhid_iface.h
===================================================================
--- uspace/lib/drv/include/usbhid_iface.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/drv/include/usbhid_iface.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -81,5 +81,5 @@
 	 * @return Error code.
 	 */
-	errno_t (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc, 
+	errno_t (*get_report_descriptor)(ddf_fun_t *fun, uint8_t *desc,
 	    size_t size, size_t *act_size);
 } usbhid_iface_t;
Index: uspace/lib/ext4/include/ext4/inode.h
===================================================================
--- uspace/lib/ext4/include/ext4/inode.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/ext4/include/ext4/inode.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -73,5 +73,5 @@
 extern uint32_t ext4_inode_get_indirect_block(ext4_inode_t *, uint32_t);
 extern void ext4_inode_set_indirect_block(ext4_inode_t *, uint32_t, uint32_t);
-extern ext4_extent_header_t * ext4_inode_get_extent_header(ext4_inode_t *);
+extern ext4_extent_header_t *ext4_inode_get_extent_header(ext4_inode_t *);
 extern bool ext4_inode_is_type(ext4_superblock_t *, ext4_inode_t *, uint32_t);
 extern bool ext4_inode_has_flag(ext4_inode_t *, uint32_t);
Index: uspace/lib/ext4/include/ext4/superblock.h
===================================================================
--- uspace/lib/ext4/include/ext4/superblock.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/ext4/include/ext4/superblock.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -113,14 +113,14 @@
     uint32_t);
 
-extern const uint8_t * ext4_superblock_get_uuid(ext4_superblock_t *);
+extern const uint8_t *ext4_superblock_get_uuid(ext4_superblock_t *);
 extern void ext4_superblock_set_uuid(ext4_superblock_t *, const uint8_t *);
-extern const char * ext4_superblock_get_volume_name(ext4_superblock_t *);
+extern const char *ext4_superblock_get_volume_name(ext4_superblock_t *);
 extern void ext4_superblock_set_volume_name(ext4_superblock_t *, const char *);
-extern const char * ext4_superblock_get_last_mounted(ext4_superblock_t *);
+extern const char *ext4_superblock_get_last_mounted(ext4_superblock_t *);
 extern void ext4_superblock_set_last_mounted(ext4_superblock_t *, const char *);
 
 extern uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *);
 extern void ext4_superblock_set_last_orphan(ext4_superblock_t *, uint32_t);
-extern const uint32_t * ext4_superblock_get_hash_seed(ext4_superblock_t *);
+extern const uint32_t *ext4_superblock_get_hash_seed(ext4_superblock_t *);
 extern void ext4_superblock_set_hash_seed(ext4_superblock_t *,
     const uint32_t *);
Index: uspace/lib/fmtutil/fmtutil.c
===================================================================
--- uspace/lib/fmtutil/fmtutil.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/fmtutil/fmtutil.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -31,4 +31,5 @@
 #include <fmtutil.h>
 #include <stdlib.h>
+#include <str.h>
 
 typedef struct {
Index: uspace/lib/fs/libfs.c
===================================================================
--- uspace/lib/fs/libfs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/fs/libfs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -733,5 +733,5 @@
 	size_t size;
 	if ((!async_data_read_receive(&callid, &size)) ||
-	    (size != sizeof(struct stat))) {
+	    (size != sizeof(vfs_stat_t))) {
 		ops->node_put(fn);
 		async_answer_0(callid, EINVAL);
@@ -740,6 +740,6 @@
 	}
 
-	struct stat stat;
-	memset(&stat, 0, sizeof(struct stat));
+	vfs_stat_t stat;
+	memset(&stat, 0, sizeof(vfs_stat_t));
 
 	stat.fs_handle = fs_handle;
@@ -755,5 +755,5 @@
 
 
-	async_data_read_finalize(callid, &stat, sizeof(struct stat));
+	async_data_read_finalize(callid, &stat, sizeof(vfs_stat_t));
 	async_answer_0(rid, EOK);
 }
@@ -772,10 +772,10 @@
 	size_t size;
 	if ((!async_data_read_receive(&callid, &size)) ||
-	    (size != sizeof(struct statfs))) {
+	    (size != sizeof(vfs_statfs_t))) {
 		goto error;
 	}
 
-	struct statfs st;
-	memset(&st, 0, sizeof(struct statfs));
+	vfs_statfs_t st;
+	memset(&st, 0, sizeof(vfs_statfs_t));
 
 	str_cpy(st.fs_name, sizeof(st.fs_name), fs_name);
@@ -800,5 +800,5 @@
 
 	ops->node_put(fn);
-	async_data_read_finalize(callid, &st, sizeof(struct statfs));
+	async_data_read_finalize(callid, &st, sizeof(vfs_statfs_t));
 	async_answer_0(rid, EOK);
 	return;
Index: uspace/lib/fs/libfs.h
===================================================================
--- uspace/lib/fs/libfs.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/fs/libfs.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,14 +43,14 @@
 
 typedef struct {
-	errno_t (* fsprobe)(service_id_t, vfs_fs_probe_info_t *);
-	errno_t (* mounted)(service_id_t, const char *, fs_index_t *, aoff64_t *);
-	errno_t (* unmounted)(service_id_t);
-	errno_t (* read)(service_id_t, fs_index_t, aoff64_t, size_t *);
-	errno_t (* write)(service_id_t, fs_index_t, aoff64_t, size_t *,
+	errno_t (*fsprobe)(service_id_t, vfs_fs_probe_info_t *);
+	errno_t (*mounted)(service_id_t, const char *, fs_index_t *, aoff64_t *);
+	errno_t (*unmounted)(service_id_t);
+	errno_t (*read)(service_id_t, fs_index_t, aoff64_t, size_t *);
+	errno_t (*write)(service_id_t, fs_index_t, aoff64_t, size_t *,
 	    aoff64_t *);
-	errno_t (* truncate)(service_id_t, fs_index_t, aoff64_t);
-	errno_t (* close)(service_id_t, fs_index_t);
-	errno_t (* destroy)(service_id_t, fs_index_t);
-	errno_t (* sync)(service_id_t, fs_index_t);
+	errno_t (*truncate)(service_id_t, fs_index_t, aoff64_t);
+	errno_t (*close)(service_id_t, fs_index_t);
+	errno_t (*destroy)(service_id_t, fs_index_t);
+	errno_t (*sync)(service_id_t, fs_index_t);
 } vfs_out_ops_t;
 
@@ -65,27 +65,27 @@
 	 * argument holds the output argument.
 	 */
-	errno_t (* root_get)(fs_node_t **, service_id_t);
-	errno_t (* match)(fs_node_t **, fs_node_t *, const char *);
-	errno_t (* node_get)(fs_node_t **, service_id_t, fs_index_t);
-	errno_t (* node_open)(fs_node_t *);
-	errno_t (* node_put)(fs_node_t *);
-	errno_t (* create)(fs_node_t **, service_id_t, int);
-	errno_t (* destroy)(fs_node_t *);
-	errno_t (* link)(fs_node_t *, fs_node_t *, const char *);
-	errno_t (* unlink)(fs_node_t *, fs_node_t *, const char *);
-	errno_t (* has_children)(bool *, fs_node_t *);
+	errno_t (*root_get)(fs_node_t **, service_id_t);
+	errno_t (*match)(fs_node_t **, fs_node_t *, const char *);
+	errno_t (*node_get)(fs_node_t **, service_id_t, fs_index_t);
+	errno_t (*node_open)(fs_node_t *);
+	errno_t (*node_put)(fs_node_t *);
+	errno_t (*create)(fs_node_t **, service_id_t, int);
+	errno_t (*destroy)(fs_node_t *);
+	errno_t (*link)(fs_node_t *, fs_node_t *, const char *);
+	errno_t (*unlink)(fs_node_t *, fs_node_t *, const char *);
+	errno_t (*has_children)(bool *, fs_node_t *);
 	/*
 	 * The second set of methods are usually mere getters that do not
 	 * return an integer error code.
 	 */
-	fs_index_t (* index_get)(fs_node_t *);
-	aoff64_t (* size_get)(fs_node_t *);
-	unsigned int (* lnkcnt_get)(fs_node_t *);
-	bool (* is_directory)(fs_node_t *);
-	bool (* is_file)(fs_node_t *);
-	service_id_t (* service_get)(fs_node_t *);
-	errno_t (* size_block)(service_id_t, uint32_t *);
-	errno_t (* total_block_count)(service_id_t, uint64_t *);
-	errno_t (* free_block_count)(service_id_t, uint64_t *);
+	fs_index_t (*index_get)(fs_node_t *);
+	aoff64_t (*size_get)(fs_node_t *);
+	unsigned int (*lnkcnt_get)(fs_node_t *);
+	bool (*is_directory)(fs_node_t *);
+	bool (*is_file)(fs_node_t *);
+	service_id_t (*service_get)(fs_node_t *);
+	errno_t (*size_block)(service_id_t, uint32_t *);
+	errno_t (*total_block_count)(service_id_t, uint64_t *);
+	errno_t (*free_block_count)(service_id_t, uint64_t *);
 } libfs_ops_t;
 
Index: uspace/lib/graph/graph.h
===================================================================
--- uspace/lib/graph/graph.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/graph/graph.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -54,5 +54,5 @@
 	 * Device driver shall allocate any necessary internal structures
 	 * specific for a claimed visualizer. */
-	errno_t (* claim)(struct visualizer *vs);
+	errno_t (*claim)(struct visualizer *vs);
 	
 	/**
@@ -61,5 +61,5 @@
 	 * the mode is set and if so it shall change its internal state
 	 * accordingly (e.g. deallocate frame buffers). */
-	errno_t (* yield)(struct visualizer *vs);
+	errno_t (*yield)(struct visualizer *vs);
 	
 	/**
@@ -72,5 +72,5 @@
 	 * optimization), the pointer to the handle_damage operation can be
 	 * changed at this point. */
-	errno_t (* change_mode)(struct visualizer *vs, vslmode_t new_mode);
+	errno_t (*change_mode)(struct visualizer *vs, vslmode_t new_mode);
 	
 	/**
@@ -82,7 +82,7 @@
 	 * shall be added to the coordinates and if necessary the result shall be
 	 * wrapped around the edge of the backbuffer). */
-	errno_t (* handle_damage)(struct visualizer *vs,
+	errno_t (*handle_damage)(struct visualizer *vs,
 	    sysarg_t x, sysarg_t y, sysarg_t width, sysarg_t height,
-		sysarg_t x_offset, sysarg_t y_offset);
+	    sysarg_t x_offset, sysarg_t y_offset);
 	
 	/**
@@ -90,10 +90,10 @@
 	 * case, device driver might enable power saving mode on the device
 	 * corresponding to the visualizer. */
-	errno_t (* suspend)(struct visualizer *vs);
+	errno_t (*suspend)(struct visualizer *vs);
 	
 	/**
 	 * When upper layers detect activity on suspended visualizer, device
 	 * driver shall disable power saving mode on the corresponding device. */
-	errno_t (* wakeup)(struct visualizer *vs);
+	errno_t (*wakeup)(struct visualizer *vs);
 } visualizer_ops_t;
 
Index: uspace/lib/gui/terminal.c
===================================================================
--- uspace/lib/gui/terminal.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/gui/terminal.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <atomic.h>
 #include <stdarg.h>
+#include <str.h>
 #include "window.h"
 #include "terminal.h"
Index: uspace/lib/gui/terminal.h
===================================================================
--- uspace/lib/gui/terminal.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/gui/terminal.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,4 +45,5 @@
 #include <adt/prodcons.h>
 #include <atomic.h>
+#include <str.h>
 #include "widget.h"
 
Index: uspace/lib/hound/include/hound/client.h
===================================================================
--- uspace/lib/hound/include/hound/client.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/hound/include/hound/client.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,7 +47,7 @@
 typedef struct hound_stream hound_stream_t;
 
-hound_context_t * hound_context_create_playback(const char *name,
+hound_context_t *hound_context_create_playback(const char *name,
     pcm_format_t format, size_t bsize);
-hound_context_t * hound_context_create_capture(const char *name,
+hound_context_t *hound_context_create_capture(const char *name,
     pcm_format_t format, size_t bsize);
 void hound_context_destroy(hound_context_t *hound);
@@ -57,10 +57,10 @@
 
 errno_t hound_context_get_available_targets(hound_context_t *hound,
-    const char ***names, size_t *count);
+    char ***names, size_t *count);
 errno_t hound_context_get_connected_targets(hound_context_t *hound,
-    const char ***names, size_t *count);
+    char ***names, size_t *count);
 
-errno_t hound_context_connect_target(hound_context_t *hound, const char* target);
-errno_t hound_context_disconnect_target(hound_context_t *hound, const char* target);
+errno_t hound_context_connect_target(hound_context_t *hound, const char *target);
+errno_t hound_context_disconnect_target(hound_context_t *hound, const char *target);
 
 hound_stream_t *hound_stream_create(hound_context_t *hound, unsigned flags,
Index: uspace/lib/hound/include/hound/protocol.h
===================================================================
--- uspace/lib/hound/include/hound/protocol.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/hound/include/hound/protocol.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -65,5 +65,5 @@
 errno_t hound_service_unregister_context(hound_sess_t *sess, hound_context_id_t id);
 
-errno_t hound_service_get_list(hound_sess_t *sess, const char ***ids, size_t *count,
+errno_t hound_service_get_list(hound_sess_t *sess, char ***ids, size_t *count,
     int flags, const char *connection);
 
@@ -77,5 +77,5 @@
  */
 static inline errno_t hound_service_get_list_all(hound_sess_t *sess,
-    const char ***ids, size_t *count, int flags)
+    char ***ids, size_t *count, int flags)
 {
 	return hound_service_get_list(sess, ids, count, flags, NULL);
@@ -106,5 +106,5 @@
 	bool (*is_record_context)(void *, hound_context_id_t);
 	/** Get string identifiers of specified objects */
-	errno_t (*get_list)(void *, const char ***, size_t *, const char *, int);
+	errno_t (*get_list)(void *, char ***, size_t *, const char *, int);
 	/** Create connection between source and sink */
 	errno_t (*connect)(void *, const char *, const char *);
Index: uspace/lib/hound/src/client.c
===================================================================
--- uspace/lib/hound/src/client.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/hound/src/client.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -76,5 +76,5 @@
 	hound_sess_t *session;
 	/** context name, reported to the daemon */
-	const char *name;
+	char *name;
 	/** True if the instance is record context */
 	bool record;
@@ -196,5 +196,5 @@
  */
 errno_t hound_context_get_available_targets(hound_context_t *hound,
-    const char ***names, size_t *count)
+    char ***names, size_t *count)
 {
 	assert(hound);
@@ -213,5 +213,5 @@
  */
 errno_t hound_context_get_connected_targets(hound_context_t *hound,
-    const char ***names, size_t *count)
+    char ***names, size_t *count)
 {
 	assert(hound);
@@ -237,5 +237,5 @@
 	assert(target);
 
-	const char **tgt = NULL;
+	char **tgt = NULL;
 	size_t count = 1;
 	errno_t ret = EOK;
Index: uspace/lib/hound/src/protocol.c
===================================================================
--- uspace/lib/hound/src/protocol.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/hound/src/protocol.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -173,5 +173,5 @@
  * @retval Error code.
  */
-errno_t hound_service_get_list(hound_sess_t *sess, const char ***ids, size_t *count,
+errno_t hound_service_get_list(hound_sess_t *sess, char ***ids, size_t *count,
     int flags, const char *connection)
 {
@@ -206,5 +206,5 @@
 
 	/* Start receiving names */
-	const char **names = NULL;
+	char **names = NULL;
 	if (name_count) {
 		size_t *sizes = calloc(name_count, sizeof(size_t));
@@ -446,5 +446,5 @@
 			}
 
-			const char **list = NULL;
+			char **list = NULL;
 			const int flags = IPC_GET_ARG1(call);
 			size_t count = IPC_GET_ARG2(call);
Index: uspace/lib/nic/include/nic.h
===================================================================
--- uspace/lib/nic/include/nic.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/nic/include/nic.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -57,5 +57,5 @@
 	nic_wv_id_t id;
 	nic_wv_type_t type;
-	const void *data;
+	void *data;
 	size_t length;
 	struct nic_wol_virtue *next;
Index: uspace/lib/nic/include/nic_addr_db.h
===================================================================
--- uspace/lib/nic/include/nic_addr_db.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/nic/include/nic_addr_db.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -62,5 +62,5 @@
 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);
+    void (*func)(const uint8_t *, void *), void *arg);
 
 #endif
Index: uspace/lib/nic/include/nic_impl.h
===================================================================
--- uspace/lib/nic/include/nic_impl.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/nic/include/nic_impl.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -82,5 +82,5 @@
 
 extern void nic_default_handler_impl(ddf_fun_t *dev_fun,
-	ipc_callid_t callid, ipc_call_t *call);
+    ipc_callid_t callid, ipc_call_t *call);
 extern errno_t nic_open_impl(ddf_fun_t *fun);
 extern void nic_close_impl(ddf_fun_t *fun);
Index: uspace/lib/nic/include/nic_wol_virtues.h
===================================================================
--- uspace/lib/nic/include/nic_wol_virtues.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/nic/include/nic_wol_virtues.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -78,10 +78,10 @@
 extern errno_t nic_wol_virtues_verify(nic_wv_type_t, const void *, size_t);
 extern errno_t nic_wol_virtues_list(const nic_wol_virtues_t *, nic_wv_type_t type,
-	size_t max_count, nic_wv_id_t *id_list, size_t *id_count);
+    size_t max_count, nic_wv_id_t *id_list, size_t *id_count);
 extern errno_t nic_wol_virtues_add(nic_wol_virtues_t *, nic_wol_virtue_t *);
 extern nic_wol_virtue_t *nic_wol_virtues_remove(nic_wol_virtues_t *,
-	nic_wv_id_t);
+    nic_wv_id_t);
 extern const nic_wol_virtue_t *nic_wol_virtues_find(const nic_wol_virtues_t *,
-	nic_wv_id_t);
+    nic_wv_id_t);
 
 #endif
Index: pace/lib/packet/include/netdb.h
===================================================================
--- uspace/lib/packet/include/netdb.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,109 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 netdb
- *  @{
- */
-
-/** @file
- *  Structures and interfaces according to the BSD netdb.h file.
- */
-
-#ifndef __NET_NETDB_H__
-#define __NET_NETDB_H__
-
-#include <sys/types.h>
-
-/** Structure returned by network data base library.
- *  All addresses are supplied in host order, and returned in network order (suitable for use in system calls).
- */
-struct	hostent {
-	/** Official host name.
-	 */
-	char * h_name;
-	/** Alias list.
-	 */
-	char **	h_aliases;
-	/** Host address type.
-	 */
-	int h_addrtype;
-	/** Address length.
-	 */
-	int h_length;
-	/** List of addresses from name server.
-	 */
-	char **	h_addr_list;
-	/** Address, for backward compatiblity.
-	 */
-#define	h_addr	h_addr_list[0]
-};
-
-/** @name Host entry address types definitions.
- */
-/*@{*/
-
-/** Authoritative Answer Host not found address type.
- */
-#define	HOST_NOT_FOUND	1
-
-/** Non-Authoritive Host not found, or SERVERFAIL address type.
- */
-#define	TRY_AGAIN	2
-
-/** Non recoverable errors, FORMERR, REFUSED, NOTIMP address type.
- */
-#define	NO_RECOVERY	3
-
-/** Valid name, no data record of requested type address type.
- */
-#define	NO_DATA		4
-
-/** No address, look for MX record address type.
- */
-#define	NO_ADDRESS	NO_DATA
-
-/*@}*/
-
-/** Returns host entry by the host address.
- *  @param[in] address The host address.
- *  @param[in] len The address length.
- *  @param[in] type The address type.
- *  @returns Host entry information.
- */
-//struct hostent *	gethostbyaddr(const void * address, int len, int type);
-
-/** Returns host entry by the host name.
- *  @param[in] name The host name.
- *  @returns Host entry information.
- */
-//struct hostent *	gethostbyname(const char * name);
-
-#endif
-
-/** @}
- */
Index: pace/lib/packet/include/tcp_codes.h
===================================================================
--- uspace/lib/packet/include/tcp_codes.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,88 +1,0 @@
-/*
- * Copyright (c) 2009 Lukas Mejdrech
- * 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 tcp
- *  @{
- */
-
-/** @file
- *  TCP options definitions.
- */
-
-#ifndef __NET_TCP_CODES_H__
-#define __NET_TCP_CODES_H__
-
-/** End of list TCP option.
- */
-#define TCPOPT_END_OF_LIST				0x0
-
-/** No operation TCP option.
- */
-#define TCPOPT_NO_OPERATION				0x1
-
-/** Maximum segment size TCP option.
- */
-#define TCPOPT_MAX_SEGMENT_SIZE			0x2
-
-/** Maximum segment size TCP option length.
- */
-#define TCPOPT_MAX_SEGMENT_SIZE_LENGTH	4
-
-/** Window scale TCP option.
- */
-#define TCPOPT_WINDOW_SCALE				0x3
-
-/** Window scale TCP option length.
- */
-#define TCPOPT_WINDOW_SCALE_LENGTH		3
-
-/** Selective acknowledgement permitted TCP option.
- */
-#define TCPOPT_SACK_PERMITTED			0x4
-
-/** Selective acknowledgement permitted TCP option length.
- */
-#define TCPOPT_SACK_PERMITTED_LENGTH	2
-
-/** Selective acknowledgement TCP option.
- *  Has variable length.
- */
-#define TCPOPT_SACK						0x5
-
-/** Timestamp TCP option.
- */
-#define TCPOPT_TIMESTAMP				0x8
-
-/** Timestamp TCP option length.
- */
-#define TCPOPT_TIMESTAMP_LENGTH			10
-
-#endif
-
-/** @}
- */
Index: uspace/lib/pcm/include/pcm/sample_format.h
===================================================================
--- uspace/lib/pcm/include/pcm/sample_format.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/pcm/include/pcm/sample_format.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -184,11 +184,11 @@
 	switch(format) {
 	case PCM_SAMPLE_UINT8:
-		return "8 bit unsinged";
+		return "8 bit unsigned";
 	case PCM_SAMPLE_SINT8:
-		return "8 bit singed";
+		return "8 bit signed";
 	case PCM_SAMPLE_UINT16_LE:
 		return "16 bit unsigned(LE)";
 	case PCM_SAMPLE_SINT16_LE:
-		return "16 bit singed(LE)";
+		return "16 bit signed(LE)";
 	case PCM_SAMPLE_UINT16_BE:
 		return "16 bit unsigned(BE)";
Index: uspace/lib/pcut/src/internal.h
===================================================================
--- uspace/lib/pcut/src/internal.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/pcut/src/internal.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -125,5 +125,5 @@
 	/** Test completed. */
 	void (*test_done)(pcut_item_t *, int, const char *, const char *,
-		const char *);
+	    const char *);
 };
 
@@ -135,8 +135,8 @@
 void pcut_report_test_start(pcut_item_t *test);
 void pcut_report_test_done(pcut_item_t *test, int outcome,
-		const char *error_message, const char *teardown_error_message,
-		const char *extra_output);
+    const char *error_message, const char *teardown_error_message,
+    const char *extra_output);
 void pcut_report_test_done_unparsed(pcut_item_t *test, int outcome,
-		const char *unparsed_output, size_t unparsed_output_size);
+    const char *unparsed_output, size_t unparsed_output_size);
 void pcut_report_done(void);
 
Index: uspace/lib/pcut/src/report/report.c
===================================================================
--- uspace/lib/pcut/src/report/report.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/pcut/src/report/report.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -33,5 +33,7 @@
 
 #include "../internal.h"
-#ifndef __helenos__
+#ifdef __helenos__
+#include <str.h>
+#else
 #include <string.h>
 #endif
Index: uspace/lib/posix/Makefile
===================================================================
--- uspace/lib/posix/Makefile	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/Makefile	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,16 +37,13 @@
 LIBC_FILE = $(LIBC_PREFIX)/libc.a
 
-FIXED_POSIX_LIBRARY = libposixaslibc.a
 FIXED_C_LIBRARY = libc4posix.a
 MERGED_C_LIBRARY = libc.a
 MERGE_LIBRARIES = \
 	$(FIXED_C_LIBRARY) \
-	$(FIXED_POSIX_LIBRARY) \
+	$(LIBRARY).a \
 	$(LIBSOFTFLOAT_PREFIX)/libsoftfloat.a \
 	$(LIBSOFTINT_PREFIX)/libsoftint.a
 
 REDEFS_HIDE_LIBC = redefs-hide-libc-symbols.list
-REDEFS_SHOW_LIBPOSIX = redefs-show-posix-symbols.list
-COLLISIONS_LIST = collisions.list
 
 PRE_DEPEND = $(INCLUDE_LIBC)
@@ -54,6 +51,4 @@
 	$(INCLUDE_LIBC) \
 	$(REDEFS_HIDE_LIBC) \
-	$(REDEFS_SHOW_LIBPOSIX) \
-	$(COLLISIONS_LIST) \
 	libc.o
 
@@ -61,28 +56,26 @@
 
 SOURCES = \
-	source/ctype.c \
-	source/dlfcn.c \
-	source/fcntl.c \
-	source/fnmatch.c \
-	source/getopt.c \
-	source/locale.c \
-	source/pthread/condvar.c \
-	source/pthread/keys.c \
-	source/pthread/mutex.c \
-	source/pthread/threads.c \
-	source/pwd.c \
-	source/signal.c \
-	source/stdio.c \
-	source/stdio/scanf.c \
-	source/stdlib.c \
-	source/stdlib/strtol.c \
-	source/stdlib/strtold.c \
-	source/string.c \
-	source/strings.c \
-	source/sys/mman.c \
-	source/sys/stat.c \
-	source/sys/wait.c \
-	source/time.c \
-	source/unistd.c
+	src/ctype.c \
+	src/dlfcn.c \
+	src/fcntl.c \
+	src/fnmatch.c \
+	src/locale.c \
+	src/pthread/condvar.c \
+	src/pthread/keys.c \
+	src/pthread/mutex.c \
+	src/pthread/threads.c \
+	src/pwd.c \
+	src/signal.c \
+	src/stdio.c \
+	src/stdio/scanf.c \
+	src/stdlib.c \
+	src/stdlib/strtold.c \
+	src/string.c \
+	src/strings.c \
+	src/sys/mman.c \
+	src/sys/stat.c \
+	src/sys/wait.c \
+	src/time.c \
+	src/unistd.c
 
 TEST_SOURCES = \
@@ -95,11 +88,6 @@
 	ln -s -f -n ../$^ $@
 
-$(FIXED_C_LIBRARY): $(LIBC_FILE) $(REDEFS_HIDE_LIBC) $(REDEFS_SHOW_LIBPOSIX)
+$(FIXED_C_LIBRARY): $(LIBC_FILE) $(REDEFS_HIDE_LIBC)
 	$(OBJCOPY) --redefine-syms=$(REDEFS_HIDE_LIBC) $(LIBC_FILE) $@
-	$(OBJCOPY) --redefine-syms=$(REDEFS_SHOW_LIBPOSIX) $@ $@
-
-$(FIXED_POSIX_LIBRARY): $(LIBRARY).a $(REDEFS_HIDE_LIBC) $(REDEFS_SHOW_LIBPOSIX)
-	$(OBJCOPY) --redefine-syms=$(REDEFS_HIDE_LIBC) $(LIBRARY).a $@
-	$(OBJCOPY) --redefine-syms=$(REDEFS_SHOW_LIBPOSIX) $@ $@
 
 $(MERGED_C_LIBRARY): $(MERGE_LIBRARIES)
@@ -107,13 +95,5 @@
 	$(AR) rc $@ libc.o
 
-$(REDEFS_HIDE_LIBC): $(COLLISIONS_LIST)
-	sed 's/.*/& __helenos_libc_&/' <$(COLLISIONS_LIST) >$@
+$(REDEFS_HIDE_LIBC): $(SOURCES)
+	sed -n -e 's/_HIDE_LIBC_SYMBOL(\(.*\))/\1 __helenos_libc_\1/p' $(SOURCES) >$@
 
-$(REDEFS_SHOW_LIBPOSIX): $(COLLISIONS_LIST)
-	sed 's/.*/posix_& &/' <$(COLLISIONS_LIST) >$@
-
-$(COLLISIONS_LIST): include/posix/*.h include/posix/*/*.h
-	find ./include/posix -name '*.h' -exec \
-		sed -n -e '/^#/d' -e 's/__POSIX_DEF__/\n&/gp' {} \; | \
-		sed -n -e 's/__POSIX_DEF__(\([^)]*\)).*/\1/p' | \
-		sort -u >$@
Index: uspace/lib/posix/include/posix/assert.h
===================================================================
--- uspace/lib/posix/include/posix/assert.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/include/posix/assert.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,1 @@
+#include "libc/assert.h"
Index: uspace/lib/posix/include/posix/ctype.h
===================================================================
--- uspace/lib/posix/include/posix/ctype.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/ctype.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,27 +37,12 @@
 #define POSIX_CTYPE_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "libc/ctype.h"
 
-/* Classification of Characters */
-extern int __POSIX_DEF__(isxdigit)(int c);
-extern int __POSIX_DEF__(isblank)(int c);
-extern int __POSIX_DEF__(iscntrl)(int c);
-extern int __POSIX_DEF__(isgraph)(int c);
-extern int __POSIX_DEF__(isprint)(int c);
-extern int __POSIX_DEF__(ispunct)(int c);
+/* Obsolete Functions and Macros */
+extern int isascii(int c);
+extern int toascii(int c);
 
-/* Obsolete Functions and Macros */
-extern int __POSIX_DEF__(isascii)(int c);
-extern int __POSIX_DEF__(toascii)(int c);
-#undef _tolower
 #define _tolower(c) ((c) - 'A' + 'a')
-#undef _toupper
 #define _toupper(c) ((c) - 'a' + 'A')
-
-
 
 #endif /* POSIX_CTYPE_H_ */
Index: uspace/lib/posix/include/posix/dirent.h
===================================================================
--- uspace/lib/posix/include/posix/dirent.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/dirent.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_DIRENT_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include <libc/dirent.h>
 
Index: uspace/lib/posix/include/posix/dlfcn.h
===================================================================
--- uspace/lib/posix/include/posix/dlfcn.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/dlfcn.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,7 +34,5 @@
 #define POSIX_DLFCN_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
+#include "libc/dlfcn.h"
 
 #define RTLD_LAZY 1
@@ -43,10 +41,8 @@
 #define RTLD_LOCAL 0
 
-
-extern void *__POSIX_DEF__(dlopen)(const char *, int);
-extern void *__POSIX_DEF__(dlsym)(void *, const char *);
-extern int __POSIX_DEF__(dlclose)(void *);
-extern char *__POSIX_DEF__(dlerror)(void);
-
+extern void *dlopen(const char *, int);
+extern void *dlsym(void *, const char *);
+extern int dlclose(void *);
+extern char *dlerror(void);
 
 #endif
Index: uspace/lib/posix/include/posix/errno.h
===================================================================
--- uspace/lib/posix/include/posix/errno.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/include/posix/errno.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,1 @@
+#include "libc/errno.h"
Index: uspace/lib/posix/include/posix/fcntl.h
===================================================================
--- uspace/lib/posix/include/posix/fcntl.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/fcntl.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,8 +35,4 @@
 #ifndef POSIX_FCNTL_H_
 #define POSIX_FCNTL_H_
-
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
 
 #include "sys/types.h"
@@ -93,7 +89,6 @@
 #define FD_CLOEXEC         1 /* Close on exec. */
 
-extern int __POSIX_DEF__(open)(const char *pathname, int flags, ...);
-extern int __POSIX_DEF__(fcntl)(int fd, int cmd, ...);
-
+extern int open(const char *pathname, int flags, ...);
+extern int fcntl(int fd, int cmd, ...);
 
 #endif /* POSIX_FCNTL_H_ */
Index: uspace/lib/posix/include/posix/fenv.h
===================================================================
--- uspace/lib/posix/include/posix/fenv.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/fenv.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,5 +37,4 @@
 #define POSIX_FENV_H_
 
-
 #define FE_DIVBYZERO 1
 #define FE_INEXACT 2
Index: uspace/lib/posix/include/posix/float.h
===================================================================
--- uspace/lib/posix/include/posix/float.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/float.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -41,40 +41,40 @@
 /* define some standard C constants in terms of GCC built-ins */
 #ifdef __GNUC__
-	#undef DBL_MANT_DIG
-	#define DBL_MANT_DIG __DBL_MANT_DIG__
-	#undef DBL_MIN_EXP
-	#define DBL_MIN_EXP __DBL_MIN_EXP__
-	#undef DBL_MAX_EXP
-	#define DBL_MAX_EXP __DBL_MAX_EXP__
-	#undef DBL_MAX
-	#define DBL_MAX __DBL_MAX__
-	#undef DBL_MAX_10_EXP
-	#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
-	#undef DBL_MIN_10_EXP
-	#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
-	#undef DBL_MIN
-	#define DBL_MIN __DBL_MIN__
-	#undef DBL_DIG
-	#define DBL_DIG __DBL_DIG__
-	#undef DBL_EPSILON
-	#define DBL_EPSILON __DBL_EPSILON__
-	#undef LDBL_EPSILON
-	#define LDBL_EPSILON __LDBL_EPSILON__
-	#undef FLT_RADIX
-	#define FLT_RADIX __FLT_RADIX__
-	#undef FLT_MIN
-	#define FLT_MIN __FLT_MIN__
-	#undef FLT_MAX
-	#define FLT_MAX __FLT_MAX__
-	#undef FLT_EPSILON
-	#define FLT_EPSILON __FLT_EPSILON__
-	#undef FLT_MANT_DIG
-	#define FLT_MANT_DIG __FLT_MANT_DIG__
-	#undef LDBL_MIN
-	#define LDBL_MIN __LDBL_MIN__
-	#undef LDBL_MAX
-	#define LDBL_MAX __LDBL_MAX__
-	#undef LDBL_MANT_DIG 
-	#define LDBL_MANT_DIG __LDBL_MANT_DIG__
+#undef DBL_MANT_DIG
+#define DBL_MANT_DIG __DBL_MANT_DIG__
+#undef DBL_MIN_EXP
+#define DBL_MIN_EXP __DBL_MIN_EXP__
+#undef DBL_MAX_EXP
+#define DBL_MAX_EXP __DBL_MAX_EXP__
+#undef DBL_MAX
+#define DBL_MAX __DBL_MAX__
+#undef DBL_MAX_10_EXP
+#define DBL_MAX_10_EXP __DBL_MAX_10_EXP__
+#undef DBL_MIN_10_EXP
+#define DBL_MIN_10_EXP __DBL_MIN_10_EXP__
+#undef DBL_MIN
+#define DBL_MIN __DBL_MIN__
+#undef DBL_DIG
+#define DBL_DIG __DBL_DIG__
+#undef DBL_EPSILON
+#define DBL_EPSILON __DBL_EPSILON__
+#undef LDBL_EPSILON
+#define LDBL_EPSILON __LDBL_EPSILON__
+#undef FLT_RADIX
+#define FLT_RADIX __FLT_RADIX__
+#undef FLT_MIN
+#define FLT_MIN __FLT_MIN__
+#undef FLT_MAX
+#define FLT_MAX __FLT_MAX__
+#undef FLT_EPSILON
+#define FLT_EPSILON __FLT_EPSILON__
+#undef FLT_MANT_DIG
+#define FLT_MANT_DIG __FLT_MANT_DIG__
+#undef LDBL_MIN
+#define LDBL_MIN __LDBL_MIN__
+#undef LDBL_MAX
+#define LDBL_MAX __LDBL_MAX__
+#undef LDBL_MANT_DIG 
+#define LDBL_MANT_DIG __LDBL_MANT_DIG__
 #else
 /* For something else than GCC, following definitions are provided.
Index: uspace/lib/posix/include/posix/fnmatch.h
===================================================================
--- uspace/lib/posix/include/posix/fnmatch.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/fnmatch.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_FNMATCH_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 /* Error Values */
 #undef FNM_NOMATCH
@@ -60,5 +56,5 @@
 #define FNM_CASEFOLD 16
 
-extern int __POSIX_DEF__(fnmatch)(const char *pattern, const char *string, int flags);
+extern int fnmatch(const char *pattern, const char *string, int flags);
 
 
Index: uspace/lib/posix/include/posix/getopt.h
===================================================================
--- uspace/lib/posix/include/posix/getopt.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/getopt.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,26 +35,6 @@
 #define POSIX_GETOPT_H
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "unistd.h"
-
-/* Option Arguments */
-#define no_argument        0
-#define required_argument  1
-#define optional_argument  2
-
-#ifndef LIBPOSIX_INTERNAL
-struct option {
-	const char *name;
-	int has_arg;
-	int *flag;
-	int val;
-};
-#endif
-
-extern int __POSIX_DEF__(getopt_long)(int, char * const [], const char *, const struct option *, int *);
-
+#include "libc/getopt.h"
 
 #endif
Index: uspace/lib/posix/include/posix/inttypes.h
===================================================================
--- uspace/lib/posix/include/posix/inttypes.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/inttypes.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,16 +36,6 @@
 #define POSIX_INTTYPES_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "stdint.h"
 #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);
-
 
 #endif /* POSIX_INTTYPES_H_ */
Index: uspace/lib/posix/include/posix/locale.h
===================================================================
--- uspace/lib/posix/include/posix/locale.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/locale.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,16 +36,9 @@
 #define POSIX_LOCALE_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include <_bits/NULL.h>
 
 #ifndef __locale_t_defined
-	#define __locale_t_defined
-	typedef struct __posix_locale *__POSIX_DEF__(locale_t);
-	#ifndef LIBPOSIX_INTERNAL
-		#define locale_t __POSIX_DEF__(locale_t)
-	#endif
+#define __locale_t_defined
+typedef struct __posix_locale *locale_t;
 #endif
 
@@ -84,5 +77,5 @@
 #define LC_GLOBAL_LOCALE NULL
 
-struct __POSIX_DEF__(lconv) {
+struct lconv {
 	char *currency_symbol;
 	char *decimal_point;
@@ -111,13 +104,13 @@
 };
 
-extern char *__POSIX_DEF__(setlocale)(int category, const char *locale);
-extern struct __POSIX_DEF__(lconv) *__POSIX_DEF__(localeconv)(void);
+extern char *setlocale(int category, const char *locale);
+extern struct lconv *localeconv(void);
 
 /* POSIX Extensions */
-extern __POSIX_DEF__(locale_t) __POSIX_DEF__(duplocale)(__POSIX_DEF__(locale_t) locobj);
-extern void __POSIX_DEF__(freelocale)(__POSIX_DEF__(locale_t) locobj);
-extern __POSIX_DEF__(locale_t) __POSIX_DEF__(newlocale)(int category_mask, const char *locale,
-    __POSIX_DEF__(locale_t) base);
-extern __POSIX_DEF__(locale_t) __POSIX_DEF__(uselocale)(__POSIX_DEF__(locale_t) newloc);
+extern locale_t duplocale(locale_t locobj);
+extern void freelocale(locale_t locobj);
+extern locale_t newlocale(int category_mask, const char *locale,
+    locale_t base);
+extern locale_t uselocale(locale_t newloc);
 
 
Index: uspace/lib/posix/include/posix/math.h
===================================================================
--- uspace/lib/posix/include/posix/math.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/math.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,5 +43,5 @@
 
 #ifdef __GNUC__
-	#define HUGE_VAL (__builtin_huge_val())
+#define HUGE_VAL (__builtin_huge_val())
 #endif
 
Index: uspace/lib/posix/include/posix/pthread.h
===================================================================
--- uspace/lib/posix/include/posix/pthread.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/pthread.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -32,8 +32,4 @@
 #ifndef POSIX_PTHREAD_H_
 #define POSIX_PTHREAD_H_
-
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
 
 #include "libc/thread.h"
@@ -99,5 +95,5 @@
 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__);
+    pthread_mutex_t *__restrict__, const struct timespec *__restrict__);
 extern int pthread_cond_wait(pthread_cond_t *__restrict__,
     pthread_mutex_t *__restrict__);
@@ -109,5 +105,5 @@
 extern int pthread_setspecific(pthread_key_t, const void *);
 extern int pthread_key_delete(pthread_key_t);
-extern int pthread_key_create(pthread_key_t *, void (*)(void*));
+extern int pthread_key_create(pthread_key_t *, void (*)(void *));
 
 #endif
Index: uspace/lib/posix/include/posix/pwd.h
===================================================================
--- uspace/lib/posix/include/posix/pwd.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/pwd.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,29 +36,25 @@
 #define POSIX_PWD_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
-struct __POSIX_DEF__(passwd) {
+struct passwd {
 	char *pw_name;
-	__POSIX_DEF__(uid_t) pw_uid;
-	__POSIX_DEF__(gid_t) pw_gid;
+	uid_t pw_uid;
+	gid_t pw_gid;
 	char *pw_dir;
 	char *pw_shell;
 };
 
-extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwent)(void);
-extern void __POSIX_DEF__(setpwent)(void);
-extern void __POSIX_DEF__(endpwent)(void);
+extern struct passwd *getpwent(void);
+extern void setpwent(void);
+extern void endpwent(void);
 
-extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwnam)(const char *name);
-extern int __POSIX_DEF__(getpwnam_r)(const char *name, struct __POSIX_DEF__(passwd) *pwd,
-    char *buffer, size_t bufsize, struct __POSIX_DEF__(passwd) **result);
+extern struct passwd *getpwnam(const char *name);
+extern int getpwnam_r(const char *name, struct passwd *pwd,
+    char *buffer, size_t bufsize, struct passwd **result);
 
-extern struct __POSIX_DEF__(passwd) *__POSIX_DEF__(getpwuid)(__POSIX_DEF__(uid_t) uid);
-extern int __POSIX_DEF__(getpwuid_r)(__POSIX_DEF__(uid_t) uid, struct __POSIX_DEF__(passwd) *pwd,
-    char *buffer, size_t bufsize, struct __POSIX_DEF__(passwd) **result);
+extern struct passwd *getpwuid(uid_t uid);
+extern int getpwuid_r(uid_t uid, struct passwd *pwd,
+    char *buffer, size_t bufsize, struct passwd **result);
 
 
Index: uspace/lib/posix/include/posix/signal.h
===================================================================
--- uspace/lib/posix/include/posix/signal.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/signal.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_SIGNAL_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 #include <posix/ucontext.h>
@@ -63,6 +59,6 @@
 	int si_errno;
 
-	__POSIX_DEF__(pid_t) si_pid;
-	__POSIX_DEF__(uid_t) si_uid;
+	pid_t si_pid;
+	uid_t si_uid;
 	void *si_addr;
 	int si_status;
@@ -70,16 +66,16 @@
 	long si_band;
 
-	union __POSIX_DEF__(sigval) si_value;
-} __POSIX_DEF__(siginfo_t);
-
-struct __POSIX_DEF__(sigaction) {
+	union sigval si_value;
+} siginfo_t;
+
+struct sigaction {
 	void (*sa_handler)(int);
-	__POSIX_DEF__(sigset_t) sa_mask;
+	sigset_t sa_mask;
 	int sa_flags;
-	void (*sa_sigaction)(int, __POSIX_DEF__(siginfo_t) *, void *);
+	void (*sa_sigaction)(int, siginfo_t *, void *);
 };
 
 
-/* Values of __POSIX_DEF__(sigevent)::sigev_notify */
+/* Values of sigevent::sigev_notify */
 #undef SIGEV_NONE
 #undef SIGEV_SIGNAL
@@ -229,25 +225,25 @@
 };
 
-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);
-extern int __POSIX_DEF__(raise)(int sig);
-extern int __POSIX_DEF__(kill)(__POSIX_DEF__(pid_t) pid, int sig);
-extern int __POSIX_DEF__(killpg)(__POSIX_DEF__(pid_t) pid, int sig);
-
-extern void __POSIX_DEF__(psiginfo)(const __POSIX_DEF__(siginfo_t) *pinfo, const char *message);
-extern void __POSIX_DEF__(psignal)(int signum, const char *message);
-
-extern int __POSIX_DEF__(sigemptyset)(__POSIX_DEF__(sigset_t) *set);
-extern int __POSIX_DEF__(sigfillset)(__POSIX_DEF__(sigset_t) *set);
-extern int __POSIX_DEF__(sigaddset)(__POSIX_DEF__(sigset_t) *set, int signo);
-extern int __POSIX_DEF__(sigdelset)(__POSIX_DEF__(sigset_t) *set, int signo);
-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 sigaction(int sig, const struct sigaction *__restrict__ act,
+    struct sigaction *__restrict__ oact);
+
+extern void (*signal(int sig, void (*func)(int)))(int);
+extern int raise(int sig);
+extern int kill(pid_t pid, int sig);
+extern int killpg(pid_t pid, int sig);
+
+extern void psiginfo(const siginfo_t *pinfo, const char *message);
+extern void psignal(int signum, const char *message);
+
+extern int sigemptyset(sigset_t *set);
+extern int sigfillset(sigset_t *set);
+extern int sigaddset(sigset_t *set, int signo);
+extern int sigdelset(sigset_t *set, int signo);
+extern int sigismember(const sigset_t *set, int signo);
+
+extern int thread_sigmask(int how, const sigset_t *__restrict__ set,
+    sigset_t *__restrict__ oset);
+extern int sigprocmask(int how, const sigset_t *__restrict__ set,
+    sigset_t *__restrict__ oset);
 
 
Index: uspace/lib/posix/include/posix/stddef.h
===================================================================
--- uspace/lib/posix/include/posix/stddef.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/stddef.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_STDDEF_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
Index: uspace/lib/posix/include/posix/stdint.h
===================================================================
--- uspace/lib/posix/include/posix/stdint.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/stdint.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_STDINT_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "libc/stdint.h"
 
Index: uspace/lib/posix/include/posix/stdio.h
===================================================================
--- uspace/lib/posix/include/posix/stdio.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/stdio.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,12 +37,5 @@
 #define POSIX_STDIO_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-/* DEBUG macro does not belong to POSIX stdio.h. Its unconditional
- * definition in the native stdio.h causes unexpected behaviour of
- * applications which uses their own DEBUG macro (e.g. debugging
- * output is printed even if not desirable). */
-#undef DEBUG
-#endif
+#include "libc/stdio.h"
 
 #include "stddef.h"
@@ -72,15 +65,4 @@
 typedef struct _IO_FILE FILE;
 
-#ifndef LIBPOSIX_INTERNAL
-	enum _buffer_type {
-		/** No buffering */
-		_IONBF,
-		/** Line buffering */
-		_IOLBF,
-		/** Full buffering */
-		_IOFBF
-	};
-#endif
-
 extern FILE *stdin;
 extern FILE *stdout;
@@ -99,14 +81,14 @@
 extern int puts(const char *);
 
-extern int fprintf(FILE *, const char*, ...) PRINTF_ATTRIBUTE(2, 3);
+extern int fprintf(FILE *, const char*, ...) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 extern int vfprintf(FILE *, const char *, va_list);
 
-extern int printf(const char *, ...) PRINTF_ATTRIBUTE(1, 2);
+extern int printf(const char *, ...) _HELENOS_PRINTF_ATTRIBUTE(1, 2);
 extern int vprintf(const char *, va_list);
 
-extern int snprintf(char *, size_t , const char *, ...) PRINTF_ATTRIBUTE(3, 4);
+extern int snprintf(char *, size_t , const char *, ...) _HELENOS_PRINTF_ATTRIBUTE(3, 4);
 #ifdef _GNU_SOURCE
 extern int vasprintf(char **, const char *, va_list);
-extern int asprintf(char **, const char *, ...) PRINTF_ATTRIBUTE(2, 3);
+extern int asprintf(char **, const char *, ...) _HELENOS_PRINTF_ATTRIBUTE(2, 3);
 #endif
 extern int vsnprintf(char *, size_t, const char *, va_list);
@@ -135,84 +117,84 @@
 #undef L_ctermid
 #define L_ctermid PATH_MAX
-extern char *__POSIX_DEF__(ctermid)(char *s);
+extern char *ctermid(char *s);
 
 /* Error Recovery */
-extern void __POSIX_DEF__(clearerr)(FILE *stream);
+extern void clearerr(FILE *stream);
 
 /* Input/Output */
 #undef putc
 #define putc fputc
-extern int __POSIX_DEF__(fputs)(const char *__restrict__ s, FILE *__restrict__ stream);
+extern int 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,
+extern int ungetc(int c, FILE *stream);
+extern ssize_t 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,
+extern ssize_t getline(char **__restrict__ lineptr, size_t *__restrict__ n,
     FILE *__restrict__ stream);
 
 /* Opening Streams */
-extern FILE *__POSIX_DEF__(freopen)(const char *__restrict__ filename,
+extern FILE *freopen(const char *__restrict__ filename,
     const char *__restrict__ mode, FILE *__restrict__ stream);
 
 /* Error Messages */
-extern void __POSIX_DEF__(perror)(const char *s);
+extern void perror(const char *s);
 
 /* File Positioning */
 typedef struct {
 	off64_t offset;
-} __POSIX_DEF__(fpos_t);
-
-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__(fseek)(FILE *stream, long offset, int whence);
-extern int __POSIX_DEF__(fseeko)(FILE *stream, __POSIX_DEF__(off_t) offset, int whence);
-extern long __POSIX_DEF__(ftell)(FILE *stream);
-extern __POSIX_DEF__(off_t) __POSIX_DEF__(ftello)(FILE *stream);
+} fpos_t;
+
+extern int fsetpos(FILE *stream, const fpos_t *pos);
+extern int fgetpos(FILE *__restrict__ stream, fpos_t *__restrict__ pos);
+extern int fseek(FILE *stream, long offset, int whence);
+extern int fseeko(FILE *stream, off_t offset, int whence);
+extern long ftell(FILE *stream);
+extern off_t ftello(FILE *stream);
 
 /* Flushing Buffers */
-extern int __POSIX_DEF__(fflush)(FILE *stream);
+extern int fflush(FILE *stream);
 
 /* Formatted Output */
-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, ...)
-    PRINTF_ATTRIBUTE(2, 3);
-extern int __POSIX_DEF__(vsprintf)(char *__restrict__ s, const char *__restrict__ format, va_list ap);
+extern int dprintf(int fildes, const char *__restrict__ format, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
+extern int vdprintf(int fildes, const char *__restrict__ format, va_list ap);
+extern int sprintf(char *__restrict__ s, const char *__restrict__ format, ...)
+    _HELENOS_PRINTF_ATTRIBUTE(2, 3);
+extern int vsprintf(char *__restrict__ s, const char *__restrict__ format, va_list ap);
 
 /* Formatted Input */
-extern int __POSIX_DEF__(fscanf)(
+extern int fscanf(
     FILE *__restrict__ stream, const char *__restrict__ format, ...);
-extern int __POSIX_DEF__(vfscanf)(
+extern int 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);
-extern int __POSIX_DEF__(sscanf)(
+extern int scanf(const char *__restrict__ format, ...);
+extern int vscanf(const char *__restrict__ format, va_list arg);
+extern int sscanf(
     const char *__restrict__ s, const char *__restrict__ format, ...);
-extern int __POSIX_DEF__(vsscanf)(
+extern int vsscanf(
     const char *__restrict__ s, const char *__restrict__ format, va_list arg);
 
 /* File Locking */
-extern void __POSIX_DEF__(flockfile)(FILE *file);
-extern int __POSIX_DEF__(ftrylockfile)(FILE *file);
-extern void __POSIX_DEF__(funlockfile)(FILE *file);
-extern int __POSIX_DEF__(getc_unlocked)(FILE *stream);
-extern int __POSIX_DEF__(getchar_unlocked)(void);
-extern int __POSIX_DEF__(putc_unlocked)(int c, FILE *stream);
-extern int __POSIX_DEF__(putchar_unlocked)(int c);
+extern void flockfile(FILE *file);
+extern int ftrylockfile(FILE *file);
+extern void funlockfile(FILE *file);
+extern int getc_unlocked(FILE *stream);
+extern int getchar_unlocked(void);
+extern int putc_unlocked(int c, FILE *stream);
+extern int putchar_unlocked(int c);
 
 /* Deleting Files */
-extern int __POSIX_DEF__(remove)(const char *path);
+extern int remove(const char *path);
 
 /* Renaming Files */
-extern int __POSIX_DEF__(rename)(const char *oldname, const char *newname);
+extern int rename(const char *oldname, const char *newname);
 
 /* Temporary Files */
 #undef L_tmpnam
 #define L_tmpnam PATH_MAX
-extern char *__POSIX_DEF__(tmpnam)(char *s);
-extern char *__POSIX_DEF__(tempnam)(const char *dir, const char *pfx);
-extern FILE *__POSIX_DEF__(tmpfile)(void);
+extern char *tmpnam(char *s);
+extern char *tempnam(const char *dir, const char *pfx);
+extern FILE *tmpfile(void);
 
 
Index: uspace/lib/posix/include/posix/stdlib.h
===================================================================
--- uspace/lib/posix/include/posix/stdlib.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/stdlib.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,8 +37,4 @@
 #define POSIX_STDLIB_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
@@ -53,12 +49,12 @@
 #define EXIT_SUCCESS 0
 #define _Exit exit
-extern int __POSIX_DEF__(atexit)(void (*func)(void));
+extern int atexit(void (*func)(void));
 extern void exit(int status) __attribute__((noreturn));
 extern void abort(void) __attribute__((noreturn));
 
 /* Absolute Value */
-extern int __POSIX_DEF__(abs)(int i);
-extern long __POSIX_DEF__(labs)(long i);
-extern long long __POSIX_DEF__(llabs)(long long i);
+extern int abs(int i);
+extern long labs(long i);
+extern long long llabs(long long i);
 
 /* Integer Division */
@@ -66,69 +62,69 @@
 typedef struct {
 	int quot, rem;
-} __POSIX_DEF__(div_t);
+} div_t;
 
 typedef struct {
 	long quot, rem;
-} __POSIX_DEF__(ldiv_t);
+} ldiv_t;
 
 typedef struct {
 	long long quot, rem;
-} __POSIX_DEF__(lldiv_t);
+} lldiv_t;
 
-extern __POSIX_DEF__(div_t) __POSIX_DEF__(div)(int numer, int denom);
-extern __POSIX_DEF__(ldiv_t) __POSIX_DEF__(ldiv)(long numer, long denom);
-extern __POSIX_DEF__(lldiv_t) __POSIX_DEF__(lldiv)(long long numer, long long denom);
+extern div_t div(int numer, int denom);
+extern ldiv_t ldiv(long numer, long denom);
+extern lldiv_t lldiv(long long numer, long long denom);
 
 /* Array Functions */
-extern void __POSIX_DEF__(qsort)(void *array, size_t count, size_t size,
+extern void qsort(void *array, size_t count, size_t size,
     int (*compare)(const void *, const void *));
-extern void *__POSIX_DEF__(bsearch)(const void *key, const void *base,
+extern void *bsearch(const void *key, const void *base,
     size_t nmemb, size_t size, int (*compar)(const void *, const void *));
 
 /* Environment Access */
-extern char *__POSIX_DEF__(getenv)(const char *name);
-extern int __POSIX_DEF__(putenv)(char *string);
-extern int __POSIX_DEF__(system)(const char *string);
+extern char *getenv(const char *name);
+extern int putenv(char *string);
+extern int system(const char *string);
 
 /* Symbolic Links */
-extern char *__POSIX_DEF__(realpath)(const char *__restrict__ name, char *__restrict__ resolved);
+extern char *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 double atof(const char *nptr);
+extern float strtof(const char *__restrict__ nptr, char **__restrict__ endptr);
+extern double strtod(const char *__restrict__ nptr, char **__restrict__ endptr);
+extern long double strtold(const char *__restrict__ nptr, char **__restrict__ endptr);
 
 /* Integer Conversion */
-extern int __POSIX_DEF__(atoi)(const char *nptr);
-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,
+extern int atoi(const char *nptr);
+extern long int atol(const char *nptr);
+extern long long int atoll(const char *nptr);
+extern long int strtol(const char *__restrict__ nptr,
     char **__restrict__ endptr, int base);
-extern long long int __POSIX_DEF__(strtoll)(const char *__restrict__ nptr,
+extern long long int strtoll(const char *__restrict__ nptr,
     char **__restrict__ endptr, int base);
-extern unsigned long int __POSIX_DEF__(strtoul)(const char *__restrict__ nptr,
+extern unsigned long int strtoul(const char *__restrict__ nptr,
     char **__restrict__ endptr, int base);
-extern unsigned long long int __POSIX_DEF__(strtoull)(
+extern unsigned long long int strtoull(
     const char *__restrict__ nptr, char **__restrict__ endptr, int base);
 
 /* Memory Allocation */
-extern void *__POSIX_DEF__(malloc)(size_t size)
+extern void *malloc(size_t size)
     __attribute__((malloc));
-extern void *__POSIX_DEF__(calloc)(size_t nelem, size_t elsize)
+extern void *calloc(size_t nelem, size_t elsize)
     __attribute__((malloc));
-extern void *__POSIX_DEF__(realloc)(void *ptr, size_t size)
+extern void *realloc(void *ptr, size_t size)
     __attribute__((warn_unused_result));
-extern void __POSIX_DEF__(free)(void *ptr);
+extern void free(void *ptr);
 
 /* Temporary Files */
-extern int __POSIX_DEF__(mkstemp)(char *tmpl);
+extern int mkstemp(char *tmpl);
 
 /* Pseudo-random number generator */
-extern int __POSIX_DEF__(rand)(void);
-extern void __POSIX_DEF__(srand)(unsigned int seed);
+extern int rand(void);
+extern void srand(unsigned int seed);
 
 /* Legacy Declarations */
-extern char *__POSIX_DEF__(mktemp)(char *tmpl);
+extern char *mktemp(char *tmpl);
 extern int bsd_getloadavg(double loadavg[], int nelem);
 
Index: uspace/lib/posix/include/posix/string.h
===================================================================
--- uspace/lib/posix/include/posix/string.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/string.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,8 +37,4 @@
 #define POSIX_STRING_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
@@ -74,54 +70,54 @@
 
 /* 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__(strdup)(const char *s);
-extern char *__POSIX_DEF__(strndup)(const char *s, size_t n);
+extern char *strcpy(char *__restrict__ dest, const char *__restrict__ src);
+extern char *strncpy(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern char *stpcpy(char *__restrict__ dest, const char *__restrict__ src);
+extern char *stpncpy(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern char *strcat(char *__restrict__ dest, const char *__restrict__ src);
+extern char *strncat(char *__restrict__ dest, const char *__restrict__ src, size_t n);
+extern void *memccpy(void *__restrict__ dest, const void *__restrict__ src, int c, size_t n);
+extern char *strdup(const char *s);
+extern char *strndup(const char *s, size_t n);
 
 /* String/Array Comparison */
-extern int __POSIX_DEF__(memcmp)(const void *mem1, const void *mem2, size_t n);
-extern int __POSIX_DEF__(strcmp)(const char *s1, const char *s2);
-extern int __POSIX_DEF__(strncmp)(const char *s1, const char *s2, size_t n);
+extern int memcmp(const void *mem1, const void *mem2, size_t n);
+extern int strcmp(const char *s1, const char *s2);
+extern int strncmp(const char *s1, const char *s2, size_t n);
 
 /* Search Functions */
-extern void *__POSIX_DEF__(memchr)(const void *mem, int c, size_t n);
-extern char *__POSIX_DEF__(strchr)(const char *s, int c);
-extern char *__POSIX_DEF__(strrchr)(const char *s, int c);
+extern void *memchr(const void *mem, int c, size_t n);
+extern char *strchr(const char *s, int c);
+extern char *strrchr(const char *s, int c);
 extern char *gnu_strchrnul(const char *s, int c);
-extern char *__POSIX_DEF__(strpbrk)(const char *s1, const char *s2);
-extern size_t __POSIX_DEF__(strcspn)(const char *s1, const char *s2);
-extern size_t __POSIX_DEF__(strspn)(const char *s1, const char *s2);
-extern char *__POSIX_DEF__(strstr)(const char *haystack, const char *needle);
+extern char *strpbrk(const char *s1, const char *s2);
+extern size_t strcspn(const char *s1, const char *s2);
+extern size_t strspn(const char *s1, const char *s2);
+extern char *strstr(const char *haystack, const char *needle);
 
 /* Tokenization functions. */
-extern char *__POSIX_DEF__(strtok_r)(char *, const char *, char **);
-extern char *__POSIX_DEF__(strtok)(char *, const char *);
+extern char *strtok_r(char *, const char *, char **);
+extern char *strtok(char *, const char *);
 
 
 /* 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 int strcoll(const char *s1, const char *s2);
+extern size_t strxfrm(char *__restrict__ s1, const char *__restrict__ s2, size_t n);
 
 /* Error Messages */
-extern char *__POSIX_DEF__(strerror)(int errnum);
-extern int __POSIX_DEF__(strerror_r)(int errnum, char *buf, size_t bufsz);
+extern char *strerror(int errnum);
+extern int strerror_r(int errnum, char *buf, size_t bufsz);
 
 /* String Length */
-extern size_t __POSIX_DEF__(strlen)(const char *s);
-extern size_t __POSIX_DEF__(strnlen)(const char *s, size_t n);
+extern size_t strlen(const char *s);
+extern size_t strnlen(const char *s, size_t n);
 
 /* Signal Messages */
-extern char *__POSIX_DEF__(strsignal)(int signum);
+extern char *strsignal(int signum);
 
 /* Legacy Declarations */
 #ifndef POSIX_STRINGS_H_
-extern int __POSIX_DEF__(ffs)(int i);
-extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
-extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);
+extern int ffs(int i);
+extern int strcasecmp(const char *s1, const char *s2);
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
 #endif
 
Index: uspace/lib/posix/include/posix/strings.h
===================================================================
--- uspace/lib/posix/include/posix/strings.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/strings.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,20 +37,15 @@
 #define POSIX_STRINGS_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
-
 #include "libc/types/common.h"
 
 /* Search Functions */
 #ifndef POSIX_STRING_H_
-extern int __POSIX_DEF__(ffs)(int i);
+extern int ffs(int i);
 #endif
 
 /* String/Array Comparison */
 #ifndef POSIX_STRING_H_
-extern int __POSIX_DEF__(strcasecmp)(const char *s1, const char *s2);
-extern int __POSIX_DEF__(strncasecmp)(const char *s1, const char *s2, size_t n);
+extern int strcasecmp(const char *s1, const char *s2);
+extern int strncasecmp(const char *s1, const char *s2, size_t n);
 #endif
 
@@ -62,9 +57,9 @@
 
 /* Legacy Functions */
-extern int __POSIX_DEF__(bcmp)(const void *mem1, const void *mem2, size_t n);
-extern void __POSIX_DEF__(bcopy)(const void *src, void *dest, size_t n);
-extern void __POSIX_DEF__(bzero)(void *mem, size_t n);
-extern char *__POSIX_DEF__(index)(const char *s, int c);
-extern char *__POSIX_DEF__(rindex)(const char *s, int c);
+extern int bcmp(const void *mem1, const void *mem2, size_t n);
+extern void bcopy(const void *src, void *dest, size_t n);
+extern void bzero(void *mem, size_t n);
+extern char *index(const char *s, int c);
+extern char *rindex(const char *s, int c);
 
 
Index: uspace/lib/posix/include/posix/sys/mman.h
===================================================================
--- uspace/lib/posix/include/posix/sys/mman.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/sys/mman.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_SYS_MMAN_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "types.h"
 #include <abi/mm/as.h>
@@ -60,8 +56,7 @@
 #define PROT_EXEC  AS_AREA_EXEC
 
-extern void *
-__POSIX_DEF__(mmap)(void *start, size_t length, int prot, int flags, int fd,
-    __POSIX_DEF__(off_t) offset);
-extern int __POSIX_DEF__(munmap)(void *start, size_t length);
+extern void *mmap(void *start, size_t length, int prot, int flags, int fd,
+    off_t offset);
+extern int munmap(void *start, size_t length);
 
 
Index: uspace/lib/posix/include/posix/sys/stat.h
===================================================================
--- uspace/lib/posix/include/posix/sys/stat.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/sys/stat.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -39,8 +39,4 @@
 #include "types.h"
 #include "../time.h"
-
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
 
 /* values are the same as on Linux */
@@ -112,15 +108,15 @@
 #define S_ISSOCK(m) ((m & S_IFSOCK) != 0) /* socket? (Not in POSIX.1-1996.) */
 
-struct __POSIX_DEF__(stat) {
-	__POSIX_DEF__(dev_t)     st_dev;     /* ID of device containing file */
-	__POSIX_DEF__(ino_t)     st_ino;     /* inode number */
-	__POSIX_DEF__(mode_t)    st_mode;    /* protection */
-	__POSIX_DEF__(nlink_t)   st_nlink;   /* number of hard links */
-	__POSIX_DEF__(uid_t)     st_uid;     /* user ID of owner */
-	__POSIX_DEF__(gid_t)     st_gid;     /* group ID of owner */
-	__POSIX_DEF__(dev_t)     st_rdev;    /* device ID (if special file) */
-	__POSIX_DEF__(off_t)     st_size;    /* total size, in bytes */
-	__POSIX_DEF__(blksize_t) st_blksize; /* blocksize for file system I/O */
-	__POSIX_DEF__(blkcnt_t)  st_blocks;  /* number of 512B blocks allocated */
+struct stat {
+	dev_t     st_dev;     /* ID of device containing file */
+	ino_t     st_ino;     /* inode number */
+	mode_t    st_mode;    /* protection */
+	nlink_t   st_nlink;   /* number of hard links */
+	uid_t     st_uid;     /* user ID of owner */
+	gid_t     st_gid;     /* group ID of owner */
+	dev_t     st_rdev;    /* device ID (if special file) */
+	off_t     st_size;    /* total size, in bytes */
+	blksize_t st_blksize; /* blocksize for file system I/O */
+	blkcnt_t  st_blocks;  /* number of 512B blocks allocated */
 	time_t          st_atime;   /* time of last access */
 	time_t          st_mtime;   /* time of last modification */
@@ -128,10 +124,10 @@
 };
 
-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__(chmod)(const char *path, __POSIX_DEF__(mode_t) mode);
-extern __POSIX_DEF__(mode_t) __POSIX_DEF__(umask)(__POSIX_DEF__(mode_t) mask);
-extern int __POSIX_DEF__(mkdir)(const char *path, __POSIX_DEF__(mode_t) mode);
+extern int fstat(int fd, struct stat *st);
+extern int lstat(const char *__restrict__ path, struct stat *__restrict__ st);
+extern int stat(const char *__restrict__ path, struct stat *__restrict__ st);
+extern int chmod(const char *path, mode_t mode);
+extern mode_t umask(mode_t mask);
+extern int mkdir(const char *path, mode_t mode);
 
 
Index: uspace/lib/posix/include/posix/sys/time.h
===================================================================
--- uspace/lib/posix/include/posix/sys/time.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/sys/time.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -34,8 +34,4 @@
 #define POSIX_SYS_TIME_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "libc/sys/time.h"
 
Index: uspace/lib/posix/include/posix/sys/types.h
===================================================================
--- uspace/lib/posix/include/posix/sys/types.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/sys/types.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,29 +37,25 @@
 #define POSIX_SYS_TYPES_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "libc/offset.h"
 #include "libc/sys/time.h"
 #include "libc/types/common.h"
 
-typedef unsigned int __POSIX_DEF__(ino_t);
-typedef unsigned int __POSIX_DEF__(nlink_t);
-typedef unsigned int __POSIX_DEF__(uid_t);
-typedef unsigned int __POSIX_DEF__(gid_t);
-typedef off64_t __POSIX_DEF__(off_t);
-typedef long __POSIX_DEF__(blksize_t);
-typedef long __POSIX_DEF__(blkcnt_t);
-typedef int64_t __POSIX_DEF__(pid_t);
-typedef sysarg_t __POSIX_DEF__(dev_t);
-typedef unsigned int __POSIX_DEF__(mode_t);
+typedef unsigned int ino_t;
+typedef unsigned int nlink_t;
+typedef unsigned int uid_t;
+typedef unsigned int gid_t;
+typedef off64_t off_t;
+typedef long blksize_t;
+typedef long blkcnt_t;
+typedef int64_t pid_t;
+typedef sysarg_t dev_t;
+typedef unsigned int mode_t;
 
 /* PThread Types */
-typedef struct __POSIX_DEF__(thread_attr) __POSIX_DEF__(thread_attr_t);
+typedef struct thread_attr thread_attr_t;
 
 /* Clock Types */
-typedef long __POSIX_DEF__(clock_t);
-typedef int __POSIX_DEF__(clockid_t);
+typedef long clock_t;
+typedef int clockid_t;
 
 
Index: uspace/lib/posix/include/posix/sys/wait.h
===================================================================
--- uspace/lib/posix/include/posix/sys/wait.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/sys/wait.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,8 +36,4 @@
 #define POSIX_SYS_WAIT_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "types.h"
 
@@ -56,6 +52,6 @@
 extern int __posix_wtermsig(int status);
 
-extern __POSIX_DEF__(pid_t) __POSIX_DEF__(wait)(int *stat_ptr);
-extern __POSIX_DEF__(pid_t) __POSIX_DEF__(waitpid)(__POSIX_DEF__(pid_t) pid, int *stat_ptr, int options);
+extern pid_t wait(int *stat_ptr);
+extern pid_t waitpid(pid_t pid, int *stat_ptr, int options);
 
 
Index: uspace/lib/posix/include/posix/time.h
===================================================================
--- uspace/lib/posix/include/posix/time.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/time.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,8 +37,4 @@
 #define POSIX_TIME_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
@@ -51,69 +47,63 @@
 #ifndef __locale_t_defined
 	#define __locale_t_defined
-	typedef struct __posix_locale *__POSIX_DEF__(locale_t);
-	#ifndef LIBPOSIX_INTERNAL
-		#define locale_t __POSIX_DEF__(locale_t)
-	#endif
+	typedef struct __posix_locale *locale_t;
 #endif
 
 #ifndef POSIX_SIGNAL_H_
-	struct __POSIX_DEF__(sigevent);
-	#ifndef LIBPOSIX_INTERNAL
-		#define sigevent __POSIX_DEF__(sigevent)
-	#endif
+	struct sigevent;
 #endif
 
 #undef CLOCK_REALTIME
-#define CLOCK_REALTIME ((__POSIX_DEF__(clockid_t)) 0)
+#define CLOCK_REALTIME ((clockid_t) 0)
 
-struct __POSIX_DEF__(timespec) {
+struct timespec {
 	time_t tv_sec; /* Seconds. */
 	long tv_nsec; /* Nanoseconds. */
 };
 
-struct __POSIX_DEF__(itimerspec) {
-	struct __POSIX_DEF__(timespec) it_interval; /* Timer period. */
-	struct __POSIX_DEF__(timespec) it_value; /* Timer expiration. */
+struct itimerspec {
+	struct timespec it_interval; /* Timer period. */
+	struct timespec it_value; /* Timer expiration. */
 };
 
-typedef struct __posix_timer *__POSIX_DEF__(timer_t);
+typedef struct __posix_timer *timer_t;
 
 /* Timezones */
-extern int __POSIX_DEF__(daylight);
-extern long __POSIX_DEF__(timezone);
-extern char *__POSIX_DEF__(tzname)[2];
-extern void __POSIX_DEF__(tzset)(void);
+extern int daylight;
+extern long timezone;
+extern char *tzname[2];
+extern void tzset(void);
 
 /* Time */
-extern time_t __POSIX_DEF__(time)(time_t *t);
+extern time_t time(time_t *t);
 
 /* Broken-down Time */
-extern struct tm *__POSIX_DEF__(gmtime_r)(const time_t *__restrict__ timer,
+extern struct tm *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,
+extern struct tm *gmtime(const time_t *__restrict__ timep);
+extern struct tm *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 *localtime(const time_t *__restrict__ timep);
 
 /* Formatting Calendar Time */
-extern char *__POSIX_DEF__(asctime_r)(const struct tm *__restrict__ timeptr,
+extern char *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);
+extern char *asctime(const struct tm *__restrict__ timeptr);
+extern char *ctime_r(const time_t *timer, char *buf);
+extern char *ctime(const time_t *timer);
 extern time_t time(time_t *t);
 
 /* Clocks */
-extern int __POSIX_DEF__(clock_getres)(__POSIX_DEF__(clockid_t) clock_id,
-    struct __POSIX_DEF__(timespec) *res);
-extern int __POSIX_DEF__(clock_gettime)(__POSIX_DEF__(clockid_t) clock_id,
-    struct __POSIX_DEF__(timespec) *tp);
-extern int __POSIX_DEF__(clock_settime)(__POSIX_DEF__(clockid_t) clock_id,
-    const struct __POSIX_DEF__(timespec) *tp); 
-extern int __POSIX_DEF__(clock_nanosleep)(__POSIX_DEF__(clockid_t) clock_id, int flags,
-    const struct __POSIX_DEF__(timespec) *rqtp, struct __POSIX_DEF__(timespec) *rmtp);
+extern int clock_getres(clockid_t clock_id,
+    struct timespec *res);
+extern int clock_gettime(clockid_t clock_id,
+    struct timespec *tp);
+extern int clock_settime(clockid_t clock_id,
+    const struct timespec *tp);
+extern int clock_nanosleep(clockid_t clock_id, int flags,
+    const struct timespec *rqtp, struct timespec *rmtp);
 
 /* CPU Time */
-extern __POSIX_DEF__(clock_t) __POSIX_DEF__(clock)(void);
+extern clock_t clock(void);
 
 
Index: uspace/lib/posix/include/posix/ucontext.h
===================================================================
--- uspace/lib/posix/include/posix/ucontext.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/ucontext.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,28 +36,24 @@
 #define POSIX_UCONTEXT_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 
-typedef int __POSIX_DEF__(sig_atomic_t);
-typedef uint32_t __POSIX_DEF__(sigset_t);
-typedef struct __POSIX_DEF__(mcontext) {
+typedef int sig_atomic_t;
+typedef uint32_t sigset_t;
+typedef struct mcontext {
 	/* must not be empty to avoid compiler warnings (-pedantic) */
 	int dummy;
-} __POSIX_DEF__(mcontext_t);
+} mcontext_t;
 
-union __POSIX_DEF__(sigval) {
+union sigval {
 	int sival_int;
 	void *sival_ptr;
 };
 
-struct __POSIX_DEF__(sigevent) {
+struct sigevent {
 	int sigev_notify; /* Notification type. */
 	int sigev_signo; /* Signal number. */
-	union __POSIX_DEF__(sigval) sigev_value; /* Signal value. */
-	void (*sigev_notify_function)(union __POSIX_DEF__(sigval)); /* Notification function. */
-	__POSIX_DEF__(thread_attr_t) *sigev_notify_attributes; /* Notification attributes. */
+	union sigval sigev_value; /* Signal value. */
+	void (*sigev_notify_function)(union sigval); /* Notification function. */
+	thread_attr_t *sigev_notify_attributes; /* Notification attributes. */
 };
 
@@ -66,12 +62,12 @@
 	size_t ss_size;
 	int ss_flags;
-} __POSIX_DEF__(stack_t);
+} stack_t;
 
-typedef struct __POSIX_DEF__(ucontext) {
-	struct __POSIX_DEF__(ucontext) *uc_link;
-	__POSIX_DEF__(sigset_t) uc_sigmask;
-	__POSIX_DEF__(stack_t) uc_stack;
-	__POSIX_DEF__(mcontext_t) uc_mcontext;
-} __POSIX_DEF__(ucontext_t);
+typedef struct ucontext {
+	struct ucontext *uc_link;
+	sigset_t uc_sigmask;
+	stack_t uc_stack;
+	mcontext_t uc_mcontext;
+} ucontext_t;
 
 
Index: uspace/lib/posix/include/posix/unistd.h
===================================================================
--- uspace/lib/posix/include/posix/unistd.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/include/posix/unistd.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,8 +37,4 @@
 #define POSIX_UNISTD_H_
 
-#ifndef __POSIX_DEF__
-#define __POSIX_DEF__(x) x
-#endif
-
 #include "sys/types.h"
 #include "stddef.h"
@@ -51,45 +47,45 @@
 #define _exit exit
 
-extern char *__POSIX_DEF__(optarg);
+extern char *optarg;
 extern int optind, opterr, optopt;
-extern int __POSIX_DEF__(getopt)(int, char * const [], const char *);
+extern int getopt(int, char * const [], const char *);
 
 /* Environment */
-extern char **__POSIX_DEF__(environ);
+extern char **environ;
 
 /* Sleeping */
-extern unsigned int __POSIX_DEF__(sleep)(unsigned int);
+extern unsigned int sleep(unsigned int);
 
 /* Login Information */
-extern char *__POSIX_DEF__(getlogin)(void);
-extern int __POSIX_DEF__(getlogin_r)(char *name, size_t namesize);
+extern char *getlogin(void);
+extern int getlogin_r(char *name, size_t namesize);
 
 /* Identifying Terminals */
-extern int __POSIX_DEF__(isatty)(int fd);
+extern int isatty(int fd);
 
 /* Working Directory */
-extern char *__POSIX_DEF__(getcwd)(char *buf, size_t size);
-extern int __POSIX_DEF__(chdir)(const char *path);
+extern char *getcwd(char *buf, size_t size);
+extern int chdir(const char *path);
 
 /* Query Memory Parameters */
-extern int __POSIX_DEF__(getpagesize)(void);
+extern int getpagesize(void);
 
 /* Process Identification */
-extern __POSIX_DEF__(pid_t) __POSIX_DEF__(getpid)(void);
-extern __POSIX_DEF__(uid_t) __POSIX_DEF__(getuid)(void);
-extern __POSIX_DEF__(gid_t) __POSIX_DEF__(getgid)(void);
+extern pid_t getpid(void);
+extern uid_t getuid(void);
+extern gid_t getgid(void);
 
 /* File Manipulation */
-extern int __POSIX_DEF__(close)(int fildes);
-extern ssize_t __POSIX_DEF__(read)(int fildes, void *buf, size_t nbyte);
-extern ssize_t __POSIX_DEF__(write)(int fildes, const void *buf, size_t nbyte);
-extern __POSIX_DEF__(off_t) __POSIX_DEF__(lseek)(int fildes,
-    __POSIX_DEF__(off_t) offset, int whence);
-extern int __POSIX_DEF__(fsync)(int fildes);
-extern int __POSIX_DEF__(ftruncate)(int fildes, __POSIX_DEF__(off_t) length);
-extern int __POSIX_DEF__(rmdir)(const char *path);
-extern int __POSIX_DEF__(unlink)(const char *path);
-extern int __POSIX_DEF__(dup)(int fildes);
-extern int __POSIX_DEF__(dup2)(int fildes, int fildes2);
+extern int close(int fildes);
+extern ssize_t read(int fildes, void *buf, size_t nbyte);
+extern ssize_t write(int fildes, const void *buf, size_t nbyte);
+extern off_t lseek(int fildes,
+    off_t offset, int whence);
+extern int fsync(int fildes);
+extern int ftruncate(int fildes, off_t length);
+extern int rmdir(const char *path);
+extern int unlink(const char *path);
+extern int dup(int fildes);
+extern int dup2(int fildes, int fildes2);
 
 /* Standard Streams */
@@ -110,5 +106,5 @@
 #define	W_OK 2 /* Test for write permission. */
 #define	R_OK 4 /* Test for read permission. */
-extern int __POSIX_DEF__(access)(const char *path, int amode);
+extern int access(const char *path, int amode);
 
 /* System Parameters */
@@ -119,5 +115,5 @@
 	_SC_CLK_TCK
 };
-extern long __POSIX_DEF__(sysconf)(int name);
+extern long sysconf(int name);
 
 /* Path Configuration Parameters */
@@ -143,18 +139,18 @@
 	_PC_VDISABLE
 };
-extern long __POSIX_DEF__(pathconf)(const char *path, int name);
+extern long pathconf(const char *path, int name);
 
 /* Creating a Process */
-extern __POSIX_DEF__(pid_t) __POSIX_DEF__(fork)(void);
+extern pid_t fork(void);
 
 /* Executing a File */
-extern int __POSIX_DEF__(execv)(const char *path, char *const argv[]);
-extern int __POSIX_DEF__(execvp)(const char *file, char *const argv[]);
+extern int execv(const char *path, char *const argv[]);
+extern int execvp(const char *file, char *const argv[]);
 
 /* Creating a Pipe */
-extern int __POSIX_DEF__(pipe)(int fildes[2]);
+extern int pipe(int fildes[2]);
 
 /* Issue alarm signal. */
-extern unsigned int __POSIX_DEF__(alarm)(unsigned int);
+extern unsigned int alarm(unsigned int);
 
 #endif /* POSIX_UNISTD_H_ */
Index: pace/lib/posix/source/ctype.c
===================================================================
--- uspace/lib/posix/source/ctype.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,132 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * Copyright (c) 2011 Petr Koupy
- * 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 Character classification.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/ctype.h"
-
-/**
- * Checks whether character is a hexadecimal digit.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_isxdigit(int c)
-{
-	return isdigit(c) ||
-	    (c >= 'a' && c <= 'f') ||
-	    (c >= 'A' && c <= 'F');
-}
-
-/**
- * Checks whether character is a word separator.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_isblank(int c)
-{
-	return c == ' ' || c == '\t';
-}
-
-/**
- * Checks whether character is a control character.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_iscntrl(int c)
-{
-	return c < 0x20 || c == 0x7E;
-}
-
-/**
- * Checks whether character is any printing character except space.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_isgraph(int c)
-{
-	return posix_isprint(c) && c != ' ';
-}
-
-/**
- * Checks whether character is a printing character.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_isprint(int c)
-{
-	return posix_isascii(c) && !posix_iscntrl(c);
-}
-
-/**
- * Checks whether character is a punctuation.
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_ispunct(int c)
-{
-	return !isspace(c) && !isalnum(c) && posix_isprint(c);
-}
-
-/**
- * Checks whether character is ASCII. (obsolete)
- *
- * @param c Character to inspect.
- * @return Non-zero if character match the definition, zero otherwise.
- */
-int posix_isascii(int c)
-{
-	return c >= 0 && c < 128;
-}
-
-/**
- * Converts argument to a 7-bit ASCII character. (obsolete)
- *
- * @param c Character to convert.
- * @return Coverted character.
- */
-int posix_toascii(int c)
-{
-	return c & 0x7F;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/dlfcn.c
===================================================================
--- uspace/lib/posix/source/dlfcn.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,68 +1,0 @@
-/*
- * Copyright (c) 2017 Vojtech Horky
- * 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
- * @{
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/dlfcn.h"
-
-#include "libc/dlfcn.h"
-
-void *posix_dlopen(const char *filename, int flags)
-{
-	if (flags != 0) {
-		fprintf(stderr, "dlopen() not implemented with non-zero flags (%s:%d), something will NOT work.\n", __FILE__, __LINE__);
-	}
-	
-	return dlopen(filename, 0);
-}
-
-void *posix_dlsym(void *handle, const char *symbol)
-{
-	return dlsym(handle, symbol);
-}
-
-int posix_dlclose(void *handle)
-{
-	not_implemented();
-	return 0;
-}
-
-char *posix_dlerror(void)
-{
-	not_implemented();
-	return (char *)"dlerror()";
-}
-
-/** @}
- */
Index: pace/lib/posix/source/fcntl.c
===================================================================
--- uspace/lib/posix/source/fcntl.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,161 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 File control.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/fcntl.h"
-
-#include "libc/vfs/vfs.h"
-
-#include <errno.h>
-
-/**
- * Performs set of operations on the opened files.
- *
- * @param fd File descriptor of the opened file.
- * @param cmd Operation to carry out.
- * @return Non-negative on success. Might have special meaning corresponding
- *     to the requested operation.
- */
-int posix_fcntl(int fd, int cmd, ...)
-{
-	int flags;
-
-	switch (cmd) {
-	case F_DUPFD:
-	case F_DUPFD_CLOEXEC:
-		/* VFS currently does not provide the functionality to duplicate
-		 * opened file descriptor. */
-		// FIXME: implement this once dup() is available
-		errno = ENOTSUP;
-		return -1;
-	case F_GETFD:
-		/* FD_CLOEXEC is not supported. There are no other flags. */
-		return 0;
-	case F_SETFD:
-		/* FD_CLOEXEC is not supported. Ignore arguments and report success. */
-		return 0;
-	case F_GETFL:
-		/* File status flags (i.e. O_APPEND) are currently private to the
-		 * VFS server so it cannot be easily retrieved. */
-		flags = 0;
-		/* File access flags are currently not supported for file descriptors.
-		 * Provide full access. */
-		flags |= O_RDWR;
-		return flags;
-	case F_SETFL:
-		/* File access flags are currently not supported for file descriptors.
-		 * Ignore arguments and report success. */
-		return 0;
-	case F_GETOWN:
-	case F_SETOWN:
-	case F_GETLK:
-	case F_SETLK:
-	case F_SETLKW:
-		/* Signals (SIGURG) and file locks are not supported. */
-		errno = ENOTSUP;
-		return -1;
-	default:
-		/* Unknown command */
-		errno = EINVAL;
-		return -1;
-	}
-}
-
-/**
- * Open, possibly create, a file.
- *
- * @param pathname Path to the file.
- * @param posix_flags Access mode flags.
- */
-int posix_open(const char *pathname, int posix_flags, ...)
-{
-	posix_mode_t posix_mode = 0;
-	if (posix_flags & O_CREAT) {
-		va_list args;
-		va_start(args, posix_flags);
-		posix_mode = va_arg(args, posix_mode_t);
-		va_end(args);
-		(void) posix_mode;
-	}
-
-	if (((posix_flags & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) ||
-	    ((posix_flags & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) ||
-	    ((posix_flags & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) ||
-	    ((posix_flags & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	int flags = WALK_REGULAR;
-	if (posix_flags & O_CREAT) {
-		if (posix_flags & O_EXCL)
-			flags |= WALK_MUST_CREATE;
-		else
-			flags |= WALK_MAY_CREATE;
-	}
-
-	int mode =
-	    ((posix_flags & O_RDWR) ? MODE_READ | MODE_WRITE : 0) |
-	    ((posix_flags & O_RDONLY) ? MODE_READ : 0) |
-	    ((posix_flags & O_WRONLY) ? MODE_WRITE : 0) |
-	    ((posix_flags & O_APPEND) ? MODE_APPEND : 0);
-
-	int file;
-
-	if (failed(vfs_lookup(pathname, flags, &file)))
-		return -1;
-
-	if (failed(vfs_open(file, mode))) {
-		vfs_put(file);
-		return -1;
-	}
-
-	if (posix_flags & O_TRUNC) {
-		if (posix_flags & (O_RDWR | O_WRONLY)) {
-			if (failed(vfs_resize(file, 0))) {
-				vfs_put(file);
-				return -1;
-			}
-		}
-	}
-
-	return file;
-}
-
-/** @}
- */
-
Index: pace/lib/posix/source/fnmatch.c
===================================================================
--- uspace/lib/posix/source/fnmatch.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,717 +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 Filename-matching.
- */
-
-/* This file contains an implementation of the fnmatch() pattern matching
- * function. There is more code than necessary to account for the possibility
- * of adding POSIX-like locale support to the system in the future. Functions
- * that are only necessary for locale support currently simply use single
- * characters for "collation elements". 
- * When (or if) locales are properly implemented, extending this implementation
- * will be fairly straightforward.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "libc/stdbool.h"
-#include "posix/ctype.h"
-#include "posix/string.h"
-#include "posix/stdlib.h"
-#include <assert.h>
-
-#include "internal/common.h"
-#include "posix/fnmatch.h"
-
-/* Returned by _match... functions. */
-#define INVALID_PATTERN -1
-
-/* Type for collating element, simple identity with characters now,
- * but may be extended for better locale support.
- */
-typedef int coll_elm_t;
-
-/** Return value indicating that the element in question
- * is not valid in the current locale. (That is, if locales are supported.)
- */
-#define COLL_ELM_INVALID -1
-
-/**
- * Get collating element matching a string.
- *
- * @param str String representation of the element.
- * @return Matching collating element or COLL_ELM_INVALID.
- */
-static coll_elm_t _coll_elm_get(const char* str)
-{
-	if (str[0] == '\0' || str[1] != '\0') {
-		return COLL_ELM_INVALID;
-	}
-	return str[0];
-}
-
-/**
- * Get collating element matching a single character.
- *
- * @param c Character representation of the element.
- * @return Matching collating element.
- */
-static coll_elm_t _coll_elm_char(int c)
-{
-	return c;
-}
-
-/**
- * Match collating element with a beginning of a string.
- *
- * @param elm Collating element to match.
- * @param str String which beginning should match the element.
- * @return 0 if the element doesn't match, or the number of characters matched.
- */
-static int _coll_elm_match(coll_elm_t elm, const char *str)
-{
-	return elm == *str;
-}
-
-/**
- * Checks whether a string begins with a collating element in the given range.
- * Ordering depends on the locale (if locales are supported).
- *
- * @param first First element of the range.
- * @param second Last element of the range.
- * @param str String to match.
- * @return 0 if there is no match, or the number of characters matched.
- */
-static int _coll_elm_between(coll_elm_t first, coll_elm_t second,
-    const char *str)
-{
-	return *str >= first && *str <= second;
-}
-
-/**
- * Read a string delimited by [? and ?].
- *
- * @param pattern Pointer to the string to read from. Its position is moved
- *    to the first character after the closing ].
- * @param seq The character on the inside of brackets.
- * @param buf Read buffer.
- * @param buf_sz Read buffer's size. If the buffer is not large enough for
- *    the entire string, the string is cut with no error indication.
- * @param flags Flags modifying the behavior.
- * @return True on success, false if the pattern is invalid.
- */
-static bool _get_delimited(
-    const char **pattern, int seq,
-    char *buf, size_t buf_sz, int flags)
-{
-	const bool noescape = (flags & FNM_NOESCAPE) != 0;
-	const bool pathname = (flags & FNM_PATHNAME) != 0;
-
-	const char *p = *pattern;
-	assert(p[0] == '[' && p[1] == seq /* Caller should ensure this. */);
-	p += 2;
-
-	while (true) {
-		if (*p == seq && *(p + 1) == ']') {
-			/* String properly ended, return. */
-			*pattern = p + 2;
-			*buf = '\0';
-			return true;
-		}
-		if (!noescape && *p == '\\') {
-			p++;
-		}
-		if (*p == '\0') {
-			/* String not ended properly, invalid pattern. */
-			return false;
-		}
-		if (pathname && *p == '/') {
-			/* Slash in a pathname pattern is invalid. */
-			return false;
-		}
-		if (buf_sz > 1) {
-			/* Only add to the buffer if there is space. */
-			*buf = *p;
-			buf++;
-			buf_sz--;
-		}
-		p++;
-	}
-}
-
-/************** CHARACTER CLASSES ****************/
-
-#define MAX_CLASS_OR_COLL_LEN 6
-
-struct _char_class {
-	const char *name;
-	int (*func) (int);
-};
-
-/* List of supported character classes. */
-static const struct _char_class _char_classes[] = {
-	{ "alnum", isalnum },
-	{ "alpha", isalpha },
-	{ "blank", posix_isblank },
-	{ "cntrl", posix_iscntrl },
-	{ "digit", isdigit },
-	{ "graph", posix_isgraph },
-	{ "lower", islower },
-	{ "print", posix_isprint },
-	{ "punct", posix_ispunct },
-	{ "space", isspace },
-	{ "upper", isupper },
-	{ "xdigit", posix_isxdigit }
-};
-
-/**
- * Compare function for binary search in the _char_classes array.
- * 
- * @param key Key of the searched element.
- * @param elem Element of _char_classes array.
- * @return Ordering indicator (-1 less than, 0 equal, 1 greater than).
- */
-static int _class_compare(const void *key, const void *elem)
-{
-	const struct _char_class *class = elem;
-	return posix_strcmp((const char *) key, class->name);
-}
-
-/**
- * Returns whether the given character belongs to the specified character class.
- * 
- * @param cname Name of the character class.
- * @param c Character.
- * @return True if the character belongs to the class, false otherwise.
- */
-static bool _is_in_class (const char *cname, int c)
-{
-	/* Search for class in the array of supported character classes. */
-	const struct _char_class *class = posix_bsearch(cname, _char_classes,
-	    sizeof(_char_classes) / sizeof(struct _char_class),
-	    sizeof(struct _char_class), _class_compare);
-
-	if (class == NULL) {
-		/* No such class supported - treat as an empty class. */
-		return false;
-	} else {
-		/* Class matched. */
-		return class->func(c);
-	}
-}
-
-/**
- * Tries to parse an initial part of the pattern as a character class pattern,
- * and if successful, matches the beginning of the given string against the class.
- * 
- * @param pattern Pointer to the pattern to match. Must begin with a class
- *    specifier and is repositioned to the first character after the specifier
- *    if successful.
- * @param str String to match.
- * @param flags Flags modifying the behavior (see fnmatch()).
- * @return INVALID_PATTERN if the pattern doesn't start with a valid class
- *    specifier, 0 if the beginning of the matched string doesn't belong
- *    to the class, or positive number of characters matched.
- */
-static int _match_char_class(const char **pattern, const char *str, int flags)
-{
-	char class[MAX_CLASS_OR_COLL_LEN + 1];
-
-	if (!_get_delimited(pattern, ':', class, sizeof(class), flags)) {
-		return INVALID_PATTERN;
-	}
-
-	return _is_in_class(class, *str);
-}
-
-/************** END CHARACTER CLASSES ****************/
-
-/**
- * Reads the next collating element in the pattern, taking into account
- * locale (if supported) and flags (see fnmatch()).
- * 
- * @param pattern Pattern.
- * @param flags Flags given to fnmatch().
- * @return Collating element on success,
- *     or COLL_ELM_INVALID if the pattern is invalid.
- */
-static coll_elm_t _next_coll_elm(const char **pattern, int flags)
-{
-	assert(pattern != NULL);
-	assert(*pattern != NULL);
-	assert(**pattern != '\0');
-
-	const char *p = *pattern;
-	const bool noescape = (flags & FNM_NOESCAPE) != 0;
-	const bool pathname = (flags & FNM_PATHNAME) != 0;
-
-	if (*p == '[') {
-		if (*(p + 1) == '.') {
-			char buf[MAX_CLASS_OR_COLL_LEN + 1];
-			if (!_get_delimited(pattern, '.', buf, sizeof(buf), flags)) {
-				return COLL_ELM_INVALID;
-			}
-			return _coll_elm_get(buf);
-		}
-
-		if (*(p + 1) == '=') {
-			char buf[MAX_CLASS_OR_COLL_LEN + 1];
-			if (!_get_delimited(pattern, '=', buf, sizeof(buf), flags)) {
-				return COLL_ELM_INVALID;
-			}
-			return _coll_elm_get(buf);
-		}
-	}
-
-	if (!noescape && *p == '\\') {
-		p++;
-		if (*p == '\0') {
-			*pattern = p;
-			return COLL_ELM_INVALID;
-		}
-	}
-	if (pathname && *p == '/') {
-		return COLL_ELM_INVALID;
-	}
-	
-	*pattern = p + 1;
-	return _coll_elm_char(*p);
-}
-
-/**
- * Matches the beginning of the given string against a bracket expression
- * the pattern begins with.
- * 
- * @param pattern Pointer to the beginning of a bracket expression in a pattern.
- *     On success, the pointer is moved to the first character after the
- *     bracket expression.
- * @param str Unmatched part of the string.
- * @param flags Flags given to fnmatch().
- * @return INVALID_PATTERN if the pattern is invalid, 0 if there is no match
- *     or the number of matched characters on success.
- */
-static int _match_bracket_expr(const char **pattern, const char *str, int flags)
-{
-	const bool pathname = (flags & FNM_PATHNAME) != 0;
-	const bool special_period = (flags & FNM_PERIOD) != 0;
-	const char *p = *pattern;
-	bool negative = false;
-	int matched = 0;
-
-	#define _matched(match) { \
-		int _match = match; \
-		if (_match < 0) { \
-			/* Invalid pattern */ \
-			return _match; \
-		} else if (matched == 0 && _match > 0) { \
-			/* First match */ \
-			matched = _match; \
-		} \
-	}
-
-	assert(*p == '[');  /* calling code should ensure this */
-	p++;
-
-	if (*str == '\0' || (pathname && *str == '/') ||
-	    (pathname && special_period && *str == '.' && *(str - 1) == '/')) {
-		/* No bracket expression matches end of string,
-		 * slash in pathname match or initial period with FNM_PERIOD
-		 * option.
-		 */
-		return 0;
-	}
-
-	if (*p == '^' || *p == '!') {
-		negative = true;
-		p++;
-	}
-
-	if (*p == ']') {
-		/* When ']' is first, treat it as a normal character. */
-		_matched(*str == ']');
-		p++;
-	}
-	
-	coll_elm_t current_elm = COLL_ELM_INVALID;
-	
-	while (*p != ']') {
-		if (*p == '-' && *(p + 1) != ']' &&
-		    current_elm != COLL_ELM_INVALID) {
-			/* Range expression. */
-			p++;
-			coll_elm_t end_elm = _next_coll_elm(&p, flags);
-			if (end_elm == COLL_ELM_INVALID) {
-				return INVALID_PATTERN;
-			}
-			_matched(_coll_elm_between(current_elm, end_elm, str));
-			continue;
-		}
-	
-		if (*p == '[' && *(p + 1) == ':') {
-			current_elm = COLL_ELM_INVALID;
-			_matched(_match_char_class(&p, str, flags));
-			continue;
-		}
-		
-		current_elm = _next_coll_elm(&p, flags);
-		if (current_elm == COLL_ELM_INVALID) {
-			return INVALID_PATTERN;
-		}
-		_matched(_coll_elm_match(current_elm, str));
-	}
-
-	/* No error occured - update pattern pointer. */
-	*pattern = p + 1;
-
-	if (matched == 0) {
-		/* No match found */
-		return negative;
-	} else {
-		/* Matched 'match' characters. */
-		return negative ? 0 : matched;
-	}
-
-	#undef _matched
-}
-
-/**
- * Matches a portion of the pattern containing no asterisks (*) against
- * the given string.
- * 
- * @param pattern Pointer to the unmatched portion of the pattern.
- *     On success, the pointer is moved to the first asterisk, or to the
- *     terminating nul character, whichever occurs first.
- * @param string Pointer to the input string. On success, the pointer is moved
- *     to the first character that wasn't explicitly matched.
- * @param flags Flags given to fnmatch().
- * @return True if the entire subpattern matched. False otherwise.
- */
-static bool _partial_match(const char **pattern, const char **string, int flags)
-{
-	/* Only a single *-delimited subpattern is matched here.
-	 * So in this function, '*' is understood as the end of pattern.
-	 */
-
-	const bool pathname = (flags & FNM_PATHNAME) != 0;
-	const bool special_period = (flags & FNM_PERIOD) != 0;
-	const bool noescape = (flags & FNM_NOESCAPE) != 0;
-	const bool leading_dir = (flags & FNM_LEADING_DIR) != 0;
-
-	const char *s = *string;
-	const char *p = *pattern;
-
-	while (*p != '*') {
-		/* Bracket expression. */
-		if (*p == '[') {
-			int matched = _match_bracket_expr(&p, s, flags);
-			if (matched == 0) {
-				/* Doesn't match. */
-				return false;
-			}
-			if (matched != INVALID_PATTERN) {
-				s += matched;
-				continue;
-			}
-
-			assert(matched == INVALID_PATTERN);
-			/* Fall through to match [ as an ordinary character. */
-		}
-
-		/* Wildcard match. */
-		if (*p == '?') {
-			if (*s == '\0') {
-				/* No character to match. */
-				return false;
-			}
-			if (pathname && *s == '/') {
-				/* Slash must be matched explicitly. */
-				return false;
-			}
-			if (special_period && pathname &&
-			    *s == '.' && *(s - 1) == '/') {
-				/* Initial period must be matched explicitly. */
-				return false;
-			}
-			
-			/* None of the above, match anything else. */
-			p++;
-			s++;
-			continue;
-		}
-
-		if (!noescape && *p == '\\') {
-			/* Escaped character. */
-			p++;
-		}
-
-		if (*p == '\0') {
-			/* End of pattern, must match end of string or
-			 * an end of subdirectory name (optional).
-			 */
-
-			if (*s == '\0' || (leading_dir && *s == '/')) {
-				break;
-			}
-
-			return false;
-		}
-
-		if (*p == *s) {
-			/* Exact match. */
-			p++;
-			s++;
-			continue;
-		}
-
-		/* Nothing matched. */
-		return false;
-	}
-
-	/* Entire sub-pattern matched. */
-	
-	/* postconditions */
-	assert(*p == '\0' || *p == '*');
-	assert(*p != '\0' || *s == '\0' || (leading_dir && *s == '/'));
-	
-	*pattern = p;
-	*string = s;
-	return true;
-}
-
-/**
- * Match string against a pattern.
- * 
- * @param pattern Pattern.
- * @param string String to match.
- * @param flags Flags given to fnmatch().
- * @return True if the string matched the pattern, false otherwise.
- */
-static bool _full_match(const char *pattern, const char *string, int flags)
-{
-	const bool pathname = (flags & FNM_PATHNAME) != 0;
-	const bool special_period = (flags & FNM_PERIOD) != 0;
-	const bool leading_dir = (flags & FNM_LEADING_DIR) != 0;
-
-	if (special_period && *string == '.') {
-		/* Initial dot must be matched by an explicit dot in pattern. */
-		if (*pattern != '.') {
-			return false;
-		}
-		pattern++;
-		string++;
-	}
-
-	if (*pattern != '*') {
-		if (!_partial_match(&pattern, &string, flags)) {
-			/* The initial match must succeed. */
-			return false;
-		}
-	}
-
-	while (*pattern != '\0') {
-		assert(*pattern == '*');
-		pattern++;
-
-		bool matched = false;
-
-		const char *end;
-		if (pathname && special_period &&
-		    *string == '.' && *(string - 1) == '/') {
-			end = string;
-		} else {
-			end = gnu_strchrnul(string, pathname ? '/' : '\0');
-		}
-
-		/* Try to match every possible offset. */
-		while (string <= end) {
-			if (_partial_match(&pattern, &string, flags)) {
-				matched = true;
-				break;
-			}
-			string++;
-		}
-
-		if (matched) {
-			continue;
-		}
-
-		return false;
-	}
-
-	return *string == '\0' || (leading_dir && *string == '/');
-}
-
-/**
- * Transform the entire string to lowercase.
- * 
- * @param s Input string.
- * @return Newly allocated copy of the input string with all uppercase
- *     characters folded to their lowercase variants.
- */
-static char *_casefold(const char *s)
-{
-	assert(s != NULL);
-	char *result = posix_strdup(s);
-	for (char *i = result; *i != '\0'; ++i) {
-		*i = tolower(*i);
-	}
-	return result;
-}
-
-/**
- * Filename pattern matching.
- *
- * @param pattern Pattern to match the string against.
- * @param string Matched string.
- * @param flags Flags altering the matching of special characters
- *     (mainly for dot and slash).
- * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise.
- */
-int posix_fnmatch(const char *pattern, const char *string, int flags)
-{
-	assert(pattern != NULL);
-	assert(string != NULL);
-
-	// TODO: don't fold everything in advance, but only when needed
-
-	if ((flags & FNM_CASEFOLD) != 0) {
-		/* Just fold the entire pattern and string. */
-		pattern = _casefold(pattern);
-		string = _casefold(string);
-	}
-
-	bool result = _full_match(pattern, string, flags);
-
-	if ((flags & FNM_CASEFOLD) != 0) {
-		if (pattern) {
-			free((char *) pattern);
-		}
-		if (string) {
-			free((char *) string);
-		}
-	}
-
-	return result ? 0 : FNM_NOMATCH;
-}
-
-// FIXME: put the testcases to the app/tester after fnmatch is included into libc
-
-#if 0
-
-#include <stdio.h>
-
-void __posix_fnmatch_test()
-{
-	int fail = 0;
-
-	#undef assert
-	#define assert(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } }
-	#define match(s1, s2, flags) assert(posix_fnmatch(s1, s2, flags) == 0)
-	#define nomatch(s1, s2, flags) assert(posix_fnmatch(s1, s2, flags) == FNM_NOMATCH)
-
-	static_assert(FNM_PATHNAME == FNM_FILE_NAME);
-	match("", "", 0);
-	match("*", "hello", 0);
-	match("hello", "hello", 0);
-	match("hello*", "hello", 0);
-	nomatch("hello?", "hello", 0);
-	match("*hello", "prdel hello", 0);
-	match("he[sl]lo", "hello", 0);
-	match("he[sl]lo", "heslo", 0);
-	nomatch("he[sl]lo", "heblo", 0);
-	nomatch("he[^sl]lo", "hello", 0);
-	nomatch("he[^sl]lo", "heslo", 0);
-	match("he[^sl]lo", "heblo", 0);
-	nomatch("he[!sl]lo", "hello", 0);
-	nomatch("he[!sl]lo", "heslo", 0);
-	match("he[!sl]lo", "heblo", 0);
-	match("al*[c-t]a*vis*ta", "alheimer talir jehovista", 0);
-	match("al*[c-t]a*vis*ta", "alfons had jehovista", 0);
-	match("[a-ce-z]", "a", 0);
-	match("[a-ce-z]", "c", 0);
-	nomatch("[a-ce-z]", "d", 0);
-	match("[a-ce-z]", "e", 0);
-	match("[a-ce-z]", "z", 0);
-	nomatch("[^a-ce-z]", "a", 0);
-	nomatch("[^a-ce-z]", "c", 0);
-	match("[^a-ce-z]", "d", 0);
-	nomatch("[^a-ce-z]", "e", 0);
-	nomatch("[^a-ce-z]", "z", 0);
-	match("helen??", "helenos", 0);
-	match("****booo****", "booo", 0);
-	
-	match("hello[[:space:]]world", "hello world", 0);
-	nomatch("hello[[:alpha:]]world", "hello world", 0);
-	
-	match("/hoooo*", "/hooooooo/hooo", 0);
-	nomatch("/hoooo*", "/hooooooo/hooo", FNM_PATHNAME);
-	nomatch("/hoooo*/", "/hooooooo/hooo", FNM_PATHNAME);
-	match("/hoooo*/*", "/hooooooo/hooo", FNM_PATHNAME);
-	match("/hoooo*/hooo", "/hooooooo/hooo", FNM_PATHNAME);
-	match("/hoooo*", "/hooooooo/hooo", FNM_PATHNAME | FNM_LEADING_DIR);
-	nomatch("/hoooo*/", "/hooooooo/hooo", FNM_PATHNAME | FNM_LEADING_DIR);
-	nomatch("/hoooo", "/hooooooo/hooo", FNM_LEADING_DIR);
-	match("/hooooooo", "/hooooooo/hooo", FNM_LEADING_DIR);
-	
-	match("*", "hell", 0);
-	match("*?", "hell", 0);
-	match("?*?", "hell", 0);
-	match("?*??", "hell", 0);
-	match("??*??", "hell", 0);
-	nomatch("???*??", "hell", 0);
-	
-	nomatch("", "hell", 0);
-	nomatch("?", "hell", 0);
-	nomatch("??", "hell", 0);
-	nomatch("???", "hell", 0);
-	match("????", "hell", 0);
-	
-	match("*", "h.ello", FNM_PERIOD);
-	match("*", "h.ello", FNM_PATHNAME | FNM_PERIOD);
-	nomatch("*", ".hello", FNM_PERIOD);
-	match("h?ello", "h.ello", FNM_PERIOD);
-	nomatch("?hello", ".hello", FNM_PERIOD);
-	match("/home/user/.*", "/home/user/.hello", FNM_PATHNAME | FNM_PERIOD);
-	match("/home/user/*", "/home/user/.hello", FNM_PERIOD);
-	nomatch("/home/user/*", "/home/user/.hello", FNM_PATHNAME | FNM_PERIOD);
-
-	nomatch("HeLlO", "hello", 0);
-	match("HeLlO", "hello", FNM_CASEFOLD);
-
-	printf("Failed: %d\n", fail);
-}
-
-#endif
-
-/** @}
- */
Index: pace/lib/posix/source/getopt.c
===================================================================
--- uspace/lib/posix/source/getopt.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,55 +1,0 @@
-/*
- * Copyright (c) 2012 Vojtech Horky
- * 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 Command line argument parsing.
- */
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "libc/getopt.h"
-#include "posix/getopt.h"
-
-
-int posix_getopt_long(int argc, char * const argv[],
-    const char *opt_string, const struct option *long_opts, int *long_index)
-{
-	int rc = getopt_long(argc, argv, opt_string, long_opts, long_index);
-	posix_optarg = (char *) optarg;
-	return rc;
-}
-
-int posix_getopt(int argc, char * const argv[], const char *opt_string)
-{
-	int rc = getopt(argc, argv, opt_string);
-	posix_optarg = (char *) optarg;
-	return rc;
-}
Index: pace/lib/posix/source/internal/common.h
===================================================================
--- uspace/lib/posix/source/internal/common.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,68 +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 Helper definitions common for all libposix files.
- */
-
-#ifndef LIBPOSIX_COMMON_H_
-#define LIBPOSIX_COMMON_H_
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <offset.h>
-#include <vfs/vfs.h>
-
-#define not_implemented() do { \
-		static int __not_implemented_counter = 0; \
-		if (__not_implemented_counter == 0) { \
-			fprintf(stderr, "%s() not implemented in %s:%d, something will NOT work.\n", \
-				__func__, __FILE__, __LINE__); \
-		} \
-		__not_implemented_counter++; \
-	} while (0)
-
-/* 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];
-
-#endif /* LIBPOSIX_COMMON_H_ */
-
-/** @}
- */
Index: pace/lib/posix/source/locale.c
===================================================================
--- uspace/lib/posix/source/locale.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,185 +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 Locale-specific definitions.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/locale.h"
-
-#include <errno.h>
-
-#include "posix/limits.h"
-#include "posix/string.h"
-
-/* Just a very basic dummy implementation.
- * This should allow code using locales to work properly, but doesn't provide
- * any localization functionality.
- * Should be extended/rewritten when or if HelenOS supports locales natively.
- */
-
-struct __posix_locale {
-	int _dummy;
-};
-
-const struct posix_lconv C_LOCALE = {
-	.currency_symbol = (char *) "",
-	.decimal_point = (char *) ".",
-	.frac_digits = CHAR_MAX,
-	.grouping = (char *) "",
-	.int_curr_symbol = (char *) "",
-	.int_frac_digits = CHAR_MAX,
-	.int_n_cs_precedes = CHAR_MAX,
-	.int_n_sep_by_space = CHAR_MAX,
-	.int_n_sign_posn = CHAR_MAX,
-	.int_p_cs_precedes = CHAR_MAX,
-	.int_p_sep_by_space = CHAR_MAX,
-	.int_p_sign_posn = CHAR_MAX,
-	.mon_decimal_point = (char *) "",
-	.mon_grouping = (char *) "",
-	.mon_thousands_sep = (char *) "",
-	.negative_sign = (char *) "",
-	.n_cs_precedes = CHAR_MAX,
-	.n_sep_by_space = CHAR_MAX,
-	.n_sign_posn = CHAR_MAX,
-	.positive_sign = (char *) "",
-	.p_cs_precedes = CHAR_MAX,
-	.p_sep_by_space = CHAR_MAX,
-	.p_sign_posn = CHAR_MAX,
-	.thousands_sep = (char *) ""
-};
-
-/**
- * Set program locale.
- * 
- * @param category What category to set.
- * @param locale Locale name.
- * @return Original locale name on success, NULL on failure.
- */
-char *posix_setlocale(int category, const char *locale)
-{
-	// TODO
-	if (locale == NULL || *locale == '\0' ||
-	    posix_strcmp(locale, "C") == 0) {
-		return (char *) "C";
-	}
-	return NULL;
-}
-
-/**
- * Return locale-specific information.
- * 
- * @return Information about the current locale.
- */
-struct posix_lconv *posix_localeconv(void)
-{
-	// TODO
-	return (struct posix_lconv *) &C_LOCALE;
-}
-
-/**
- * Duplicate locale object.
- * 
- * @param locobj Object to duplicate.
- * @return Duplicated object.
- */
-posix_locale_t posix_duplocale(posix_locale_t locobj)
-{
-	if (locobj == NULL) {
-		errno = EINVAL;
-		return NULL;
-	}
-	posix_locale_t copy = malloc(sizeof(struct __posix_locale));
-	if (copy == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	memcpy(copy, locobj, sizeof(struct __posix_locale));
-	return copy;
-}
-
-/**
- * Free locale object.
- * 
- * @param locobj Object to free.
- */
-void posix_freelocale(posix_locale_t locobj)
-{
-	if (locobj) {
-		free(locobj);
-	}
-}
-
-/**
- * Create or modify a locale object.
- * 
- * @param category_mask Mask of categories to be set or modified.
- * @param locale Locale to be used.
- * @param base Object to modify. 0 if new object is to be created.
- * @return The new/modified locale object.
- */
-posix_locale_t posix_newlocale(int category_mask, const char *locale,
-    posix_locale_t base)
-{
-	if (locale == NULL ||
-	    (category_mask & LC_ALL_MASK) != category_mask) {
-		errno = EINVAL;
-		return NULL;
-	}
-	// TODO
-	posix_locale_t new = malloc(sizeof(struct __posix_locale));
-	if (new == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	if (base != NULL) {
-		posix_freelocale(base);
-	}
-	return new;
-}
-
-/**
- * Set locale for the current thread.
- * 
- * @param newloc Locale to use.
- * @return The previously set locale or LC_GLOBAL_LOCALE
- */
-posix_locale_t posix_uselocale(posix_locale_t newloc)
-{
-	// TODO
-	return LC_GLOBAL_LOCALE;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/pthread/condvar.c
===================================================================
--- uspace/lib/posix/source/pthread/condvar.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,96 +1,0 @@
-/*
- * Copyright (c) 2013 Vojtech Horky
- * 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 Pthread: condition variables.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/pthread.h"
-#include "errno.h"
-#include "../internal/common.h"
-
-int pthread_cond_init(pthread_cond_t *restrict condvar,
-    const pthread_condattr_t *restrict attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_cond_destroy(pthread_cond_t *condvar)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_cond_broadcast(pthread_cond_t *condvar)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_cond_signal(pthread_cond_t *condvar)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_cond_timedwait(pthread_cond_t *restrict condvar,
-    pthread_mutex_t *restrict mutex, const struct __POSIX_DEF__(timespec) *restrict timeout)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_cond_wait(pthread_cond_t *restrict condvar,
-    pthread_mutex_t *restrict mutex)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-
-int pthread_condattr_init(pthread_condattr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_condattr_destroy(pthread_condattr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-
-/** @}
- */
Index: pace/lib/posix/source/pthread/keys.c
===================================================================
--- uspace/lib/posix/source/pthread/keys.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,69 +1,0 @@
-/*
- * Copyright (c) 2013 Vojtech Horky
- * 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 Pthread: keys and thread-specific storage.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/stdlib.h"
-#include "posix/pthread.h"
-#include <errno.h>
-#include "../internal/common.h"
-
-
-void *pthread_getspecific(pthread_key_t key)
-{
-	not_implemented();
-	return NULL;
-}
-
-int pthread_setspecific(pthread_key_t key, const void *data)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_key_delete(pthread_key_t key)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/pthread/mutex.c
===================================================================
--- uspace/lib/posix/source/pthread/mutex.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,102 +1,0 @@
-/*
- * Copyright (c) 2013 Vojtech Horky
- * 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 Pthread: mutexes.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/pthread.h"
-#include <errno.h>
-#include "../internal/common.h"
-
-
-int pthread_mutex_init(pthread_mutex_t *restrict mutex,
-    const pthread_mutexattr_t *restrict attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutex_destroy(pthread_mutex_t *mutex)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutex_lock(pthread_mutex_t *mutex)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutex_trylock(pthread_mutex_t *mutex)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutex_unlock(pthread_mutex_t *mutex)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutexattr_init(pthread_mutexattr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
-    int *restrict type)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-
-
-/** @}
- */
Index: pace/lib/posix/source/pthread/threads.c
===================================================================
--- uspace/lib/posix/source/pthread/threads.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,86 +1,0 @@
-/*
- * Copyright (c) 2013 Vojtech Horky
- * 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 Pthread: thread management.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/pthread.h"
-#include "errno.h"
-#include "posix/stdlib.h"
-#include "libc/thread.h"
-#include "../internal/common.h"
-
-pthread_t pthread_self(void)
-{
-	return thread_get_id();
-}
-
-int pthread_equal(pthread_t thread1, pthread_t thread2)
-{
-	return thread1 == thread2;
-}
-
-int pthread_create(pthread_t *thread_id, const pthread_attr_t *attributes,
-    void *(*start_routine)(void *), void *arg)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_join(pthread_t thread, void **ret_val)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_detach(pthread_t thread)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_attr_init(pthread_attr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-int pthread_attr_destroy(pthread_attr_t *attr)
-{
-	not_implemented();
-	return ENOTSUP;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/pwd.c
===================================================================
--- uspace/lib/posix/source/pwd.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,192 +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 Password handling.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "libc/stdbool.h"
-#include "posix/pwd.h"
-#include "posix/string.h"
-#include <errno.h>
-#include <assert.h>
-
-static bool entry_read = false;
-
-/* dummy user account */
-static const struct posix_passwd dummy_pwd = {
-	.pw_name = (char *) "user",
-	.pw_uid = 0,
-	.pw_gid = 0,
-	.pw_dir = (char *) "/",
-	.pw_shell = (char *) "/app/bdsh"
-};
-
-/**
- * Retrieve next broken-down entry from the user database.
- *
- * Since HelenOS doesn't have user accounts, this always returns
- * the same made-up entry.
- *
- * @return Next user database entry or NULL if not possible. Since HelenOS
- *     doesn't have user accounts, this always returns the same made-up entry.
- */
-struct posix_passwd *posix_getpwent(void)
-{
-	if (entry_read) {
-		return NULL;
-	}
-
-	entry_read = true;
-	return (struct posix_passwd *) &dummy_pwd;
-}
-
-/**
- * Rewind the user list.
- */
-void posix_setpwent(void)
-{
-	entry_read = false;
-}
-
-/**
- * Ends enumerating and releases all resources. (Noop)
- */
-void posix_endpwent(void)
-{
-	/* noop */
-}
-
-/**
- * Find an entry by name.
- *
- * @param name Name of the entry.
- * @return Either found entry or NULL if no such entry exists.
- */
-struct posix_passwd *posix_getpwnam(const char *name)
-{
-	assert(name != NULL);
-
-	if (posix_strcmp(name, "user") != 0) {
-		return NULL;
-	}
-
-	return (struct posix_passwd *) &dummy_pwd;
-}
-
-/**
- * Find an entry by name, thread safely.
- *
- * @param name Name of the entry.
- * @param pwd Original structure.
- * @param buffer Buffer for the strings referenced from the result structure.
- * @param bufsize Length of the buffer.
- * @param result Where to store updated structure.
- * @return Zero on success (either found or not found, but without an error),
- *     non-zero error number if error occured.
- */
-int posix_getpwnam_r(const char *name, struct posix_passwd *pwd,
-    char *buffer, size_t bufsize, struct posix_passwd **result)
-{
-	assert(name != NULL);
-	assert(pwd != NULL);
-	assert(buffer != NULL);
-	assert(result != NULL);
-	
-	if (posix_strcmp(name, "user") != 0) {
-		*result = NULL;
-		return 0;
-	}
-	
-	return posix_getpwuid_r(0, pwd, buffer, bufsize, result);
-}
-
-/**
- * Find an entry by UID.
- *
- * @param uid UID of the entry.
- * @return Either found entry or NULL if no such entry exists.
- */
-struct posix_passwd *posix_getpwuid(posix_uid_t uid)
-{
-	if (uid != 0) {
-		return NULL;
-	}
-
-	return (struct posix_passwd *) &dummy_pwd;
-}
-
-/**
- * Find an entry by UID, thread safely.
- *
- * @param uid UID of the entry.
- * @param pwd Original structure.
- * @param buffer Buffer for the strings referenced from the result structure.
- * @param bufsize Length of the buffer.
- * @param result Where to store updated structure.
- * @return Zero on success (either found or not found, but without an error),
- *     non-zero error number if error occured.
- */
-int posix_getpwuid_r(posix_uid_t uid, struct posix_passwd *pwd,
-    char *buffer, size_t bufsize, struct posix_passwd **result)
-{
-	assert(pwd != NULL);
-	assert(buffer != NULL);
-	assert(result != NULL);
-	
-	static const char bf[] = { 'u', 's', 'e', 'r', '\0',
-	    '/', '\0', 'b', 'd', 's', 'h', '\0' };
-	
-	if (uid != 0) {
-		*result = NULL;
-		return 0;
-	}
-	if (bufsize < sizeof(bf)) {
-		*result = NULL;
-		return ERANGE;
-	}
-
-	memcpy(buffer, bf, sizeof(bf));
-
-	pwd->pw_name = (char *) bf;
-	pwd->pw_uid = 0;
-	pwd->pw_gid = 0;
-	pwd->pw_dir = (char *) bf + 5;
-	pwd->pw_shell = (char *) bf + 7;
-	*result = (struct posix_passwd *) pwd;
-
-	return 0;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/signal.c
===================================================================
--- uspace/lib/posix/source/signal.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,568 +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 Signal handling.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "posix/signal.h"
-#include "internal/common.h"
-#include "posix/limits.h"
-#include "posix/stdlib.h"
-#include "posix/string.h"
-
-#include <errno.h>
-
-#include "libc/fibril_synch.h"
-#include "libc/task.h"
-
-/* This file implements a fairly dumb and incomplete "simulation" of
- * POSIX signals. Since HelenOS doesn't support signals and mostly doesn't
- * have any equivalent functionality, most of the signals are useless. The
- * main purpose of this implementation is thus to help port applications using
- * signals with minimal modification, but if the application uses signals for
- * anything non-trivial, it's quite probable it won't work properly even if
- * it builds without problems.
- */
-
-/* Used to serialize signal handling. */
-static FIBRIL_MUTEX_INITIALIZE(_signal_mutex);
-
-static LIST_INITIALIZE(_signal_queue);
-
-static posix_sigset_t _signal_mask = 0;
-
-#define DEFAULT_HANDLER { .sa_handler = SIG_DFL, \
-    .sa_mask = 0, .sa_flags = 0, .sa_sigaction = NULL }
-
-/* Actions associated with each signal number. */
-static struct posix_sigaction _signal_actions[_TOP_SIGNAL + 1] = {
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
-	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER
-};
-
-/**
- * Default signal handler. Executes the default action for each signal,
- * as reasonable within HelenOS.
- *
- * @param signo Signal number.
- */
-void __posix_default_signal_handler(int signo)
-{
-	switch (signo) {
-	case SIGABRT:
-		abort();
-	case SIGQUIT:
-		fprintf(stderr, "Quit signal raised. Exiting.\n");
-		exit(EXIT_FAILURE);
-	case SIGINT:
-		fprintf(stderr, "Interrupt signal caught. Exiting.\n");
-		exit(EXIT_FAILURE);
-	case SIGTERM:
-		fprintf(stderr, "Termination signal caught. Exiting.\n");
-		exit(EXIT_FAILURE);
-	case SIGSTOP:
-		fprintf(stderr, "Stop signal caught, but unsupported. Ignoring.\n");
-		break;
-	case SIGKILL:
-		/* This will only occur when raise or similar is called. */
-		/* Commit suicide. */
-		task_kill(task_get_id());
-		
-		/* Should not be reached. */
-		abort();
-	case SIGFPE:
-	case SIGBUS:
-	case SIGILL:
-	case SIGSEGV:
-		posix_psignal(signo, "Hardware exception raised by user code");
-		abort();
-	case SIGSYS:
-	case SIGXCPU:
-	case SIGXFSZ:
-	case SIGTRAP:
-	case SIGHUP:
-	case SIGPIPE:
-	case SIGPOLL:
-	case SIGURG:
-	case SIGTSTP:
-	case SIGTTIN:
-	case SIGTTOU:
-		posix_psignal(signo, "Unsupported signal caught");
-		abort();
-	case SIGCHLD:
-	case SIGUSR1:
-	case SIGUSR2:
-	case SIGALRM:
-	case SIGVTALRM:
-	case SIGPROF:
-	case SIGCONT:
-		/* ignored */
-		break;
-	}
-}
-
-/**
- * Just an empty function to get an unique pointer value for comparison.
- *
- * @param signo Signal number.
- */
-void __posix_hold_signal_handler(int signo)
-{
-	/* Nothing */
-}
-
-/**
- * Empty function to be used as ignoring handler.
- * 
- * @param signo Signal number.
- */
-void __posix_ignore_signal_handler(int signo)
-{
-	/* Nothing */
-}
-
-/**
- * Clear the signal set.
- * 
- * @param set Pointer to the signal set.
- * @return Always returns zero.
- */
-int posix_sigemptyset(posix_sigset_t *set)
-{
-	assert(set != NULL);
-
-	*set = 0;
-	return 0;
-}
-
-/**
- * Fill the signal set (i.e. add all signals).
- * 
- * @param set Pointer to the signal set.
- * @return Always returns zero.
- */
-int posix_sigfillset(posix_sigset_t *set)
-{
-	assert(set != NULL);
-
-	*set = UINT32_MAX;
-	return 0;
-}
-
-/**
- * Add a signal to the set.
- * 
- * @param set Pointer to the signal set.
- * @param signo Signal number to add.
- * @return Always returns zero.
- */
-int posix_sigaddset(posix_sigset_t *set, int signo)
-{
-	assert(set != NULL);
-
-	*set |= (1 << signo);
-	return 0;
-}
-
-/**
- * Delete a signal from the set.
- * 
- * @param set Pointer to the signal set.
- * @param signo Signal number to remove.
- * @return Always returns zero.
- */
-int posix_sigdelset(posix_sigset_t *set, int signo)
-{
-	assert(set != NULL);
-
-	*set &= ~(1 << signo);
-	return 0;
-}
-
-/**
- * Inclusion test for a signal set.
- * 
- * @param set Pointer to the signal set.
- * @param signo Signal number to query.
- * @return 1 if the signal is in the set, 0 otherwise.
- */
-int posix_sigismember(const posix_sigset_t *set, int signo)
-{
-	assert(set != NULL);
-	
-	return (*set & (1 << signo)) != 0;
-}
-
-/**
- * Unsafe variant of the sigaction() function.
- * Doesn't do any checking of its arguments and
- * does not deal with thread-safety.
- * 
- * @param sig
- * @param act
- * @param oact
- */
-static void _sigaction_unsafe(int sig, const struct posix_sigaction *restrict act,
-    struct posix_sigaction *restrict oact)
-{
-	if (oact != NULL) {
-		memcpy(oact, &_signal_actions[sig],
-		    sizeof(struct posix_sigaction));
-	}
-
-	if (act != NULL) {
-		memcpy(&_signal_actions[sig], act,
-		    sizeof(struct posix_sigaction));
-	}
-}
-
-/**
- * Sets a new action for the given signal number.
- * 
- * @param sig Signal number to set action for.
- * @param act If not NULL, contents of this structure are
- *     used as the new action for the signal.
- * @param oact If not NULL, the original action associated with the signal
- *     is stored in the structure pointer to. 
- * @return -1 with errno set on failure, 0 on success.
- */
-int posix_sigaction(int sig, const struct posix_sigaction *restrict act,
-    struct posix_sigaction *restrict oact)
-{
-	if (sig > _TOP_SIGNAL || (act != NULL &&
-	    (sig == SIGKILL || sig == SIGSTOP))) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	if (sig > _TOP_CATCHABLE_SIGNAL) {
-		posix_psignal(sig,
-		    "WARNING: registering handler for a partially"
-		    " or fully unsupported signal. This handler may only be"
-		    " invoked by the raise() function, which may not be what"
-		    " the application developer intended");
-	}
-
-	fibril_mutex_lock(&_signal_mutex);
-	_sigaction_unsafe(sig, act, oact);
-	fibril_mutex_unlock(&_signal_mutex);
-
-	return 0;
-}
-
-/**
- * Sets a new handler for the given signal number.
- * 
- * @param sig Signal number to set handler for.
- * @param func Handler function.
- * @return SIG_ERR on failure, original handler on success.
- */
-void (*posix_signal(int sig, void (*func)(int)))(int)
-{
-	struct posix_sigaction new = {
-		.sa_handler = func,
-		.sa_mask = 0,
-		.sa_flags = 0,
-		.sa_sigaction = NULL
-	};
-	struct posix_sigaction old;
-	if (posix_sigaction(sig, func == NULL ? NULL : &new, &old) == 0) {
-		return old.sa_handler;
-	} else {
-		return SIG_ERR;
-	}
-}
-
-typedef struct {
-	link_t link;
-	int signo;
-	posix_siginfo_t siginfo;
-} signal_queue_item;
-
-/**
- * Queue blocked signal.
- *
- * @param signo Signal number.
- * @param siginfo Additional information about the signal.
- */
-static void _queue_signal(int signo, posix_siginfo_t *siginfo)
-{
-	assert(signo >= 0 && signo <= _TOP_SIGNAL);
-	assert(siginfo != NULL);
-	
-	signal_queue_item *item = malloc(sizeof(signal_queue_item));
-	link_initialize(&(item->link));
-	item->signo = signo;
-	memcpy(&item->siginfo, siginfo, sizeof(posix_siginfo_t));
-	list_append(&(item->link), &_signal_queue);
-}
-
-
-/**
- * Executes an action associated with the given signal.
- *
- * @param signo Signal number.
- * @param siginfo Additional information about the circumstances of this raise.
- * @return 0 if the action has been successfully executed. -1 if the signal is
- *     blocked.
- */
-static int _raise_sigaction(int signo, posix_siginfo_t *siginfo)
-{
-	assert(signo >= 0 && signo <= _TOP_SIGNAL);
-	assert(siginfo != NULL);
-
-	fibril_mutex_lock(&_signal_mutex);
-
-	struct posix_sigaction action = _signal_actions[signo];
-
-	if (posix_sigismember(&_signal_mask, signo) ||
-	    action.sa_handler == SIG_HOLD) {
-		_queue_signal(signo, siginfo);
-		fibril_mutex_unlock(&_signal_mutex);
-		return -1;
-	}
-
-	/* Modifying signal mask is unnecessary,
-	 * signal handling is serialized.
-	 */
-
-	if ((action.sa_flags & SA_RESETHAND) && signo != SIGILL && signo != SIGTRAP) {
-		_signal_actions[signo] = (struct posix_sigaction) DEFAULT_HANDLER;
-	}
-
-	if (action.sa_flags & SA_SIGINFO) {
-		assert(action.sa_sigaction != NULL);
-		action.sa_sigaction(signo, siginfo, NULL);
-	} else {
-		assert(action.sa_handler != NULL);
-		action.sa_handler(signo);
-	}
-
-	fibril_mutex_unlock(&_signal_mutex);
-
-	return 0;
-}
-
-/**
- * Raise all unblocked previously queued signals.
- */
-static void _dequeue_unblocked_signals(void)
-{
-	link_t *iterator = _signal_queue.head.next;
-	link_t *next;
-	
-	while (iterator != &(_signal_queue).head) {
-		next = iterator->next;
-		
-		signal_queue_item *item =
-		    list_get_instance(iterator, signal_queue_item, link);
-		
-		if (!posix_sigismember(&_signal_mask, item->signo) &&
-		    _signal_actions[item->signo].sa_handler != SIG_HOLD) {
-			list_remove(&(item->link));
-			_raise_sigaction(item->signo, &(item->siginfo));
-			free(item);
-		}
-		
-		iterator = next;
-	}
-}
-
-/**
- * Raise a signal for the calling process.
- * 
- * @param sig Signal number.
- * @return -1 with errno set on failure, 0 on success.
- */
-int posix_raise(int sig)
-{
-	if (sig >= 0 && sig <= _TOP_SIGNAL) {
-		posix_siginfo_t siginfo = {
-			.si_signo = sig,
-			.si_code = SI_USER
-		};
-		return _raise_sigaction(sig, &siginfo);
-	} else {
-		errno = EINVAL;
-		return -1;
-	}
-}
-
-/**
- * Raises a signal for a selected process.
- * 
- * @param pid PID of the process for which the signal shall be raised.
- * @param signo Signal to raise.
- * @return -1 with errno set on failure (possible errors include unsupported
- *     action, invalid signal number, lack of permissions, etc.), 0 on success.
- */
-int posix_kill(posix_pid_t pid, int signo)
-{
-	if (pid < 1) {
-		// TODO
-		errno = ENOTSUP;
-		return -1;
-	}
-
-	if (signo > _TOP_SIGNAL) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	if (pid == (posix_pid_t) task_get_id()) {
-		return posix_raise(signo);
-	}
-
-	switch (signo) {
-	case SIGKILL:
-		task_kill(pid);
-		break;
-	default:
-		/* Nothing else supported yet. */
-		errno = ENOTSUP;
-		return -1;
-	}
-
-	return 0;
-}
-
-/**
- * Send a signal to a process group. Always fails at the moment because of
- * lack of this functionality in HelenOS.
- * 
- * @param pid PID of the process group.
- * @param sig Signal number.
- * @return -1 on failure, 0 on success (see kill()).
- */
-int posix_killpg(posix_pid_t pid, int sig)
-{
-	assert(pid > 1);
-	return posix_kill(-pid, sig);
-}
-
-/**
- * Outputs information about the signal to the standard error stream.
- * 
- * @param pinfo SigInfo struct to write.
- * @param message String to output alongside human-readable signal description.
- */
-void posix_psiginfo(const posix_siginfo_t *pinfo, const char *message)
-{
-	assert(pinfo != NULL);
-	posix_psignal(pinfo->si_signo, message);
-	// TODO: print si_code
-}
-
-/**
- * Outputs information about the signal to the standard error stream.
- * 
- * @param signum Signal number.
- * @param message String to output alongside human-readable signal description.
- */
-void posix_psignal(int signum, const char *message)
-{
-	char *sigmsg = posix_strsignal(signum);
-	if (message == NULL || *message == '\0') {
-		fprintf(stderr, "%s\n", sigmsg);
-	} else {
-		fprintf(stderr, "%s: %s\n", message, sigmsg);
-	}
-}
-
-/**
- * Manipulate the signal mask of the calling thread.
- * 
- * @param how What to do with the mask.
- * @param set Signal set to work with.
- * @param oset If not NULL, the original signal mask is coppied here.
- * @return 0 success, errorcode on failure.
- */
-int posix_thread_sigmask(int how, const posix_sigset_t *restrict set,
-    posix_sigset_t *restrict oset)
-{
-	fibril_mutex_lock(&_signal_mutex);
-
-	if (oset != NULL) {
-		*oset = _signal_mask;
-	}
-	if (set != NULL) {
-		switch (how) {
-		case SIG_BLOCK:
-			_signal_mask |= *set;
-			break;
-		case SIG_UNBLOCK:
-			_signal_mask &= ~*set;
-			break;
-		case SIG_SETMASK:
-			_signal_mask = *set;
-			break;
-		default:
-			fibril_mutex_unlock(&_signal_mutex);
-			return EINVAL;
-		}
-	}
-	
-	_dequeue_unblocked_signals();
-
-	fibril_mutex_unlock(&_signal_mutex);
-
-	return 0;
-}
-
-/**
- * Manipulate the signal mask of the process.
- * 
- * @param how What to do with the mask.
- * @param set Signal set to work with.
- * @param oset If not NULL, the original signal mask is coppied here.
- * @return 0 on success, -1 with errno set on failure.
- */
-int posix_sigprocmask(int how, const posix_sigset_t *restrict set,
-    posix_sigset_t *restrict oset)
-{
-	int result = posix_thread_sigmask(how, set, oset);
-	if (result != 0) {
-		errno = result;
-		return -1;
-	}
-	return 0;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/stdio.c
===================================================================
--- uspace/lib/posix/source/stdio.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,711 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * Copyright (c) 2011 Petr Koupy
- * 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 Standard buffered input/output.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/stdio.h"
-
-#include <assert.h>
-
-#include <errno.h>
-
-#include "posix/stdlib.h"
-#include "posix/string.h"
-#include "posix/sys/types.h"
-#include "posix/unistd.h"
-
-#include "libc/stdio.h"
-#include "libc/io/printf_core.h"
-#include "libc/str.h"
-#include "libc/malloc.h"
-#include "libc/adt/list.h"
-
-/** Clears the stream's error and end-of-file indicators.
- *
- * @param stream Stream whose indicators shall be cleared.
- */
-void posix_clearerr(FILE *stream)
-{
-	clearerr(stream);
-}
-
-/**
- * Generate a pathname for the controlling terminal.
- *
- * @param s Allocated buffer to which the pathname shall be put.
- * @return Either s or static location filled with the requested pathname.
- */
-char *posix_ctermid(char *s)
-{
-	/* Currently always returns an error value (empty string). */
-	// TODO: return a real terminal path
-
-	static char dummy_path[L_ctermid] = {'\0'};
-
-	if (s == NULL) {
-		return dummy_path;
-	}
-
-	s[0] = '\0';
-	return s;
-}
-
-/**
- * Put a string on the stream.
- * 
- * @param s String to be written.
- * @param stream Output stream.
- * @return Non-negative on success, EOF on failure.
- */
-int posix_fputs(const char *restrict s, FILE *restrict stream)
-{
-	return fputs(s, stream);
-}
-
-/**
- * Push byte back into input stream.
- * 
- * @param c Byte to be pushed back.
- * @param stream Stream to where the byte shall be pushed.
- * @return Provided byte on success or EOF if not possible.
- */
-int posix_ungetc(int c, FILE *stream)
-{
-	return ungetc(c, stream);
-}
-
-/**
- * Read a stream until the delimiter (or EOF) is encountered.
- *
- * @param lineptr Pointer to the output buffer in which there will be stored
- *     nul-terminated string together with the delimiter (if encountered).
- *     Will be resized if necessary.
- * @param n Pointer to the size of the output buffer. Will be increased if
- *     necessary.
- * @param delimiter Delimiter on which to finish reading the stream.
- * @param stream Input stream.
- * @return Number of fetched characters (including delimiter if encountered)
- *     or -1 on error (set in errno).
- */
-ssize_t posix_getdelim(char **restrict lineptr, size_t *restrict n,
-    int delimiter, FILE *restrict stream)
-{
-	/* Check arguments for sanity. */
-	if (!lineptr || !n) {
-		errno = EINVAL;
-		return -1;
-	}
-
-	size_t alloc_step = 80; /* Buffer size gain during reallocation. */
-	char *pos = *lineptr; /* Next free byte of the output buffer. */
-	size_t cnt = 0; /* Number of fetched characters. */
-	int c = fgetc(stream); /* Current input character. Might be EOF. */
-
-	do {
-		/* Mask EOF as NUL to terminate string. */
-		if (c == EOF) {
-			c = '\0';
-		}
-
-		/* Ensure there is still space left in the buffer. */
-		if (pos == *lineptr + *n) {
-			*lineptr = realloc(*lineptr, *n + alloc_step);
-			if (*lineptr) {
-				pos = *lineptr + *n;
-				*n += alloc_step;
-			} else {
-				errno = ENOMEM;
-				return -1;
-			}
-		}
-
-		/* Store the fetched character. */
-		*pos = c;
-
-		/* Fetch the next character according to the current character. */
-		if (c != '\0') {
-			++pos;
-			++cnt;
-			if (c == delimiter) {
-				/* Delimiter was just stored. Provide EOF as the next
-				 * character - it will be masked as NUL and output string
-				 * will be properly terminated. */
-				c = EOF;
-			} else {
-				/* Neither delimiter nor EOF were encountered. Just fetch
-				 * the next character from the stream. */
-				c = fgetc(stream);
-			}
-		}
-	} while (c != '\0');
-
-	if (errno == EOK && cnt > 0) {
-		return cnt;
-	} else {
-		/* Either some error occured or the stream was already at EOF. */
-		return -1;
-	}
-}
-
-/**
- * Read a stream until the newline (or EOF) is encountered.
- * 
- * @param lineptr Pointer to the output buffer in which there will be stored
- *     nul-terminated string together with the delimiter (if encountered).
- *     Will be resized if necessary.
- * @param n Pointer to the size of the output buffer. Will be increased if
- *     necessary.
- * @param stream Input stream.
- * @return Number of fetched characters (including newline if encountered)
- *     or -1 on error (set in errno).
- */
-ssize_t posix_getline(char **restrict lineptr, size_t *restrict n,
-    FILE *restrict stream)
-{
-	return posix_getdelim(lineptr, n, '\n', stream);
-}
-
-/**
- * Reopen a file stream.
- * 
- * @param filename Pathname of a file to be reopened or NULL for changing
- *     the mode of the stream.
- * @param mode Mode to be used for reopening the file or changing current
- *     mode of the stream.
- * @param stream Current stream associated with the opened file.
- * @return On success, either a stream of the reopened file or the provided
- *     stream with a changed mode. NULL otherwise.
- */
-FILE *posix_freopen(const char *restrict filename, 
-    const char *restrict mode, FILE *restrict stream)
-{
-	return freopen(filename, mode, stream);
-}
-
-/**
- * Write error messages to standard error.
- *
- * @param s Error message.
- */
-void posix_perror(const char *s)
-{
-	if (s == NULL || s[0] == '\0') {
-		fprintf(stderr, "%s\n", posix_strerror(errno));
-	} else {
-		fprintf(stderr, "%s: %s\n", s, posix_strerror(errno));
-	}
-}
-
-/** Restores stream a to position previously saved with fgetpos().
- *
- * @param stream Stream to restore
- * @param pos Position to restore
- * @return Zero on success, non-zero (with errno set) on failure
- */
-int posix_fsetpos(FILE *stream, const posix_fpos_t *pos)
-{
-	return fseek(stream, pos->offset, SEEK_SET);
-}
-
-/** Saves the stream's position for later use by fsetpos().
- *
- * @param stream Stream to save
- * @param pos Place to store the position
- * @return Zero on success, non-zero (with errno set) on failure
- */
-int posix_fgetpos(FILE *restrict stream, posix_fpos_t *restrict pos)
-{
-	off64_t ret = ftell(stream);
-	if (ret != -1) {
-		pos->offset = ret;
-		return 0;
-	} else {
-		return -1;
-	}
-}
-
-/**
- * Reposition a file-position indicator in a stream.
- * 
- * @param stream Stream to seek in.
- * @param offset Direction and amount of bytes to seek.
- * @param whence From where to seek.
- * @return Zero on success, -1 otherwise.
- */
-int posix_fseek(FILE *stream, long offset, int whence)
-{
-	return fseek(stream, (off64_t) offset, whence);
-}
-
-/**
- * Reposition a file-position indicator in a stream.
- * 
- * @param stream Stream to seek in.
- * @param offset Direction and amount of bytes to seek.
- * @param whence From where to seek.
- * @return Zero on success, -1 otherwise.
- */
-int posix_fseeko(FILE *stream, posix_off_t offset, int whence)
-{
-	return fseek(stream, (off64_t) offset, whence);
-}
-
-/**
- * Discover current file offset in a stream.
- * 
- * @param stream Stream for which the offset shall be retrieved.
- * @return Current offset or -1 if not possible.
- */
-long posix_ftell(FILE *stream)
-{
-	return (long) ftell(stream);
-}
-
-/**
- * Discover current file offset in a stream.
- * 
- * @param stream Stream for which the offset shall be retrieved.
- * @return Current offset or -1 if not possible.
- */
-posix_off_t posix_ftello(FILE *stream)
-{
-	return (posix_off_t) ftell(stream);
-}
-
-/**
- * Discard prefetched data or write unwritten data.
- * 
- * @param stream Stream that shall be flushed.
- * @return Zero on success, EOF on failure.
- */
-int posix_fflush(FILE *stream)
-{
-	return fflush(stream);
-}
-
-/**
- * Print formatted output to the opened file.
- *
- * @param fildes File descriptor of the opened file.
- * @param format Format description.
- * @return Either the number of printed characters or negative value on error.
- */
-int posix_dprintf(int fildes, const char *restrict format, ...)
-{
-	va_list list;
-	va_start(list, format);
-	int result = posix_vdprintf(fildes, format, list);
-	va_end(list);
-	return result;
-}
-
-/**
- * Write ordinary string to the opened file.
- *
- * @param str String to be written.
- * @param size Size of the string (in bytes)..
- * @param fd File descriptor of the opened file.
- * @return The number of written characters.
- */
-static int _dprintf_str_write(const char *str, size_t size, void *fd)
-{
-	const int fildes = *(int *) fd;
-	size_t wr;
-	if (failed(vfs_write(fildes, &posix_pos[fildes], str, size, &wr)))
-		return -1;
-	return str_nlength(str, wr);
-}
-
-/**
- * Write wide string to the opened file.
- * 
- * @param str String to be written.
- * @param size Size of the string (in bytes).
- * @param fd File descriptor of the opened file.
- * @return The number of written characters.
- */
-static int _dprintf_wstr_write(const wchar_t *str, size_t size, void *fd)
-{
-	size_t offset = 0;
-	size_t chars = 0;
-	size_t sz;
-	char buf[4];
-	
-	while (offset < size) {
-		sz = 0;
-		if (chr_encode(str[chars], buf, &sz, sizeof(buf)) != EOK) {
-			break;
-		}
-		
-		const int fildes = *(int *) fd;
-		size_t nwr;
-		if (vfs_write(fildes, &posix_pos[fildes], buf, sz, &nwr) != EOK)
-			break;
-		
-		chars++;
-		offset += sizeof(wchar_t);
-	}
-	
-	return chars;
-}
-
-/**
- * Print formatted output to the opened file.
- * 
- * @param fildes File descriptor of the opened file.
- * @param format Format description.
- * @param ap Print arguments.
- * @return Either the number of printed characters or negative value on error.
- */
-int posix_vdprintf(int fildes, const char *restrict format, va_list ap)
-{
-	printf_spec_t spec = {
-		.str_write = _dprintf_str_write,
-		.wstr_write = _dprintf_wstr_write,
-		.data = &fildes
-	};
-	
-	return printf_core(format, &spec, ap);
-}
-
-/**
- * Print formatted output to the string.
- * 
- * @param s Output string.
- * @param format Format description.
- * @return Either the number of printed characters (excluding null byte) or
- *     negative value on error.
- */
-int posix_sprintf(char *s, const char *restrict format, ...)
-{
-	va_list list;
-	va_start(list, format);
-	int result = posix_vsprintf(s, format, list);
-	va_end(list);
-	return result;
-}
-
-/**
- * Print formatted output to the string.
- * 
- * @param s Output string.
- * @param format Format description.
- * @param ap Print arguments.
- * @return Either the number of printed characters (excluding null byte) or
- *     negative value on error.
- */
-int posix_vsprintf(char *s, const char *restrict format, va_list ap)
-{
-	return vsnprintf(s, STR_NO_LIMIT, format, ap);
-}
-
-/**
- * Convert formatted input from the stream.
- * 
- * @param stream Input stream.
- * @param format Format description.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_fscanf(FILE *restrict stream, const char *restrict format, ...)
-{
-	va_list list;
-	va_start(list, format);
-	int result = posix_vfscanf(stream, format, list);
-	va_end(list);
-	return result;
-}
-
-/**
- * Convert formatted input from the standard input.
- * 
- * @param format Format description.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_scanf(const char *restrict format, ...)
-{
-	va_list list;
-	va_start(list, format);
-	int result = posix_vscanf(format, list);
-	va_end(list);
-	return result;
-}
-
-/**
- * Convert formatted input from the standard input.
- * 
- * @param format Format description.
- * @param arg Output items.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_vscanf(const char *restrict format, va_list arg)
-{
-	return posix_vfscanf(stdin, format, arg);
-}
-
-/**
- * Convert formatted input from the string.
- * 
- * @param s Input string.
- * @param format Format description.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_sscanf(const char *restrict s, const char *restrict format, ...)
-{
-	va_list list;
-	va_start(list, format);
-	int result = posix_vsscanf(s, format, list);
-	va_end(list);
-	return result;
-}
-
-/**
- * Acquire file stream for the thread.
- *
- * @param file File stream to lock.
- */
-void posix_flockfile(FILE *file)
-{
-	/* dummy */
-}
-
-/**
- * Acquire file stream for the thread (non-blocking).
- *
- * @param file File stream to lock.
- * @return Zero for success and non-zero if the lock cannot be acquired.
- */
-int posix_ftrylockfile(FILE *file)
-{
-	/* dummy */
-	return 0;
-}
-
-/**
- * Relinquish the ownership of the locked file stream.
- *
- * @param file File stream to unlock.
- */
-void posix_funlockfile(FILE *file)
-{
-	/* dummy */
-}
-
-/**
- * Get a byte from a stream (thread-unsafe).
- *
- * @param stream Input file stream.
- * @return Either read byte or EOF.
- */
-int posix_getc_unlocked(FILE *stream)
-{
-	return getc(stream);
-}
-
-/**
- * Get a byte from the standard input stream (thread-unsafe).
- *
- * @return Either read byte or EOF.
- */
-int posix_getchar_unlocked(void)
-{
-	return getchar();
-}
-
-/**
- * Put a byte on a stream (thread-unsafe).
- *
- * @param c Byte to output.
- * @param stream Output file stream.
- * @return Either written byte or EOF.
- */
-int posix_putc_unlocked(int c, FILE *stream)
-{
-	return putc(c, stream);
-}
-
-/**
- * Put a byte on the standard output stream (thread-unsafe).
- * 
- * @param c Byte to output.
- * @return Either written byte or EOF.
- */
-int posix_putchar_unlocked(int c)
-{
-	return putchar(c);
-}
-
-/**
- * Remove a file or directory.
- *
- * @param path Pathname of the file that shall be removed.
- * @return Zero on success, -1 (with errno set) otherwise.
- */
-int posix_remove(const char *path)
-{
-	if (failed(vfs_unlink_path(path)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Rename a file or directory.
- *
- * @param old Old pathname.
- * @param new New pathname.
- * @return Zero on success, -1 (with errno set) otherwise.
- */
-int posix_rename(const char *old, const char *new)
-{
-	if (failed(vfs_rename_path(old, new)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Get a unique temporary file name (obsolete).
- *
- * @param s Buffer for the file name. Must be at least L_tmpnam bytes long.
- * @return The value of s on success, NULL on failure.
- */
-char *posix_tmpnam(char *s)
-{
-	assert(L_tmpnam >= posix_strlen("/tmp/tnXXXXXX"));
-	
-	static char buffer[L_tmpnam + 1];
-	if (s == NULL) {
-		s = buffer;
-	}
-	
-	posix_strcpy(s, "/tmp/tnXXXXXX");
-	posix_mktemp(s);
-	
-	if (*s == '\0') {
-		/* Errno set by mktemp(). */
-		return NULL;
-	}
-	
-	return s;
-}
-
-/**
- * Get an unique temporary file name with additional constraints (obsolete).
- *
- * @param dir Path to directory, where the file should be created.
- * @param pfx Optional prefix up to 5 characters long.
- * @return Newly allocated unique path for temporary file. NULL on failure.
- */
-char *posix_tempnam(const char *dir, const char *pfx)
-{
-	/* Sequence number of the filename. */
-	static int seq = 0;
-	
-	size_t dir_len = posix_strlen(dir);
-	if (dir[dir_len - 1] == '/') {
-		dir_len--;
-	}
-	
-	size_t pfx_len = posix_strlen(pfx);
-	if (pfx_len > 5) {
-		pfx_len = 5;
-	}
-	
-	char *result = malloc(dir_len + /* slash*/ 1 +
-	    pfx_len + /* three-digit seq */ 3 + /* .tmp */ 4 + /* nul */ 1);
-	
-	if (result == NULL) {
-		errno = ENOMEM;
-		return NULL;
-	}
-	
-	char *res_ptr = result;
-	posix_strncpy(res_ptr, dir, dir_len);
-	res_ptr += dir_len;
-	posix_strncpy(res_ptr, pfx, pfx_len);
-	res_ptr += pfx_len;
-	
-	for (; seq < 1000; ++seq) {
-		snprintf(res_ptr, 8, "%03d.tmp", seq);
-		
-		int orig_errno = errno;
-		errno = EOK;
-		/* Check if the file exists. */
-		if (posix_access(result, F_OK) == -1) {
-			if (errno == ENOENT) {
-				errno = orig_errno;
-				break;
-			} else {
-				/* errno set by access() */
-				return NULL;
-			}
-		}
-	}
-	
-	if (seq == 1000) {
-		free(result);
-		errno = EINVAL;
-		return NULL;
-	}
-	
-	return result;
-}
-
-/**
- * Create and open an unique temporary file.
- * The file is automatically removed when the stream is closed.
- *
- * @param dir Path to directory, where the file should be created.
- * @param pfx Optional prefix up to 5 characters long.
- * @return Newly allocated unique path for temporary file. NULL on failure.
- */
-FILE *posix_tmpfile(void)
-{
-	char filename[] = "/tmp/tfXXXXXX";
-	int fd = posix_mkstemp(filename);
-	if (fd == -1) {
-		/* errno set by mkstemp(). */
-		return NULL;
-	}
-	
-	/* Unlink the created file, so that it's removed on close(). */
-	posix_unlink(filename);
-	return fdopen(fd, "w+");
-}
-
-/** @}
- */
Index: pace/lib/posix/source/stdio/scanf.c
===================================================================
--- uspace/lib/posix/source/stdio/scanf.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,1224 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 Implementation of the scanf backend.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include <assert.h>
-
-#include <errno.h>
-
-#include "posix/stdio.h"
-#include "posix/stdlib.h"
-#include "posix/stddef.h"
-#include "posix/string.h"
-#include "posix/ctype.h"
-#include "posix/sys/types.h"
-
-#include "../internal/common.h"
-#include "libc/malloc.h"
-#include "libc/stdbool.h"
-
-/** Unified data type for possible data sources for scanf. */
-typedef union __data_source {
-	FILE *stream; /**< Input file stream. */
-	const char *string; /**< Input string. */
-} _data_source;
-
-/** Internal state of the input provider. */
-enum {
-	/** Partly constructed but not yet functional. */
-	_PROV_CONSTRUCTED,
-	/** Ready to serve any request. */
-	_PROV_READY,
-	/** Cursor is temporarily lent to the external entity. No action is
-	  * possible until the cursor is returned.  */
-	_PROV_CURSOR_LENT,
-};
-
-/** Universal abstraction over data input for scanf. */
-typedef struct __input_provider {
-	/** Source of data elements. */
-	_data_source source;
-	/** How many elements was already processed. */
-	int consumed;
-	/** How many elements was already fetched from the source. */
-	int fetched;
-	/** Elements are fetched from the source in batches (e.g. by getline())
-	  * to allow using strtol/strtod family even on streams. */
-	char *window;
-	/** Size of the current window. */
-	size_t window_size;
-	/** Points to the next element to be processed inside the current window. */
-	const char *cursor;
-	/** Internal state of the provider. */
-	int state;
-
-	/** Take control over data source. Finish initialization of the internal
-	  * structures (e.g. allocation of window). */
-	void (*capture)(struct __input_provider *);
-	/** Get a single element from the source and update the internal structures
-	  * accordingly (e.g. greedy update of the window). Return -1 if the
-	  * element cannot be obtained. */
-	int (*pop)(struct __input_provider *);
-	/** Undo the most recent not-undone pop operation. Might be necesarry to
-	  * flush current window and seek data source backwards. Return 0 if the
-	  * pop history is exhausted, non-zero on success. */
-	int (*undo)(struct __input_provider *);
-	/** Lend the cursor to the caller.  */
-	const char * (*borrow_cursor)(struct __input_provider *);
-	/** Take control over possibly incremented cursor and update the internal
-	  * structures if necessary. */
-	void (*return_cursor)(struct __input_provider *, const char *);
-	/** Release the control over the source. That is, synchronize any
-	  * fetched but non-consumed elements (e.g. by seeking) and destruct
-	  * internal structures (e.g. window deallocation). */
-	void (*release)(struct __input_provider *);
-} _input_provider;
-
-/** @see __input_provider */
-static void _capture_stream(_input_provider *self)
-{
-	assert(self->source.stream);
-	assert(self->state == _PROV_CONSTRUCTED);
-	/* Caller could already pre-allocated the window. */
-	assert((self->window == NULL && self->window_size == 0) ||
-	    (self->window && self->window_size > 0));
-
-	/* Initialize internal structures. */
-	self->consumed = 0;
-	ssize_t fetched = posix_getline(
-	    &self->window, &self->window_size, self->source.stream);
-	if (fetched != -1) {
-		self->fetched = fetched;
-		self->cursor = self->window;
-	} else {
-		/* EOF encountered. */
-		self->fetched = 0;
-		self->cursor = NULL;
-	}
-	self->state = _PROV_READY;
-}
-
-/** @see __input_provider */
-static void _capture_string(_input_provider *self)
-{
-	assert(self->source.string);
-	assert(self->state == _PROV_CONSTRUCTED);
-
-	/* Initialize internal structures. */
-	self->consumed = 0;
-	self->fetched = posix_strlen(self->source.string);
-	self->window = (char *) self->source.string;
-	self->window_size = self->fetched + 1;
-	self->cursor = self->window;
-	self->state = _PROV_READY;
-}
-
-/** @see __input_provider */
-static int _pop_stream(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	if (self->cursor) {
-		int c = *self->cursor;
-		++self->consumed;
-		++self->cursor;
-		/* Do we need to fetch a new line from the source? */
-		if (*self->cursor == '\0') {
-			ssize_t fetched = posix_getline(&self->window,
-			    &self->window_size, self->source.stream);
-			if (fetched != -1) {
-				self->fetched += fetched;
-				self->cursor = self->window;
-			} else {
-				/* EOF encountered. */
-				self->cursor = NULL;
-			}
-		}
-		return c;
-	} else {
-		/* Already at EOF. */
-		return -1;
-	}
-}
-
-/** @see __input_provider */
-static int _pop_string(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	if (*self->cursor != '\0') {
-		int c = *self->cursor;
-		++self->consumed;
-		++self->cursor;
-		return c;
-	} else {
-		/* String depleted. */
-		return -1;
-	}
-}
-
-/** @see __input_provider */
-static int _undo_stream(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	if (self->consumed == 0) {
-		/* Undo history exhausted. */
-		return 0;
-	}
-
-	if (!self->cursor || self->window == self->cursor) {
-		/* Complex case. Either at EOF (cursor == NULL) or there is no more
-		 * place to retreat to inside the window. Seek the source backwards
-		 * and flush the window. Regarding the scanf, this could happend only
-		 * when matching unbounded string (%s) or unbounded scanset (%[) not
-		 * containing newline, while at the same time newline is the character
-		 * that breaks the matching process. */
-		int rc = posix_fseek(
-		    self->source.stream, -1, SEEK_CUR);
-		if (rc == -1) {
-			/* Seek failed.  */
-			return 0;
-		}
-		ssize_t fetched = posix_getline(&self->window,
-		    &self->window_size, self->source.stream);
-		if (fetched != -1) {
-			assert(fetched == 1);
-			self->fetched = self->consumed + 1;
-			self->cursor = self->window;
-		} else {
-			/* Stream is broken. */
-			return 0;
-		}
-	} else {
-		/* Simple case. Still inside window. */
-		--self->cursor;
-	}
-	--self->consumed;
-	return 1; /* Success. */
-}
-
-/** @see __input_provider */
-static int _undo_string(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	if (self->consumed > 0) {
-		--self->consumed;
-		--self->cursor;
-	} else {
-		/* Undo history exhausted. */
-		return 0;
-	}
-	return 1; /* Success. */
-}
-
-/** @see __input_provider */
-static const char *_borrow_cursor_universal(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	self->state = _PROV_CURSOR_LENT;
-	return self->cursor;
-}
-
-/** @see __input_provider */
-static void _return_cursor_stream(_input_provider *self, const char *cursor)
-{
-	assert(self->state == _PROV_CURSOR_LENT);
-
-	/* Check how much of the window did external entity consumed. */
-	self->consumed += cursor - self->cursor;
-	self->cursor = cursor;
-	if (*self->cursor == '\0') {
-		/* Window was completely consumed, fetch new data. */
-		ssize_t fetched = posix_getline(&self->window,
-		    &self->window_size, self->source.stream);
-		if (fetched != -1) {
-			self->fetched += fetched;
-			self->cursor = self->window;
-		} else {
-			/* EOF encountered. */
-			self->cursor = NULL;
-		}
-	}
-	self->state = _PROV_READY;
-}
-
-/** @see __input_provider */
-static void _return_cursor_string(_input_provider *self, const char *cursor)
-{
-	assert(self->state == _PROV_CURSOR_LENT);
-
-	/* Check how much of the window did external entity consumed. */
-	self->consumed += cursor - self->cursor;
-	self->cursor = cursor;
-	self->state = _PROV_READY;
-}
-
-/** @see __input_provider */
-static void _release_stream(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-	assert(self->consumed >= self->fetched);
-
-	/* Try to correct the difference between the stream position and what was
-	 * actually consumed. If it is not possible, continue anyway. */
-	posix_fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR);
-
-	/* Destruct internal structures. */
-	self->fetched = 0;
-	self->cursor = NULL;
-	if (self->window) {
-		free(self->window);
-		self->window = NULL;
-	}
-	self->window_size = 0;
-	self->state = _PROV_CONSTRUCTED;
-}
-
-/** @see __input_provider */
-static void _release_string(_input_provider *self)
-{
-	assert(self->state == _PROV_READY);
-
-	/* Destruct internal structures. */
-	self->fetched = 0;
-	self->cursor = NULL;
-	self->window = NULL;
-	self->window_size = 0;
-	self->state = _PROV_CONSTRUCTED;
-}
-
-/** Length modifier values. */
-enum {
-	LMOD_NONE,
-	LMOD_hh,
-	LMOD_h,
-	LMOD_l,
-	LMOD_ll,
-	LMOD_j,
-	LMOD_z,
-	LMOD_t,
-	LMOD_L,
-	LMOD_p, /* Reserved for %p conversion. */
-};
-
-/**
- * Decides whether provided characters specify length modifier. If so, the
- * recognized modifier is stored through provider pointer.
- *
- * @param c Candidate on the length modifier.
- * @param _c Next character (might be NUL).
- * @param modifier Pointer to the modifier value.
- * @return Whether the modifier was recognized or not.
- */
-static inline int is_length_mod(int c, int _c, int *modifier)
-{
-	assert(modifier);
-
-	switch (c) {
-	case 'h':
-		/* Check whether the modifier was not already recognized. */
-		if (*modifier == LMOD_NONE) {
-			*modifier = _c == 'h' ? LMOD_hh : LMOD_h;
-		} else {
-			/* Format string is invalid. Notify the caller. */
-			*modifier = LMOD_NONE;
-		}
-		return 1;
-	case 'l':
-		if (*modifier == LMOD_NONE) {
-			*modifier = _c == 'l' ? LMOD_ll : LMOD_l;
-		} else {
-			*modifier = LMOD_NONE;
-		}
-		return 1;
-	case 'j':
-		*modifier = *modifier == LMOD_NONE ? LMOD_j : LMOD_NONE;
-		return 1;
-	case 'z':
-		*modifier = *modifier == LMOD_NONE ? LMOD_z : LMOD_NONE;
-		return 1;
-	case 't':
-		*modifier = *modifier == LMOD_NONE ? LMOD_t : LMOD_NONE;
-		return 1;
-	case 'L':
-		*modifier = *modifier == LMOD_NONE ? LMOD_L : LMOD_NONE;
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-/**
- * Decides whether provided character specifies integer conversion. If so, the
- * semantics of the conversion is stored through provided pointers..
- * 
- * @param c Candidate on the integer conversion.
- * @param is_unsigned Pointer to store whether the conversion is signed or not.
- * @param base Pointer to store the base of the integer conversion.
- * @return Whether the conversion was recognized or not.
- */
-static inline int is_int_conv(int c, bool *is_unsigned, int *base)
-{
-	assert(is_unsigned && base);
-
-	switch (c) {
-	case 'd':
-		*is_unsigned = false;
-		*base = 10;
-		return 1;
-	case 'i':
-		*is_unsigned = false;
-		*base = 0;
-		return 1;
-	case 'o':
-		*is_unsigned = true;
-		*base = 8;
-		return 1;
-	case 'u':
-		*is_unsigned = true;
-		*base = 10;
-		return 1;
-	case 'p': /* According to POSIX, %p modifier is implementation defined but
-			   * must correspond to its printf counterpart. */
-	case 'x':
-	case 'X':
-		*is_unsigned = true;
-		*base = 16;
-		return 1;
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-/**
- * Decides whether provided character specifies conversion of the floating
- * point number.
- *
- * @param c Candidate on the floating point conversion.
- * @return Whether the conversion was recognized or not.
- */
-static inline int is_float_conv(int c)
-{
-	switch (c) {
-	case 'a':
-	case 'A':
-	case 'e':
-	case 'E':
-	case 'f':
-	case 'F':
-	case 'g':
-	case 'G':
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-/**
- * Decides whether provided character specifies conversion of the character
- * sequence.
- *
- * @param c Candidate on the character sequence conversion.
- * @param modifier Pointer to store length modifier for wide chars.
- * @return Whether the conversion was recognized or not.
- */
-static inline int is_seq_conv(int c, int *modifier)
-{
-	assert(modifier);
-	
-	switch (c) {
-	case 'S':
-		*modifier = LMOD_l;
-		/* Fallthrough */
-	case 's':
-		return 1;
-	case 'C':
-		*modifier = LMOD_l;
-		/* Fallthrough */
-	case 'c':
-		return 1;
-	case '[':
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-/**
- * Backend for the whole family of scanf functions. Uses input provider
- * to abstract over differences between strings and streams. Should be
- * POSIX compliant (apart from the not supported stuff).
- *
- * NOT SUPPORTED: locale (see strtold), wide chars, numbered output arguments
- * 
- * @param in Input provider.
- * @param fmt Format description.
- * @param arg Output arguments.
- * @return The number of converted output items or EOF on failure.
- */
-static inline int _internal_scanf(
-    _input_provider *in, const char *restrict fmt, va_list arg)
-{
-	int c = -1;
-	int converted_cnt = 0;
-	bool converting = false;
-	bool matching_failure = false;
-
-	bool assign_supress = false;
-	bool assign_alloc = false;
-	long width = -1;
-	int length_mod = LMOD_NONE;
-	bool int_conv_unsigned = false;
-	int int_conv_base = 0;
-
-	/* Buffers allocated by scanf for optional 'm' specifier must be remembered
-	 * to deallocaate them in case of an error. Because each of those buffers
-	 * corresponds to one of the argument from va_list, there is an upper bound
-	 * on the number of those arguments. In case of C99, this uppper bound is
-	 * 127 arguments. */
-	char *buffers[127];
-	for (int i = 0; i < 127; ++i) {
-		buffers[i] = NULL;
-	}
-	int next_unused_buffer_idx = 0;
-
-	in->capture(in);
-
-	/* Interpret format string. Control shall prematurely jump from the cycle
-	 * on input failure, matching failure or illegal format string. In order
-	 * to keep error reporting simple enough and to keep input consistent,
-	 * error condition shall be always manifested as jump from the cycle,
-	 * not function return. Format string pointer shall be updated specifically
-	 * for each sub-case (i.e. there shall be no loop-wide increment).*/
-	while (*fmt) {
-
-		if (converting) {
-
-			/* Processing inside conversion specifier. Either collect optional
-			 * parameters or execute the conversion. When the conversion
-			 * is successfully completed, increment conversion count and switch
-			 * back to normal mode. */
-			if (*fmt == '*') {
-				/* Assignment-supression (optional). */
-				if (assign_supress) {
-					/* Already set. Illegal format string. */
-					break;
-				}
-				assign_supress = true;
-				++fmt;
-			} else if (*fmt == 'm') {
-				/* Assignment-allocation (optional). */
-				if (assign_alloc) {
-					/* Already set. Illegal format string. */
-					break;
-				}
-				assign_alloc = true;
-				++fmt;
-			} else if (*fmt == '$') {
-				/* Reference to numbered output argument. */
-				// TODO
-				not_implemented();
-			} else if (isdigit(*fmt)) {
-				/* Maximum field length (optional). */
-				if (width != -1) {
-					/* Already set. Illegal format string. */
-					break;
-				}
-				char *fmt_new = NULL;
-				width = posix_strtol(fmt, &fmt_new, 10);
-				if (width != 0) {
-					fmt = fmt_new;
-				} else {
-					/* Since POSIX requires width to be non-zero, it is
-					 * sufficient to interpret zero width as error without
-					 * referring to errno. */
-					break;
-				}
-			} else if (is_length_mod(*fmt, *(fmt + 1), &length_mod)) {
-				/* Length modifier (optional). */
-				if (length_mod == LMOD_NONE) {
-					/* Already set. Illegal format string. The actual detection
-					 * is carried out in the is_length_mod(). */
-					break;
-				}
-				if (length_mod == LMOD_hh || length_mod == LMOD_ll) {
-					/* Modifier was two characters long. */
-					++fmt;
-				}
-				++fmt;
-			} else if (is_int_conv(*fmt, &int_conv_unsigned, &int_conv_base)) {
-				/* Integer conversion. */
-
-				/* Check sanity of optional parts of conversion specifier. */
-				if (assign_alloc || length_mod == LMOD_L) {
-					/* Illegal format string. */
-					break;
-				}
-
-				/* Conversion of the integer with %p specifier needs special
-				 * handling, because it is not allowed to have arbitrary
-				 * length modifier.  */
-				if (*fmt == 'p') {
-					if (length_mod == LMOD_NONE) {
-						length_mod = LMOD_p;
-					} else {
-						/* Already set. Illegal format string. */
-						break;
-					}
-				}
-
-				/* First consume any white spaces, so we can borrow cursor
-				 * from the input provider. This way, the cursor will either
-				 * point to the non-white space while the input will be
-				 * prefetched up to the newline (which is suitable for strtol),
-				 * or the input will be at EOF. */
-				do {
-					c = in->pop(in);
-				} while (isspace(c));
-
-				/* After skipping the white spaces, can we actually continue? */
-				if (c == -1) {
-					/* Input failure. */
-					break;
-				} else {
-					/* Everything is OK, just undo the last pop, so the cursor
-					 * can be borrowed. */
-					in->undo(in);
-				}
-
-				const char *cur_borrowed = NULL;
-				const char *cur_limited = NULL;
-				char *cur_updated = NULL;
-
-				/* Borrow the cursor. Until it is returned to the provider
-				 * we cannot jump from the cycle, because it would leave
-				 * the input inconsistent. */
-				cur_borrowed = in->borrow_cursor(in);
-
-				/* If the width is limited, the cursor horizont must be
-				 * decreased accordingly. Otherwise the strtol could read more
-				 * than allowed by width. */
-				if (width != -1) {
-					cur_limited = posix_strndup(cur_borrowed, width);
-				} else {
-					cur_limited = cur_borrowed;
-				}
-				cur_updated = (char *) cur_limited;
-
-				long long sres = 0;
-				unsigned long long ures = 0;
-				errno = 0; /* Reset errno to recognize error later. */
-				/* Try to convert the integer. */
-				if (int_conv_unsigned) {
-					ures = posix_strtoull(cur_limited, &cur_updated, int_conv_base);
-				} else {
-					sres = posix_strtoll(cur_limited, &cur_updated, int_conv_base);
-				}
-
-				/* Update the cursor so it can be returned to the provider. */
-				cur_borrowed += cur_updated - cur_limited;
-				if (width != -1 && cur_limited != NULL) {
-					/* Deallocate duplicated part of the cursor view. */
-					free(cur_limited);
-				}
-				cur_limited = NULL;
-				cur_updated = NULL;
-				/* Return the cursor to the provider. Input consistency is again
-				 * the job of the provider, so we can report errors from
-				 * now on. */
-				in->return_cursor(in, cur_borrowed);
-				cur_borrowed = NULL;
-
-				/* Check whether the conversion was successful. */
-				if (errno != EOK) {
-					matching_failure = true;
-					break;
-				}
-
-				/* If not supressed, assign the converted integer into
-				 * the next output argument. */
-				if (!assign_supress) {
-					if (int_conv_unsigned) {
-						switch (length_mod) {
-						case LMOD_hh: ; /* Label cannot be part of declaration. */
-							unsigned char *phh = va_arg(arg, unsigned char *);
-							*phh = (unsigned char) ures;
-							break;
-						case LMOD_h: ;
-							unsigned short *ph = va_arg(arg, unsigned short *);
-							*ph = (unsigned short) ures;
-							break;
-						case LMOD_NONE: ;
-							unsigned *pdef = va_arg(arg, unsigned *);
-							*pdef = (unsigned) ures;
-							break;
-						case LMOD_l: ;
-							unsigned long *pl = va_arg(arg, unsigned long *);
-							*pl = (unsigned long) ures;
-							break;
-						case LMOD_ll: ;
-							unsigned long long *pll = va_arg(arg, unsigned long long *);
-							*pll = (unsigned long long) ures;
-							break;
-						case LMOD_j: ;
-							uintmax_t *pj = va_arg(arg, uintmax_t *);
-							*pj = (uintmax_t) ures;
-							break;
-						case LMOD_z: ;
-							size_t *pz = va_arg(arg, size_t *);
-							*pz = (size_t) ures;
-							break;
-						case LMOD_t: ;
-							// XXX: What is unsigned counterpart of the ptrdiff_t?
-							size_t *pt = va_arg(arg, size_t *);
-							*pt = (size_t) ures;
-							break;
-						case LMOD_p: ;
-							void **pp = va_arg(arg, void **);
-							*pp = (void *) (uintptr_t) ures;
-							break;
-						default:
-							assert(false);
-						}
-					} else {
-						switch (length_mod) {
-						case LMOD_hh: ; /* Label cannot be part of declaration. */
-							signed char *phh = va_arg(arg, signed char *);
-							*phh = (signed char) sres;
-							break;
-						case LMOD_h: ;
-							short *ph = va_arg(arg, short *);
-							*ph = (short) sres;
-							break;
-						case LMOD_NONE: ;
-							int *pdef = va_arg(arg, int *);
-							*pdef = (int) sres;
-							break;
-						case LMOD_l: ;
-							long *pl = va_arg(arg, long *);
-							*pl = (long) sres;
-							break;
-						case LMOD_ll: ;
-							long long *pll = va_arg(arg, long long *);
-							*pll = (long long) sres;
-							break;
-						case LMOD_j: ;
-							intmax_t *pj = va_arg(arg, intmax_t *);
-							*pj = (intmax_t) sres;
-							break;
-						case LMOD_z: ;
-							ssize_t *pz = va_arg(arg, ssize_t *);
-							*pz = (ssize_t) sres;
-							break;
-						case LMOD_t: ;
-							ptrdiff_t *pt = va_arg(arg, ptrdiff_t *);
-							*pt = (ptrdiff_t) sres;
-							break;
-						default:
-							assert(false);
-						}
-					}
-					++converted_cnt;
-				}
-
-				converting = false;
-				++fmt;
-			} else if (is_float_conv(*fmt)) {
-				/* Floating point number conversion. */
-
-				/* Check sanity of optional parts of conversion specifier. */
-				if (assign_alloc) {
-					/* Illegal format string. */
-					break;
-				}
-				if (length_mod != LMOD_NONE &&
-				    length_mod != LMOD_l &&
-				    length_mod != LMOD_L) {
-					/* Illegal format string. */
-					break;
-				}
-
-				/* First consume any white spaces, so we can borrow cursor
-				 * from the input provider. This way, the cursor will either
-				 * point to the non-white space while the input will be
-				 * prefetched up to the newline (which is suitable for strtof),
-				 * or the input will be at EOF. */
-				do {
-					c = in->pop(in);
-				} while (isspace(c));
-
-				/* After skipping the white spaces, can we actually continue? */
-				if (c == -1) {
-					/* Input failure. */
-					break;
-				} else {
-					/* Everything is OK, just undo the last pop, so the cursor
-					 * can be borrowed. */
-					in->undo(in);
-				}
-
-				const char *cur_borrowed = NULL;
-				const char *cur_limited = NULL;
-				char *cur_updated = NULL;
-
-				/* Borrow the cursor. Until it is returned to the provider
-				 * we cannot jump from the cycle, because it would leave
-				 * the input inconsistent. */
-				cur_borrowed = in->borrow_cursor(in);
-
-				/* If the width is limited, the cursor horizont must be
-				 * decreased accordingly. Otherwise the strtof could read more
-				 * than allowed by width. */
-				if (width != -1) {
-					cur_limited = posix_strndup(cur_borrowed, width);
-				} else {
-					cur_limited = cur_borrowed;
-				}
-				cur_updated = (char *) cur_limited;
-
-				float fres = 0.0;
-				double dres = 0.0;
-				long double ldres = 0.0;
-				errno = 0; /* Reset errno to recognize error later. */
-				/* Try to convert the floating point nubmer. */
-				switch (length_mod) {
-				case LMOD_NONE:
-					fres = posix_strtof(cur_limited, &cur_updated);
-					break;
-				case LMOD_l:
-					dres = posix_strtod(cur_limited, &cur_updated);
-					break;
-				case LMOD_L:
-					ldres = posix_strtold(cur_limited, &cur_updated);
-					break;
-				default:
-					assert(false);
-				}
-
-				/* Update the cursor so it can be returned to the provider. */
-				cur_borrowed += cur_updated - cur_limited;
-				if (width != -1 && cur_limited != NULL) {
-					/* Deallocate duplicated part of the cursor view. */
-					free(cur_limited);
-				}
-				cur_limited = NULL;
-				cur_updated = NULL;
-				/* Return the cursor to the provider. Input consistency is again
-				 * the job of the provider, so we can report errors from
-				 * now on. */
-				in->return_cursor(in, cur_borrowed);
-				cur_borrowed = NULL;
-
-				/* Check whether the conversion was successful. */
-				if (errno != EOK) {
-					matching_failure = true;
-					break;
-				}
-
-				/* If nto supressed, assign the converted floating point number
-				 * into the next output argument. */
-				if (!assign_supress) {
-					switch (length_mod) {
-					case LMOD_NONE: ; /* Label cannot be part of declaration. */
-						float *pf = va_arg(arg, float *);
-						*pf = fres;
-						break;
-					case LMOD_l: ;
-						double *pd = va_arg(arg, double *);
-						*pd = dres;
-						break;
-					case LMOD_L: ;
-						long double *pld = va_arg(arg, long double *);
-						*pld = ldres;
-						break;
-					default:
-						assert(false);
-					}
-					++converted_cnt;
-				}
-
-				converting = false;
-				++fmt;
-			} else if (is_seq_conv(*fmt, &length_mod)) {
-				/* Character sequence conversion. */
-				
-				/* Check sanity of optional parts of conversion specifier. */
-				if (length_mod != LMOD_NONE &&
-				    length_mod != LMOD_l) {
-					/* Illegal format string. */
-					break;
-				}
-
-				if (length_mod == LMOD_l) {
-					/* Wide chars not supported. */
-					// TODO
-					not_implemented();
-				}
-
-				int term_size = 1; /* Size of the terminator (0 or 1)). */
-				if (*fmt == 'c') {
-					term_size = 0;
-					width = width == -1 ? 1 : width;
-				}
-
-				if (*fmt == 's') {
-					/* Skip white spaces. */
-					do {
-						c = in->pop(in);
-					} while (isspace(c));
-				} else {
-					/* Fetch a single character. */
-					c = in->pop(in);
-				}
-
-				/* Check whether there is still input to read. */
-				if (c == -1) {
-					/* Input failure. */
-					break;
-				}
-
-				/* Prepare scanset. */
-				char terminate_on[256];
-				for (int i = 0; i < 256; ++i) {
-					terminate_on[i] = 0;
-				}
-				if (*fmt == 'c') {
-					++fmt;
-				} else if (*fmt == 's') {
-					terminate_on[' '] = 1;
-					terminate_on['\n'] = 1;
-					terminate_on['\t'] = 1;
-					terminate_on['\f'] = 1;
-					terminate_on['\r'] = 1;
-					terminate_on['\v'] = 1;
-					++fmt;
-				} else {
-					assert(*fmt == '[');
-					bool not = false;
-					bool dash = false;
-					++fmt;
-					/* Check for negation. */
-					if (*fmt == '^') {
-						not = true;
-						++fmt;
-					}
-					/* Check for escape sequences. */
-					if (*fmt == '-' || *fmt == ']') {
-						terminate_on[(int) *fmt] = 1;
-						++fmt;
-					}
-					/* Check for ordinary characters and ranges. */
-					while (*fmt != '\0' && *fmt != ']') {
-						if (dash) {
-							for (char chr = *(fmt - 2); chr <= *fmt; ++chr) {
-								terminate_on[(int) chr] = 1;
-							}
-							dash = false;
-						} else if (*fmt == '-') {
-							dash = true;
-						} else {
-							terminate_on[(int) *fmt] = 1;
-						}
-						++fmt;
-					}
-					/* Check for escape sequence. */
-					if (dash == true) {
-						terminate_on['-'] = 1;
-					}
-					/* Check whether the specifier was correctly terminated.*/
-					if (*fmt == '\0') {
-						/* Illegal format string. */
-						break;
-					} else {
-						++fmt;
-					}
-					/* Inverse the scanset if necessary. */
-					if (not == false) {
-						for (int i = 0; i < 256; ++i) {
-							terminate_on[i] = terminate_on[i] ? 0 : 1;
-						}
-					}
-				}
-
-				char * buf = NULL;
-				size_t buf_size = 0;
-				char * cur = NULL;
-				size_t alloc_step = 80; /* Buffer size gain during reallocation. */
-				int my_buffer_idx = 0;
-
-				/* Retrieve the buffer into which popped characters
-				 * will be stored. */
-				if (!assign_supress) {
-					if (assign_alloc) {
-						/* We must allocate our own buffer. */
-						buf_size =
-						    width == -1 ? alloc_step : (size_t) width + term_size;
-						buf = malloc(buf_size);
-						if (!buf) {
-							/* No memory. */
-							break;
-						}
-						my_buffer_idx = next_unused_buffer_idx;
-						++next_unused_buffer_idx;
-						buffers[my_buffer_idx] = buf;
-						cur = buf;
-					} else {
-						/* Caller provided its buffer. */
-						buf = va_arg(arg, char *);
-						cur = buf;
-						buf_size =
-						    width == -1 ? SIZE_MAX : (size_t) width + term_size;
-					}
-				}
-
-				/* Match the string. The next character is already popped. */
-				while ((width == -1 || width > 0) && c != -1 && !terminate_on[c]) {
-
-					/* Check whether the buffer is still sufficiently large. */
-					if (!assign_supress) {
-						/* Always reserve space for the null terminator. */
-						if (cur == buf + buf_size - term_size) {
-							/* Buffer size must be increased. */
-							buf = realloc(buf, buf_size + alloc_step);
-							if (buf) {
-								buffers[my_buffer_idx] = buf;
-								cur = buf + buf_size - term_size;
-								buf_size += alloc_step;
-							} else {
-								/* Break just from this tight loop. Errno will
-								 * be checked after it. */
-								break;
-							}
-						}
-						/* Store the input character. */
-						*cur = c;
-					}
-
-					width = width == -1 ? -1 : width - 1;
-					++cur;
-					c = in->pop(in);
-				}
-				if (errno == ENOMEM) {
-					/* No memory. */
-					break;
-				}
-				if (c != -1) {
-					/* There is still more input, so undo the last pop. */
-					in->undo(in);
-				}
-
-				/* Check for failures. */
-				if (cur == buf) {
-					/* Matching failure. Input failure was already checked
-					 * earlier. */
-					matching_failure = true;
-					if (!assign_supress && assign_alloc) {
-						/* Roll back. */
-						free(buf);
-						buffers[my_buffer_idx] = NULL;
-						--next_unused_buffer_idx;
-					}
-					break;
-				}
-
-				/* Store the terminator. */
-				if (!assign_supress && term_size > 0) {
-					/* Space for the terminator was reserved. */
-					*cur = '\0';
-				}
-
-				/* Store the result if not already stored. */
-				if (!assign_supress) {
-					if (assign_alloc) {
-						char **pbuf = va_arg(arg, char **);
-						*pbuf = buf;
-					}
-					++converted_cnt;
-				}
-				
-				converting = false;
-				/* Format string pointer already incremented. */
-			} else if (*fmt == 'n') {
-				/* Report the number of consumed bytes so far. */
-
-				/* Sanity check. */
-				bool sane =
-				    width == -1 &&
-				    length_mod == LMOD_NONE &&
-				    assign_alloc == false &&
-				    assign_supress == false;
-
-				if (sane) {
-					int *pi = va_arg(arg, int *);
-					*pi = in->consumed;
-				} else {
-					/* Illegal format string. */
-					break;
-				}
-
-				/* This shall not be counted as conversion. */
-				converting = false;
-				++fmt;
-			} else {
-				/* Illegal format string. */
-				break;
-			}
-			
-		} else {
-
-			/* Processing outside conversion specifier. Either skip white
-			 * spaces or match characters one by one. If conversion specifier
-			 * is detected, switch to coversion mode. */
-			if (isspace(*fmt)) {
-				/* Skip white spaces in the format string. */
-				while (isspace(*fmt)) {
-					++fmt;
-				}
-				/* Skip white spaces in the input. */
-				do {
-					c = in->pop(in);
-				} while (isspace(c));
-				if (c != -1) {
-					/* Input is not at EOF, so undo the last pop operation. */
-					in->undo(in);
-				}
-			} else if (*fmt == '%' && *(fmt + 1) != '%') {
-				/* Conversion specifier detected. Switch modes. */
-				converting = true;
-				/* Reset the conversion context. */
-				assign_supress = false;
-				assign_alloc = false;
-				width = -1;
-				length_mod = LMOD_NONE;
-				int_conv_unsigned = false;
-				int_conv_base = 0;
-				++fmt;
-			} else {
-				/* One by one matching. */
-				if (*fmt == '%') {
-					/* Escape sequence detected. */
-					++fmt;
-					assert(*fmt == '%');
-				}
-				c = in->pop(in);
-				if (c == -1) {
-					/* Input failure. */
-					break;
-				} else if (c != *fmt) {
-					/* Matching failure. */
-					in->undo(in);
-					matching_failure = true;
-					break;
-				} else {
-					++fmt;
-				}
-			}
-			
-		}
-
-	}
-
-	in->release(in);
-
-	/* This somewhat complicated return value decision is required by POSIX. */
-	int rc;
-	if (matching_failure) {
-		rc = converted_cnt;
-	} else {
-		if (errno == EOK) {
-			rc = converted_cnt > 0 ? converted_cnt : EOF;
-		} else {
-			rc = EOF;
-		}
-	}
-	if (rc == EOF) {
-		/* Caller will not know how many arguments were successfully converted,
-		 * so the deallocation of buffers is our responsibility. */
-		for (int i = 0; i < next_unused_buffer_idx; ++i) {
-			free(buffers[i]);
-			buffers[i] = NULL;
-		}
-		next_unused_buffer_idx = 0;
-	}
-	return rc;
-}
-
-/**
- * Convert formatted input from the stream.
- *
- * @param stream Input stream.
- * @param format Format description.
- * @param arg Output items.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_vfscanf(
-    FILE *restrict stream, const char *restrict format, va_list arg)
-{
-	_input_provider provider = {
-	    { 0 }, 0, 0, NULL, 0, NULL, _PROV_CONSTRUCTED,
-	    _capture_stream, _pop_stream, _undo_stream,
-	    _borrow_cursor_universal, _return_cursor_stream, _release_stream
-	};
-	provider.source.stream = stream;
-	return _internal_scanf(&provider, format, arg);
-}
-
-/**
- * Convert formatted input from the string.
- *
- * @param s Input string.
- * @param format Format description.
- * @param arg Output items.
- * @return The number of converted output items or EOF on failure.
- */
-int posix_vsscanf(
-    const char *restrict s, const char *restrict format, va_list arg)
-{
-	_input_provider provider = {
-	    { 0 }, 0, 0, NULL, 0, NULL, _PROV_CONSTRUCTED,
-	    _capture_string, _pop_string, _undo_string,
-	    _borrow_cursor_universal, _return_cursor_string, _release_string
-	};
-	provider.source.string = s;
-	return _internal_scanf(&provider, format, arg);
-}
-
-/** @}
- */
Index: pace/lib/posix/source/stdlib.c
===================================================================
--- uspace/lib/posix/source/stdlib.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,505 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 Standard library definitions.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/stdlib.h"
-
-#include <errno.h>
-
-#include "posix/fcntl.h"
-#include "posix/limits.h"
-#include "posix/string.h"
-#include "posix/sys/stat.h"
-#include "posix/unistd.h"
-
-#include "libc/qsort.h"
-#include "libc/str.h"
-#include "libc/vfs/vfs.h"
-#include "libc/stats.h"
-
-/**
- * 
- * @param array
- * @param count
- * @param size
- * @param compare
- */
-int posix_atexit(void (*func)(void))
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return 0;
-}
-
-/**
- * Integer absolute value.
- * 
- * @param i Input value.
- * @return Absolute value of the parameter.
- */
-int posix_abs(int i)
-{
-	return i < 0 ? -i : i;
-}
-
-/**
- * Long integer absolute value.
- * 
- * @param i Input value.
- * @return Absolute value of the parameter.
- */
-long posix_labs(long i)
-{
-	return i < 0 ? -i : i;
-}
-
-/**
- * Long long integer absolute value.
- * 
- * @param i Input value.
- * @return Absolute value of the parameter.
- */
-long long posix_llabs(long long i)
-{
-	return i < 0 ? -i : i;
-}
-
-/**
- * Compute the quotient and remainder of an integer division.
- *
- * @param numer Numerator.
- * @param denom Denominator.
- * @return Quotient and remainder packed into structure.
- */
-posix_div_t posix_div(int numer, int denom)
-{
-	return (posix_div_t) { .quot = numer / denom, .rem = numer % denom };
-}
-
-/**
- * Compute the quotient and remainder of a long integer division.
- *
- * @param numer Numerator.
- * @param denom Denominator.
- * @return Quotient and remainder packed into structure.
- */
-posix_ldiv_t posix_ldiv(long numer, long denom)
-{
-	return (posix_ldiv_t) { .quot = numer / denom, .rem = numer % denom };
-}
-
-/**
- * Compute the quotient and remainder of a long long integer division.
- *
- * @param numer Numerator.
- * @param denom Denominator.
- * @return Quotient and remainder packed into structure.
- */
-posix_lldiv_t posix_lldiv(long long numer, long long denom)
-{
-	return (posix_lldiv_t) { .quot = numer / denom, .rem = numer % denom };
-}
-
-/**
- * Array sorting utilizing the quicksort algorithm.
- *
- * @param array Array of elements to sort.
- * @param count Number of elements in the array.
- * @param size Width of each element.
- * @param compare Decides relative ordering of two elements.
- */
-void posix_qsort(void *array, size_t count, size_t size,
-    int (*compare)(const void *, const void *))
-{
-	qsort(array, count, size, compare);
-}
-
-/**
- * Binary search in a sorted array.
- *
- * @param key Object to search for.
- * @param base Pointer to the first element of the array.
- * @param nmemb Number of elements in the array.
- * @param size Size of each array element.
- * @param compar Comparison function.
- * @return Pointer to a matching element, or NULL if none can be found.
- */
-void *posix_bsearch(const void *key, const void *base,
-    size_t nmemb, size_t size, int (*compar)(const void *, const void *))
-{
-	while (nmemb > 0) {
-		const void *middle = base + (nmemb / 2) * size;
-		int cmp = compar(key, middle);
-		if (cmp == 0) {
-			return (void *) middle;
-		}
-		if (middle == base) {
-			/* There is just one member left to check and it
-			 * didn't match the key. Avoid infinite loop.
-			 */
-			break;
-		}
-		if (cmp < 0) {
-			nmemb = nmemb / 2;
-		} else if (cmp > 0) {
-			nmemb = nmemb - (nmemb / 2);
-			base = middle;
-		}
-	}
-	
-	return NULL;
-}
-
-/**
- * Retrieve a value of the given environment variable.
- *
- * Since HelenOS doesn't support env variables at the moment,
- * this function always returns NULL.
- *
- * @param name Name of the variable.
- * @return Value of the variable or NULL if such variable does not exist.
- */
-char *posix_getenv(const char *name)
-{
-	return NULL;
-}
-
-/**
- * 
- * @param name
- * @param resolved
- * @return
- */
-int posix_putenv(char *string)
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return 0;
-}
-
-/**
- * Issue a command.
- *
- * @param string String to be passed to a command interpreter or NULL.
- * @return Termination status of the command if the command is not NULL,
- *     otherwise indicate whether there is a command interpreter (non-zero)
- *     or not (zero).
- */
-int posix_system(const char *string) {
-	// TODO: does nothing at the moment
-	not_implemented();
-	return 0;
-}
-
-/**
- * Resolve absolute pathname.
- * 
- * @param name Pathname to be resolved.
- * @param resolved Either buffer for the resolved absolute pathname or NULL.
- * @return On success, either resolved (if it was not NULL) or pointer to the
- *     newly allocated buffer containing the absolute pathname (if resolved was
- *     NULL). Otherwise NULL.
- *
- */
-char *posix_realpath(const char *restrict name, char *restrict resolved)
-{
-	#ifndef PATH_MAX
-		assert(resolved == NULL);
-	#endif
-	
-	if (name == NULL) {
-		errno = EINVAL;
-		return NULL;
-	}
-	
-	// TODO: symlink resolution
-	
-	/* Function absolutize is implemented in libc and declared in vfs.h.
-	 * No more processing is required as HelenOS doesn't have symlinks
-	 * so far (as far as I can tell), although this function will need
-	 * to be updated when that support is implemented.
-	 */
-	char* absolute = vfs_absolutize(name, NULL);
-	
-	if (absolute == NULL) {
-		/* POSIX requires some specific errnos to be set
-		 * for some cases, but there is no way to find out from
-		 * absolutize().
-		 */
-		errno = EINVAL;
-		return NULL;
-	}
-	
-	if (resolved == NULL) {
-		return absolute;
-	} else {
-		#ifdef PATH_MAX
-			str_cpy(resolved, PATH_MAX, absolute);
-		#endif
-		free(absolute);
-		return resolved;
-	}
-}
-
-/**
- * Converts a string representation of a floating-point number to
- * its native representation. See posix_strtold().
- *
- * @param nptr String representation of a floating-point number.
- * @return Double-precision number resulting from the string conversion.
- */
-double posix_atof(const char *nptr)
-{
-	return posix_strtod(nptr, NULL);
-}
-
-/**
- * Converts a string representation of a floating-point number to
- * its native representation. See posix_strtold().
- *
- * @param nptr String representation of a floating-point number.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @return Single-precision number resulting from the string conversion.
- */
-float posix_strtof(const char *restrict nptr, char **restrict endptr)
-{
-	return (float) posix_strtold(nptr, endptr);
-}
-
-/**
- * Converts a string representation of a floating-point number to
- * its native representation. See posix_strtold().
- *
- * @param nptr String representation of a floating-point number.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @return Double-precision number resulting from the string conversion.
- */
-double posix_strtod(const char *restrict nptr, char **restrict endptr)
-{
-	return (double) posix_strtold(nptr, endptr);
-}
-
-/**
- * Allocate memory chunk.
- *
- * @param size Size of the chunk to allocate.
- * @return Either pointer to the allocated chunk or NULL if not possible.
- */
-void *posix_malloc(size_t size)
-{
-	return malloc(size);
-}
-
-/**
- * Allocate memory for an array of elements.
- *
- * @param nelem Number of elements in the array.
- * @param elsize Size of each element.
- * @return Either pointer to the allocated array or NULL if not possible.
- */
-void *posix_calloc(size_t nelem, size_t elsize)
-{
-	return calloc(nelem, elsize);
-}
-
-/**
- * Reallocate memory chunk to a new size.
- *
- * @param ptr Memory chunk to reallocate. Might be NULL.
- * @param size Size of the reallocated chunk. Might be zero.
- * @return Either NULL or the pointer to the newly reallocated chunk.
- */
-void *posix_realloc(void *ptr, size_t size)
-{
-	if (ptr != NULL && size == 0) {
-		/* Native realloc does not handle this special case. */
-		free(ptr);
-		return NULL;
-	} else {
-		return realloc(ptr, size);
-	}
-}
-
-/**
- * Free allocated memory chunk.
- *
- * @param ptr Memory chunk to be freed.
- */
-void posix_free(void *ptr)
-{
-	if (ptr) {
-		free(ptr);
-	}
-}
-
-/**
- * Generate a pseudo random integer in the range 0 to RAND_MAX inclusive.
- *
- * @return The pseudo random integer.
- */
-int posix_rand(void)
-{
-	return (int) random();
-}
-
-/**
- * Initialize a new sequence of pseudo-random integers.
- *
- * @param seed The seed of the new sequence.
- */
-void posix_srand(unsigned int seed)
-{
-	srandom(seed);
-}
-
-/**
- * Creates and opens an unique temporary file from template.
- *
- * @param tmpl Template. Last six characters must be XXXXXX.
- * @return The opened file descriptor or -1 on error.
- */
-int posix_mkstemp(char *tmpl)
-{
-	int fd = -1;
-	
-	char *tptr = tmpl + posix_strlen(tmpl) - 6;
-	
-	while (fd < 0) {
-		if (*posix_mktemp(tmpl) == '\0') {
-			/* Errno set by mktemp(). */
-			return -1;
-		}
-		
-		fd = posix_open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
-		
-		if (fd == -1) {
-			/* Restore template to it's original state. */
-			snprintf(tptr, 7, "XXXXXX");
-		}
-	}
-	
-	return fd;
-}
-
-/**
- * Creates an unique temporary file name from template.
- *
- * @param tmpl Template. Last six characters must be XXXXXX.
- * @return The value of tmpl. The template is modified in place.
- *    If no temporary file name can be created, template is
- *    reduced to an empty string.
- */
-char *posix_mktemp(char *tmpl)
-{
-	int tmpl_len = posix_strlen(tmpl);
-	if (tmpl_len < 6) {
-		errno = EINVAL;
-		*tmpl = '\0';
-		return tmpl;
-	}
-	
-	char *tptr = tmpl + tmpl_len - 6;
-	if (posix_strcmp(tptr, "XXXXXX") != 0) {
-		errno = EINVAL;
-		*tmpl = '\0';
-		return tmpl;
-	}
-	
-	static int seq = 0;
-	
-	for (; seq < 1000000; ++seq) {
-		snprintf(tptr, 7, "%06d", seq);
-		
-		int orig_errno = errno;
-		errno = 0;
-		/* Check if the file exists. */
-		if (posix_access(tmpl, F_OK) == -1) {
-			if (errno == ENOENT) {
-				errno = orig_errno;
-				break;
-			} else {
-				/* errno set by access() */
-				*tmpl = '\0';
-				return tmpl;
-			}
-		}
-	}
-	
-	if (seq == 10000000) {
-		errno = EEXIST;
-		*tmpl = '\0';
-		return tmpl;
-	}
-	
-	return tmpl;
-}
-
-/**
- * Get system load average statistics.
- *
- * @param loadavg Array where the load averages shall be placed.
- * @param nelem Maximum number of elements to be placed into the array.
- * @return Number of elements placed into the array on success, -1 otherwise.
- */
-int bsd_getloadavg(double loadavg[], int nelem)
-{
-	assert(nelem > 0);
-	
-	size_t count;
-	load_t *loads = stats_get_load(&count);
-	
-	if (loads == NULL) {
-		return -1;
-	}
-	
-	if (((size_t) nelem) < count) {
-		count = nelem;
-	}
-	
-	for (size_t i = 0; i < count; ++i) {
-		loadavg[i] = (double) loads[i];
-	}
-	
-	free(loads);
-	return count;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/stdlib/strtol.c
===================================================================
--- uspace/lib/posix/source/stdlib/strtol.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,399 +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 Backend for integer conversions.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "../internal/common.h"
-#include "posix/stdlib.h"
-
-#include "posix/ctype.h"
-
-#include <errno.h>
-
-#include "posix/inttypes.h"
-#include "posix/limits.h"
-
-/**
- * Decides whether a digit belongs to a particular base.
- *
- * @param c Character representation of the digit.
- * @param base Base against which the digit shall be tested.
- * @return True if the digit belongs to the base, false otherwise.
- */
-static inline bool is_digit_in_base(int c, int base)
-{
-	if (base <= 10) {
-		return c >= '0' && c < '0' + base;
-	} else {
-		return isdigit(c) ||
-		    (tolower(c) >= 'a' && tolower(c) < ('a' + base - 10));
-	}
-}
-
-/**
- * Derive a digit from its character representation.
- *
- * @param c Character representation of the digit.
- * @return Digit value represented by an integer.
- */
-static inline int digit_value(int c)
-{
-	if (c <= '9') {
-		return c - '0';
-	} else {
-		return 10 + tolower(c) - 'a';
-	}
-}
-
-/**
- * Generic function for parsing an integer from it's string representation.
- * Different variants differ in lower and upper bounds.
- * The parsed string returned by this function is always positive, sign
- * information is provided via a dedicated parameter.
- *
- * @param nptr Input string.
- * @param endptr If non-NULL, *endptr is set to the position of the first
- *     unrecognized character. If no digit has been parsed, value of
- *     nptr is stored there (regardless of any skipped characters at the
- *     beginning).
- * @param base Expected base of the string representation. If 0, base is
- *    determined to be decimal, octal or hexadecimal using the same rules
- *    as C syntax. Otherwise, value must be between 2 and 36, inclusive.
- * @param min_value Lower bound for the resulting conversion.
- * @param max_value Upper bound for the resulting conversion.
- * @param out_negative Either NULL for unsigned conversion or a pointer to the
- *     bool variable into which shall be placed the negativity of the resulting
- *     converted value.
- * @return The absolute value of the parsed value, or the closest in-range value
- *     if the parsed value is out of range. If the input is invalid, zero is
- *     returned and errno is set to EINVAL.
- */
-static inline uintmax_t internal_strtol(
-    const char *restrict nptr, char **restrict endptr, int base,
-    const intmax_t min_value, const uintmax_t max_value,
-    bool *restrict out_negative)
-{
-	if (nptr == NULL) {
-		errno = EINVAL;
-		return 0;
-	}
-	
-	if (base < 0 || base == 1 || base > 36) {
-		errno = EINVAL;
-		return 0;
-	}
-	
-	/* The maximal absolute value that can be returned in this run.
-	 * Depends on sign.
-	 */
-	uintmax_t real_max_value = max_value;
-	
-	/* Current index in the input string. */
-	size_t i = 0;
-	bool negative = false;
-	
-	/* Skip whitespace. */
-	while (isspace(nptr[i])) {
-		i++;
-	}
-	
-	/* Parse sign. */
-	switch (nptr[i]) {
-	case '-':
-		negative = true;
-		
-		/* The strange computation is are there to avoid a corner case
-		 * where -min_value can't be represented in intmax_t.
-		 * (I'm not exactly sure what the semantics are in such a
-		 *  case, but this should be safe for any case.)
-		 */
-		real_max_value = (min_value == 0)
-		    ? 0
-		    :(((uintmax_t) -(min_value + 1)) + 1);
-		
-		/* Fallthrough */
-	case '+':
-		i++;
-	}
-	
-	/* Figure out the base. */
-	switch (base) {
-	case 0:
-		if (nptr[i] == '0') {
-			if (tolower(nptr[i + 1]) == 'x') {
-				/* 0x... is hex. */
-				base = 16;
-				i += 2;
-			} else {
-				/* 0... is octal. */
-				base = 8;
-			}
-		} else {
-			/* Anything else is decimal by default. */
-			base = 10;
-		}
-		break;
-	case 16:
-		/* Allow hex number to be prefixed with "0x". */
-		if (nptr[i] == '0' && tolower(nptr[i + 1]) == 'x') {
-			i += 2;
-		}
-		break;
-	}
-	
-	if (!is_digit_in_base(nptr[i], base)) {
-		/* No digits to parse, invalid input. */
-		
-		errno = EINVAL;
-		if (endptr != NULL) {
-			*endptr = (char *) nptr;
-		}
-		return 0;
-	}
-	
-	/* Maximal value to which a digit can be added without a risk
-	 * of overflow.
-	 */
-	uintmax_t max_safe_value = (real_max_value - base + 1) / base;
-	
-	uintmax_t result = 0;
-	
-	if (real_max_value == 0) {
-		/* Special case when a negative number is parsed as
-		 * unsigned integer. Only -0 is accepted.
-		 */
-		
-		while (is_digit_in_base(nptr[i], base)) {
-			if (nptr[i] != '0') {
-				errno = ERANGE;
-				result = 0;
-			}
-			i++;
-		}
-	}
-	
-	while (is_digit_in_base(nptr[i], base)) {
-		int digit = digit_value(nptr[i]);
-		
-		if (result > max_safe_value) {
-			/* corner case, check for overflow */
-			
-			uintmax_t boundary = (real_max_value - digit) / base;
-			
-			if (result > boundary) {
-				/* overflow */
-				errno = ERANGE;
-				result = real_max_value;
-				break;
-			}
-		}
-		
-		result = result * base + digit;
-		i++;
-	}
-	
-	if (endptr != NULL) {
-		/* Move the pointer to the end of the number,
-		 * in case it isn't there already.
-		 */
-		while (is_digit_in_base(nptr[i], base)) {
-			i++;
-		}
-		
-		*endptr = (char *) &nptr[i];
-	}
-	if (out_negative != NULL) {
-		*out_negative = negative;
-	}
-	return result;
-}
-
-/**
- * Convert a string to an integer.
- *
- * @param nptr Input string.
- * @return Result of the conversion.
- */
-int posix_atoi(const char *nptr)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, NULL, 10, INT_MIN, INT_MAX, &neg);
-
-	return (neg ? ((int) -result) : (int) result);
-}
-
-/**
- * Convert a string to a long integer.
- *
- * @param nptr Input string.
- * @return Result of the conversion.
- */
-long posix_atol(const char *nptr)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, NULL, 10, LONG_MIN, LONG_MAX, &neg);
-
-	return (neg ? ((long) -result) : (long) result);
-}
-
-/**
- * Convert a string to a long long integer.
- *
- * @param nptr Input string.
- * @return Result of the conversion.
- */
-long long posix_atoll(const char *nptr)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, NULL, 10, LLONG_MIN, LLONG_MAX, &neg);
-
-	return (neg ? ((long long) -result) : (long long) result);
-}
-
-/**
- * Convert a string to a long integer.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-long posix_strtol(const char *restrict nptr, char **restrict endptr, int base)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, LONG_MIN, LONG_MAX, &neg);
-
-	return (neg ? ((long) -result) : ((long) result));
-}
-
-/**
- * Convert a string to a long long integer.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-long long posix_strtoll(
-    const char *restrict nptr, char **restrict endptr, int base)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, LLONG_MIN, LLONG_MAX, &neg);
-
-	return (neg ? ((long long) -result) : (long long) result);
-}
-
-/**
- * Convert a string to a largest signed integer type.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-intmax_t posix_strtoimax(
-    const char *restrict nptr, char **restrict endptr, int base)
-{
-	bool neg = false;
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX, &neg);
-
-	return (neg ? ((intmax_t) -result) : (intmax_t) result);
-}
-
-/**
- * Convert a string to an unsigned long integer.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-unsigned long posix_strtoul(
-    const char *restrict nptr, char **restrict endptr, int base)
-{
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, 0, ULONG_MAX, NULL);
-
-	return (unsigned long) result;
-}
-
-/**
- * Convert a string to an unsigned long long integer.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-unsigned long long posix_strtoull(
-    const char *restrict nptr, char **restrict endptr, int base)
-{
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, 0, ULLONG_MAX, NULL);
-
-	return (unsigned long long) result;
-}
-
-/**
- * Convert a string to a largest unsigned integer type.
- *
- * @param nptr Input string.
- * @param endptr Pointer to the final part of the string which
- *     was not used for conversion.
- * @param base Expected base of the string representation.
- * @return Result of the conversion.
- */
-uintmax_t posix_strtoumax(
-    const char *restrict nptr, char **restrict endptr, int base)
-{
-	uintmax_t result =
-	    internal_strtol(nptr, endptr, base, 0, UINTMAX_MAX, NULL);
-
-	return result;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/stdlib/strtold.c
===================================================================
--- uspace/lib/posix/source/stdlib/strtold.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,492 +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 Backend for floating point conversions.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "../internal/common.h"
-#include "libc/stdbool.h"
-#include "posix/stdlib.h"
-
-#include <assert.h>
-#include "posix/ctype.h"
-#include "posix/stdint.h"
-#include "posix/strings.h"
-
-#include <errno.h>
-
-#include "posix/limits.h"
-
-#include "posix/float.h"
-
-#ifndef HUGE_VALL
-	#define HUGE_VALL (+1.0l / +0.0l)
-#endif
-
-#ifndef abs
-	#define abs(x) (((x) < 0) ? -(x) : (x))
-#endif
-
-/* If the constants are not defined, use double precision as default. */
-#ifndef LDBL_MANT_DIG
-	#define LDBL_MANT_DIG 53
-#endif
-#ifndef LDBL_MAX_EXP
-	#define LDBL_MAX_EXP 1024
-#endif
-#ifndef LDBL_MIN_EXP
-	#define LDBL_MIN_EXP (-1021)
-#endif
-#ifndef LDBL_DIG
-	#define LDBL_DIG 15
-#endif
-#ifndef LDBL_MIN
-	#define LDBL_MIN 2.2250738585072014E-308
-#endif
-
-/* power functions ************************************************************/
-
-#if LDBL_MAX_EXP >= 16384
-const int MAX_POW5 = 12;
-#else
-const int MAX_POW5 = 8;
-#endif
-
-/* The value at index i is approximately 5**(2**i). */
-long double pow5[] = {
-	0x5p0l,
-	0x19p0l,
-	0x271p0l,
-	0x5F5E1p0l,
-	0x2386F26FC1p0l,
-	0x4EE2D6D415B85ACEF81p0l,
-	0x184F03E93FF9F4DAA797ED6E38ED6p36l,
-	0x127748F9301D319BF8CDE66D86D62p185l,
-	0x154FDD7F73BF3BD1BBB77203731FDp482l,
-#if LDBL_MAX_EXP >= 16384
-	0x1C633415D4C1D238D98CAB8A978A0p1076l,
-	0x192ECEB0D02EA182ECA1A7A51E316p2265l,
-	0x13D1676BB8A7ABBC94E9A519C6535p4643l,
-	0x188C0A40514412F3592982A7F0094p9398l,
-#endif
-};
-
-#if LDBL_MAX_EXP >= 16384
-const int MAX_POW2 = 15;
-#else
-const int MAX_POW2 = 9;
-#endif
-
-/* Powers of two. */
-long double pow2[] = {
-	0x1P1l,
-	0x1P2l,
-	0x1P4l,
-	0x1P8l,
-	0x1P16l,
-	0x1P32l,
-	0x1P64l,
-	0x1P128l,
-	0x1P256l,
-	0x1P512l,
-#if LDBL_MAX_EXP >= 16384
-	0x1P1024l,
-	0x1P2048l,
-	0x1P4096l,
-	0x1P8192l,
-#endif
-};
-
-/**
- * Multiplies a number by a power of five.
- * The result may be inexact and may not be the best possible approximation.
- *
- * @param mant Number to be multiplied.
- * @param exp Base 5 exponent.
- * @return mant multiplied by 5**exp
- */
-static long double mul_pow5(long double mant, int exp)
-{
-	if (mant == 0.0l || mant == HUGE_VALL) {
-		return mant;
-	}
-	
-	if (abs(exp) >> (MAX_POW5 + 1) != 0) {
-		/* Too large exponent. */
-		errno = ERANGE;
-		return exp < 0 ? LDBL_MIN : HUGE_VALL;
-	}
-	
-	if (exp < 0) {
-		exp = abs(exp);
-		for (int bit = 0; bit <= MAX_POW5; ++bit) {
-			/* Multiply by powers of five bit-by-bit. */
-			if (((exp >> bit) & 1) != 0) {
-				mant /= pow5[bit];
-				if (mant == 0.0l) {
-					/* Underflow. */
-					mant = LDBL_MIN;
-					errno = ERANGE;
-					break;
-				}
-			}
-		}
-	} else {
-		for (int bit = 0; bit <= MAX_POW5; ++bit) {
-			/* Multiply by powers of five bit-by-bit. */
-			if (((exp >> bit) & 1) != 0) {
-				mant *= pow5[bit];
-				if (mant == HUGE_VALL) {
-					/* Overflow. */
-					errno = ERANGE;
-					break;
-				}
-			}
-		}
-	}
-	
-	return mant;
-}
-
-/**
- * Multiplies a number by a power of two. This is always exact.
- *
- * @param mant Number to be multiplied.
- * @param exp Base 2 exponent.
- * @return mant multiplied by 2**exp.
- */
-static long double mul_pow2(long double mant, int exp)
-{
-	if (mant == 0.0l || mant == HUGE_VALL) {
-		return mant;
-	}
-	
-	if (exp > LDBL_MAX_EXP || exp < LDBL_MIN_EXP) {
-		errno = ERANGE;
-		return exp < 0 ? LDBL_MIN : HUGE_VALL;
-	}
-	
-	if (exp < 0) {
-		exp = abs(exp);
-		for (int i = 0; i <= MAX_POW2; ++i) {
-			if (((exp >> i) & 1) != 0) {
-				mant /= pow2[i];
-				if (mant == 0.0l) {
-					mant = LDBL_MIN;
-					errno = ERANGE;
-					break;
-				}
-			}
-		}
-	} else {
-		for (int i = 0; i <= MAX_POW2; ++i) {
-			if (((exp >> i) & 1) != 0) {
-				mant *= pow2[i];
-				if (mant == HUGE_VALL) {
-					errno = ERANGE;
-					break;
-				}
-			}
-		}
-	}
-	
-	return mant;
-}
-
-/* end power functions ********************************************************/
-
-
-
-/**
- * Convert decimal string representation of the floating point number.
- * Function expects the string pointer to be already pointed at the first
- * digit (i.e. leading optional sign was already consumed by the caller).
- * 
- * @param sptr Pointer to the storage of the string pointer. Upon successful
- *     conversion, the string pointer is updated to point to the first
- *     unrecognized character.
- * @return An approximate representation of the input floating-point number.
- */
-static long double parse_decimal(const char **sptr)
-{
-	assert(sptr != NULL);
-	assert (*sptr != NULL);
-	
-	const int DEC_BASE = 10;
-	const char DECIMAL_POINT = '.';
-	const char EXPONENT_MARK = 'e';
-	
-	const char *str = *sptr;
-	long double significand = 0;
-	long exponent = 0;
-	
-	/* number of digits parsed so far */
-	int parsed_digits = 0;
-	bool after_decimal = false;
-	
-	while (isdigit(*str) || (!after_decimal && *str == DECIMAL_POINT)) {
-		if (*str == DECIMAL_POINT) {
-			after_decimal = true;
-			str++;
-			continue;
-		}
-		
-		if (parsed_digits == 0 && *str == '0') {
-			/* Nothing, just skip leading zeros. */
-		} else if (parsed_digits < LDBL_DIG) {
-			significand = significand * DEC_BASE + (*str - '0');
-			parsed_digits++;
-		} else {
-			exponent++;
-		}
-		
-		if (after_decimal) {
-			/* Decrement exponent if we are parsing the fractional part. */
-			exponent--;
-		}
-		
-		str++;
-	}
-	
-	/* exponent */
-	if (tolower(*str) == EXPONENT_MARK) {
-		str++;
-		
-		/* Returns MIN/MAX value on error, which is ok. */
-		long exp = strtol(str, (char **) &str, DEC_BASE);
-		
-		if (exponent > 0 && exp > LONG_MAX - exponent) {
-			exponent = LONG_MAX;
-		} else if (exponent < 0 && exp < LONG_MIN - exponent) {
-			exponent = LONG_MIN;
-		} else {
-			exponent += exp;
-		}
-	}
-	
-	*sptr = str;
-	
-	/* Return multiplied by a power of ten. */
-	return mul_pow2(mul_pow5(significand, exponent), exponent);
-}
-
-/**
- * Derive a hexadecimal digit from its character representation.
- * 
- * @param ch Character representation of the hexadecimal digit.
- * @return Digit value represented by an integer.
- */
-static inline int hex_value(char ch)
-{
-	if (ch <= '9') {
-		return ch - '0';
-	} else {
-		return 10 + tolower(ch) - 'a';
-	}
-}
-
-/**
- * Convert hexadecimal string representation of the floating point number.
- * Function expects the string pointer to be already pointed at the first
- * digit (i.e. leading optional sign and 0x prefix were already consumed
- * by the caller).
- *
- * @param sptr Pointer to the storage of the string pointer. Upon successful
- *     conversion, the string pointer is updated to point to the first
- *     unrecognized character.
- * @return Representation of the input floating-point number.
- */
-static long double parse_hexadecimal(const char **sptr)
-{
-	assert(sptr != NULL && *sptr != NULL);
-	
-	const int DEC_BASE = 10;
-	const int HEX_BASE = 16;
-	const char DECIMAL_POINT = '.';
-	const char EXPONENT_MARK = 'p';
-	
-	const char *str = *sptr;
-	long double significand = 0;
-	long exponent = 0;
-	
-	/* number of bits parsed so far */
-	int parsed_bits = 0;
-	bool after_decimal = false;
-	
-	while (posix_isxdigit(*str) || (!after_decimal && *str == DECIMAL_POINT)) {
-		if (*str == DECIMAL_POINT) {
-			after_decimal = true;
-			str++;
-			continue;
-		}
-		
-		if (parsed_bits == 0 && *str == '0') {
-			/* Nothing, just skip leading zeros. */
-		} else if (parsed_bits <= LDBL_MANT_DIG) {
-			significand = significand * HEX_BASE + hex_value(*str);
-			parsed_bits += 4;
-		} else {
-			exponent += 4;
-		}
-		
-		if (after_decimal) {
-			exponent -= 4;
-		}
-		
-		str++;
-	}
-	
-	/* exponent */
-	if (tolower(*str) == EXPONENT_MARK) {
-		str++;
-		
-		/* Returns MIN/MAX value on error, which is ok. */
-		long exp = strtol(str, (char **) &str, DEC_BASE);
-		
-		if (exponent > 0 && exp > LONG_MAX - exponent) {
-			exponent = LONG_MAX;
-		} else if (exponent < 0 && exp < LONG_MIN - exponent) {
-			exponent = LONG_MIN;
-		} else {
-			exponent += exp;
-		}
-	}
-	
-	*sptr = str;
-	
-	/* Return multiplied by a power of two. */
-	return mul_pow2(significand, exponent);
-}
-
-/**
- * Converts a string representation of a floating-point number to
- * its native representation. Largely POSIX compliant, except for
- * locale differences (always uses '.' at the moment) and rounding.
- * Decimal strings are NOT guaranteed to be correctly rounded. This function
- * should return a good enough approximation for most purposes but if you
- * depend on a precise conversion, use hexadecimal representation.
- * Hexadecimal strings are currently always rounded towards zero, regardless
- * of the current rounding mode.
- *
- * @param nptr Input string.
- * @param endptr If non-NULL, *endptr is set to the position of the first
- *     unrecognized character.
- * @return An approximate representation of the input floating-point number.
- */
-long double posix_strtold(const char *restrict nptr, char **restrict endptr)
-{
-	assert(nptr != NULL);
-	
-	const int RADIX = '.';
-	
-	/* minus sign */
-	bool negative = false;
-	/* current position in the string */
-	int i = 0;
-	
-	/* skip whitespace */
-	while (isspace(nptr[i])) {
-		i++;
-	}
-	
-	/* parse sign */
-	switch (nptr[i]) {
-	case '-':
-		negative = true;
-		/* Fallthrough */
-	case '+':
-		i++;
-	}
-	
-	/* check for NaN */
-	if (posix_strncasecmp(&nptr[i], "nan", 3) == 0) {
-		// FIXME: return NaN
-		// TODO: handle the parenthesised case
-		
-		if (endptr != NULL) {
-			*endptr = (char *) nptr;
-		}
-		errno = EINVAL;
-		return 0;
-	}
-	
-	/* check for Infinity */
-	if (posix_strncasecmp(&nptr[i], "inf", 3) == 0) {
-		i += 3;
-		if (posix_strncasecmp(&nptr[i], "inity", 5) == 0) {
-			i += 5;
-		}
-		
-		if (endptr != NULL) {
-			*endptr = (char *) &nptr[i];
-		}
-		return negative ? -HUGE_VALL : +HUGE_VALL;
-	}
-
-	/* check for a hex number */
-	if (nptr[i] == '0' && tolower(nptr[i + 1]) == 'x' &&
-	    (posix_isxdigit(nptr[i + 2]) ||
-	    (nptr[i + 2] == RADIX && posix_isxdigit(nptr[i + 3])))) {
-		i += 2;
-		
-		const char *ptr = &nptr[i];
-		/* this call sets errno if appropriate. */
-		long double result = parse_hexadecimal(&ptr);
-		if (endptr != NULL) {
-			*endptr = (char *) ptr;
-		}
-		return negative ? -result : result;
-	}
-	
-	/* check for a decimal number */
-	if (isdigit(nptr[i]) || (nptr[i] == RADIX && isdigit(nptr[i + 1]))) {
-		const char *ptr = &nptr[i];
-		/* this call sets errno if appropriate. */
-		long double result = parse_decimal(&ptr);
-		if (endptr != NULL) {
-			*endptr = (char *) ptr;
-		}
-		return negative ? -result : result;
-	}
-	
-	/* nothing to parse */
-	if (endptr != NULL) {
-		*endptr = (char *) nptr;
-	}
-	errno = EINVAL;
-	return 0;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/string.c
===================================================================
--- uspace/lib/posix/source/string.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,727 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 String manipulation.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/string.h"
-
-#include <assert.h>
-
-#include <errno.h>
-
-#include "posix/limits.h"
-#include "posix/stdlib.h"
-#include "posix/signal.h"
-
-#include "libc/str_error.h"
-
-/**
- * The same as strpbrk, except it returns pointer to the nul terminator
- * if no occurence is found.
- *
- * @param s1 String in which to look for the bytes.
- * @param s2 String of bytes to look for.
- * @return Pointer to the found byte on success, pointer to the
- *     string terminator otherwise.
- */
-static char *strpbrk_null(const char *s1, const char *s2)
-{
-	while (!posix_strchr(s2, *s1)) {
-		++s1;
-	}
-	
-	return (char *) s1;
-}
-
-/**
- * Copy a string.
- *
- * @param dest Destination pre-allocated buffer.
- * @param src Source string to be copied.
- * @return Pointer to the destination buffer.
- */
-char *posix_strcpy(char *restrict dest, const char *restrict src)
-{
-	posix_stpcpy(dest, src);
-	return dest;
-}
-
-/**
- * Copy fixed length string.
- *
- * @param dest Destination pre-allocated buffer.
- * @param src Source string to be copied.
- * @param n Number of bytes to be stored into destination buffer.
- * @return Pointer to the destination buffer.
- */
-char *posix_strncpy(char *restrict dest, const char *restrict src, size_t n)
-{
-	posix_stpncpy(dest, src, n);
-	return dest;
-}
-
-/**
- * Copy a string.
- *
- * @param dest Destination pre-allocated buffer.
- * @param src Source string to be copied.
- * @return Pointer to the nul character in the destination string.
- */
-char *posix_stpcpy(char *restrict dest, const char *restrict src)
-{
-	assert(dest != NULL);
-	assert(src != NULL);
-
-	for (size_t i = 0; ; ++i) {
-		dest[i] = src[i];
-		
-		if (src[i] == '\0') {
-			/* pointer to the terminating nul character */
-			return &dest[i];
-		}
-	}
-	
-	/* unreachable */
-	return NULL;
-}
-
-/**
- * Copy fixed length string.
- *
- * @param dest Destination pre-allocated buffer.
- * @param src Source string to be copied.
- * @param n Number of bytes to be stored into destination buffer.
- * @return Pointer to the first written nul character or &dest[n].
- */
-char *posix_stpncpy(char *restrict dest, const char *restrict src, size_t n)
-{
-	assert(dest != NULL);
-	assert(src != NULL);
-
-	for (size_t i = 0; i < n; ++i) {
-		dest[i] = src[i];
-	
-		/* the standard requires that nul characters
-		 * are appended to the length of n, in case src is shorter
-		 */
-		if (src[i] == '\0') {
-			char *result = &dest[i];
-			for (++i; i < n; ++i) {
-				dest[i] = '\0';
-			}
-			return result;
-		}
-	}
-	
-	return &dest[n];
-}
-
-/**
- * Concatenate two strings.
- *
- * @param dest String to which src shall be appended.
- * @param src String to be appended after dest.
- * @return Pointer to destination buffer.
- */
-char *posix_strcat(char *restrict dest, const char *restrict src)
-{
-	assert(dest != NULL);
-	assert(src != NULL);
-
-	posix_strcpy(posix_strchr(dest, '\0'), src);
-	return dest;
-}
-
-/**
- * Concatenate a string with part of another.
- *
- * @param dest String to which part of src shall be appended.
- * @param src String whose part shall be appended after dest.
- * @param n Number of bytes to append after dest.
- * @return Pointer to destination buffer.
- */
-char *posix_strncat(char *restrict dest, const char *restrict src, size_t n)
-{
-	assert(dest != NULL);
-	assert(src != NULL);
-
-	char *zeroptr = posix_strncpy(posix_strchr(dest, '\0'), src, n);
-	/* strncpy doesn't append the nul terminator, so we do it here */
-	zeroptr[n] = '\0';
-	return dest;
-}
-
-/**
- * Copy limited number of bytes in memory.
- *
- * @param dest Destination buffer.
- * @param src Source buffer.
- * @param c Character after which the copying shall stop.
- * @param n Number of bytes that shall be copied if not stopped earlier by c.
- * @return Pointer to the first byte after c in dest if found, NULL otherwise.
- */
-void *posix_memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
-{
-	assert(dest != NULL);
-	assert(src != NULL);
-	
-	unsigned char* bdest = dest;
-	const unsigned char* bsrc = src;
-	
-	for (size_t i = 0; i < n; ++i) {
-		bdest[i] = bsrc[i];
-	
-		if (bsrc[i] == (unsigned char) c) {
-			/* pointer to the next byte */
-			return &bdest[i + 1];
-		}
-	}
-	
-	return NULL;
-}
-
-/**
- * Duplicate a string.
- *
- * @param s String to be duplicated.
- * @return Newly allocated copy of the string.
- */
-char *posix_strdup(const char *s)
-{
-	return posix_strndup(s, SIZE_MAX);
-}
-
-/**
- * Duplicate a specific number of bytes from a string.
- *
- * @param s String to be duplicated.
- * @param n Maximum length of the resulting string..
- * @return Newly allocated string copy of length at most n.
- */
-char *posix_strndup(const char *s, size_t n)
-{
-	assert(s != NULL);
-
-	size_t len = posix_strnlen(s, n);
-	char *dup = malloc(len + 1);
-	if (dup == NULL) {
-		return NULL;
-	}
-
-	memcpy(dup, s, len);
-	dup[len] = '\0';
-
-	return dup;
-}
-
-/**
- * Compare bytes in memory.
- *
- * @param mem1 First area of memory to be compared.
- * @param mem2 Second area of memory to be compared.
- * @param n Maximum number of bytes to be compared.
- * @return Difference of the first pair of inequal bytes,
- *     or 0 if areas have the same content.
- */
-int posix_memcmp(const void *mem1, const void *mem2, size_t n)
-{
-	assert(mem1 != NULL);
-	assert(mem2 != NULL);
-
-	const unsigned char *s1 = mem1;
-	const unsigned char *s2 = mem2;
-	
-	for (size_t i = 0; i < n; ++i) {
-		if (s1[i] != s2[i]) {
-			return s1[i] - s2[i];
-		}
-	}
-	
-	return 0;
-}
-
-/**
- * Compare two strings.
- *
- * @param s1 First string to be compared.
- * @param s2 Second string to be compared.
- * @return Difference of the first pair of inequal characters,
- *     or 0 if strings have the same content.
- */
-int posix_strcmp(const char *s1, const char *s2)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	return posix_strncmp(s1, s2, STR_NO_LIMIT);
-}
-
-/**
- * Compare part of two strings.
- *
- * @param s1 First string to be compared.
- * @param s2 Second string to be compared.
- * @param n Maximum number of characters to be compared.
- * @return Difference of the first pair of inequal characters,
- *     or 0 if strings have the same content.
- */
-int posix_strncmp(const char *s1, const char *s2, size_t n)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	for (size_t i = 0; i < n; ++i) {
-		if (s1[i] != s2[i]) {
-			return s1[i] - s2[i];
-		}
-		if (s1[i] == '\0') {
-			break;
-		}
-	}
-
-	return 0;
-}
-
-/**
- * Find byte in memory.
- *
- * @param mem Memory area in which to look for the byte.
- * @param c Byte to look for.
- * @param n Maximum number of bytes to be inspected.
- * @return Pointer to the specified byte on success,
- *     NULL pointer otherwise.
- */
-void *posix_memchr(const void *mem, int c, size_t n)
-{
-	assert(mem != NULL);
-	
-	const unsigned char *s = mem;
-	
-	for (size_t i = 0; i < n; ++i) {
-		if (s[i] == (unsigned char) c) {
-			return (void *) &s[i];
-		}
-	}
-	return NULL;
-}
-
-/**
- * Scan string for a first occurence of a character.
- *
- * @param s String in which to look for the character.
- * @param c Character to look for.
- * @return Pointer to the specified character on success,
- *     NULL pointer otherwise.
- */
-char *posix_strchr(const char *s, int c)
-{
-	assert(s != NULL);
-	
-	char *res = gnu_strchrnul(s, c);
-	return (*res == c) ? res : NULL;
-}
-
-/**
- * Scan string for a last occurence of a character.
- *
- * @param s String in which to look for the character.
- * @param c Character to look for.
- * @return Pointer to the specified character on success,
- *     NULL pointer otherwise.
- */
-char *posix_strrchr(const char *s, int c)
-{
-	assert(s != NULL);
-	
-	const char *ptr = posix_strchr(s, '\0');
-	
-	/* the same as in strchr, except it loops in reverse direction */
-	while (*ptr != (char) c) {
-		if (ptr == s) {
-			return NULL;
-		}
-
-		ptr--;
-	}
-
-	return (char *) ptr;
-}
-
-/**
- * Scan string for a first occurence of a character.
- *
- * @param s String in which to look for the character.
- * @param c Character to look for.
- * @return Pointer to the specified character on success, pointer to the
- *     string terminator otherwise.
- */
-char *gnu_strchrnul(const char *s, int c)
-{
-	assert(s != NULL);
-	
-	while (*s != c && *s != '\0') {
-		s++;
-	}
-	
-	return (char *) s;
-}
-
-/**
- * Scan a string for a first occurence of one of provided bytes.
- *
- * @param s1 String in which to look for the bytes.
- * @param s2 String of bytes to look for.
- * @return Pointer to the found byte on success,
- *     NULL pointer otherwise.
- */
-char *posix_strpbrk(const char *s1, const char *s2)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	char *ptr = strpbrk_null(s1, s2);
-	return (*ptr == '\0') ? NULL : ptr;
-}
-
-/**
- * Get the length of a complementary substring.
- *
- * @param s1 String that shall be searched for complementary prefix.
- * @param s2 String of bytes that shall not occur in the prefix.
- * @return Length of the prefix.
- */
-size_t posix_strcspn(const char *s1, const char *s2)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	char *ptr = strpbrk_null(s1, s2);
-	return (size_t) (ptr - s1);
-}
-
-/**
- * Get length of a substring.
- *
- * @param s1 String that shall be searched for prefix.
- * @param s2 String of bytes that the prefix must consist of.
- * @return Length of the prefix.
- */
-size_t posix_strspn(const char *s1, const char *s2)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	const char *ptr;
-	for (ptr = s1; *ptr != '\0'; ++ptr) {
-		if (!posix_strchr(s2, *ptr)) {
-			break;
-		}
-	}
-	return ptr - s1;
-}
-
-/**
- * Find a substring. Uses Knuth-Morris-Pratt algorithm.
- *
- * @param s1 String in which to look for a substring.
- * @param s2 Substring to look for.
- * @return Pointer to the first character of the substring in s1, or NULL if
- *     not found.
- */
-char *posix_strstr(const char *haystack, const char *needle)
-{
-	assert(haystack != NULL);
-	assert(needle != NULL);
-	
-	/* Special case - needle is an empty string. */
-	if (needle[0] == '\0') {
-		return (char *) haystack;
-	}
-	
-	/* Preprocess needle. */
-	size_t nlen = posix_strlen(needle);
-	size_t prefix_table[nlen + 1];
-	
-	{
-		size_t i = 0;
-		ssize_t j = -1;
-		
-		prefix_table[i] = j;
-		
-		while (i < nlen) {
-			while (j >= 0 && needle[i] != needle[j]) {
-				j = prefix_table[j];
-			}
-			i++; j++;
-			prefix_table[i] = j;
-		}
-	}
-	
-	/* Search needle using the precomputed table. */
-	size_t npos = 0;
-	
-	for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) {
-		while (npos != 0 && haystack[hpos] != needle[npos]) {
-			npos = prefix_table[npos];
-		}
-		
-		if (haystack[hpos] == needle[npos]) {
-			npos++;
-			
-			if (npos == nlen) {
-				return (char *) (haystack + hpos - nlen + 1);
-			}
-		}
-	}
-	
-	return NULL;
-}
-
-/** Split string by delimiters.
- *
- * @param s             String to be tokenized. May not be NULL.
- * @param delim		String with the delimiters.
- * @return              Pointer to the prefix of @a s before the first
- *                      delimiter character. NULL if no such prefix
- *                      exists.
- */
-char *posix_strtok(char *s, const char *delim)
-{
-	static char *next;
-
-	return posix_strtok_r(s, delim, &next);
-}
-
-
-/** Split string by delimiters.
- *
- * @param s             String to be tokenized. May not be NULL.
- * @param delim		String with the delimiters.
- * @param next		Variable which will receive the pointer to the
- *                      continuation of the string following the first
- *                      occurrence of any of the delimiter characters.
- *                      May be NULL.
- * @return              Pointer to the prefix of @a s before the first
- *                      delimiter character. NULL if no such prefix
- *                      exists.
- */
-char *posix_strtok_r(char *s, const char *delim, char **next)
-{
-	char *start, *end;
-
-	if (s == NULL)
-		s = *next;
-
-	/* Skip over leading delimiters. */
-	while (*s && (posix_strchr(delim, *s) != NULL)) ++s;
-	start = s;
-
-	/* Skip over token characters. */
-	while (*s && (posix_strchr(delim, *s) == NULL)) ++s;
-	end = s;
-	*next = (*s ? s + 1 : s);
-
-	if (start == end) {
-		return NULL;	/* No more tokens. */
-	}
-
-	/* Overwrite delimiter with NULL terminator. */
-	*end = '\0';
-	return start;
-}
-
-/**
- * String comparison using collating information.
- *
- * Currently ignores locale and just calls strcmp.
- *
- * @param s1 First string to be compared.
- * @param s2 Second string to be compared.
- * @return Difference of the first pair of inequal characters,
- *     or 0 if strings have the same content.
- */
-int posix_strcoll(const char *s1, const char *s2)
-{
-	assert(s1 != NULL);
-	assert(s2 != NULL);
-
-	return posix_strcmp(s1, s2);
-}
-
-/**
- * Transform a string in such a way that the resulting string yields the same
- * results when passed to the strcmp as if the original string is passed to
- * the strcoll.
- *
- * Since strcoll is equal to strcmp here, this just makes a copy.
- *
- * @param s1 Transformed string.
- * @param s2 Original string.
- * @param n Maximum length of the transformed string.
- * @return Length of the transformed string.
- */
-size_t posix_strxfrm(char *restrict s1, const char *restrict s2, size_t n)
-{
-	assert(s1 != NULL || n == 0);
-	assert(s2 != NULL);
-
-	size_t len = posix_strlen(s2);
-
-	if (n > len) {
-		posix_strcpy(s1, s2);
-	}
-
-	return len;
-}
-
-/**
- * Get error message string.
- *
- * @param errnum Error code for which to obtain human readable string.
- * @return Error message.
- */
-char *posix_strerror(int errnum)
-{
-	// FIXME: move strerror() and strerror_r() to libc.
-	return (char *) str_error(errnum);
-}
-
-/**
- * Get error message string.
- *
- * @param errnum Error code for which to obtain human readable string.
- * @param buf Buffer to store a human readable string to.
- * @param bufsz Size of buffer pointed to by buf.
- * @return Zero on success, errno otherwise.
- */
-int posix_strerror_r(int errnum, char *buf, size_t bufsz)
-{
-	assert(buf != NULL);
-	
-	char *errstr = posix_strerror(errnum);
-	
-	if (posix_strlen(errstr) + 1 > bufsz) {
-		return ERANGE;
-	} else {
-		posix_strcpy(buf, errstr);
-	}
-
-	return EOK;
-}
-
-/**
- * Get length of the string.
- *
- * @param s String which length shall be determined.
- * @return Length of the string.
- */
-size_t posix_strlen(const char *s)
-{
-	assert(s != NULL);
-	
-	return (size_t) (posix_strchr(s, '\0') - s);
-}
-
-/**
- * Get limited length of the string.
- *
- * @param s String which length shall be determined.
- * @param n Maximum number of bytes that can be examined to determine length.
- * @return The lower of either string length or n limit.
- */
-size_t posix_strnlen(const char *s, size_t n)
-{
-	assert(s != NULL);
-	
-	for (size_t sz = 0; sz < n; ++sz) {
-		
-		if (s[sz] == '\0') {
-			return sz;
-		}
-	}
-	
-	return n;
-}
-
-/**
- * Get description of a signal.
- *
- * @param signum Signal number.
- * @return Human readable signal description.
- */
-char *posix_strsignal(int signum)
-{
-	static const char *const sigstrings[] = {
-		[SIGABRT] = "SIGABRT (Process abort signal)",
-		[SIGALRM] = "SIGALRM (Alarm clock)",
-		[SIGBUS] = "SIGBUS (Access to an undefined portion of a memory object)",
-		[SIGCHLD] = "SIGCHLD (Child process terminated, stopped, or continued)",
-		[SIGCONT] = "SIGCONT (Continue executing, if stopped)",
-		[SIGFPE] = "SIGFPE (Erroneous arithmetic operation)",
-		[SIGHUP] = "SIGHUP (Hangup)",
-		[SIGILL] = "SIGILL (Illegal instruction)",
-		[SIGINT] = "SIGINT (Terminal interrupt signal)",
-		[SIGKILL] = "SIGKILL (Kill process)",
-		[SIGPIPE] = "SIGPIPE (Write on a pipe with no one to read it)",
-		[SIGQUIT] = "SIGQUIT (Terminal quit signal)",
-		[SIGSEGV] = "SIGSEGV (Invalid memory reference)",
-		[SIGSTOP] = "SIGSTOP (Stop executing)",
-		[SIGTERM] = "SIGTERM (Termination signal)",
-		[SIGTSTP] = "SIGTSTP (Terminal stop signal)",
-		[SIGTTIN] = "SIGTTIN (Background process attempting read)",
-		[SIGTTOU] = "SIGTTOU (Background process attempting write)",
-		[SIGUSR1] = "SIGUSR1 (User-defined signal 1)",
-		[SIGUSR2] = "SIGUSR2 (User-defined signal 2)",
-		[SIGPOLL] = "SIGPOLL (Pollable event)",
-		[SIGPROF] = "SIGPROF (Profiling timer expired)",
-		[SIGSYS] = "SIGSYS (Bad system call)",
-		[SIGTRAP] = "SIGTRAP (Trace/breakpoint trap)",
-		[SIGURG] = "SIGURG (High bandwidth data is available at a socket)",
-		[SIGVTALRM] = "SIGVTALRM (Virtual timer expired)",
-		[SIGXCPU] = "SIGXCPU (CPU time limit exceeded)",
-		[SIGXFSZ] = "SIGXFSZ (File size limit exceeded)"
-	};
-
-	if (signum <= _TOP_SIGNAL) {
-		return (char *) sigstrings[signum];
-	}
-
-	return (char *) "ERROR, Invalid signal number";
-}
-
-/** @}
- */
Index: pace/lib/posix/source/strings.c
===================================================================
--- uspace/lib/posix/source/strings.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,188 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * Copyright (c) 2011 Petr Koupy
- * 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 Additional string manipulation.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/strings.h"
-
-#include "posix/string.h"
-#include "posix/ctype.h"
-
-#include "libc/mem.h"
-
-/**
- * Find first set bit (beginning with the least significant bit).
- *
- * @param i Integer in which to look for the first set bit.
- * @return Index of first set bit. Bits are numbered starting at one.
- */
-int posix_ffs(int i)
-{
-	if (i == 0) {
-		return 0;
-	}
-
-	int result = 0;
-
-	// XXX: assumes at most 32-bit int
-	if (!(i & 0xFFFF)) {
-		result |= 16;
-		i >>= 16;
-	}
-	if (!(i & 0xFF)) {
-		result |= 8;
-		i >>= 8;
-	}
-	if (!(i & 0xF)) {
-		result |= 4;
-		i >>= 4;
-	}
-	if (!(i & 0x3)) {
-		result |= 2;
-		i >>= 2;
-	}
-	if (!(i & 0x1)) {
-		result |= 1;
-	}
-
-	return result + 1;
-}
-
-/**
- * Compare two strings (case-insensitive).
- *
- * @param s1 First string to be compared.
- * @param s2 Second string to be compared.
- * @return Difference of the first pair of inequal characters,
- *     or 0 if strings have the same content.
- */
-int posix_strcasecmp(const char *s1, const char *s2)
-{
-	return posix_strncasecmp(s1, s2, STR_NO_LIMIT);
-}
-
-/**
- * Compare part of two strings (case-insensitive).
- *
- * @param s1 First string to be compared.
- * @param s2 Second string to be compared.
- * @param n Maximum number of characters to be compared.
- * @return Difference of the first pair of inequal characters,
- *     or 0 if strings have the same content.
- */
-int posix_strncasecmp(const char *s1, const char *s2, size_t n)
-{
-	for (size_t i = 0; i < n; ++i) {
-		int cmp = tolower(s1[i]) - tolower(s2[i]);
-		if (cmp != 0) {
-			return cmp;
-		}
-		
-		if (s1[i] == 0) {
-			return 0;
-		}
-	}
-	
-	return 0;
-}
-
-/**
- * Compare two memory areas.
- *
- * @param mem1 Pointer to the first area to compare.
- * @param mem2 Pointer to the second area to compare.
- * @param n Common size of both areas.
- * @return If n is 0, return zero. If the areas match, return
- *     zero. Otherwise return non-zero.
- */
-int posix_bcmp(const void *mem1, const void *mem2, size_t n)
-{
-	return memcmp(mem1, mem2, n);
-}
-
-/**
- * Copy bytes in memory with overlapping areas.
- *
- * @param src Source area.
- * @param dest Destination area.
- * @param n Number of bytes to copy.
- */
-void posix_bcopy(const void *src, void *dest, size_t n)
-{
-	/* Note that memmove has different order of arguments. */
-	memmove(dest, src, n);
-}
-
-/**
- * Reset bytes in memory area to zero.
- *
- * @param mem Memory area to be zeroed.
- * @param n Number of bytes to reset.
- */
-void posix_bzero(void *mem, size_t n)
-{
-	memset(mem, 0, n);
-}
-
-/**
- * Scan string for a first occurence of a character.
- *
- * @param s String in which to look for the character.
- * @param c Character to look for.
- * @return Pointer to the specified character on success,
- *     NULL pointer otherwise.
- */
-char *posix_index(const char *s, int c)
-{
-	return posix_strchr(s, c);
-}
-
-/**
- * Scan string for a last occurence of a character.
- *
- * @param s String in which to look for the character.
- * @param c Character to look for.
- * @return Pointer to the specified character on success,
- *     NULL pointer otherwise.
- */
-char *posix_rindex(const char *s, int c)
-{
-	return posix_strrchr(s, c);
-}
-
-/** @}
- */
Index: pace/lib/posix/source/sys/mman.c
===================================================================
--- uspace/lib/posix/source/sys/mman.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,70 +1,0 @@
-/*
- * Copyright (c) 2006 Ondrej Palkovsky
- * 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
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "../internal/common.h"
-#include <posix/sys/mman.h>
-#include <posix/sys/types.h>
-#include <libc/as.h>
-#include <posix/unistd.h>
-
-void *posix_mmap(void *start, size_t length, int prot, int flags, int fd,
-    __POSIX_DEF__(off_t) offset)
-{
-	if (!start)
-		start = AS_AREA_ANY;
-	
-//	if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
-//		return MAP_FAILED;
-	
-	if (!(flags & MAP_ANONYMOUS))
-		return MAP_FAILED;
-	
-	return as_area_create(start, length, prot, AS_AREA_UNPAGED);
-}
-
-int posix_munmap(void *start, size_t length)
-{
-	int rc = as_area_destroy(start);
-	if (rc != EOK) {
-		errno = rc;
-		return -1;
-	}
-	return 0;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/sys/stat.c
===================================================================
--- uspace/lib/posix/source/sys/stat.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,166 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * Copyright (c) 2011 Petr Koupy
- * 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 File status handling.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "../internal/common.h"
-#include "posix/sys/stat.h"
-#include "libc/vfs/vfs.h"
-
-#include <errno.h>
-#include "libc/mem.h"
-
-/**
- * Convert HelenOS stat struct into POSIX stat struct (if possible).
- *
- * @param dest POSIX stat struct.
- * @param src HelenOS stat struct.
- *
- * @return 0 on success, -1 on error.
- */
-static int stat_to_posix(struct posix_stat *dest, struct stat *src)
-{
-	memset(dest, 0, sizeof(struct posix_stat));
-	
-	dest->st_dev = src->service;
-	dest->st_ino = src->index;
-	
-	/* HelenOS doesn't support permissions, so we set them all */
-	dest->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
-	if (src->is_file) {
-		dest->st_mode |= S_IFREG;
-	}
-	if (src->is_directory) {
-		dest->st_mode |= S_IFDIR;
-	}
-	
-	dest->st_nlink = src->lnkcnt;
-	dest->st_size = src->size;
-
-	if (src->size > INT64_MAX) {
-		errno = ERANGE;
-		return -1;
-	}
-
-	return 0;
-}
-
-/**
- * Retrieve file status for file associated with file descriptor.
- *
- * @param fd File descriptor of the opened file.
- * @param st Status structure to be filled with information.
- * @return Zero on success, -1 otherwise.
- */
-int posix_fstat(int fd, struct posix_stat *st)
-{
-	struct stat hst;
-	if (failed(vfs_stat(fd, &hst)))
-		return -1;
-	return stat_to_posix(st, &hst);
-}
-
-/**
- * Retrieve file status for symbolic link.
- * 
- * @param path Path to the symbolic link.
- * @param st Status structure to be filled with information.
- * @return Zero on success, -1 otherwise.
- */
-int posix_lstat(const char *restrict path, struct posix_stat *restrict st)
-{
-	/* There are currently no symbolic links in HelenOS. */
-	return posix_stat(path, st);
-}
-
-/**
- * Retrieve file status for regular file (or symbolic link target).
- *
- * @param path Path to the file/link.
- * @param st Status structure to be filled with information.
- * @return Zero on success, -1 otherwise.
- */
-int posix_stat(const char *restrict path, struct posix_stat *restrict st)
-{
-	struct stat hst;
-	if (failed(vfs_stat_path(path, &hst)))
-		return -1;
-	return stat_to_posix(st, &hst);
-}
-
-/**
- * Change permission bits for the file if possible.
- * 
- * @param path Path to the file.
- * @param mode Permission bits to be set.
- * @return Zero on success, -1 otherwise.
- */
-int posix_chmod(const char *path, posix_mode_t mode)
-{
-	/* HelenOS doesn't support permissions, return success. */
-	return 0;
-}
-
-/**
- * Set the file mode creation mask of the process.
- * 
- * @param mask Set permission bits are cleared in the related creation
- *     functions. Non-permission bits are ignored.
- * @return Previous file mode creation mask.
- */
-posix_mode_t posix_umask(posix_mode_t mask)
-{
-	/* HelenOS doesn't support permissions, return empty mask. */
-	return 0;
-}
-
-/**
- * Create a directory.
- * 
- * @param path Path to the new directory.
- * @param mode Permission bits to be set.
- * @return Zero on success, -1 otherwise.
- */
-int posix_mkdir(const char *path, posix_mode_t mode)
-{
-	if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL)))
-		return -1;
-	else
-		return 0;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/sys/wait.c
===================================================================
--- uspace/lib/posix/source/sys/wait.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,122 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 Support for waiting.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "../internal/common.h"
-#include "posix/sys/wait.h"
-
-#include "libc/task.h"
-#include <assert.h>
-
-#include <errno.h>
-
-#include "posix/limits.h"
-#include "posix/signal.h"
-
-int __posix_wifexited(int status) {
-	return status != INT_MIN;
-}
-
-int __posix_wexitstatus(int status) {
-	assert(__posix_wifexited(status));
-	return status;
-}
-
-int __posix_wifsignaled(int status) {
-	return status == INT_MIN;
-}
-
-int __posix_wtermsig(int status) {
-	assert(__posix_wifsignaled(status));
-	/* There is no way to distinguish reason
-	 * for unexpected termination at the moment.
-	 */
-	return SIGABRT;
-}
-
-/**
- * Wait for any child process to stop or terminate.
- * 
- * @param stat_ptr Location of the final status code of the child process.
- * @return ID of the child process for which status is reported,
- *     -1 on signal interrupt, (pid_t)-1 otherwise.
- */
-posix_pid_t posix_wait(int *stat_ptr)
-{
-	/* HelenOS does not support this. */
-	errno = ENOSYS;
-	return (posix_pid_t) -1;
-}
-
-/**
- * Wait for a child process to stop or terminate.
- * 
- * @param pid What child process shall the caller wait for. See POSIX manual
- *     for details.
- * @param stat_ptr Location of the final status code of the child process.
- * @param options Constraints of the waiting. See POSIX manual for details.
- * @return ID of the child process for which status is reported,
- *     -1 on signal interrupt, 0 if non-blocking wait is requested but there is
- *     no child process whose status can be reported, (pid_t)-1 otherwise.
- */
-posix_pid_t posix_waitpid(posix_pid_t pid, int *stat_ptr, int options)
-{
-	assert(stat_ptr != NULL);
-	assert(options == 0 /* None of the options are supported. */);
-	
-	task_exit_t texit;
-	int retval;
-	
-	if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) {
-		/* Unable to retrieve status. */
-		return (posix_pid_t) -1;
-	}
-	
-	if (texit == TASK_EXIT_NORMAL) {
-		// FIXME: relies on application not returning this value
-		assert(retval != INT_MIN);
-		*stat_ptr = retval;
-	} else {
-		/* Reserve the lowest value for unexpected termination. */
-		*stat_ptr = INT_MIN;
-	}
-	
-	return pid;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/time.c
===================================================================
--- uspace/lib/posix/source/time.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,346 +1,0 @@
-/*
- * Copyright (c) 2011 Petr Koupy
- * 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 Time measurement support.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/time.h"
-
-#include "posix/ctype.h"
-
-#include <errno.h>
-
-#include "posix/signal.h"
-#include <assert.h>
-
-#include "libc/async.h"
-#include "libc/malloc.h"
-#include "libc/task.h"
-#include "libc/stats.h"
-#include "libc/stddef.h"
-#include "libc/sys/time.h"
-
-// TODO: test everything in this file
-
-/* In some places in this file, phrase "normalized broken-down time" is used.
- * This means time broken down to components (year, month, day, hour, min, sec),
- * in which every component is in its proper bounds. Non-normalized time could
- * e.g. be 2011-54-5 29:13:-5, which would semantically mean start of year 2011
- * + 53 months + 4 days + 29 hours + 13 minutes - 5 seconds.
- */
-
-int posix_daylight;
-long posix_timezone;
-char *posix_tzname[2];
-
-/**
- * Set timezone conversion information.
- */
-void posix_tzset(void)
-{
-	// TODO: read environment
-	posix_tzname[0] = (char *) "GMT";
-	posix_tzname[1] = (char *) "GMT";
-	posix_daylight = 0;
-	posix_timezone = 0;
-}
-
-/**
- * Get the time in seconds
- *
- * @param t If t is non-NULL, the return value is also stored in the memory
- *          pointed to by t.
- * @return  On success, the value of time in seconds since the Epoch
- *          is returned. On error, (time_t)-1 is returned.
- */
-time_t posix_time(time_t *t)
-{
-	return time(t);
-}
-
-/**
- * Converts a time value to a broken-down UTC time.
- * 
- * @param timer Time to convert.
- * @param result Structure to store the result to.
- * @return Value of result on success, NULL on overflow.
- */
-struct tm *posix_gmtime_r(const time_t *restrict timer,
-    struct tm *restrict result)
-{
-	if (failed(time_utc2tm(*timer, result))) {
-		return NULL;
-	}
-
-	return result;
-}
-
-/**
- * Converts a time value to a broken-down UTC time.
- * (non reentrant version)
- *
- * @param timep  Time to convert
- * @return       Pointer to a statically allocated structure that stores
- *               the result, NULL in case of error.
- */
-struct tm *posix_gmtime(const time_t *restrict timep)
-{
-	static struct tm result;
-
-	return posix_gmtime_r(timep, &result);
-}
-
-/**
- * Converts a time value to a broken-down local time.
- * 
- * @param timer Time to convert.
- * @param result Structure to store the result to.
- * @return Value of result on success, NULL on overflow.
- */
-struct tm *posix_localtime_r(const time_t *restrict timer,
-    struct tm *restrict result)
-{
-	// TODO: deal with timezone
-	// currently assumes system and all times are in GMT
-	return posix_gmtime_r(timer, result);
-}
-
-/**
- * Converts a time value to a broken-down local time.
- * (non reentrant version)
- *
- * @param timep    Time to convert.
- * @return         Pointer to a statically allocated structure that stores
- *                 the result, NULL in case of error.
- */
-struct tm *posix_localtime(const time_t *restrict timep)
-{
-	static struct tm result;
-
-	return posix_localtime_r(timep, &result);
-}
-
-/**
- * Converts broken-down time to a string in format
- * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
- *
- * @param timeptr Broken-down time structure.
- * @param buf Buffer to store string to, must be at least ASCTIME_BUF_LEN
- *     bytes long.
- * @return Value of buf.
- */
-char *posix_asctime_r(const struct tm *restrict timeptr,
-    char *restrict buf)
-{
-	time_tm2str(timeptr, buf);
-	return buf;
-}
-
-/**
- * Convers broken-down time to a string in format
- * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
- * (non reentrant version)
- *
- * @param timeptr    Broken-down time structure.
- * @return           Pointer to a statically allocated buffer that stores
- *                   the result, NULL in case of error.
- */
-char *posix_asctime(const struct tm *restrict timeptr)
-{
-	static char buf[ASCTIME_BUF_LEN];
-
-	return posix_asctime_r(timeptr, buf);
-}
-
-/**
- * Converts the calendar time to a string in format
- * "Sun Jan 1 00:00:00 1970\n" (Obsolete)
- * 
- * @param timer Time to convert.
- * @param buf Buffer to store string to. Must be at least ASCTIME_BUF_LEN
- *     bytes long.
- * @return Pointer to buf on success, NULL on failure.
- */
-char *posix_ctime_r(const time_t *timer, char *buf)
-{
-	if (failed(time_local2str(*timer, buf))) {
-		return NULL;
-	}
-
-	return buf;
-}
-
-/**
- * Converts the calendar time to a string in format
- * "Sun Jan 1 00:00:00 1970\n" (Obsolete)
- * (non reentrant version)
- *
- * @param timep    Time to convert.
- * @return         Pointer to a statically allocated buffer that stores
- *                 the result, NULL in case of error.
- */
-char *posix_ctime(const time_t *timep)
-{
-	static char buf[ASCTIME_BUF_LEN];
-
-	return posix_ctime_r(timep, buf);
-}
-
-/**
- * Get clock resolution. Only CLOCK_REALTIME is supported.
- *
- * @param clock_id Clock ID.
- * @param res Pointer to the variable where the resolution is to be written.
- * @return 0 on success, -1 with errno set on failure.
- */
-int posix_clock_getres(posix_clockid_t clock_id, struct posix_timespec *res)
-{
-	assert(res != NULL);
-
-	switch (clock_id) {
-		case CLOCK_REALTIME:
-			res->tv_sec = 0;
-			res->tv_nsec = 1000; /* Microsecond resolution. */
-			return 0;
-		default:
-			errno = EINVAL;
-			return -1;
-	}
-}
-
-/**
- * Get time. Only CLOCK_REALTIME is supported.
- * 
- * @param clock_id ID of the clock to query.
- * @param tp Pointer to the variable where the time is to be written.
- * @return 0 on success, -1 with errno on failure.
- */
-int posix_clock_gettime(posix_clockid_t clock_id, struct posix_timespec *tp)
-{
-	assert(tp != NULL);
-
-	switch (clock_id) {
-		case CLOCK_REALTIME:
-			;
-			struct timeval tv;
-			gettimeofday(&tv, NULL);
-			tp->tv_sec = tv.tv_sec;
-			tp->tv_nsec = tv.tv_usec * 1000;
-			return 0;
-		default:
-			errno = EINVAL;
-			return -1;
-	}
-}
-
-/**
- * Set time on a specified clock. As HelenOS doesn't support this yet,
- * this function always fails.
- * 
- * @param clock_id ID of the clock to set.
- * @param tp Time to set.
- * @return 0 on success, -1 with errno on failure.
- */
-int posix_clock_settime(posix_clockid_t clock_id,
-    const struct posix_timespec *tp)
-{
-	assert(tp != NULL);
-
-	switch (clock_id) {
-		case CLOCK_REALTIME:
-			// TODO: setting clock
-			// FIXME: HelenOS doesn't actually support hardware
-			//        clock yet
-			errno = EPERM;
-			return -1;
-		default:
-			errno = EINVAL;
-			return -1;
-	}
-}
-
-/**
- * Sleep on a specified clock.
- * 
- * @param clock_id ID of the clock to sleep on (only CLOCK_REALTIME supported).
- * @param flags Flags (none supported).
- * @param rqtp Sleep time.
- * @param rmtp Remaining time is written here if sleep is interrupted.
- * @return 0 on success, -1 with errno set on failure.
- */
-int posix_clock_nanosleep(posix_clockid_t clock_id, int flags,
-    const struct posix_timespec *rqtp, struct posix_timespec *rmtp)
-{
-	assert(rqtp != NULL);
-	assert(rmtp != NULL);
-
-	switch (clock_id) {
-		case CLOCK_REALTIME:
-			// TODO: interruptible sleep
-			if (rqtp->tv_sec != 0) {
-				async_sleep(rqtp->tv_sec);
-			}
-			if (rqtp->tv_nsec != 0) {
-				async_usleep(rqtp->tv_nsec / 1000);
-			}
-			return 0;
-		default:
-			errno = EINVAL;
-			return -1;
-	}
-}
-
-/**
- * Get CPU time used since the process invocation.
- *
- * @return Consumed CPU cycles by this process or -1 if not available.
- */
-posix_clock_t posix_clock(void)
-{
-	posix_clock_t total_cycles = -1;
-	stats_task_t *task_stats = stats_get_task(task_get_id());
-	if (task_stats) {
-		total_cycles = (posix_clock_t) (task_stats->kcycles +
-		    task_stats->ucycles);
-		free(task_stats);
-		task_stats = 0;
-	}
-
-	return total_cycles;
-}
-
-/** @}
- */
Index: pace/lib/posix/source/unistd.c
===================================================================
--- uspace/lib/posix/source/unistd.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,495 +1,0 @@
-/*
- * Copyright (c) 2011 Jiri Zarevucky
- * Copyright (c) 2011 Petr Koupy
- * 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 Miscellaneous standard definitions.
- */
-
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
-
-#include "internal/common.h"
-#include "posix/unistd.h"
-
-#include <errno.h>
-
-#include "posix/string.h"
-#include "posix/fcntl.h"
-
-#include "libc/task.h"
-#include "libc/thread.h"
-#include "libc/stats.h"
-#include "libc/malloc.h"
-#include "libc/vfs/vfs.h"
-
-#include <libarch/config.h>
-
-// FIXME: replace with a hash table
-aoff64_t posix_pos[MAX_OPEN_FILES];
-
-/* Array of environment variable strings (NAME=VALUE). */
-char **posix_environ = NULL;
-char *posix_optarg;
-
-/**
- * Sleep for the specified number of seconds.
- *
- * Note that POSIX allows this call to be interrupted and then the return
- * value represents remaining seconds for the sleep. HelenOS does not offer
- * such functionality and thus always the whole sleep is taken.
- *
- * @param seconds Number of seconds to sleep.
- * @return Always 0 on HelenOS.
- */
-unsigned int posix_sleep(unsigned int seconds)
-{
-	return thread_sleep(seconds);
-}
-
-/**
- * Get current user name.
- *
- * @return User name (static) string or NULL if not found.
- */
-char *posix_getlogin(void)
-{
-	/* There is currently no support for user accounts in HelenOS. */
-	return (char *) "user";
-}
-
-/**
- * Get current user name.
- *
- * @param name Pointer to a user supplied buffer.
- * @param namesize Length of the buffer.
- * @return Zero on success, error code otherwise.
- */
-int posix_getlogin_r(char *name, size_t namesize)
-{
-	/* There is currently no support for user accounts in HelenOS. */
-	if (namesize >= 5) {
-		posix_strcpy(name, (char *) "user");
-		return 0;
-	} else {
-		errno = ERANGE;
-		return -1;
-	}
-}
-
-/**
- * Test whether open file descriptor is associated with a terminal.
- *
- * @param fd Open file descriptor to test.
- * @return Boolean result of the test.
- */
-int posix_isatty(int fd)
-{
-	// TODO
-	/* Always returns false, because there is no easy way to find
-	 * out under HelenOS. */
-	return 0;
-}
-
-/**
- * Get the pathname of the current working directory.
- *
- * @param buf Buffer into which the pathname shall be put.
- * @param size Size of the buffer.
- * @return Buffer pointer on success, NULL on failure.
- */
-char *posix_getcwd(char *buf, size_t size)
-{
-	if (failed(vfs_cwd_get(buf, size))) 
-		return NULL;
-	return buf;
-}
-
-/**
- * Change the current working directory.
- *
- * @param path New working directory.
- */
-int posix_chdir(const char *path)
-{
-	if (failed(vfs_cwd_set(path)))
-		return -1;
-	return 0;
-}
-
-/**
- * Determine the page size of the current run of the process.
- *
- * @return Page size of the process.
- */
-int posix_getpagesize(void)
-{
-	return PAGE_SIZE;
-}
-
-/**
- * Get the process ID of the calling process.
- *
- * @return Process ID.
- */
-posix_pid_t posix_getpid(void)
-{
-	return task_get_id();
-}
-
-/**
- * Get the real user ID of the calling process.
- *
- * @return User ID.
- */
-posix_uid_t posix_getuid(void)
-{
-	/* There is currently no support for user accounts in HelenOS. */
-	return 0;
-}
-
-/**
- * Get the real group ID of the calling process.
- * 
- * @return Group ID.
- */
-posix_gid_t posix_getgid(void)
-{
-	/* There is currently no support for user accounts in HelenOS. */
-	return 0;
-}
-
-/**
- * Close a file.
- *
- * @param fildes File descriptor of the opened file.
- * @return 0 on success, -1 on error.
- */
-int posix_close(int fildes)
-{
-	posix_pos[fildes] = 0;
-	if (failed(vfs_put(fildes)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Read from a file.
- *
- * @param fildes File descriptor of the opened file.
- * @param buf Buffer to which the read bytes shall be stored.
- * @param nbyte Upper limit on the number of read bytes.
- * @return Number of read bytes on success, -1 otherwise.
- */
-ssize_t posix_read(int fildes, void *buf, size_t nbyte)
-{
-	size_t nread;
-	if (failed(vfs_read(fildes, &posix_pos[fildes], buf, nbyte, &nread)))
-		return -1;
-	return (ssize_t) nread;
-}
-
-/**
- * Write to a file.
- *
- * @param fildes File descriptor of the opened file.
- * @param buf Buffer to write.
- * @param nbyte Size of the buffer.
- * @return Number of written bytes on success, -1 otherwise.
- */
-ssize_t posix_write(int fildes, const void *buf, size_t nbyte)
-{
-	size_t nwr;
-	if (failed(vfs_write(fildes, &posix_pos[fildes], buf, nbyte, &nwr)))
-		return -1;
-	return nwr;
-}
-
-/**
- * Reposition read/write file offset
- *
- * @param fildes File descriptor of the opened file.
- * @param offset New offset in the file.
- * @param whence The position from which the offset argument is specified.
- * @return Upon successful completion, returns the resulting offset
- *         as measured in bytes from the beginning of the file, -1 otherwise.
- */
-posix_off_t posix_lseek(int fildes, posix_off_t offset, int whence)
-{
-	struct stat st;
-
-	switch (whence) {
-	case SEEK_SET:
-		posix_pos[fildes] = offset;
-		break;
-	case SEEK_CUR:
-		posix_pos[fildes] += offset;
-		break;
-	case SEEK_END:
-		if (failed(vfs_stat(fildes, &st)))
-			return -1;
-		posix_pos[fildes] = st.size + offset;
-		break;
-	}
-	if (posix_pos[fildes] > INT64_MAX) {
-		/* The native width is too large for the POSIX interface. */
-		errno = ERANGE;
-		return -1;
-	}
-	return posix_pos[fildes];
-}
-
-/**
- * Requests outstanding data to be written to the underlying storage device.
- *
- * @param fildes File descriptor of the opened file.
- * @return Zero on success, -1 otherwise.
- */
-int posix_fsync(int fildes)
-{
-	if (failed(vfs_sync(fildes)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Truncate a file to a specified length.
- *
- * @param fildes File descriptor of the opened file.
- * @param length New length of the file.
- * @return Zero on success, -1 otherwise.
- */
-int posix_ftruncate(int fildes, posix_off_t length)
-{
-	if (failed(vfs_resize(fildes, (aoff64_t) length)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Remove a directory.
- *
- * @param path Directory pathname.
- * @return Zero on success, -1 otherwise.
- */
-int posix_rmdir(const char *path)
-{
-	if (failed(vfs_unlink_path(path)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Remove a link to a file.
- * 
- * @param path File pathname.
- * @return Zero on success, -1 otherwise.
- */
-int posix_unlink(const char *path)
-{
-	if (failed(vfs_unlink_path(path)))
-		return -1;
-	else
-		return 0;
-}
-
-/**
- * Duplicate an open file descriptor.
- *
- * @param fildes File descriptor to be duplicated.
- * @return On success, new file descriptor for the same file, otherwise -1.
- */
-int posix_dup(int fildes)
-{
-	return posix_fcntl(fildes, F_DUPFD, 0);
-}
-
-/**
- * Duplicate an open file descriptor.
- * 
- * @param fildes File descriptor to be duplicated.
- * @param fildes2 File descriptor to be paired with the same file description
- *     as is paired fildes.
- * @return fildes2 on success, -1 otherwise.
- */
-int posix_dup2(int fildes, int fildes2)
-{
-	int file;
-	if (failed(vfs_clone(fildes, fildes2, false, &file))) {
-		return -1;
-	}
-	return file;
-}
-
-/**
- * Determine accessibility of a file.
- *
- * @param path File to check accessibility for.
- * @param amode Either check for existence or intended access mode.
- * @return Zero on success, -1 otherwise.
- */
-int posix_access(const char *path, int amode)
-{
-	if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) {
-		/* HelenOS doesn't support permissions, permission checks
-		 * are equal to existence check.
-		 *
-		 * Check file existence by attempting to open it.
-		 */
-		int fd = posix_open(path, O_RDONLY);
-		if (fd < 0)
-			return -1;
-		posix_close(fd);
-		return 0;
-	} else {
-		/* Invalid amode argument. */
-		errno = EINVAL;
-		return -1;
-	}
-}
-
-/**
- * Get configurable system variables.
- * 
- * @param name Variable name.
- * @return Variable value.
- */
-long posix_sysconf(int name)
-{
-	long clk_tck = 0;
-	size_t cpu_count = 0;
-	stats_cpu_t *cpu_stats = stats_get_cpus(&cpu_count);
-	if (cpu_stats && cpu_count > 0) {
-		clk_tck = ((long) cpu_stats[0].frequency_mhz) * 1000000L;
-	}
-	if (cpu_stats) {
-		free(cpu_stats);
-		cpu_stats = 0;
-	}
-
-	long phys_pages = 0;
-	long avphys_pages = 0;
-	stats_physmem_t *mem_stats = stats_get_physmem();
-	if (mem_stats) {
-		phys_pages = (long) (mem_stats->total / posix_getpagesize());
-		avphys_pages = (long) (mem_stats->free / posix_getpagesize());
-		free(mem_stats);
-		mem_stats = 0;
-	}
-
-	switch (name) {
-	case _SC_PHYS_PAGES:
-		return phys_pages;
-	case _SC_AVPHYS_PAGES:
-		return avphys_pages;
-	case _SC_PAGESIZE:
-		return posix_getpagesize();
-	case _SC_CLK_TCK:
-		return clk_tck;
-	default:
-		errno = EINVAL;
-		return -1;
-	}
-}
-
-/**
- * 
- * @param path
- * @param name
- * @return
- */
-long posix_pathconf(const char *path, int name)
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return -1;
-}
-
-/**
- * 
- * @return
- */
-posix_pid_t posix_fork(void)
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return -1;
-}
-
-/**
- * 
- * @param path
- * @param argv
- * @return
- */
-int posix_execv(const char *path, char *const argv[])
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return -1;
-}
-
-/**
- * 
- * @param file
- * @param argv
- * @return
- */
-int posix_execvp(const char *file, char *const argv[])
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return -1;
-}
-
-/**
- * 
- * @param fildes
- * @return
- */
-int posix_pipe(int fildes[2])
-{
-	// TODO: low priority, just a compile-time dependency of binutils
-	not_implemented();
-	return -1;
-}
-
-unsigned int posix_alarm(unsigned int seconds)
-{
-	not_implemented();
-	return 0;
-}
-
-/** @}
- */
Index: uspace/lib/posix/src/ctype.c
===================================================================
--- uspace/lib/posix/src/ctype.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/ctype.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2011 Jiri Zarevucky
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Character classification.
+ */
+
+#include "posix/ctype.h"
+
+/**
+ * Checks whether character is ASCII. (obsolete)
+ *
+ * @param c Character to inspect.
+ * @return Non-zero if character match the definition, zero otherwise.
+ */
+int isascii(int c)
+{
+	return c >= 0 && c < 128;
+}
+
+/**
+ * Converts argument to a 7-bit ASCII character. (obsolete)
+ *
+ * @param c Character to convert.
+ * @return Coverted character.
+ */
+int toascii(int c)
+{
+	return c & 0x7F;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/dlfcn.c
===================================================================
--- uspace/lib/posix/src/dlfcn.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/dlfcn.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2017 Vojtech Horky
+ * 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
+ * @{
+ */
+
+#include "internal/common.h"
+#include "posix/dlfcn.h"
+
+_HIDE_LIBC_SYMBOL(dlopen)
+extern void *__helenos_libc_dlopen(const char *filename, int flags);
+
+void *dlopen(const char *filename, int flags)
+{
+	if (flags != 0) {
+		fprintf(stderr, "dlopen() not implemented with non-zero flags (%s:%d), something will NOT work.\n", __FILE__, __LINE__);
+	}
+	
+	return __helenos_libc_dlopen(filename, 0);
+}
+
+int dlclose(void *handle)
+{
+	not_implemented();
+	return 0;
+}
+
+char *dlerror(void)
+{
+	not_implemented();
+	return (char *)"dlerror()";
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/fcntl.c
===================================================================
--- uspace/lib/posix/src/fcntl.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/fcntl.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,158 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 File control.
+ */
+
+#include "internal/common.h"
+#include "posix/fcntl.h"
+
+#include "libc/vfs/vfs.h"
+
+#include <errno.h>
+
+/**
+ * Performs set of operations on the opened files.
+ *
+ * @param fd File descriptor of the opened file.
+ * @param cmd Operation to carry out.
+ * @return Non-negative on success. Might have special meaning corresponding
+ *     to the requested operation.
+ */
+int fcntl(int fd, int cmd, ...)
+{
+	int flags;
+
+	switch (cmd) {
+	case F_DUPFD:
+	case F_DUPFD_CLOEXEC:
+		/* VFS currently does not provide the functionality to duplicate
+		 * opened file descriptor. */
+		// FIXME: implement this once dup() is available
+		errno = ENOTSUP;
+		return -1;
+	case F_GETFD:
+		/* FD_CLOEXEC is not supported. There are no other flags. */
+		return 0;
+	case F_SETFD:
+		/* FD_CLOEXEC is not supported. Ignore arguments and report success. */
+		return 0;
+	case F_GETFL:
+		/* File status flags (i.e. O_APPEND) are currently private to the
+		 * VFS server so it cannot be easily retrieved. */
+		flags = 0;
+		/* File access flags are currently not supported for file descriptors.
+		 * Provide full access. */
+		flags |= O_RDWR;
+		return flags;
+	case F_SETFL:
+		/* File access flags are currently not supported for file descriptors.
+		 * Ignore arguments and report success. */
+		return 0;
+	case F_GETOWN:
+	case F_SETOWN:
+	case F_GETLK:
+	case F_SETLK:
+	case F_SETLKW:
+		/* Signals (SIGURG) and file locks are not supported. */
+		errno = ENOTSUP;
+		return -1;
+	default:
+		/* Unknown command */
+		errno = EINVAL;
+		return -1;
+	}
+}
+
+/**
+ * Open, possibly create, a file.
+ *
+ * @param pathname Path to the file.
+ * @param posix_flags Access mode flags.
+ */
+int open(const char *pathname, int posix_flags, ...)
+{
+	mode_t posix_mode = 0;
+	if (posix_flags & O_CREAT) {
+		va_list args;
+		va_start(args, posix_flags);
+		posix_mode = va_arg(args, mode_t);
+		va_end(args);
+		(void) posix_mode;
+	}
+
+	if (((posix_flags & (O_RDONLY | O_WRONLY | O_RDWR)) == 0) ||
+	    ((posix_flags & (O_RDONLY | O_WRONLY)) == (O_RDONLY | O_WRONLY)) ||
+	    ((posix_flags & (O_RDONLY | O_RDWR)) == (O_RDONLY | O_RDWR)) ||
+	    ((posix_flags & (O_WRONLY | O_RDWR)) == (O_WRONLY | O_RDWR))) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	int flags = WALK_REGULAR;
+	if (posix_flags & O_CREAT) {
+		if (posix_flags & O_EXCL)
+			flags |= WALK_MUST_CREATE;
+		else
+			flags |= WALK_MAY_CREATE;
+	}
+
+	int mode =
+	    ((posix_flags & O_RDWR) ? MODE_READ | MODE_WRITE : 0) |
+	    ((posix_flags & O_RDONLY) ? MODE_READ : 0) |
+	    ((posix_flags & O_WRONLY) ? MODE_WRITE : 0) |
+	    ((posix_flags & O_APPEND) ? MODE_APPEND : 0);
+
+	int file;
+
+	if (failed(vfs_lookup(pathname, flags, &file)))
+		return -1;
+
+	if (failed(vfs_open(file, mode))) {
+		vfs_put(file);
+		return -1;
+	}
+
+	if (posix_flags & O_TRUNC) {
+		if (posix_flags & (O_RDWR | O_WRONLY)) {
+			if (failed(vfs_resize(file, 0))) {
+				vfs_put(file);
+				return -1;
+			}
+		}
+	}
+
+	return file;
+}
+
+/** @}
+ */
+
Index: uspace/lib/posix/src/fnmatch.c
===================================================================
--- uspace/lib/posix/src/fnmatch.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/fnmatch.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,714 @@
+/*
+ * 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 Filename-matching.
+ */
+
+/* This file contains an implementation of the fnmatch() pattern matching
+ * function. There is more code than necessary to account for the possibility
+ * of adding POSIX-like locale support to the system in the future. Functions
+ * that are only necessary for locale support currently simply use single
+ * characters for "collation elements". 
+ * When (or if) locales are properly implemented, extending this implementation
+ * will be fairly straightforward.
+ */
+
+#include "libc/stdbool.h"
+#include "posix/ctype.h"
+#include "posix/string.h"
+#include "posix/stdlib.h"
+#include <assert.h>
+
+#include "internal/common.h"
+#include "posix/fnmatch.h"
+
+/* Returned by _match... functions. */
+#define INVALID_PATTERN -1
+
+/* Type for collating element, simple identity with characters now,
+ * but may be extended for better locale support.
+ */
+typedef int coll_elm_t;
+
+/** Return value indicating that the element in question
+ * is not valid in the current locale. (That is, if locales are supported.)
+ */
+#define COLL_ELM_INVALID -1
+
+/**
+ * Get collating element matching a string.
+ *
+ * @param str String representation of the element.
+ * @return Matching collating element or COLL_ELM_INVALID.
+ */
+static coll_elm_t _coll_elm_get(const char* str)
+{
+	if (str[0] == '\0' || str[1] != '\0') {
+		return COLL_ELM_INVALID;
+	}
+	return str[0];
+}
+
+/**
+ * Get collating element matching a single character.
+ *
+ * @param c Character representation of the element.
+ * @return Matching collating element.
+ */
+static coll_elm_t _coll_elm_char(int c)
+{
+	return c;
+}
+
+/**
+ * Match collating element with a beginning of a string.
+ *
+ * @param elm Collating element to match.
+ * @param str String which beginning should match the element.
+ * @return 0 if the element doesn't match, or the number of characters matched.
+ */
+static int _coll_elm_match(coll_elm_t elm, const char *str)
+{
+	return elm == *str;
+}
+
+/**
+ * Checks whether a string begins with a collating element in the given range.
+ * Ordering depends on the locale (if locales are supported).
+ *
+ * @param first First element of the range.
+ * @param second Last element of the range.
+ * @param str String to match.
+ * @return 0 if there is no match, or the number of characters matched.
+ */
+static int _coll_elm_between(coll_elm_t first, coll_elm_t second,
+    const char *str)
+{
+	return *str >= first && *str <= second;
+}
+
+/**
+ * Read a string delimited by [? and ?].
+ *
+ * @param pattern Pointer to the string to read from. Its position is moved
+ *    to the first character after the closing ].
+ * @param seq The character on the inside of brackets.
+ * @param buf Read buffer.
+ * @param buf_sz Read buffer's size. If the buffer is not large enough for
+ *    the entire string, the string is cut with no error indication.
+ * @param flags Flags modifying the behavior.
+ * @return True on success, false if the pattern is invalid.
+ */
+static bool _get_delimited(
+    const char **pattern, int seq,
+    char *buf, size_t buf_sz, int flags)
+{
+	const bool noescape = (flags & FNM_NOESCAPE) != 0;
+	const bool pathname = (flags & FNM_PATHNAME) != 0;
+
+	const char *p = *pattern;
+	assert(p[0] == '[' && p[1] == seq /* Caller should ensure this. */);
+	p += 2;
+
+	while (true) {
+		if (*p == seq && *(p + 1) == ']') {
+			/* String properly ended, return. */
+			*pattern = p + 2;
+			*buf = '\0';
+			return true;
+		}
+		if (!noescape && *p == '\\') {
+			p++;
+		}
+		if (*p == '\0') {
+			/* String not ended properly, invalid pattern. */
+			return false;
+		}
+		if (pathname && *p == '/') {
+			/* Slash in a pathname pattern is invalid. */
+			return false;
+		}
+		if (buf_sz > 1) {
+			/* Only add to the buffer if there is space. */
+			*buf = *p;
+			buf++;
+			buf_sz--;
+		}
+		p++;
+	}
+}
+
+/************** CHARACTER CLASSES ****************/
+
+#define MAX_CLASS_OR_COLL_LEN 6
+
+struct _char_class {
+	const char *name;
+	int (*func) (int);
+};
+
+/* List of supported character classes. */
+static const struct _char_class _char_classes[] = {
+	{ "alnum", isalnum },
+	{ "alpha", isalpha },
+	{ "blank", isblank },
+	{ "cntrl", iscntrl },
+	{ "digit", isdigit },
+	{ "graph", isgraph },
+	{ "lower", islower },
+	{ "print", isprint },
+	{ "punct", ispunct },
+	{ "space", isspace },
+	{ "upper", isupper },
+	{ "xdigit", isxdigit }
+};
+
+/**
+ * Compare function for binary search in the _char_classes array.
+ * 
+ * @param key Key of the searched element.
+ * @param elem Element of _char_classes array.
+ * @return Ordering indicator (-1 less than, 0 equal, 1 greater than).
+ */
+static int _class_compare(const void *key, const void *elem)
+{
+	const struct _char_class *class = elem;
+	return strcmp((const char *) key, class->name);
+}
+
+/**
+ * Returns whether the given character belongs to the specified character class.
+ * 
+ * @param cname Name of the character class.
+ * @param c Character.
+ * @return True if the character belongs to the class, false otherwise.
+ */
+static bool _is_in_class (const char *cname, int c)
+{
+	/* Search for class in the array of supported character classes. */
+	const struct _char_class *class = bsearch(cname, _char_classes,
+	    sizeof(_char_classes) / sizeof(struct _char_class),
+	    sizeof(struct _char_class), _class_compare);
+
+	if (class == NULL) {
+		/* No such class supported - treat as an empty class. */
+		return false;
+	} else {
+		/* Class matched. */
+		return class->func(c);
+	}
+}
+
+/**
+ * Tries to parse an initial part of the pattern as a character class pattern,
+ * and if successful, matches the beginning of the given string against the class.
+ * 
+ * @param pattern Pointer to the pattern to match. Must begin with a class
+ *    specifier and is repositioned to the first character after the specifier
+ *    if successful.
+ * @param str String to match.
+ * @param flags Flags modifying the behavior (see fnmatch()).
+ * @return INVALID_PATTERN if the pattern doesn't start with a valid class
+ *    specifier, 0 if the beginning of the matched string doesn't belong
+ *    to the class, or positive number of characters matched.
+ */
+static int _match_char_class(const char **pattern, const char *str, int flags)
+{
+	char class[MAX_CLASS_OR_COLL_LEN + 1];
+
+	if (!_get_delimited(pattern, ':', class, sizeof(class), flags)) {
+		return INVALID_PATTERN;
+	}
+
+	return _is_in_class(class, *str);
+}
+
+/************** END CHARACTER CLASSES ****************/
+
+/**
+ * Reads the next collating element in the pattern, taking into account
+ * locale (if supported) and flags (see fnmatch()).
+ * 
+ * @param pattern Pattern.
+ * @param flags Flags given to fnmatch().
+ * @return Collating element on success,
+ *     or COLL_ELM_INVALID if the pattern is invalid.
+ */
+static coll_elm_t _next_coll_elm(const char **pattern, int flags)
+{
+	assert(pattern != NULL);
+	assert(*pattern != NULL);
+	assert(**pattern != '\0');
+
+	const char *p = *pattern;
+	const bool noescape = (flags & FNM_NOESCAPE) != 0;
+	const bool pathname = (flags & FNM_PATHNAME) != 0;
+
+	if (*p == '[') {
+		if (*(p + 1) == '.') {
+			char buf[MAX_CLASS_OR_COLL_LEN + 1];
+			if (!_get_delimited(pattern, '.', buf, sizeof(buf), flags)) {
+				return COLL_ELM_INVALID;
+			}
+			return _coll_elm_get(buf);
+		}
+
+		if (*(p + 1) == '=') {
+			char buf[MAX_CLASS_OR_COLL_LEN + 1];
+			if (!_get_delimited(pattern, '=', buf, sizeof(buf), flags)) {
+				return COLL_ELM_INVALID;
+			}
+			return _coll_elm_get(buf);
+		}
+	}
+
+	if (!noescape && *p == '\\') {
+		p++;
+		if (*p == '\0') {
+			*pattern = p;
+			return COLL_ELM_INVALID;
+		}
+	}
+	if (pathname && *p == '/') {
+		return COLL_ELM_INVALID;
+	}
+	
+	*pattern = p + 1;
+	return _coll_elm_char(*p);
+}
+
+/**
+ * Matches the beginning of the given string against a bracket expression
+ * the pattern begins with.
+ * 
+ * @param pattern Pointer to the beginning of a bracket expression in a pattern.
+ *     On success, the pointer is moved to the first character after the
+ *     bracket expression.
+ * @param str Unmatched part of the string.
+ * @param flags Flags given to fnmatch().
+ * @return INVALID_PATTERN if the pattern is invalid, 0 if there is no match
+ *     or the number of matched characters on success.
+ */
+static int _match_bracket_expr(const char **pattern, const char *str, int flags)
+{
+	const bool pathname = (flags & FNM_PATHNAME) != 0;
+	const bool special_period = (flags & FNM_PERIOD) != 0;
+	const char *p = *pattern;
+	bool negative = false;
+	int matched = 0;
+
+	#define _matched(match) { \
+		int _match = match; \
+		if (_match < 0) { \
+			/* Invalid pattern */ \
+			return _match; \
+		} else if (matched == 0 && _match > 0) { \
+			/* First match */ \
+			matched = _match; \
+		} \
+	}
+
+	assert(*p == '[');  /* calling code should ensure this */
+	p++;
+
+	if (*str == '\0' || (pathname && *str == '/') ||
+	    (pathname && special_period && *str == '.' && *(str - 1) == '/')) {
+		/* No bracket expression matches end of string,
+		 * slash in pathname match or initial period with FNM_PERIOD
+		 * option.
+		 */
+		return 0;
+	}
+
+	if (*p == '^' || *p == '!') {
+		negative = true;
+		p++;
+	}
+
+	if (*p == ']') {
+		/* When ']' is first, treat it as a normal character. */
+		_matched(*str == ']');
+		p++;
+	}
+	
+	coll_elm_t current_elm = COLL_ELM_INVALID;
+	
+	while (*p != ']') {
+		if (*p == '-' && *(p + 1) != ']' &&
+		    current_elm != COLL_ELM_INVALID) {
+			/* Range expression. */
+			p++;
+			coll_elm_t end_elm = _next_coll_elm(&p, flags);
+			if (end_elm == COLL_ELM_INVALID) {
+				return INVALID_PATTERN;
+			}
+			_matched(_coll_elm_between(current_elm, end_elm, str));
+			continue;
+		}
+	
+		if (*p == '[' && *(p + 1) == ':') {
+			current_elm = COLL_ELM_INVALID;
+			_matched(_match_char_class(&p, str, flags));
+			continue;
+		}
+		
+		current_elm = _next_coll_elm(&p, flags);
+		if (current_elm == COLL_ELM_INVALID) {
+			return INVALID_PATTERN;
+		}
+		_matched(_coll_elm_match(current_elm, str));
+	}
+
+	/* No error occured - update pattern pointer. */
+	*pattern = p + 1;
+
+	if (matched == 0) {
+		/* No match found */
+		return negative;
+	} else {
+		/* Matched 'match' characters. */
+		return negative ? 0 : matched;
+	}
+
+	#undef _matched
+}
+
+/**
+ * Matches a portion of the pattern containing no asterisks (*) against
+ * the given string.
+ * 
+ * @param pattern Pointer to the unmatched portion of the pattern.
+ *     On success, the pointer is moved to the first asterisk, or to the
+ *     terminating nul character, whichever occurs first.
+ * @param string Pointer to the input string. On success, the pointer is moved
+ *     to the first character that wasn't explicitly matched.
+ * @param flags Flags given to fnmatch().
+ * @return True if the entire subpattern matched. False otherwise.
+ */
+static bool _partial_match(const char **pattern, const char **string, int flags)
+{
+	/* Only a single *-delimited subpattern is matched here.
+	 * So in this function, '*' is understood as the end of pattern.
+	 */
+
+	const bool pathname = (flags & FNM_PATHNAME) != 0;
+	const bool special_period = (flags & FNM_PERIOD) != 0;
+	const bool noescape = (flags & FNM_NOESCAPE) != 0;
+	const bool leading_dir = (flags & FNM_LEADING_DIR) != 0;
+
+	const char *s = *string;
+	const char *p = *pattern;
+
+	while (*p != '*') {
+		/* Bracket expression. */
+		if (*p == '[') {
+			int matched = _match_bracket_expr(&p, s, flags);
+			if (matched == 0) {
+				/* Doesn't match. */
+				return false;
+			}
+			if (matched != INVALID_PATTERN) {
+				s += matched;
+				continue;
+			}
+
+			assert(matched == INVALID_PATTERN);
+			/* Fall through to match [ as an ordinary character. */
+		}
+
+		/* Wildcard match. */
+		if (*p == '?') {
+			if (*s == '\0') {
+				/* No character to match. */
+				return false;
+			}
+			if (pathname && *s == '/') {
+				/* Slash must be matched explicitly. */
+				return false;
+			}
+			if (special_period && pathname &&
+			    *s == '.' && *(s - 1) == '/') {
+				/* Initial period must be matched explicitly. */
+				return false;
+			}
+			
+			/* None of the above, match anything else. */
+			p++;
+			s++;
+			continue;
+		}
+
+		if (!noescape && *p == '\\') {
+			/* Escaped character. */
+			p++;
+		}
+
+		if (*p == '\0') {
+			/* End of pattern, must match end of string or
+			 * an end of subdirectory name (optional).
+			 */
+
+			if (*s == '\0' || (leading_dir && *s == '/')) {
+				break;
+			}
+
+			return false;
+		}
+
+		if (*p == *s) {
+			/* Exact match. */
+			p++;
+			s++;
+			continue;
+		}
+
+		/* Nothing matched. */
+		return false;
+	}
+
+	/* Entire sub-pattern matched. */
+	
+	/* postconditions */
+	assert(*p == '\0' || *p == '*');
+	assert(*p != '\0' || *s == '\0' || (leading_dir && *s == '/'));
+	
+	*pattern = p;
+	*string = s;
+	return true;
+}
+
+/**
+ * Match string against a pattern.
+ * 
+ * @param pattern Pattern.
+ * @param string String to match.
+ * @param flags Flags given to fnmatch().
+ * @return True if the string matched the pattern, false otherwise.
+ */
+static bool _full_match(const char *pattern, const char *string, int flags)
+{
+	const bool pathname = (flags & FNM_PATHNAME) != 0;
+	const bool special_period = (flags & FNM_PERIOD) != 0;
+	const bool leading_dir = (flags & FNM_LEADING_DIR) != 0;
+
+	if (special_period && *string == '.') {
+		/* Initial dot must be matched by an explicit dot in pattern. */
+		if (*pattern != '.') {
+			return false;
+		}
+		pattern++;
+		string++;
+	}
+
+	if (*pattern != '*') {
+		if (!_partial_match(&pattern, &string, flags)) {
+			/* The initial match must succeed. */
+			return false;
+		}
+	}
+
+	while (*pattern != '\0') {
+		assert(*pattern == '*');
+		pattern++;
+
+		bool matched = false;
+
+		const char *end;
+		if (pathname && special_period &&
+		    *string == '.' && *(string - 1) == '/') {
+			end = string;
+		} else {
+			end = gnu_strchrnul(string, pathname ? '/' : '\0');
+		}
+
+		/* Try to match every possible offset. */
+		while (string <= end) {
+			if (_partial_match(&pattern, &string, flags)) {
+				matched = true;
+				break;
+			}
+			string++;
+		}
+
+		if (matched) {
+			continue;
+		}
+
+		return false;
+	}
+
+	return *string == '\0' || (leading_dir && *string == '/');
+}
+
+/**
+ * Transform the entire string to lowercase.
+ * 
+ * @param s Input string.
+ * @return Newly allocated copy of the input string with all uppercase
+ *     characters folded to their lowercase variants.
+ */
+static char *_casefold(const char *s)
+{
+	assert(s != NULL);
+	char *result = strdup(s);
+	for (char *i = result; *i != '\0'; ++i) {
+		*i = tolower(*i);
+	}
+	return result;
+}
+
+/**
+ * Filename pattern matching.
+ *
+ * @param pattern Pattern to match the string against.
+ * @param string Matched string.
+ * @param flags Flags altering the matching of special characters
+ *     (mainly for dot and slash).
+ * @return Zero if the string matches the pattern, FNM_NOMATCH otherwise.
+ */
+int fnmatch(const char *pattern, const char *string, int flags)
+{
+	assert(pattern != NULL);
+	assert(string != NULL);
+
+	// TODO: don't fold everything in advance, but only when needed
+
+	if ((flags & FNM_CASEFOLD) != 0) {
+		/* Just fold the entire pattern and string. */
+		pattern = _casefold(pattern);
+		string = _casefold(string);
+	}
+
+	bool result = _full_match(pattern, string, flags);
+
+	if ((flags & FNM_CASEFOLD) != 0) {
+		if (pattern) {
+			free((char *) pattern);
+		}
+		if (string) {
+			free((char *) string);
+		}
+	}
+
+	return result ? 0 : FNM_NOMATCH;
+}
+
+// FIXME: put the testcases to the app/tester after fnmatch is included into libc
+
+#if 0
+
+#include <stdio.h>
+
+void __posix_fnmatch_test()
+{
+	int fail = 0;
+
+	#undef assert
+	#define assert(x) { if (x) printf("SUCCESS: "#x"\n"); else { printf("FAILED: "#x"\n"); fail++; } }
+	#define match(s1, s2, flags) assert(fnmatch(s1, s2, flags) == 0)
+	#define nomatch(s1, s2, flags) assert(fnmatch(s1, s2, flags) == FNM_NOMATCH)
+
+	static_assert(FNM_PATHNAME == FNM_FILE_NAME);
+	match("", "", 0);
+	match("*", "hello", 0);
+	match("hello", "hello", 0);
+	match("hello*", "hello", 0);
+	nomatch("hello?", "hello", 0);
+	match("*hello", "prdel hello", 0);
+	match("he[sl]lo", "hello", 0);
+	match("he[sl]lo", "heslo", 0);
+	nomatch("he[sl]lo", "heblo", 0);
+	nomatch("he[^sl]lo", "hello", 0);
+	nomatch("he[^sl]lo", "heslo", 0);
+	match("he[^sl]lo", "heblo", 0);
+	nomatch("he[!sl]lo", "hello", 0);
+	nomatch("he[!sl]lo", "heslo", 0);
+	match("he[!sl]lo", "heblo", 0);
+	match("al*[c-t]a*vis*ta", "alheimer talir jehovista", 0);
+	match("al*[c-t]a*vis*ta", "alfons had jehovista", 0);
+	match("[a-ce-z]", "a", 0);
+	match("[a-ce-z]", "c", 0);
+	nomatch("[a-ce-z]", "d", 0);
+	match("[a-ce-z]", "e", 0);
+	match("[a-ce-z]", "z", 0);
+	nomatch("[^a-ce-z]", "a", 0);
+	nomatch("[^a-ce-z]", "c", 0);
+	match("[^a-ce-z]", "d", 0);
+	nomatch("[^a-ce-z]", "e", 0);
+	nomatch("[^a-ce-z]", "z", 0);
+	match("helen??", "helenos", 0);
+	match("****booo****", "booo", 0);
+	
+	match("hello[[:space:]]world", "hello world", 0);
+	nomatch("hello[[:alpha:]]world", "hello world", 0);
+	
+	match("/hoooo*", "/hooooooo/hooo", 0);
+	nomatch("/hoooo*", "/hooooooo/hooo", FNM_PATHNAME);
+	nomatch("/hoooo*/", "/hooooooo/hooo", FNM_PATHNAME);
+	match("/hoooo*/*", "/hooooooo/hooo", FNM_PATHNAME);
+	match("/hoooo*/hooo", "/hooooooo/hooo", FNM_PATHNAME);
+	match("/hoooo*", "/hooooooo/hooo", FNM_PATHNAME | FNM_LEADING_DIR);
+	nomatch("/hoooo*/", "/hooooooo/hooo", FNM_PATHNAME | FNM_LEADING_DIR);
+	nomatch("/hoooo", "/hooooooo/hooo", FNM_LEADING_DIR);
+	match("/hooooooo", "/hooooooo/hooo", FNM_LEADING_DIR);
+	
+	match("*", "hell", 0);
+	match("*?", "hell", 0);
+	match("?*?", "hell", 0);
+	match("?*??", "hell", 0);
+	match("??*??", "hell", 0);
+	nomatch("???*??", "hell", 0);
+	
+	nomatch("", "hell", 0);
+	nomatch("?", "hell", 0);
+	nomatch("??", "hell", 0);
+	nomatch("???", "hell", 0);
+	match("????", "hell", 0);
+	
+	match("*", "h.ello", FNM_PERIOD);
+	match("*", "h.ello", FNM_PATHNAME | FNM_PERIOD);
+	nomatch("*", ".hello", FNM_PERIOD);
+	match("h?ello", "h.ello", FNM_PERIOD);
+	nomatch("?hello", ".hello", FNM_PERIOD);
+	match("/home/user/.*", "/home/user/.hello", FNM_PATHNAME | FNM_PERIOD);
+	match("/home/user/*", "/home/user/.hello", FNM_PERIOD);
+	nomatch("/home/user/*", "/home/user/.hello", FNM_PATHNAME | FNM_PERIOD);
+
+	nomatch("HeLlO", "hello", 0);
+	match("HeLlO", "hello", FNM_CASEFOLD);
+
+	printf("Failed: %d\n", fail);
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/posix/src/internal/common.h
===================================================================
--- uspace/lib/posix/src/internal/common.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/internal/common.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,71 @@
+/*
+ * 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 Helper definitions common for all libposix files.
+ */
+
+#ifndef LIBPOSIX_COMMON_H_
+#define LIBPOSIX_COMMON_H_
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <offset.h>
+#include <vfs/vfs.h>
+
+#define not_implemented() do { \
+		static int __not_implemented_counter = 0; \
+		if (__not_implemented_counter == 0) { \
+			fprintf(stderr, "%s() not implemented in %s:%d, something will NOT work.\n", \
+				__func__, __FILE__, __LINE__); \
+		} \
+		__not_implemented_counter++; \
+	} while (0)
+
+// Just a marker for external tools.
+#define _HIDE_LIBC_SYMBOL(symbol)
+
+/* 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];
+
+#endif /* LIBPOSIX_COMMON_H_ */
+
+/** @}
+ */
Index: uspace/lib/posix/src/locale.c
===================================================================
--- uspace/lib/posix/src/locale.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/locale.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,182 @@
+/*
+ * 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 Locale-specific definitions.
+ */
+
+#include "internal/common.h"
+#include "posix/locale.h"
+
+#include <errno.h>
+
+#include "posix/limits.h"
+#include "posix/string.h"
+
+/* Just a very basic dummy implementation.
+ * This should allow code using locales to work properly, but doesn't provide
+ * any localization functionality.
+ * Should be extended/rewritten when or if HelenOS supports locales natively.
+ */
+
+struct __posix_locale {
+	int _dummy;
+};
+
+const struct lconv C_LOCALE = {
+	.currency_symbol = (char *) "",
+	.decimal_point = (char *) ".",
+	.frac_digits = CHAR_MAX,
+	.grouping = (char *) "",
+	.int_curr_symbol = (char *) "",
+	.int_frac_digits = CHAR_MAX,
+	.int_n_cs_precedes = CHAR_MAX,
+	.int_n_sep_by_space = CHAR_MAX,
+	.int_n_sign_posn = CHAR_MAX,
+	.int_p_cs_precedes = CHAR_MAX,
+	.int_p_sep_by_space = CHAR_MAX,
+	.int_p_sign_posn = CHAR_MAX,
+	.mon_decimal_point = (char *) "",
+	.mon_grouping = (char *) "",
+	.mon_thousands_sep = (char *) "",
+	.negative_sign = (char *) "",
+	.n_cs_precedes = CHAR_MAX,
+	.n_sep_by_space = CHAR_MAX,
+	.n_sign_posn = CHAR_MAX,
+	.positive_sign = (char *) "",
+	.p_cs_precedes = CHAR_MAX,
+	.p_sep_by_space = CHAR_MAX,
+	.p_sign_posn = CHAR_MAX,
+	.thousands_sep = (char *) ""
+};
+
+/**
+ * Set program locale.
+ * 
+ * @param category What category to set.
+ * @param locale Locale name.
+ * @return Original locale name on success, NULL on failure.
+ */
+char *setlocale(int category, const char *locale)
+{
+	// TODO
+	if (locale == NULL || *locale == '\0' ||
+	    strcmp(locale, "C") == 0) {
+		return (char *) "C";
+	}
+	return NULL;
+}
+
+/**
+ * Return locale-specific information.
+ * 
+ * @return Information about the current locale.
+ */
+struct lconv *localeconv(void)
+{
+	// TODO
+	return (struct lconv *) &C_LOCALE;
+}
+
+/**
+ * Duplicate locale object.
+ * 
+ * @param locobj Object to duplicate.
+ * @return Duplicated object.
+ */
+locale_t duplocale(locale_t locobj)
+{
+	if (locobj == NULL) {
+		errno = EINVAL;
+		return NULL;
+	}
+	locale_t copy = malloc(sizeof(struct __posix_locale));
+	if (copy == NULL) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	memcpy(copy, locobj, sizeof(struct __posix_locale));
+	return copy;
+}
+
+/**
+ * Free locale object.
+ * 
+ * @param locobj Object to free.
+ */
+void freelocale(locale_t locobj)
+{
+	if (locobj) {
+		free(locobj);
+	}
+}
+
+/**
+ * Create or modify a locale object.
+ * 
+ * @param category_mask Mask of categories to be set or modified.
+ * @param locale Locale to be used.
+ * @param base Object to modify. 0 if new object is to be created.
+ * @return The new/modified locale object.
+ */
+locale_t newlocale(int category_mask, const char *locale,
+    locale_t base)
+{
+	if (locale == NULL ||
+	    (category_mask & LC_ALL_MASK) != category_mask) {
+		errno = EINVAL;
+		return NULL;
+	}
+	// TODO
+	locale_t new = malloc(sizeof(struct __posix_locale));
+	if (new == NULL) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	if (base != NULL) {
+		freelocale(base);
+	}
+	return new;
+}
+
+/**
+ * Set locale for the current thread.
+ * 
+ * @param newloc Locale to use.
+ * @return The previously set locale or LC_GLOBAL_LOCALE
+ */
+locale_t uselocale(locale_t newloc)
+{
+	// TODO
+	return LC_GLOBAL_LOCALE;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/pthread/condvar.c
===================================================================
--- uspace/lib/posix/src/pthread/condvar.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/pthread/condvar.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,93 @@
+/*
+ * Copyright (c) 2013 Vojtech Horky
+ * 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 Pthread: condition variables.
+ */
+
+#include "posix/pthread.h"
+#include "errno.h"
+#include "../internal/common.h"
+
+int pthread_cond_init(pthread_cond_t *restrict condvar,
+    const pthread_condattr_t *restrict attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_cond_destroy(pthread_cond_t *condvar)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_cond_broadcast(pthread_cond_t *condvar)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_cond_signal(pthread_cond_t *condvar)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_cond_timedwait(pthread_cond_t *restrict condvar,
+    pthread_mutex_t *restrict mutex, const struct timespec *restrict timeout)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_cond_wait(pthread_cond_t *restrict condvar,
+    pthread_mutex_t *restrict mutex)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+
+int pthread_condattr_init(pthread_condattr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_condattr_destroy(pthread_condattr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+
+/** @}
+ */
Index: uspace/lib/posix/src/pthread/keys.c
===================================================================
--- uspace/lib/posix/src/pthread/keys.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/pthread/keys.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,66 @@
+/*
+ * Copyright (c) 2013 Vojtech Horky
+ * 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 Pthread: keys and thread-specific storage.
+ */
+
+#include "posix/stdlib.h"
+#include "posix/pthread.h"
+#include <errno.h>
+#include "../internal/common.h"
+
+
+void *pthread_getspecific(pthread_key_t key)
+{
+	not_implemented();
+	return NULL;
+}
+
+int pthread_setspecific(pthread_key_t key, const void *data)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_key_delete(pthread_key_t key)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_key_create(pthread_key_t *key, void (*destructor)(void*))
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/pthread/mutex.c
===================================================================
--- uspace/lib/posix/src/pthread/mutex.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/pthread/mutex.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,99 @@
+/*
+ * Copyright (c) 2013 Vojtech Horky
+ * 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 Pthread: mutexes.
+ */
+
+#include "posix/pthread.h"
+#include <errno.h>
+#include "../internal/common.h"
+
+
+int pthread_mutex_init(pthread_mutex_t *restrict mutex,
+    const pthread_mutexattr_t *restrict attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutex_destroy(pthread_mutex_t *mutex)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutex_lock(pthread_mutex_t *mutex)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutex_trylock(pthread_mutex_t *mutex)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutex_unlock(pthread_mutex_t *mutex)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutexattr_init(pthread_mutexattr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutexattr_destroy(pthread_mutexattr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutexattr_gettype(const pthread_mutexattr_t *restrict attr,
+    int *restrict type)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_mutexattr_settype(pthread_mutexattr_t *attr, int type)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+
+
+/** @}
+ */
Index: uspace/lib/posix/src/pthread/threads.c
===================================================================
--- uspace/lib/posix/src/pthread/threads.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/pthread/threads.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,83 @@
+/*
+ * Copyright (c) 2013 Vojtech Horky
+ * 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 Pthread: thread management.
+ */
+
+#include "posix/pthread.h"
+#include "errno.h"
+#include "posix/stdlib.h"
+#include "libc/thread.h"
+#include "../internal/common.h"
+
+pthread_t pthread_self(void)
+{
+	return thread_get_id();
+}
+
+int pthread_equal(pthread_t thread1, pthread_t thread2)
+{
+	return thread1 == thread2;
+}
+
+int pthread_create(pthread_t *thread_id, const pthread_attr_t *attributes,
+    void *(*start_routine)(void *), void *arg)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_join(pthread_t thread, void **ret_val)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_detach(pthread_t thread)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_attr_init(pthread_attr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+int pthread_attr_destroy(pthread_attr_t *attr)
+{
+	not_implemented();
+	return ENOTSUP;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/pwd.c
===================================================================
--- uspace/lib/posix/src/pwd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/pwd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,189 @@
+/*
+ * 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 Password handling.
+ */
+
+#include "libc/stdbool.h"
+#include "posix/pwd.h"
+#include "posix/string.h"
+#include <errno.h>
+#include <assert.h>
+
+static bool entry_read = false;
+
+/* dummy user account */
+static const struct passwd dummy_pwd = {
+	.pw_name = (char *) "user",
+	.pw_uid = 0,
+	.pw_gid = 0,
+	.pw_dir = (char *) "/",
+	.pw_shell = (char *) "/app/bdsh"
+};
+
+/**
+ * Retrieve next broken-down entry from the user database.
+ *
+ * Since HelenOS doesn't have user accounts, this always returns
+ * the same made-up entry.
+ *
+ * @return Next user database entry or NULL if not possible. Since HelenOS
+ *     doesn't have user accounts, this always returns the same made-up entry.
+ */
+struct passwd *getpwent(void)
+{
+	if (entry_read) {
+		return NULL;
+	}
+
+	entry_read = true;
+	return (struct passwd *) &dummy_pwd;
+}
+
+/**
+ * Rewind the user list.
+ */
+void setpwent(void)
+{
+	entry_read = false;
+}
+
+/**
+ * Ends enumerating and releases all resources. (Noop)
+ */
+void endpwent(void)
+{
+	/* noop */
+}
+
+/**
+ * Find an entry by name.
+ *
+ * @param name Name of the entry.
+ * @return Either found entry or NULL if no such entry exists.
+ */
+struct passwd *getpwnam(const char *name)
+{
+	assert(name != NULL);
+
+	if (strcmp(name, "user") != 0) {
+		return NULL;
+	}
+
+	return (struct passwd *) &dummy_pwd;
+}
+
+/**
+ * Find an entry by name, thread safely.
+ *
+ * @param name Name of the entry.
+ * @param pwd Original structure.
+ * @param buffer Buffer for the strings referenced from the result structure.
+ * @param bufsize Length of the buffer.
+ * @param result Where to store updated structure.
+ * @return Zero on success (either found or not found, but without an error),
+ *     non-zero error number if error occured.
+ */
+int getpwnam_r(const char *name, struct passwd *pwd,
+    char *buffer, size_t bufsize, struct passwd **result)
+{
+	assert(name != NULL);
+	assert(pwd != NULL);
+	assert(buffer != NULL);
+	assert(result != NULL);
+	
+	if (strcmp(name, "user") != 0) {
+		*result = NULL;
+		return 0;
+	}
+	
+	return getpwuid_r(0, pwd, buffer, bufsize, result);
+}
+
+/**
+ * Find an entry by UID.
+ *
+ * @param uid UID of the entry.
+ * @return Either found entry or NULL if no such entry exists.
+ */
+struct passwd *getpwuid(uid_t uid)
+{
+	if (uid != 0) {
+		return NULL;
+	}
+
+	return (struct passwd *) &dummy_pwd;
+}
+
+/**
+ * Find an entry by UID, thread safely.
+ *
+ * @param uid UID of the entry.
+ * @param pwd Original structure.
+ * @param buffer Buffer for the strings referenced from the result structure.
+ * @param bufsize Length of the buffer.
+ * @param result Where to store updated structure.
+ * @return Zero on success (either found or not found, but without an error),
+ *     non-zero error number if error occured.
+ */
+int getpwuid_r(uid_t uid, struct passwd *pwd,
+    char *buffer, size_t bufsize, struct passwd **result)
+{
+	assert(pwd != NULL);
+	assert(buffer != NULL);
+	assert(result != NULL);
+	
+	static const char bf[] = { 'u', 's', 'e', 'r', '\0',
+	    '/', '\0', 'b', 'd', 's', 'h', '\0' };
+	
+	if (uid != 0) {
+		*result = NULL;
+		return 0;
+	}
+	if (bufsize < sizeof(bf)) {
+		*result = NULL;
+		return ERANGE;
+	}
+
+	memcpy(buffer, bf, sizeof(bf));
+
+	pwd->pw_name = (char *) bf;
+	pwd->pw_uid = 0;
+	pwd->pw_gid = 0;
+	pwd->pw_dir = (char *) bf + 5;
+	pwd->pw_shell = (char *) bf + 7;
+	*result = (struct passwd *) pwd;
+
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/signal.c
===================================================================
--- uspace/lib/posix/src/signal.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/signal.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,565 @@
+/*
+ * 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 Signal handling.
+ */
+
+#include "posix/signal.h"
+#include "internal/common.h"
+#include "posix/limits.h"
+#include "posix/stdlib.h"
+#include "posix/string.h"
+
+#include <errno.h>
+
+#include "libc/fibril_synch.h"
+#include "libc/task.h"
+
+/* This file implements a fairly dumb and incomplete "simulation" of
+ * POSIX signals. Since HelenOS doesn't support signals and mostly doesn't
+ * have any equivalent functionality, most of the signals are useless. The
+ * main purpose of this implementation is thus to help port applications using
+ * signals with minimal modification, but if the application uses signals for
+ * anything non-trivial, it's quite probable it won't work properly even if
+ * it builds without problems.
+ */
+
+/* Used to serialize signal handling. */
+static FIBRIL_MUTEX_INITIALIZE(_signal_mutex);
+
+static LIST_INITIALIZE(_signal_queue);
+
+static sigset_t _signal_mask = 0;
+
+#define DEFAULT_HANDLER { .sa_handler = SIG_DFL, \
+    .sa_mask = 0, .sa_flags = 0, .sa_sigaction = NULL }
+
+/* Actions associated with each signal number. */
+static struct sigaction _signal_actions[_TOP_SIGNAL + 1] = {
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, 
+	DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER, DEFAULT_HANDLER
+};
+
+/**
+ * Default signal handler. Executes the default action for each signal,
+ * as reasonable within HelenOS.
+ *
+ * @param signo Signal number.
+ */
+void __posix_default_signal_handler(int signo)
+{
+	switch (signo) {
+	case SIGABRT:
+		abort();
+	case SIGQUIT:
+		fprintf(stderr, "Quit signal raised. Exiting.\n");
+		exit(EXIT_FAILURE);
+	case SIGINT:
+		fprintf(stderr, "Interrupt signal caught. Exiting.\n");
+		exit(EXIT_FAILURE);
+	case SIGTERM:
+		fprintf(stderr, "Termination signal caught. Exiting.\n");
+		exit(EXIT_FAILURE);
+	case SIGSTOP:
+		fprintf(stderr, "Stop signal caught, but unsupported. Ignoring.\n");
+		break;
+	case SIGKILL:
+		/* This will only occur when raise or similar is called. */
+		/* Commit suicide. */
+		task_kill(task_get_id());
+		
+		/* Should not be reached. */
+		abort();
+	case SIGFPE:
+	case SIGBUS:
+	case SIGILL:
+	case SIGSEGV:
+		psignal(signo, "Hardware exception raised by user code");
+		abort();
+	case SIGSYS:
+	case SIGXCPU:
+	case SIGXFSZ:
+	case SIGTRAP:
+	case SIGHUP:
+	case SIGPIPE:
+	case SIGPOLL:
+	case SIGURG:
+	case SIGTSTP:
+	case SIGTTIN:
+	case SIGTTOU:
+		psignal(signo, "Unsupported signal caught");
+		abort();
+	case SIGCHLD:
+	case SIGUSR1:
+	case SIGUSR2:
+	case SIGALRM:
+	case SIGVTALRM:
+	case SIGPROF:
+	case SIGCONT:
+		/* ignored */
+		break;
+	}
+}
+
+/**
+ * Just an empty function to get an unique pointer value for comparison.
+ *
+ * @param signo Signal number.
+ */
+void __posix_hold_signal_handler(int signo)
+{
+	/* Nothing */
+}
+
+/**
+ * Empty function to be used as ignoring handler.
+ * 
+ * @param signo Signal number.
+ */
+void __posix_ignore_signal_handler(int signo)
+{
+	/* Nothing */
+}
+
+/**
+ * Clear the signal set.
+ * 
+ * @param set Pointer to the signal set.
+ * @return Always returns zero.
+ */
+int sigemptyset(sigset_t *set)
+{
+	assert(set != NULL);
+
+	*set = 0;
+	return 0;
+}
+
+/**
+ * Fill the signal set (i.e. add all signals).
+ * 
+ * @param set Pointer to the signal set.
+ * @return Always returns zero.
+ */
+int sigfillset(sigset_t *set)
+{
+	assert(set != NULL);
+
+	*set = UINT32_MAX;
+	return 0;
+}
+
+/**
+ * Add a signal to the set.
+ * 
+ * @param set Pointer to the signal set.
+ * @param signo Signal number to add.
+ * @return Always returns zero.
+ */
+int sigaddset(sigset_t *set, int signo)
+{
+	assert(set != NULL);
+
+	*set |= (1 << signo);
+	return 0;
+}
+
+/**
+ * Delete a signal from the set.
+ * 
+ * @param set Pointer to the signal set.
+ * @param signo Signal number to remove.
+ * @return Always returns zero.
+ */
+int sigdelset(sigset_t *set, int signo)
+{
+	assert(set != NULL);
+
+	*set &= ~(1 << signo);
+	return 0;
+}
+
+/**
+ * Inclusion test for a signal set.
+ * 
+ * @param set Pointer to the signal set.
+ * @param signo Signal number to query.
+ * @return 1 if the signal is in the set, 0 otherwise.
+ */
+int sigismember(const sigset_t *set, int signo)
+{
+	assert(set != NULL);
+	
+	return (*set & (1 << signo)) != 0;
+}
+
+/**
+ * Unsafe variant of the sigaction() function.
+ * Doesn't do any checking of its arguments and
+ * does not deal with thread-safety.
+ * 
+ * @param sig
+ * @param act
+ * @param oact
+ */
+static void _sigaction_unsafe(int sig, const struct sigaction *restrict act,
+    struct sigaction *restrict oact)
+{
+	if (oact != NULL) {
+		memcpy(oact, &_signal_actions[sig],
+		    sizeof(struct sigaction));
+	}
+
+	if (act != NULL) {
+		memcpy(&_signal_actions[sig], act,
+		    sizeof(struct sigaction));
+	}
+}
+
+/**
+ * Sets a new action for the given signal number.
+ * 
+ * @param sig Signal number to set action for.
+ * @param act If not NULL, contents of this structure are
+ *     used as the new action for the signal.
+ * @param oact If not NULL, the original action associated with the signal
+ *     is stored in the structure pointer to. 
+ * @return -1 with errno set on failure, 0 on success.
+ */
+int sigaction(int sig, const struct sigaction *restrict act,
+    struct sigaction *restrict oact)
+{
+	if (sig > _TOP_SIGNAL || (act != NULL &&
+	    (sig == SIGKILL || sig == SIGSTOP))) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (sig > _TOP_CATCHABLE_SIGNAL) {
+		psignal(sig,
+		    "WARNING: registering handler for a partially"
+		    " or fully unsupported signal. This handler may only be"
+		    " invoked by the raise() function, which may not be what"
+		    " the application developer intended");
+	}
+
+	fibril_mutex_lock(&_signal_mutex);
+	_sigaction_unsafe(sig, act, oact);
+	fibril_mutex_unlock(&_signal_mutex);
+
+	return 0;
+}
+
+/**
+ * Sets a new handler for the given signal number.
+ * 
+ * @param sig Signal number to set handler for.
+ * @param func Handler function.
+ * @return SIG_ERR on failure, original handler on success.
+ */
+void (*signal(int sig, void (*func)(int)))(int)
+{
+	struct sigaction new = {
+		.sa_handler = func,
+		.sa_mask = 0,
+		.sa_flags = 0,
+		.sa_sigaction = NULL
+	};
+	struct sigaction old;
+	if (sigaction(sig, func == NULL ? NULL : &new, &old) == 0) {
+		return old.sa_handler;
+	} else {
+		return SIG_ERR;
+	}
+}
+
+typedef struct {
+	link_t link;
+	int signo;
+	siginfo_t siginfo;
+} signal_queue_item;
+
+/**
+ * Queue blocked signal.
+ *
+ * @param signo Signal number.
+ * @param siginfo Additional information about the signal.
+ */
+static void _queue_signal(int signo, siginfo_t *siginfo)
+{
+	assert(signo >= 0 && signo <= _TOP_SIGNAL);
+	assert(siginfo != NULL);
+	
+	signal_queue_item *item = malloc(sizeof(signal_queue_item));
+	link_initialize(&(item->link));
+	item->signo = signo;
+	memcpy(&item->siginfo, siginfo, sizeof(siginfo_t));
+	list_append(&(item->link), &_signal_queue);
+}
+
+
+/**
+ * Executes an action associated with the given signal.
+ *
+ * @param signo Signal number.
+ * @param siginfo Additional information about the circumstances of this raise.
+ * @return 0 if the action has been successfully executed. -1 if the signal is
+ *     blocked.
+ */
+static int _raise_sigaction(int signo, siginfo_t *siginfo)
+{
+	assert(signo >= 0 && signo <= _TOP_SIGNAL);
+	assert(siginfo != NULL);
+
+	fibril_mutex_lock(&_signal_mutex);
+
+	struct sigaction action = _signal_actions[signo];
+
+	if (sigismember(&_signal_mask, signo) ||
+	    action.sa_handler == SIG_HOLD) {
+		_queue_signal(signo, siginfo);
+		fibril_mutex_unlock(&_signal_mutex);
+		return -1;
+	}
+
+	/* Modifying signal mask is unnecessary,
+	 * signal handling is serialized.
+	 */
+
+	if ((action.sa_flags & SA_RESETHAND) && signo != SIGILL && signo != SIGTRAP) {
+		_signal_actions[signo] = (struct sigaction) DEFAULT_HANDLER;
+	}
+
+	if (action.sa_flags & SA_SIGINFO) {
+		assert(action.sa_sigaction != NULL);
+		action.sa_sigaction(signo, siginfo, NULL);
+	} else {
+		assert(action.sa_handler != NULL);
+		action.sa_handler(signo);
+	}
+
+	fibril_mutex_unlock(&_signal_mutex);
+
+	return 0;
+}
+
+/**
+ * Raise all unblocked previously queued signals.
+ */
+static void _dequeue_unblocked_signals(void)
+{
+	link_t *iterator = _signal_queue.head.next;
+	link_t *next;
+	
+	while (iterator != &(_signal_queue).head) {
+		next = iterator->next;
+		
+		signal_queue_item *item =
+		    list_get_instance(iterator, signal_queue_item, link);
+		
+		if (!sigismember(&_signal_mask, item->signo) &&
+		    _signal_actions[item->signo].sa_handler != SIG_HOLD) {
+			list_remove(&(item->link));
+			_raise_sigaction(item->signo, &(item->siginfo));
+			free(item);
+		}
+		
+		iterator = next;
+	}
+}
+
+/**
+ * Raise a signal for the calling process.
+ * 
+ * @param sig Signal number.
+ * @return -1 with errno set on failure, 0 on success.
+ */
+int raise(int sig)
+{
+	if (sig >= 0 && sig <= _TOP_SIGNAL) {
+		siginfo_t siginfo = {
+			.si_signo = sig,
+			.si_code = SI_USER
+		};
+		return _raise_sigaction(sig, &siginfo);
+	} else {
+		errno = EINVAL;
+		return -1;
+	}
+}
+
+/**
+ * Raises a signal for a selected process.
+ * 
+ * @param pid PID of the process for which the signal shall be raised.
+ * @param signo Signal to raise.
+ * @return -1 with errno set on failure (possible errors include unsupported
+ *     action, invalid signal number, lack of permissions, etc.), 0 on success.
+ */
+int kill(pid_t pid, int signo)
+{
+	if (pid < 1) {
+		// TODO
+		errno = ENOTSUP;
+		return -1;
+	}
+
+	if (signo > _TOP_SIGNAL) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	if (pid == (pid_t) task_get_id()) {
+		return raise(signo);
+	}
+
+	switch (signo) {
+	case SIGKILL:
+		task_kill(pid);
+		break;
+	default:
+		/* Nothing else supported yet. */
+		errno = ENOTSUP;
+		return -1;
+	}
+
+	return 0;
+}
+
+/**
+ * Send a signal to a process group. Always fails at the moment because of
+ * lack of this functionality in HelenOS.
+ * 
+ * @param pid PID of the process group.
+ * @param sig Signal number.
+ * @return -1 on failure, 0 on success (see kill()).
+ */
+int killpg(pid_t pid, int sig)
+{
+	assert(pid > 1);
+	return kill(-pid, sig);
+}
+
+/**
+ * Outputs information about the signal to the standard error stream.
+ * 
+ * @param pinfo SigInfo struct to write.
+ * @param message String to output alongside human-readable signal description.
+ */
+void psiginfo(const siginfo_t *pinfo, const char *message)
+{
+	assert(pinfo != NULL);
+	psignal(pinfo->si_signo, message);
+	// TODO: print si_code
+}
+
+/**
+ * Outputs information about the signal to the standard error stream.
+ * 
+ * @param signum Signal number.
+ * @param message String to output alongside human-readable signal description.
+ */
+void psignal(int signum, const char *message)
+{
+	char *sigmsg = strsignal(signum);
+	if (message == NULL || *message == '\0') {
+		fprintf(stderr, "%s\n", sigmsg);
+	} else {
+		fprintf(stderr, "%s: %s\n", message, sigmsg);
+	}
+}
+
+/**
+ * Manipulate the signal mask of the calling thread.
+ * 
+ * @param how What to do with the mask.
+ * @param set Signal set to work with.
+ * @param oset If not NULL, the original signal mask is coppied here.
+ * @return 0 success, errorcode on failure.
+ */
+int thread_sigmask(int how, const sigset_t *restrict set,
+    sigset_t *restrict oset)
+{
+	fibril_mutex_lock(&_signal_mutex);
+
+	if (oset != NULL) {
+		*oset = _signal_mask;
+	}
+	if (set != NULL) {
+		switch (how) {
+		case SIG_BLOCK:
+			_signal_mask |= *set;
+			break;
+		case SIG_UNBLOCK:
+			_signal_mask &= ~*set;
+			break;
+		case SIG_SETMASK:
+			_signal_mask = *set;
+			break;
+		default:
+			fibril_mutex_unlock(&_signal_mutex);
+			return EINVAL;
+		}
+	}
+	
+	_dequeue_unblocked_signals();
+
+	fibril_mutex_unlock(&_signal_mutex);
+
+	return 0;
+}
+
+/**
+ * Manipulate the signal mask of the process.
+ * 
+ * @param how What to do with the mask.
+ * @param set Signal set to work with.
+ * @param oset If not NULL, the original signal mask is coppied here.
+ * @return 0 on success, -1 with errno set on failure.
+ */
+int sigprocmask(int how, const sigset_t *restrict set,
+    sigset_t *restrict oset)
+{
+	int result = thread_sigmask(how, set, oset);
+	if (result != 0) {
+		errno = result;
+		return -1;
+	}
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/stdio.c
===================================================================
--- uspace/lib/posix/src/stdio.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/stdio.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,594 @@
+/*
+ * Copyright (c) 2011 Jiri Zarevucky
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Standard buffered input/output.
+ */
+
+#include "internal/common.h"
+#include "posix/stdio.h"
+
+#include <assert.h>
+
+#include <errno.h>
+
+#include "posix/stdlib.h"
+#include "posix/string.h"
+#include "posix/sys/types.h"
+#include "posix/unistd.h"
+
+#include "libc/stdio.h"
+#include "libc/io/printf_core.h"
+#include "libc/str.h"
+#include "libc/malloc.h"
+#include "libc/adt/list.h"
+
+/**
+ * Generate a pathname for the controlling terminal.
+ *
+ * @param s Allocated buffer to which the pathname shall be put.
+ * @return Either s or static location filled with the requested pathname.
+ */
+char *ctermid(char *s)
+{
+	/* Currently always returns an error value (empty string). */
+	// TODO: return a real terminal path
+
+	static char dummy_path[L_ctermid] = {'\0'};
+
+	if (s == NULL) {
+		return dummy_path;
+	}
+
+	s[0] = '\0';
+	return s;
+}
+
+/**
+ * Read a stream until the delimiter (or EOF) is encountered.
+ *
+ * @param lineptr Pointer to the output buffer in which there will be stored
+ *     nul-terminated string together with the delimiter (if encountered).
+ *     Will be resized if necessary.
+ * @param n Pointer to the size of the output buffer. Will be increased if
+ *     necessary.
+ * @param delimiter Delimiter on which to finish reading the stream.
+ * @param stream Input stream.
+ * @return Number of fetched characters (including delimiter if encountered)
+ *     or -1 on error (set in errno).
+ */
+ssize_t getdelim(char **restrict lineptr, size_t *restrict n,
+    int delimiter, FILE *restrict stream)
+{
+	/* Check arguments for sanity. */
+	if (!lineptr || !n) {
+		errno = EINVAL;
+		return -1;
+	}
+
+	size_t alloc_step = 80; /* Buffer size gain during reallocation. */
+	char *pos = *lineptr; /* Next free byte of the output buffer. */
+	size_t cnt = 0; /* Number of fetched characters. */
+	int c = fgetc(stream); /* Current input character. Might be EOF. */
+
+	do {
+		/* Mask EOF as NUL to terminate string. */
+		if (c == EOF) {
+			c = '\0';
+		}
+
+		/* Ensure there is still space left in the buffer. */
+		if (pos == *lineptr + *n) {
+			*lineptr = realloc(*lineptr, *n + alloc_step);
+			if (*lineptr) {
+				pos = *lineptr + *n;
+				*n += alloc_step;
+			} else {
+				errno = ENOMEM;
+				return -1;
+			}
+		}
+
+		/* Store the fetched character. */
+		*pos = c;
+
+		/* Fetch the next character according to the current character. */
+		if (c != '\0') {
+			++pos;
+			++cnt;
+			if (c == delimiter) {
+				/* Delimiter was just stored. Provide EOF as the next
+				 * character - it will be masked as NUL and output string
+				 * will be properly terminated. */
+				c = EOF;
+			} else {
+				/* Neither delimiter nor EOF were encountered. Just fetch
+				 * the next character from the stream. */
+				c = fgetc(stream);
+			}
+		}
+	} while (c != '\0');
+
+	if (errno == EOK && cnt > 0) {
+		return cnt;
+	} else {
+		/* Either some error occured or the stream was already at EOF. */
+		return -1;
+	}
+}
+
+/**
+ * Read a stream until the newline (or EOF) is encountered.
+ * 
+ * @param lineptr Pointer to the output buffer in which there will be stored
+ *     nul-terminated string together with the delimiter (if encountered).
+ *     Will be resized if necessary.
+ * @param n Pointer to the size of the output buffer. Will be increased if
+ *     necessary.
+ * @param stream Input stream.
+ * @return Number of fetched characters (including newline if encountered)
+ *     or -1 on error (set in errno).
+ */
+ssize_t getline(char **restrict lineptr, size_t *restrict n,
+    FILE *restrict stream)
+{
+	return getdelim(lineptr, n, '\n', stream);
+}
+
+/**
+ * Write error messages to standard error.
+ *
+ * @param s Error message.
+ */
+void perror(const char *s)
+{
+	if (s == NULL || s[0] == '\0') {
+		fprintf(stderr, "%s\n", strerror(errno));
+	} else {
+		fprintf(stderr, "%s: %s\n", s, strerror(errno));
+	}
+}
+
+/** Restores stream a to position previously saved with fgetpos().
+ *
+ * @param stream Stream to restore
+ * @param pos Position to restore
+ * @return Zero on success, non-zero (with errno set) on failure
+ */
+int fsetpos(FILE *stream, const fpos_t *pos)
+{
+	return fseek64(stream, pos->offset, SEEK_SET);
+}
+
+/** Saves the stream's position for later use by fsetpos().
+ *
+ * @param stream Stream to save
+ * @param pos Place to store the position
+ * @return Zero on success, non-zero (with errno set) on failure
+ */
+int fgetpos(FILE *restrict stream, fpos_t *restrict pos)
+{
+	off64_t ret = ftell64(stream);
+	if (ret != -1) {
+		pos->offset = ret;
+		return 0;
+	} else {
+		return -1;
+	}
+}
+
+/**
+ * Reposition a file-position indicator in a stream.
+ * 
+ * @param stream Stream to seek in.
+ * @param offset Direction and amount of bytes to seek.
+ * @param whence From where to seek.
+ * @return Zero on success, -1 otherwise.
+ */
+int fseeko(FILE *stream, off_t offset, int whence)
+{
+	return fseek64(stream, offset, whence);
+}
+
+/**
+ * Discover current file offset in a stream.
+ * 
+ * @param stream Stream for which the offset shall be retrieved.
+ * @return Current offset or -1 if not possible.
+ */
+off_t ftello(FILE *stream)
+{
+	return ftell64(stream);
+}
+
+/**
+ * Print formatted output to the opened file.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @param format Format description.
+ * @return Either the number of printed characters or negative value on error.
+ */
+int dprintf(int fildes, const char *restrict format, ...)
+{
+	va_list list;
+	va_start(list, format);
+	int result = vdprintf(fildes, format, list);
+	va_end(list);
+	return result;
+}
+
+/**
+ * Write ordinary string to the opened file.
+ *
+ * @param str String to be written.
+ * @param size Size of the string (in bytes)..
+ * @param fd File descriptor of the opened file.
+ * @return The number of written characters.
+ */
+static int _dprintf_str_write(const char *str, size_t size, void *fd)
+{
+	const int fildes = *(int *) fd;
+	size_t wr;
+	if (failed(vfs_write(fildes, &posix_pos[fildes], str, size, &wr)))
+		return -1;
+	return str_nlength(str, wr);
+}
+
+/**
+ * Write wide string to the opened file.
+ * 
+ * @param str String to be written.
+ * @param size Size of the string (in bytes).
+ * @param fd File descriptor of the opened file.
+ * @return The number of written characters.
+ */
+static int _dprintf_wstr_write(const wchar_t *str, size_t size, void *fd)
+{
+	size_t offset = 0;
+	size_t chars = 0;
+	size_t sz;
+	char buf[4];
+	
+	while (offset < size) {
+		sz = 0;
+		if (chr_encode(str[chars], buf, &sz, sizeof(buf)) != EOK) {
+			break;
+		}
+		
+		const int fildes = *(int *) fd;
+		size_t nwr;
+		if (vfs_write(fildes, &posix_pos[fildes], buf, sz, &nwr) != EOK)
+			break;
+		
+		chars++;
+		offset += sizeof(wchar_t);
+	}
+	
+	return chars;
+}
+
+/**
+ * Print formatted output to the opened file.
+ * 
+ * @param fildes File descriptor of the opened file.
+ * @param format Format description.
+ * @param ap Print arguments.
+ * @return Either the number of printed characters or negative value on error.
+ */
+int vdprintf(int fildes, const char *restrict format, va_list ap)
+{
+	printf_spec_t spec = {
+		.str_write = _dprintf_str_write,
+		.wstr_write = _dprintf_wstr_write,
+		.data = &fildes
+	};
+	
+	return printf_core(format, &spec, ap);
+}
+
+/**
+ * Print formatted output to the string.
+ * 
+ * @param s Output string.
+ * @param format Format description.
+ * @return Either the number of printed characters (excluding null byte) or
+ *     negative value on error.
+ */
+int sprintf(char *s, const char *restrict format, ...)
+{
+	va_list list;
+	va_start(list, format);
+	int result = vsprintf(s, format, list);
+	va_end(list);
+	return result;
+}
+
+/**
+ * Print formatted output to the string.
+ * 
+ * @param s Output string.
+ * @param format Format description.
+ * @param ap Print arguments.
+ * @return Either the number of printed characters (excluding null byte) or
+ *     negative value on error.
+ */
+int vsprintf(char *s, const char *restrict format, va_list ap)
+{
+	return vsnprintf(s, STR_NO_LIMIT, format, ap);
+}
+
+/**
+ * Convert formatted input from the stream.
+ * 
+ * @param stream Input stream.
+ * @param format Format description.
+ * @return The number of converted output items or EOF on failure.
+ */
+int fscanf(FILE *restrict stream, const char *restrict format, ...)
+{
+	va_list list;
+	va_start(list, format);
+	int result = vfscanf(stream, format, list);
+	va_end(list);
+	return result;
+}
+
+/**
+ * Convert formatted input from the standard input.
+ * 
+ * @param format Format description.
+ * @return The number of converted output items or EOF on failure.
+ */
+int scanf(const char *restrict format, ...)
+{
+	va_list list;
+	va_start(list, format);
+	int result = vscanf(format, list);
+	va_end(list);
+	return result;
+}
+
+/**
+ * Convert formatted input from the standard input.
+ * 
+ * @param format Format description.
+ * @param arg Output items.
+ * @return The number of converted output items or EOF on failure.
+ */
+int vscanf(const char *restrict format, va_list arg)
+{
+	return vfscanf(stdin, format, arg);
+}
+
+/**
+ * Convert formatted input from the string.
+ * 
+ * @param s Input string.
+ * @param format Format description.
+ * @return The number of converted output items or EOF on failure.
+ */
+int sscanf(const char *restrict s, const char *restrict format, ...)
+{
+	va_list list;
+	va_start(list, format);
+	int result = vsscanf(s, format, list);
+	va_end(list);
+	return result;
+}
+
+/**
+ * Acquire file stream for the thread.
+ *
+ * @param file File stream to lock.
+ */
+void flockfile(FILE *file)
+{
+	/* dummy */
+}
+
+/**
+ * Acquire file stream for the thread (non-blocking).
+ *
+ * @param file File stream to lock.
+ * @return Zero for success and non-zero if the lock cannot be acquired.
+ */
+int ftrylockfile(FILE *file)
+{
+	/* dummy */
+	return 0;
+}
+
+/**
+ * Relinquish the ownership of the locked file stream.
+ *
+ * @param file File stream to unlock.
+ */
+void funlockfile(FILE *file)
+{
+	/* dummy */
+}
+
+/**
+ * Get a byte from a stream (thread-unsafe).
+ *
+ * @param stream Input file stream.
+ * @return Either read byte or EOF.
+ */
+int getc_unlocked(FILE *stream)
+{
+	return getc(stream);
+}
+
+/**
+ * Get a byte from the standard input stream (thread-unsafe).
+ *
+ * @return Either read byte or EOF.
+ */
+int getchar_unlocked(void)
+{
+	return getchar();
+}
+
+/**
+ * Put a byte on a stream (thread-unsafe).
+ *
+ * @param c Byte to output.
+ * @param stream Output file stream.
+ * @return Either written byte or EOF.
+ */
+int putc_unlocked(int c, FILE *stream)
+{
+	return putc(c, stream);
+}
+
+/**
+ * Put a byte on the standard output stream (thread-unsafe).
+ * 
+ * @param c Byte to output.
+ * @return Either written byte or EOF.
+ */
+int putchar_unlocked(int c)
+{
+	return putchar(c);
+}
+
+/**
+ * Get a unique temporary file name (obsolete).
+ *
+ * @param s Buffer for the file name. Must be at least L_tmpnam bytes long.
+ * @return The value of s on success, NULL on failure.
+ */
+char *tmpnam(char *s)
+{
+	assert(L_tmpnam >= strlen("/tmp/tnXXXXXX"));
+	
+	static char buffer[L_tmpnam + 1];
+	if (s == NULL) {
+		s = buffer;
+	}
+	
+	strcpy(s, "/tmp/tnXXXXXX");
+	mktemp(s);
+	
+	if (*s == '\0') {
+		/* Errno set by mktemp(). */
+		return NULL;
+	}
+	
+	return s;
+}
+
+/**
+ * Get an unique temporary file name with additional constraints (obsolete).
+ *
+ * @param dir Path to directory, where the file should be created.
+ * @param pfx Optional prefix up to 5 characters long.
+ * @return Newly allocated unique path for temporary file. NULL on failure.
+ */
+char *tempnam(const char *dir, const char *pfx)
+{
+	/* Sequence number of the filename. */
+	static int seq = 0;
+	
+	size_t dir_len = strlen(dir);
+	if (dir[dir_len - 1] == '/') {
+		dir_len--;
+	}
+	
+	size_t pfx_len = strlen(pfx);
+	if (pfx_len > 5) {
+		pfx_len = 5;
+	}
+	
+	char *result = malloc(dir_len + /* slash*/ 1 +
+	    pfx_len + /* three-digit seq */ 3 + /* .tmp */ 4 + /* nul */ 1);
+	
+	if (result == NULL) {
+		errno = ENOMEM;
+		return NULL;
+	}
+	
+	char *res_ptr = result;
+	strncpy(res_ptr, dir, dir_len);
+	res_ptr += dir_len;
+	strncpy(res_ptr, pfx, pfx_len);
+	res_ptr += pfx_len;
+	
+	for (; seq < 1000; ++seq) {
+		snprintf(res_ptr, 8, "%03d.tmp", seq);
+		
+		int orig_errno = errno;
+		errno = EOK;
+		/* Check if the file exists. */
+		if (access(result, F_OK) == -1) {
+			if (errno == ENOENT) {
+				errno = orig_errno;
+				break;
+			} else {
+				/* errno set by access() */
+				return NULL;
+			}
+		}
+	}
+	
+	if (seq == 1000) {
+		free(result);
+		errno = EINVAL;
+		return NULL;
+	}
+	
+	return result;
+}
+
+/**
+ * Create and open an unique temporary file.
+ * The file is automatically removed when the stream is closed.
+ *
+ * @param dir Path to directory, where the file should be created.
+ * @param pfx Optional prefix up to 5 characters long.
+ * @return Newly allocated unique path for temporary file. NULL on failure.
+ */
+FILE *tmpfile(void)
+{
+	char filename[] = "/tmp/tfXXXXXX";
+	int fd = mkstemp(filename);
+	if (fd == -1) {
+		/* errno set by mkstemp(). */
+		return NULL;
+	}
+	
+	/* Unlink the created file, so that it's removed on close(). */
+	unlink(filename);
+	return fdopen(fd, "w+");
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/stdio/scanf.c
===================================================================
--- uspace/lib/posix/src/stdio/scanf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/stdio/scanf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,1225 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Implementation of the scanf backend.
+ */
+
+#include <assert.h>
+
+#include <errno.h>
+
+#include "posix/stdio.h"
+#include "posix/stdlib.h"
+#include "posix/stddef.h"
+#include "posix/string.h"
+#include "posix/ctype.h"
+#include "posix/sys/types.h"
+
+#include "../internal/common.h"
+#include "libc/malloc.h"
+#include "libc/stdbool.h"
+
+/** Unified data type for possible data sources for scanf. */
+typedef union __data_source {
+	FILE *stream; /**< Input file stream. */
+	const char *string; /**< Input string. */
+} _data_source;
+
+/** Internal state of the input provider. */
+enum {
+	/** Partly constructed but not yet functional. */
+	_PROV_CONSTRUCTED,
+	/** Ready to serve any request. */
+	_PROV_READY,
+	/** Cursor is temporarily lent to the external entity. No action is
+	  * possible until the cursor is returned.  */
+	_PROV_CURSOR_LENT,
+};
+
+/** Universal abstraction over data input for scanf. */
+typedef struct __input_provider {
+	/** Source of data elements. */
+	_data_source source;
+	/** How many elements was already processed. */
+	int consumed;
+	/** How many elements was already fetched from the source. */
+	int fetched;
+	/** Elements are fetched from the source in batches (e.g. by getline())
+	  * to allow using strtol/strtod family even on streams. */
+	char *window;
+	/** Size of the current window. */
+	size_t window_size;
+	/** Points to the next element to be processed inside the current window. */
+	const char *cursor;
+	/** Internal state of the provider. */
+	int state;
+
+	/** Take control over data source. Finish initialization of the internal
+	  * structures (e.g. allocation of window). */
+	void (*capture)(struct __input_provider *);
+	/** Get a single element from the source and update the internal structures
+	  * accordingly (e.g. greedy update of the window). Return -1 if the
+	  * element cannot be obtained. */
+	int (*pop)(struct __input_provider *);
+	/** Undo the most recent not-undone pop operation. Might be necesarry to
+	  * flush current window and seek data source backwards. Return 0 if the
+	  * pop history is exhausted, non-zero on success. */
+	int (*undo)(struct __input_provider *);
+	/** Lend the cursor to the caller.  */
+	const char * (*borrow_cursor)(struct __input_provider *);
+	/** Take control over possibly incremented cursor and update the internal
+	  * structures if necessary. */
+	void (*return_cursor)(struct __input_provider *, const char *);
+	/** Release the control over the source. That is, synchronize any
+	  * fetched but non-consumed elements (e.g. by seeking) and destruct
+	  * internal structures (e.g. window deallocation). */
+	void (*release)(struct __input_provider *);
+} _input_provider;
+
+/** @see __input_provider */
+static void _capture_stream(_input_provider *self)
+{
+	assert(self->source.stream);
+	assert(self->state == _PROV_CONSTRUCTED);
+	/* Caller could already pre-allocated the window. */
+	assert((self->window == NULL && self->window_size == 0) ||
+	    (self->window && self->window_size > 0));
+
+	/* Initialize internal structures. */
+	self->consumed = 0;
+	ssize_t fetched = getline(
+	    &self->window, &self->window_size, self->source.stream);
+	if (fetched != -1) {
+		self->fetched = fetched;
+		self->cursor = self->window;
+	} else {
+		/* EOF encountered. */
+		self->fetched = 0;
+		self->cursor = NULL;
+	}
+	self->state = _PROV_READY;
+}
+
+/** @see __input_provider */
+static void _capture_string(_input_provider *self)
+{
+	assert(self->source.string);
+	assert(self->state == _PROV_CONSTRUCTED);
+
+	/* Initialize internal structures. */
+	self->consumed = 0;
+	self->fetched = strlen(self->source.string);
+	self->window = (char *) self->source.string;
+	self->window_size = self->fetched + 1;
+	self->cursor = self->window;
+	self->state = _PROV_READY;
+}
+
+/** @see __input_provider */
+static int _pop_stream(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	if (self->cursor) {
+		int c = *self->cursor;
+		++self->consumed;
+		++self->cursor;
+		/* Do we need to fetch a new line from the source? */
+		if (*self->cursor == '\0') {
+			ssize_t fetched = getline(&self->window,
+			    &self->window_size, self->source.stream);
+			if (fetched != -1) {
+				self->fetched += fetched;
+				self->cursor = self->window;
+			} else {
+				/* EOF encountered. */
+				self->cursor = NULL;
+			}
+		}
+		return c;
+	} else {
+		/* Already at EOF. */
+		return -1;
+	}
+}
+
+/** @see __input_provider */
+static int _pop_string(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	if (*self->cursor != '\0') {
+		int c = *self->cursor;
+		++self->consumed;
+		++self->cursor;
+		return c;
+	} else {
+		/* String depleted. */
+		return -1;
+	}
+}
+
+/** @see __input_provider */
+static int _undo_stream(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	if (self->consumed == 0) {
+		/* Undo history exhausted. */
+		return 0;
+	}
+
+	if (!self->cursor || self->window == self->cursor) {
+		/* Complex case. Either at EOF (cursor == NULL) or there is no more
+		 * place to retreat to inside the window. Seek the source backwards
+		 * and flush the window. Regarding the scanf, this could happend only
+		 * when matching unbounded string (%s) or unbounded scanset (%[) not
+		 * containing newline, while at the same time newline is the character
+		 * that breaks the matching process. */
+		int rc = fseek(self->source.stream, -1, SEEK_CUR);
+		if (rc == -1) {
+			/* Seek failed.  */
+			return 0;
+		}
+		ssize_t fetched = getline(&self->window,
+		    &self->window_size, self->source.stream);
+		if (fetched != -1) {
+			assert(fetched == 1);
+			self->fetched = self->consumed + 1;
+			self->cursor = self->window;
+		} else {
+			/* Stream is broken. */
+			return 0;
+		}
+	} else {
+		/* Simple case. Still inside window. */
+		--self->cursor;
+	}
+	--self->consumed;
+	return 1; /* Success. */
+}
+
+/** @see __input_provider */
+static int _undo_string(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	if (self->consumed > 0) {
+		--self->consumed;
+		--self->cursor;
+	} else {
+		/* Undo history exhausted. */
+		return 0;
+	}
+	return 1; /* Success. */
+}
+
+/** @see __input_provider */
+static const char *_borrow_cursor_universal(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	self->state = _PROV_CURSOR_LENT;
+	return self->cursor;
+}
+
+/** @see __input_provider */
+static void _return_cursor_stream(_input_provider *self, const char *cursor)
+{
+	assert(self->state == _PROV_CURSOR_LENT);
+
+	/* Check how much of the window did external entity consumed. */
+	self->consumed += cursor - self->cursor;
+	self->cursor = cursor;
+	if (*self->cursor == '\0') {
+		/* Window was completely consumed, fetch new data. */
+		ssize_t fetched = getline(&self->window,
+		    &self->window_size, self->source.stream);
+		if (fetched != -1) {
+			self->fetched += fetched;
+			self->cursor = self->window;
+		} else {
+			/* EOF encountered. */
+			self->cursor = NULL;
+		}
+	}
+	self->state = _PROV_READY;
+}
+
+/** @see __input_provider */
+static void _return_cursor_string(_input_provider *self, const char *cursor)
+{
+	assert(self->state == _PROV_CURSOR_LENT);
+
+	/* Check how much of the window did external entity consumed. */
+	self->consumed += cursor - self->cursor;
+	self->cursor = cursor;
+	self->state = _PROV_READY;
+}
+
+/** @see __input_provider */
+static void _release_stream(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+	assert(self->consumed >= self->fetched);
+
+	/* Try to correct the difference between the stream position and what was
+	 * actually consumed. If it is not possible, continue anyway. */
+	fseek(self->source.stream, self->consumed - self->fetched, SEEK_CUR);
+
+	/* Destruct internal structures. */
+	self->fetched = 0;
+	self->cursor = NULL;
+	if (self->window) {
+		free(self->window);
+		self->window = NULL;
+	}
+	self->window_size = 0;
+	self->state = _PROV_CONSTRUCTED;
+}
+
+/** @see __input_provider */
+static void _release_string(_input_provider *self)
+{
+	assert(self->state == _PROV_READY);
+
+	/* Destruct internal structures. */
+	self->fetched = 0;
+	self->cursor = NULL;
+	self->window = NULL;
+	self->window_size = 0;
+	self->state = _PROV_CONSTRUCTED;
+}
+
+/** Length modifier values. */
+enum {
+	LMOD_NONE,
+	LMOD_hh,
+	LMOD_h,
+	LMOD_l,
+	LMOD_ll,
+	LMOD_j,
+	LMOD_z,
+	LMOD_t,
+	LMOD_L,
+	LMOD_p, /* Reserved for %p conversion. */
+};
+
+/**
+ * Decides whether provided characters specify length modifier. If so, the
+ * recognized modifier is stored through provider pointer.
+ *
+ * @param c Candidate on the length modifier.
+ * @param _c Next character (might be NUL).
+ * @param modifier Pointer to the modifier value.
+ * @return Whether the modifier was recognized or not.
+ */
+static inline int is_length_mod(int c, int _c, int *modifier)
+{
+	assert(modifier);
+
+	switch (c) {
+	case 'h':
+		/* Check whether the modifier was not already recognized. */
+		if (*modifier == LMOD_NONE) {
+			*modifier = _c == 'h' ? LMOD_hh : LMOD_h;
+		} else {
+			/* Format string is invalid. Notify the caller. */
+			*modifier = LMOD_NONE;
+		}
+		return 1;
+	case 'l':
+		if (*modifier == LMOD_NONE) {
+			*modifier = _c == 'l' ? LMOD_ll : LMOD_l;
+		} else {
+			*modifier = LMOD_NONE;
+		}
+		return 1;
+	case 'j':
+		*modifier = *modifier == LMOD_NONE ? LMOD_j : LMOD_NONE;
+		return 1;
+	case 'z':
+		*modifier = *modifier == LMOD_NONE ? LMOD_z : LMOD_NONE;
+		return 1;
+	case 't':
+		*modifier = *modifier == LMOD_NONE ? LMOD_t : LMOD_NONE;
+		return 1;
+	case 'L':
+		*modifier = *modifier == LMOD_NONE ? LMOD_L : LMOD_NONE;
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Decides whether provided character specifies integer conversion. If so, the
+ * semantics of the conversion is stored through provided pointers..
+ * 
+ * @param c Candidate on the integer conversion.
+ * @param is_unsigned Pointer to store whether the conversion is signed or not.
+ * @param base Pointer to store the base of the integer conversion.
+ * @return Whether the conversion was recognized or not.
+ */
+static inline int is_int_conv(int c, bool *is_unsigned, int *base)
+{
+	assert(is_unsigned && base);
+
+	switch (c) {
+	case 'd':
+		*is_unsigned = false;
+		*base = 10;
+		return 1;
+	case 'i':
+		*is_unsigned = false;
+		*base = 0;
+		return 1;
+	case 'o':
+		*is_unsigned = true;
+		*base = 8;
+		return 1;
+	case 'u':
+		*is_unsigned = true;
+		*base = 10;
+		return 1;
+	case 'p': /* According to POSIX, %p modifier is implementation defined but
+			   * must correspond to its printf counterpart. */
+	case 'x':
+	case 'X':
+		*is_unsigned = true;
+		*base = 16;
+		return 1;
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Decides whether provided character specifies conversion of the floating
+ * point number.
+ *
+ * @param c Candidate on the floating point conversion.
+ * @return Whether the conversion was recognized or not.
+ */
+static inline int is_float_conv(int c)
+{
+	switch (c) {
+	case 'a':
+	case 'A':
+	case 'e':
+	case 'E':
+	case 'f':
+	case 'F':
+	case 'g':
+	case 'G':
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Decides whether provided character specifies conversion of the character
+ * sequence.
+ *
+ * @param c Candidate on the character sequence conversion.
+ * @param modifier Pointer to store length modifier for wide chars.
+ * @return Whether the conversion was recognized or not.
+ */
+static inline int is_seq_conv(int c, int *modifier)
+{
+	assert(modifier);
+	
+	switch (c) {
+	case 'S':
+		*modifier = LMOD_l;
+		/* Fallthrough */
+	case 's':
+		return 1;
+	case 'C':
+		*modifier = LMOD_l;
+		/* Fallthrough */
+	case 'c':
+		return 1;
+	case '[':
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+/**
+ * Backend for the whole family of scanf functions. Uses input provider
+ * to abstract over differences between strings and streams. Should be
+ * POSIX compliant (apart from the not supported stuff).
+ *
+ * NOT SUPPORTED: locale (see strtold), wide chars, numbered output arguments
+ * 
+ * @param in Input provider.
+ * @param fmt Format description.
+ * @param arg Output arguments.
+ * @return The number of converted output items or EOF on failure.
+ */
+static inline int _internal_scanf(
+    _input_provider *in, const char *restrict fmt, va_list arg)
+{
+	int c = -1;
+	int converted_cnt = 0;
+	bool converting = false;
+	bool matching_failure = false;
+
+	bool assign_supress = false;
+	bool assign_alloc = false;
+	long width = -1;
+	int length_mod = LMOD_NONE;
+	bool int_conv_unsigned = false;
+	int int_conv_base = 0;
+
+	/* Buffers allocated by scanf for optional 'm' specifier must be remembered
+	 * to deallocaate them in case of an error. Because each of those buffers
+	 * corresponds to one of the argument from va_list, there is an upper bound
+	 * on the number of those arguments. In case of C99, this uppper bound is
+	 * 127 arguments. */
+	char *buffers[127];
+	for (int i = 0; i < 127; ++i) {
+		buffers[i] = NULL;
+	}
+	int next_unused_buffer_idx = 0;
+
+	in->capture(in);
+
+	/* Interpret format string. Control shall prematurely jump from the cycle
+	 * on input failure, matching failure or illegal format string. In order
+	 * to keep error reporting simple enough and to keep input consistent,
+	 * error condition shall be always manifested as jump from the cycle,
+	 * not function return. Format string pointer shall be updated specifically
+	 * for each sub-case (i.e. there shall be no loop-wide increment).*/
+	while (*fmt) {
+
+		if (converting) {
+
+			/* Processing inside conversion specifier. Either collect optional
+			 * parameters or execute the conversion. When the conversion
+			 * is successfully completed, increment conversion count and switch
+			 * back to normal mode. */
+			if (*fmt == '*') {
+				/* Assignment-supression (optional). */
+				if (assign_supress) {
+					/* Already set. Illegal format string. */
+					break;
+				}
+				assign_supress = true;
+				++fmt;
+			} else if (*fmt == 'm') {
+				/* Assignment-allocation (optional). */
+				if (assign_alloc) {
+					/* Already set. Illegal format string. */
+					break;
+				}
+				assign_alloc = true;
+				++fmt;
+			} else if (*fmt == '$') {
+				/* Reference to numbered output argument. */
+				// TODO
+				not_implemented();
+			} else if (isdigit(*fmt)) {
+				/* Maximum field length (optional). */
+				if (width != -1) {
+					/* Already set. Illegal format string. */
+					break;
+				}
+				char *fmt_new = NULL;
+				width = strtol(fmt, &fmt_new, 10);
+				if (width != 0) {
+					fmt = fmt_new;
+				} else {
+					/* Since POSIX requires width to be non-zero, it is
+					 * sufficient to interpret zero width as error without
+					 * referring to errno. */
+					break;
+				}
+			} else if (is_length_mod(*fmt, *(fmt + 1), &length_mod)) {
+				/* Length modifier (optional). */
+				if (length_mod == LMOD_NONE) {
+					/* Already set. Illegal format string. The actual detection
+					 * is carried out in the is_length_mod(). */
+					break;
+				}
+				if (length_mod == LMOD_hh || length_mod == LMOD_ll) {
+					/* Modifier was two characters long. */
+					++fmt;
+				}
+				++fmt;
+			} else if (is_int_conv(*fmt, &int_conv_unsigned, &int_conv_base)) {
+				/* Integer conversion. */
+
+				/* Check sanity of optional parts of conversion specifier. */
+				if (assign_alloc || length_mod == LMOD_L) {
+					/* Illegal format string. */
+					break;
+				}
+
+				/* Conversion of the integer with %p specifier needs special
+				 * handling, because it is not allowed to have arbitrary
+				 * length modifier.  */
+				if (*fmt == 'p') {
+					if (length_mod == LMOD_NONE) {
+						length_mod = LMOD_p;
+					} else {
+						/* Already set. Illegal format string. */
+						break;
+					}
+				}
+
+				/* First consume any white spaces, so we can borrow cursor
+				 * from the input provider. This way, the cursor will either
+				 * point to the non-white space while the input will be
+				 * prefetched up to the newline (which is suitable for strtol),
+				 * or the input will be at EOF. */
+				do {
+					c = in->pop(in);
+				} while (isspace(c));
+
+				/* After skipping the white spaces, can we actually continue? */
+				if (c == -1) {
+					/* Input failure. */
+					break;
+				} else {
+					/* Everything is OK, just undo the last pop, so the cursor
+					 * can be borrowed. */
+					in->undo(in);
+				}
+
+				const char *cur_borrowed = NULL;
+				char *cur_duplicated = NULL;
+				const char *cur_limited = NULL;
+				const char *cur_updated = NULL;
+
+				/* Borrow the cursor. Until it is returned to the provider
+				 * we cannot jump from the cycle, because it would leave
+				 * the input inconsistent. */
+				cur_borrowed = in->borrow_cursor(in);
+
+				/* If the width is limited, the cursor horizont must be
+				 * decreased accordingly. Otherwise the strtol could read more
+				 * than allowed by width. */
+				if (width != -1) {
+					cur_duplicated = strndup(cur_borrowed, width);
+					cur_limited = cur_duplicated;
+				} else {
+					cur_limited = cur_borrowed;
+				}
+				cur_updated = cur_limited;
+
+				long long sres = 0;
+				unsigned long long ures = 0;
+				errno = 0; /* Reset errno to recognize error later. */
+				/* Try to convert the integer. */
+				if (int_conv_unsigned) {
+					ures = strtoull(cur_limited, (char **) &cur_updated, int_conv_base);
+				} else {
+					sres = strtoll(cur_limited, (char **) &cur_updated, int_conv_base);
+				}
+
+				/* Update the cursor so it can be returned to the provider. */
+				cur_borrowed += cur_updated - cur_limited;
+				if (cur_duplicated != NULL) {
+					/* Deallocate duplicated part of the cursor view. */
+					free(cur_duplicated);
+				}
+				cur_limited = NULL;
+				cur_updated = NULL;
+				cur_duplicated = NULL;
+				/* Return the cursor to the provider. Input consistency is again
+				 * the job of the provider, so we can report errors from
+				 * now on. */
+				in->return_cursor(in, cur_borrowed);
+				cur_borrowed = NULL;
+
+				/* Check whether the conversion was successful. */
+				if (errno != EOK) {
+					matching_failure = true;
+					break;
+				}
+
+				/* If not supressed, assign the converted integer into
+				 * the next output argument. */
+				if (!assign_supress) {
+					if (int_conv_unsigned) {
+						switch (length_mod) {
+						case LMOD_hh: ; /* Label cannot be part of declaration. */
+							unsigned char *phh = va_arg(arg, unsigned char *);
+							*phh = (unsigned char) ures;
+							break;
+						case LMOD_h: ;
+							unsigned short *ph = va_arg(arg, unsigned short *);
+							*ph = (unsigned short) ures;
+							break;
+						case LMOD_NONE: ;
+							unsigned *pdef = va_arg(arg, unsigned *);
+							*pdef = (unsigned) ures;
+							break;
+						case LMOD_l: ;
+							unsigned long *pl = va_arg(arg, unsigned long *);
+							*pl = (unsigned long) ures;
+							break;
+						case LMOD_ll: ;
+							unsigned long long *pll = va_arg(arg, unsigned long long *);
+							*pll = (unsigned long long) ures;
+							break;
+						case LMOD_j: ;
+							uintmax_t *pj = va_arg(arg, uintmax_t *);
+							*pj = (uintmax_t) ures;
+							break;
+						case LMOD_z: ;
+							size_t *pz = va_arg(arg, size_t *);
+							*pz = (size_t) ures;
+							break;
+						case LMOD_t: ;
+							// XXX: What is unsigned counterpart of the ptrdiff_t?
+							size_t *pt = va_arg(arg, size_t *);
+							*pt = (size_t) ures;
+							break;
+						case LMOD_p: ;
+							void **pp = va_arg(arg, void **);
+							*pp = (void *) (uintptr_t) ures;
+							break;
+						default:
+							assert(false);
+						}
+					} else {
+						switch (length_mod) {
+						case LMOD_hh: ; /* Label cannot be part of declaration. */
+							signed char *phh = va_arg(arg, signed char *);
+							*phh = (signed char) sres;
+							break;
+						case LMOD_h: ;
+							short *ph = va_arg(arg, short *);
+							*ph = (short) sres;
+							break;
+						case LMOD_NONE: ;
+							int *pdef = va_arg(arg, int *);
+							*pdef = (int) sres;
+							break;
+						case LMOD_l: ;
+							long *pl = va_arg(arg, long *);
+							*pl = (long) sres;
+							break;
+						case LMOD_ll: ;
+							long long *pll = va_arg(arg, long long *);
+							*pll = (long long) sres;
+							break;
+						case LMOD_j: ;
+							intmax_t *pj = va_arg(arg, intmax_t *);
+							*pj = (intmax_t) sres;
+							break;
+						case LMOD_z: ;
+							ssize_t *pz = va_arg(arg, ssize_t *);
+							*pz = (ssize_t) sres;
+							break;
+						case LMOD_t: ;
+							ptrdiff_t *pt = va_arg(arg, ptrdiff_t *);
+							*pt = (ptrdiff_t) sres;
+							break;
+						default:
+							assert(false);
+						}
+					}
+					++converted_cnt;
+				}
+
+				converting = false;
+				++fmt;
+			} else if (is_float_conv(*fmt)) {
+				/* Floating point number conversion. */
+
+				/* Check sanity of optional parts of conversion specifier. */
+				if (assign_alloc) {
+					/* Illegal format string. */
+					break;
+				}
+				if (length_mod != LMOD_NONE &&
+				    length_mod != LMOD_l &&
+				    length_mod != LMOD_L) {
+					/* Illegal format string. */
+					break;
+				}
+
+				/* First consume any white spaces, so we can borrow cursor
+				 * from the input provider. This way, the cursor will either
+				 * point to the non-white space while the input will be
+				 * prefetched up to the newline (which is suitable for strtof),
+				 * or the input will be at EOF. */
+				do {
+					c = in->pop(in);
+				} while (isspace(c));
+
+				/* After skipping the white spaces, can we actually continue? */
+				if (c == -1) {
+					/* Input failure. */
+					break;
+				} else {
+					/* Everything is OK, just undo the last pop, so the cursor
+					 * can be borrowed. */
+					in->undo(in);
+				}
+
+				const char *cur_borrowed = NULL;
+				const char *cur_limited = NULL;
+				char *cur_duplicated = NULL;
+				const char *cur_updated = NULL;
+
+				/* Borrow the cursor. Until it is returned to the provider
+				 * we cannot jump from the cycle, because it would leave
+				 * the input inconsistent. */
+				cur_borrowed = in->borrow_cursor(in);
+
+				/* If the width is limited, the cursor horizont must be
+				 * decreased accordingly. Otherwise the strtof could read more
+				 * than allowed by width. */
+				if (width != -1) {
+					cur_duplicated = strndup(cur_borrowed, width);
+					cur_limited = cur_duplicated;
+				} else {
+					cur_limited = cur_borrowed;
+				}
+				cur_updated = cur_limited;
+
+				float fres = 0.0;
+				double dres = 0.0;
+				long double ldres = 0.0;
+				errno = 0; /* Reset errno to recognize error later. */
+				/* Try to convert the floating point nubmer. */
+				switch (length_mod) {
+				case LMOD_NONE:
+					fres = strtof(cur_limited, (char **) &cur_updated);
+					break;
+				case LMOD_l:
+					dres = strtod(cur_limited, (char **) &cur_updated);
+					break;
+				case LMOD_L:
+					ldres = strtold(cur_limited, (char **) &cur_updated);
+					break;
+				default:
+					assert(false);
+				}
+
+				/* Update the cursor so it can be returned to the provider. */
+				cur_borrowed += cur_updated - cur_limited;
+				if (cur_duplicated != NULL) {
+					/* Deallocate duplicated part of the cursor view. */
+					free(cur_duplicated);
+				}
+				cur_limited = NULL;
+				cur_updated = NULL;
+				/* Return the cursor to the provider. Input consistency is again
+				 * the job of the provider, so we can report errors from
+				 * now on. */
+				in->return_cursor(in, cur_borrowed);
+				cur_borrowed = NULL;
+
+				/* Check whether the conversion was successful. */
+				if (errno != EOK) {
+					matching_failure = true;
+					break;
+				}
+
+				/* If nto supressed, assign the converted floating point number
+				 * into the next output argument. */
+				if (!assign_supress) {
+					switch (length_mod) {
+					case LMOD_NONE: ; /* Label cannot be part of declaration. */
+						float *pf = va_arg(arg, float *);
+						*pf = fres;
+						break;
+					case LMOD_l: ;
+						double *pd = va_arg(arg, double *);
+						*pd = dres;
+						break;
+					case LMOD_L: ;
+						long double *pld = va_arg(arg, long double *);
+						*pld = ldres;
+						break;
+					default:
+						assert(false);
+					}
+					++converted_cnt;
+				}
+
+				converting = false;
+				++fmt;
+			} else if (is_seq_conv(*fmt, &length_mod)) {
+				/* Character sequence conversion. */
+				
+				/* Check sanity of optional parts of conversion specifier. */
+				if (length_mod != LMOD_NONE &&
+				    length_mod != LMOD_l) {
+					/* Illegal format string. */
+					break;
+				}
+
+				if (length_mod == LMOD_l) {
+					/* Wide chars not supported. */
+					// TODO
+					not_implemented();
+				}
+
+				int term_size = 1; /* Size of the terminator (0 or 1)). */
+				if (*fmt == 'c') {
+					term_size = 0;
+					width = width == -1 ? 1 : width;
+				}
+
+				if (*fmt == 's') {
+					/* Skip white spaces. */
+					do {
+						c = in->pop(in);
+					} while (isspace(c));
+				} else {
+					/* Fetch a single character. */
+					c = in->pop(in);
+				}
+
+				/* Check whether there is still input to read. */
+				if (c == -1) {
+					/* Input failure. */
+					break;
+				}
+
+				/* Prepare scanset. */
+				char terminate_on[256];
+				for (int i = 0; i < 256; ++i) {
+					terminate_on[i] = 0;
+				}
+				if (*fmt == 'c') {
+					++fmt;
+				} else if (*fmt == 's') {
+					terminate_on[' '] = 1;
+					terminate_on['\n'] = 1;
+					terminate_on['\t'] = 1;
+					terminate_on['\f'] = 1;
+					terminate_on['\r'] = 1;
+					terminate_on['\v'] = 1;
+					++fmt;
+				} else {
+					assert(*fmt == '[');
+					bool not = false;
+					bool dash = false;
+					++fmt;
+					/* Check for negation. */
+					if (*fmt == '^') {
+						not = true;
+						++fmt;
+					}
+					/* Check for escape sequences. */
+					if (*fmt == '-' || *fmt == ']') {
+						terminate_on[(int) *fmt] = 1;
+						++fmt;
+					}
+					/* Check for ordinary characters and ranges. */
+					while (*fmt != '\0' && *fmt != ']') {
+						if (dash) {
+							for (char chr = *(fmt - 2); chr <= *fmt; ++chr) {
+								terminate_on[(int) chr] = 1;
+							}
+							dash = false;
+						} else if (*fmt == '-') {
+							dash = true;
+						} else {
+							terminate_on[(int) *fmt] = 1;
+						}
+						++fmt;
+					}
+					/* Check for escape sequence. */
+					if (dash == true) {
+						terminate_on['-'] = 1;
+					}
+					/* Check whether the specifier was correctly terminated.*/
+					if (*fmt == '\0') {
+						/* Illegal format string. */
+						break;
+					} else {
+						++fmt;
+					}
+					/* Inverse the scanset if necessary. */
+					if (not == false) {
+						for (int i = 0; i < 256; ++i) {
+							terminate_on[i] = terminate_on[i] ? 0 : 1;
+						}
+					}
+				}
+
+				char * buf = NULL;
+				size_t buf_size = 0;
+				char * cur = NULL;
+				size_t alloc_step = 80; /* Buffer size gain during reallocation. */
+				int my_buffer_idx = 0;
+
+				/* Retrieve the buffer into which popped characters
+				 * will be stored. */
+				if (!assign_supress) {
+					if (assign_alloc) {
+						/* We must allocate our own buffer. */
+						buf_size =
+						    width == -1 ? alloc_step : (size_t) width + term_size;
+						buf = malloc(buf_size);
+						if (!buf) {
+							/* No memory. */
+							break;
+						}
+						my_buffer_idx = next_unused_buffer_idx;
+						++next_unused_buffer_idx;
+						buffers[my_buffer_idx] = buf;
+						cur = buf;
+					} else {
+						/* Caller provided its buffer. */
+						buf = va_arg(arg, char *);
+						cur = buf;
+						buf_size =
+						    width == -1 ? SIZE_MAX : (size_t) width + term_size;
+					}
+				}
+
+				/* Match the string. The next character is already popped. */
+				while ((width == -1 || width > 0) && c != -1 && !terminate_on[c]) {
+
+					/* Check whether the buffer is still sufficiently large. */
+					if (!assign_supress) {
+						/* Always reserve space for the null terminator. */
+						if (cur == buf + buf_size - term_size) {
+							/* Buffer size must be increased. */
+							buf = realloc(buf, buf_size + alloc_step);
+							if (buf) {
+								buffers[my_buffer_idx] = buf;
+								cur = buf + buf_size - term_size;
+								buf_size += alloc_step;
+							} else {
+								/* Break just from this tight loop. Errno will
+								 * be checked after it. */
+								break;
+							}
+						}
+						/* Store the input character. */
+						*cur = c;
+					}
+
+					width = width == -1 ? -1 : width - 1;
+					++cur;
+					c = in->pop(in);
+				}
+				if (errno == ENOMEM) {
+					/* No memory. */
+					break;
+				}
+				if (c != -1) {
+					/* There is still more input, so undo the last pop. */
+					in->undo(in);
+				}
+
+				/* Check for failures. */
+				if (cur == buf) {
+					/* Matching failure. Input failure was already checked
+					 * earlier. */
+					matching_failure = true;
+					if (!assign_supress && assign_alloc) {
+						/* Roll back. */
+						free(buf);
+						buffers[my_buffer_idx] = NULL;
+						--next_unused_buffer_idx;
+					}
+					break;
+				}
+
+				/* Store the terminator. */
+				if (!assign_supress && term_size > 0) {
+					/* Space for the terminator was reserved. */
+					*cur = '\0';
+				}
+
+				/* Store the result if not already stored. */
+				if (!assign_supress) {
+					if (assign_alloc) {
+						char **pbuf = va_arg(arg, char **);
+						*pbuf = buf;
+					}
+					++converted_cnt;
+				}
+				
+				converting = false;
+				/* Format string pointer already incremented. */
+			} else if (*fmt == 'n') {
+				/* Report the number of consumed bytes so far. */
+
+				/* Sanity check. */
+				bool sane =
+				    width == -1 &&
+				    length_mod == LMOD_NONE &&
+				    assign_alloc == false &&
+				    assign_supress == false;
+
+				if (sane) {
+					int *pi = va_arg(arg, int *);
+					*pi = in->consumed;
+				} else {
+					/* Illegal format string. */
+					break;
+				}
+
+				/* This shall not be counted as conversion. */
+				converting = false;
+				++fmt;
+			} else {
+				/* Illegal format string. */
+				break;
+			}
+			
+		} else {
+
+			/* Processing outside conversion specifier. Either skip white
+			 * spaces or match characters one by one. If conversion specifier
+			 * is detected, switch to coversion mode. */
+			if (isspace(*fmt)) {
+				/* Skip white spaces in the format string. */
+				while (isspace(*fmt)) {
+					++fmt;
+				}
+				/* Skip white spaces in the input. */
+				do {
+					c = in->pop(in);
+				} while (isspace(c));
+				if (c != -1) {
+					/* Input is not at EOF, so undo the last pop operation. */
+					in->undo(in);
+				}
+			} else if (*fmt == '%' && *(fmt + 1) != '%') {
+				/* Conversion specifier detected. Switch modes. */
+				converting = true;
+				/* Reset the conversion context. */
+				assign_supress = false;
+				assign_alloc = false;
+				width = -1;
+				length_mod = LMOD_NONE;
+				int_conv_unsigned = false;
+				int_conv_base = 0;
+				++fmt;
+			} else {
+				/* One by one matching. */
+				if (*fmt == '%') {
+					/* Escape sequence detected. */
+					++fmt;
+					assert(*fmt == '%');
+				}
+				c = in->pop(in);
+				if (c == -1) {
+					/* Input failure. */
+					break;
+				} else if (c != *fmt) {
+					/* Matching failure. */
+					in->undo(in);
+					matching_failure = true;
+					break;
+				} else {
+					++fmt;
+				}
+			}
+			
+		}
+
+	}
+
+	in->release(in);
+
+	/* This somewhat complicated return value decision is required by POSIX. */
+	int rc;
+	if (matching_failure) {
+		rc = converted_cnt;
+	} else {
+		if (errno == EOK) {
+			rc = converted_cnt > 0 ? converted_cnt : EOF;
+		} else {
+			rc = EOF;
+		}
+	}
+	if (rc == EOF) {
+		/* Caller will not know how many arguments were successfully converted,
+		 * so the deallocation of buffers is our responsibility. */
+		for (int i = 0; i < next_unused_buffer_idx; ++i) {
+			free(buffers[i]);
+			buffers[i] = NULL;
+		}
+		next_unused_buffer_idx = 0;
+	}
+	return rc;
+}
+
+/**
+ * Convert formatted input from the stream.
+ *
+ * @param stream Input stream.
+ * @param format Format description.
+ * @param arg Output items.
+ * @return The number of converted output items or EOF on failure.
+ */
+int vfscanf(
+    FILE *restrict stream, const char *restrict format, va_list arg)
+{
+	_input_provider provider = {
+	    { 0 }, 0, 0, NULL, 0, NULL, _PROV_CONSTRUCTED,
+	    _capture_stream, _pop_stream, _undo_stream,
+	    _borrow_cursor_universal, _return_cursor_stream, _release_stream
+	};
+	provider.source.stream = stream;
+	return _internal_scanf(&provider, format, arg);
+}
+
+/**
+ * Convert formatted input from the string.
+ *
+ * @param s Input string.
+ * @param format Format description.
+ * @param arg Output items.
+ * @return The number of converted output items or EOF on failure.
+ */
+int vsscanf(
+    const char *restrict s, const char *restrict format, va_list arg)
+{
+	_input_provider provider = {
+	    { 0 }, 0, 0, NULL, 0, NULL, _PROV_CONSTRUCTED,
+	    _capture_string, _pop_string, _undo_string,
+	    _borrow_cursor_universal, _return_cursor_string, _release_string
+	};
+	provider.source.string = s;
+	return _internal_scanf(&provider, format, arg);
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/stdlib.c
===================================================================
--- uspace/lib/posix/src/stdlib.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/stdlib.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,415 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Standard library definitions.
+ */
+
+#include "internal/common.h"
+#include "posix/stdlib.h"
+
+#include <errno.h>
+
+#include "posix/fcntl.h"
+#include "posix/limits.h"
+#include "posix/string.h"
+#include "posix/sys/stat.h"
+#include "posix/unistd.h"
+
+#include "libc/qsort.h"
+#include "libc/str.h"
+#include "libc/vfs/vfs.h"
+#include "libc/stats.h"
+
+/**
+ * 
+ * @param array
+ * @param count
+ * @param size
+ * @param compare
+ */
+int atexit(void (*func)(void))
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return 0;
+}
+
+/**
+ * Integer absolute value.
+ * 
+ * @param i Input value.
+ * @return Absolute value of the parameter.
+ */
+int abs(int i)
+{
+	return i < 0 ? -i : i;
+}
+
+/**
+ * Long integer absolute value.
+ * 
+ * @param i Input value.
+ * @return Absolute value of the parameter.
+ */
+long labs(long i)
+{
+	return i < 0 ? -i : i;
+}
+
+/**
+ * Long long integer absolute value.
+ * 
+ * @param i Input value.
+ * @return Absolute value of the parameter.
+ */
+long long llabs(long long i)
+{
+	return i < 0 ? -i : i;
+}
+
+/**
+ * Compute the quotient and remainder of an integer division.
+ *
+ * @param numer Numerator.
+ * @param denom Denominator.
+ * @return Quotient and remainder packed into structure.
+ */
+div_t div(int numer, int denom)
+{
+	return (div_t) { .quot = numer / denom, .rem = numer % denom };
+}
+
+/**
+ * Compute the quotient and remainder of a long integer division.
+ *
+ * @param numer Numerator.
+ * @param denom Denominator.
+ * @return Quotient and remainder packed into structure.
+ */
+ldiv_t ldiv(long numer, long denom)
+{
+	return (ldiv_t) { .quot = numer / denom, .rem = numer % denom };
+}
+
+/**
+ * Compute the quotient and remainder of a long long integer division.
+ *
+ * @param numer Numerator.
+ * @param denom Denominator.
+ * @return Quotient and remainder packed into structure.
+ */
+lldiv_t lldiv(long long numer, long long denom)
+{
+	return (lldiv_t) { .quot = numer / denom, .rem = numer % denom };
+}
+
+/**
+ * Binary search in a sorted array.
+ *
+ * @param key Object to search for.
+ * @param base Pointer to the first element of the array.
+ * @param nmemb Number of elements in the array.
+ * @param size Size of each array element.
+ * @param compar Comparison function.
+ * @return Pointer to a matching element, or NULL if none can be found.
+ */
+void *bsearch(const void *key, const void *base,
+    size_t nmemb, size_t size, int (*compar)(const void *, const void *))
+{
+	while (nmemb > 0) {
+		const void *middle = base + (nmemb / 2) * size;
+		int cmp = compar(key, middle);
+		if (cmp == 0) {
+			return (void *) middle;
+		}
+		if (middle == base) {
+			/* There is just one member left to check and it
+			 * didn't match the key. Avoid infinite loop.
+			 */
+			break;
+		}
+		if (cmp < 0) {
+			nmemb = nmemb / 2;
+		} else if (cmp > 0) {
+			nmemb = nmemb - (nmemb / 2);
+			base = middle;
+		}
+	}
+	
+	return NULL;
+}
+
+/**
+ * Retrieve a value of the given environment variable.
+ *
+ * Since HelenOS doesn't support env variables at the moment,
+ * this function always returns NULL.
+ *
+ * @param name Name of the variable.
+ * @return Value of the variable or NULL if such variable does not exist.
+ */
+char *getenv(const char *name)
+{
+	return NULL;
+}
+
+/**
+ * 
+ * @param name
+ * @param resolved
+ * @return
+ */
+int putenv(char *string)
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return 0;
+}
+
+/**
+ * Issue a command.
+ *
+ * @param string String to be passed to a command interpreter or NULL.
+ * @return Termination status of the command if the command is not NULL,
+ *     otherwise indicate whether there is a command interpreter (non-zero)
+ *     or not (zero).
+ */
+int system(const char *string) {
+	// TODO: does nothing at the moment
+	not_implemented();
+	return 0;
+}
+
+/**
+ * Resolve absolute pathname.
+ * 
+ * @param name Pathname to be resolved.
+ * @param resolved Either buffer for the resolved absolute pathname or NULL.
+ * @return On success, either resolved (if it was not NULL) or pointer to the
+ *     newly allocated buffer containing the absolute pathname (if resolved was
+ *     NULL). Otherwise NULL.
+ *
+ */
+char *realpath(const char *restrict name, char *restrict resolved)
+{
+	#ifndef PATH_MAX
+		assert(resolved == NULL);
+	#endif
+	
+	if (name == NULL) {
+		errno = EINVAL;
+		return NULL;
+	}
+	
+	// TODO: symlink resolution
+	
+	/* Function absolutize is implemented in libc and declared in vfs.h.
+	 * No more processing is required as HelenOS doesn't have symlinks
+	 * so far (as far as I can tell), although this function will need
+	 * to be updated when that support is implemented.
+	 */
+	char* absolute = vfs_absolutize(name, NULL);
+	
+	if (absolute == NULL) {
+		/* POSIX requires some specific errnos to be set
+		 * for some cases, but there is no way to find out from
+		 * absolutize().
+		 */
+		errno = EINVAL;
+		return NULL;
+	}
+	
+	if (resolved == NULL) {
+		return absolute;
+	} else {
+		#ifdef PATH_MAX
+			str_cpy(resolved, PATH_MAX, absolute);
+		#endif
+		free(absolute);
+		return resolved;
+	}
+}
+
+/**
+ * Converts a string representation of a floating-point number to
+ * its native representation. See strtold().
+ *
+ * @param nptr String representation of a floating-point number.
+ * @return Double-precision number resulting from the string conversion.
+ */
+double atof(const char *nptr)
+{
+	return strtod(nptr, NULL);
+}
+
+/**
+ * Converts a string representation of a floating-point number to
+ * its native representation. See strtold().
+ *
+ * @param nptr String representation of a floating-point number.
+ * @param endptr Pointer to the final part of the string which
+ *     was not used for conversion.
+ * @return Single-precision number resulting from the string conversion.
+ */
+float strtof(const char *restrict nptr, char **restrict endptr)
+{
+	return (float) strtold(nptr, endptr);
+}
+
+/**
+ * Converts a string representation of a floating-point number to
+ * its native representation. See strtold().
+ *
+ * @param nptr String representation of a floating-point number.
+ * @param endptr Pointer to the final part of the string which
+ *     was not used for conversion.
+ * @return Double-precision number resulting from the string conversion.
+ */
+double strtod(const char *restrict nptr, char **restrict endptr)
+{
+	return (double) strtold(nptr, endptr);
+}
+
+/**
+ * Creates and opens an unique temporary file from template.
+ *
+ * @param tmpl Template. Last six characters must be XXXXXX.
+ * @return The opened file descriptor or -1 on error.
+ */
+int mkstemp(char *tmpl)
+{
+	int fd = -1;
+	
+	char *tptr = tmpl + strlen(tmpl) - 6;
+	
+	while (fd < 0) {
+		if (*mktemp(tmpl) == '\0') {
+			/* Errno set by mktemp(). */
+			return -1;
+		}
+		
+		fd = open(tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+		
+		if (fd == -1) {
+			/* Restore template to it's original state. */
+			snprintf(tptr, 7, "XXXXXX");
+		}
+	}
+	
+	return fd;
+}
+
+/**
+ * Creates an unique temporary file name from template.
+ *
+ * @param tmpl Template. Last six characters must be XXXXXX.
+ * @return The value of tmpl. The template is modified in place.
+ *    If no temporary file name can be created, template is
+ *    reduced to an empty string.
+ */
+char *mktemp(char *tmpl)
+{
+	int tmpl_len = strlen(tmpl);
+	if (tmpl_len < 6) {
+		errno = EINVAL;
+		*tmpl = '\0';
+		return tmpl;
+	}
+	
+	char *tptr = tmpl + tmpl_len - 6;
+	if (strcmp(tptr, "XXXXXX") != 0) {
+		errno = EINVAL;
+		*tmpl = '\0';
+		return tmpl;
+	}
+	
+	static int seq = 0;
+	
+	for (; seq < 1000000; ++seq) {
+		snprintf(tptr, 7, "%06d", seq);
+		
+		int orig_errno = errno;
+		errno = 0;
+		/* Check if the file exists. */
+		if (access(tmpl, F_OK) == -1) {
+			if (errno == ENOENT) {
+				errno = orig_errno;
+				break;
+			} else {
+				/* errno set by access() */
+				*tmpl = '\0';
+				return tmpl;
+			}
+		}
+	}
+	
+	if (seq == 10000000) {
+		errno = EEXIST;
+		*tmpl = '\0';
+		return tmpl;
+	}
+	
+	return tmpl;
+}
+
+/**
+ * Get system load average statistics.
+ *
+ * @param loadavg Array where the load averages shall be placed.
+ * @param nelem Maximum number of elements to be placed into the array.
+ * @return Number of elements placed into the array on success, -1 otherwise.
+ */
+int bsd_getloadavg(double loadavg[], int nelem)
+{
+	assert(nelem > 0);
+	
+	size_t count;
+	load_t *loads = stats_get_load(&count);
+	
+	if (loads == NULL) {
+		return -1;
+	}
+	
+	if (((size_t) nelem) < count) {
+		count = nelem;
+	}
+	
+	for (size_t i = 0; i < count; ++i) {
+		loadavg[i] = (double) loads[i];
+	}
+	
+	free(loads);
+	return count;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/stdlib/strtold.c
===================================================================
--- uspace/lib/posix/src/stdlib/strtold.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/stdlib/strtold.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,491 @@
+/*
+ * 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 Backend for floating point conversions.
+ */
+
+#include "../internal/common.h"
+#include "libc/stdbool.h"
+#include "posix/stdlib.h"
+
+#include <assert.h>
+#include "posix/ctype.h"
+#include "posix/stdint.h"
+#include "posix/strings.h"
+
+#include <errno.h>
+
+#include "posix/limits.h"
+
+#include "posix/float.h"
+
+#include "libc/str.h"
+
+#ifndef HUGE_VALL
+	#define HUGE_VALL (+1.0l / +0.0l)
+#endif
+
+#ifndef abs
+	#define abs(x) (((x) < 0) ? -(x) : (x))
+#endif
+
+/* If the constants are not defined, use double precision as default. */
+#ifndef LDBL_MANT_DIG
+	#define LDBL_MANT_DIG 53
+#endif
+#ifndef LDBL_MAX_EXP
+	#define LDBL_MAX_EXP 1024
+#endif
+#ifndef LDBL_MIN_EXP
+	#define LDBL_MIN_EXP (-1021)
+#endif
+#ifndef LDBL_DIG
+	#define LDBL_DIG 15
+#endif
+#ifndef LDBL_MIN
+	#define LDBL_MIN 2.2250738585072014E-308
+#endif
+
+/* power functions ************************************************************/
+
+#if LDBL_MAX_EXP >= 16384
+const int MAX_POW5 = 12;
+#else
+const int MAX_POW5 = 8;
+#endif
+
+/* The value at index i is approximately 5**(2**i). */
+long double pow5[] = {
+	0x5p0l,
+	0x19p0l,
+	0x271p0l,
+	0x5F5E1p0l,
+	0x2386F26FC1p0l,
+	0x4EE2D6D415B85ACEF81p0l,
+	0x184F03E93FF9F4DAA797ED6E38ED6p36l,
+	0x127748F9301D319BF8CDE66D86D62p185l,
+	0x154FDD7F73BF3BD1BBB77203731FDp482l,
+#if LDBL_MAX_EXP >= 16384
+	0x1C633415D4C1D238D98CAB8A978A0p1076l,
+	0x192ECEB0D02EA182ECA1A7A51E316p2265l,
+	0x13D1676BB8A7ABBC94E9A519C6535p4643l,
+	0x188C0A40514412F3592982A7F0094p9398l,
+#endif
+};
+
+#if LDBL_MAX_EXP >= 16384
+const int MAX_POW2 = 15;
+#else
+const int MAX_POW2 = 9;
+#endif
+
+/* Powers of two. */
+long double pow2[] = {
+	0x1P1l,
+	0x1P2l,
+	0x1P4l,
+	0x1P8l,
+	0x1P16l,
+	0x1P32l,
+	0x1P64l,
+	0x1P128l,
+	0x1P256l,
+	0x1P512l,
+#if LDBL_MAX_EXP >= 16384
+	0x1P1024l,
+	0x1P2048l,
+	0x1P4096l,
+	0x1P8192l,
+#endif
+};
+
+/**
+ * Multiplies a number by a power of five.
+ * The result may be inexact and may not be the best possible approximation.
+ *
+ * @param mant Number to be multiplied.
+ * @param exp Base 5 exponent.
+ * @return mant multiplied by 5**exp
+ */
+static long double mul_pow5(long double mant, int exp)
+{
+	if (mant == 0.0l || mant == HUGE_VALL) {
+		return mant;
+	}
+	
+	if (abs(exp) >> (MAX_POW5 + 1) != 0) {
+		/* Too large exponent. */
+		errno = ERANGE;
+		return exp < 0 ? LDBL_MIN : HUGE_VALL;
+	}
+	
+	if (exp < 0) {
+		exp = abs(exp);
+		for (int bit = 0; bit <= MAX_POW5; ++bit) {
+			/* Multiply by powers of five bit-by-bit. */
+			if (((exp >> bit) & 1) != 0) {
+				mant /= pow5[bit];
+				if (mant == 0.0l) {
+					/* Underflow. */
+					mant = LDBL_MIN;
+					errno = ERANGE;
+					break;
+				}
+			}
+		}
+	} else {
+		for (int bit = 0; bit <= MAX_POW5; ++bit) {
+			/* Multiply by powers of five bit-by-bit. */
+			if (((exp >> bit) & 1) != 0) {
+				mant *= pow5[bit];
+				if (mant == HUGE_VALL) {
+					/* Overflow. */
+					errno = ERANGE;
+					break;
+				}
+			}
+		}
+	}
+	
+	return mant;
+}
+
+/**
+ * Multiplies a number by a power of two. This is always exact.
+ *
+ * @param mant Number to be multiplied.
+ * @param exp Base 2 exponent.
+ * @return mant multiplied by 2**exp.
+ */
+static long double mul_pow2(long double mant, int exp)
+{
+	if (mant == 0.0l || mant == HUGE_VALL) {
+		return mant;
+	}
+	
+	if (exp > LDBL_MAX_EXP || exp < LDBL_MIN_EXP) {
+		errno = ERANGE;
+		return exp < 0 ? LDBL_MIN : HUGE_VALL;
+	}
+	
+	if (exp < 0) {
+		exp = abs(exp);
+		for (int i = 0; i <= MAX_POW2; ++i) {
+			if (((exp >> i) & 1) != 0) {
+				mant /= pow2[i];
+				if (mant == 0.0l) {
+					mant = LDBL_MIN;
+					errno = ERANGE;
+					break;
+				}
+			}
+		}
+	} else {
+		for (int i = 0; i <= MAX_POW2; ++i) {
+			if (((exp >> i) & 1) != 0) {
+				mant *= pow2[i];
+				if (mant == HUGE_VALL) {
+					errno = ERANGE;
+					break;
+				}
+			}
+		}
+	}
+	
+	return mant;
+}
+
+/* end power functions ********************************************************/
+
+
+
+/**
+ * Convert decimal string representation of the floating point number.
+ * Function expects the string pointer to be already pointed at the first
+ * digit (i.e. leading optional sign was already consumed by the caller).
+ * 
+ * @param sptr Pointer to the storage of the string pointer. Upon successful
+ *     conversion, the string pointer is updated to point to the first
+ *     unrecognized character.
+ * @return An approximate representation of the input floating-point number.
+ */
+static long double parse_decimal(const char **sptr)
+{
+	assert(sptr != NULL);
+	assert (*sptr != NULL);
+	
+	const int DEC_BASE = 10;
+	const char DECIMAL_POINT = '.';
+	const char EXPONENT_MARK = 'e';
+	
+	const char *str = *sptr;
+	long double significand = 0;
+	long exponent = 0;
+	
+	/* number of digits parsed so far */
+	int parsed_digits = 0;
+	bool after_decimal = false;
+	
+	while (isdigit(*str) || (!after_decimal && *str == DECIMAL_POINT)) {
+		if (*str == DECIMAL_POINT) {
+			after_decimal = true;
+			str++;
+			continue;
+		}
+		
+		if (parsed_digits == 0 && *str == '0') {
+			/* Nothing, just skip leading zeros. */
+		} else if (parsed_digits < LDBL_DIG) {
+			significand = significand * DEC_BASE + (*str - '0');
+			parsed_digits++;
+		} else {
+			exponent++;
+		}
+		
+		if (after_decimal) {
+			/* Decrement exponent if we are parsing the fractional part. */
+			exponent--;
+		}
+		
+		str++;
+	}
+	
+	/* exponent */
+	if (tolower(*str) == EXPONENT_MARK) {
+		str++;
+		
+		/* Returns MIN/MAX value on error, which is ok. */
+		long exp = strtol(str, (char **) &str, DEC_BASE);
+		
+		if (exponent > 0 && exp > LONG_MAX - exponent) {
+			exponent = LONG_MAX;
+		} else if (exponent < 0 && exp < LONG_MIN - exponent) {
+			exponent = LONG_MIN;
+		} else {
+			exponent += exp;
+		}
+	}
+	
+	*sptr = str;
+	
+	/* Return multiplied by a power of ten. */
+	return mul_pow2(mul_pow5(significand, exponent), exponent);
+}
+
+/**
+ * Derive a hexadecimal digit from its character representation.
+ * 
+ * @param ch Character representation of the hexadecimal digit.
+ * @return Digit value represented by an integer.
+ */
+static inline int hex_value(char ch)
+{
+	if (ch <= '9') {
+		return ch - '0';
+	} else {
+		return 10 + tolower(ch) - 'a';
+	}
+}
+
+/**
+ * Convert hexadecimal string representation of the floating point number.
+ * Function expects the string pointer to be already pointed at the first
+ * digit (i.e. leading optional sign and 0x prefix were already consumed
+ * by the caller).
+ *
+ * @param sptr Pointer to the storage of the string pointer. Upon successful
+ *     conversion, the string pointer is updated to point to the first
+ *     unrecognized character.
+ * @return Representation of the input floating-point number.
+ */
+static long double parse_hexadecimal(const char **sptr)
+{
+	assert(sptr != NULL && *sptr != NULL);
+	
+	const int DEC_BASE = 10;
+	const int HEX_BASE = 16;
+	const char DECIMAL_POINT = '.';
+	const char EXPONENT_MARK = 'p';
+	
+	const char *str = *sptr;
+	long double significand = 0;
+	long exponent = 0;
+	
+	/* number of bits parsed so far */
+	int parsed_bits = 0;
+	bool after_decimal = false;
+	
+	while (isxdigit(*str) || (!after_decimal && *str == DECIMAL_POINT)) {
+		if (*str == DECIMAL_POINT) {
+			after_decimal = true;
+			str++;
+			continue;
+		}
+		
+		if (parsed_bits == 0 && *str == '0') {
+			/* Nothing, just skip leading zeros. */
+		} else if (parsed_bits <= LDBL_MANT_DIG) {
+			significand = significand * HEX_BASE + hex_value(*str);
+			parsed_bits += 4;
+		} else {
+			exponent += 4;
+		}
+		
+		if (after_decimal) {
+			exponent -= 4;
+		}
+		
+		str++;
+	}
+	
+	/* exponent */
+	if (tolower(*str) == EXPONENT_MARK) {
+		str++;
+		
+		/* Returns MIN/MAX value on error, which is ok. */
+		long exp = strtol(str, (char **) &str, DEC_BASE);
+		
+		if (exponent > 0 && exp > LONG_MAX - exponent) {
+			exponent = LONG_MAX;
+		} else if (exponent < 0 && exp < LONG_MIN - exponent) {
+			exponent = LONG_MIN;
+		} else {
+			exponent += exp;
+		}
+	}
+	
+	*sptr = str;
+	
+	/* Return multiplied by a power of two. */
+	return mul_pow2(significand, exponent);
+}
+
+/**
+ * Converts a string representation of a floating-point number to
+ * its native representation. Largely POSIX compliant, except for
+ * locale differences (always uses '.' at the moment) and rounding.
+ * Decimal strings are NOT guaranteed to be correctly rounded. This function
+ * should return a good enough approximation for most purposes but if you
+ * depend on a precise conversion, use hexadecimal representation.
+ * Hexadecimal strings are currently always rounded towards zero, regardless
+ * of the current rounding mode.
+ *
+ * @param nptr Input string.
+ * @param endptr If non-NULL, *endptr is set to the position of the first
+ *     unrecognized character.
+ * @return An approximate representation of the input floating-point number.
+ */
+long double strtold(const char *restrict nptr, char **restrict endptr)
+{
+	assert(nptr != NULL);
+	
+	const int RADIX = '.';
+	
+	/* minus sign */
+	bool negative = false;
+	/* current position in the string */
+	int i = 0;
+	
+	/* skip whitespace */
+	while (isspace(nptr[i])) {
+		i++;
+	}
+	
+	/* parse sign */
+	switch (nptr[i]) {
+	case '-':
+		negative = true;
+		/* Fallthrough */
+	case '+':
+		i++;
+	}
+	
+	/* check for NaN */
+	if (strncasecmp(&nptr[i], "nan", 3) == 0) {
+		// FIXME: return NaN
+		// TODO: handle the parenthesised case
+		
+		if (endptr != NULL) {
+			*endptr = (char *) nptr;
+		}
+		errno = EINVAL;
+		return 0;
+	}
+	
+	/* check for Infinity */
+	if (strncasecmp(&nptr[i], "inf", 3) == 0) {
+		i += 3;
+		if (strncasecmp(&nptr[i], "inity", 5) == 0) {
+			i += 5;
+		}
+		
+		if (endptr != NULL) {
+			*endptr = (char *) &nptr[i];
+		}
+		return negative ? -HUGE_VALL : +HUGE_VALL;
+	}
+
+	/* check for a hex number */
+	if (nptr[i] == '0' && tolower(nptr[i + 1]) == 'x' &&
+	    (isxdigit(nptr[i + 2]) ||
+	    (nptr[i + 2] == RADIX && isxdigit(nptr[i + 3])))) {
+		i += 2;
+		
+		const char *ptr = &nptr[i];
+		/* this call sets errno if appropriate. */
+		long double result = parse_hexadecimal(&ptr);
+		if (endptr != NULL) {
+			*endptr = (char *) ptr;
+		}
+		return negative ? -result : result;
+	}
+	
+	/* check for a decimal number */
+	if (isdigit(nptr[i]) || (nptr[i] == RADIX && isdigit(nptr[i + 1]))) {
+		const char *ptr = &nptr[i];
+		/* this call sets errno if appropriate. */
+		long double result = parse_decimal(&ptr);
+		if (endptr != NULL) {
+			*endptr = (char *) ptr;
+		}
+		return negative ? -result : result;
+	}
+	
+	/* nothing to parse */
+	if (endptr != NULL) {
+		*endptr = (char *) nptr;
+	}
+	errno = EINVAL;
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/string.c
===================================================================
--- uspace/lib/posix/src/string.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/string.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,699 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 String manipulation.
+ */
+
+#include "internal/common.h"
+#include "posix/string.h"
+
+#include <assert.h>
+
+#include <errno.h>
+
+#include "posix/limits.h"
+#include "posix/stdlib.h"
+#include "posix/signal.h"
+
+#include "libc/str.h"
+#include "libc/str_error.h"
+
+/**
+ * The same as strpbrk, except it returns pointer to the nul terminator
+ * if no occurence is found.
+ *
+ * @param s1 String in which to look for the bytes.
+ * @param s2 String of bytes to look for.
+ * @return Pointer to the found byte on success, pointer to the
+ *     string terminator otherwise.
+ */
+static char *strpbrk_null(const char *s1, const char *s2)
+{
+	while (!strchr(s2, *s1)) {
+		++s1;
+	}
+	
+	return (char *) s1;
+}
+
+/**
+ * Copy a string.
+ *
+ * @param dest Destination pre-allocated buffer.
+ * @param src Source string to be copied.
+ * @return Pointer to the destination buffer.
+ */
+char *strcpy(char *restrict dest, const char *restrict src)
+{
+	stpcpy(dest, src);
+	return dest;
+}
+
+/**
+ * Copy fixed length string.
+ *
+ * @param dest Destination pre-allocated buffer.
+ * @param src Source string to be copied.
+ * @param n Number of bytes to be stored into destination buffer.
+ * @return Pointer to the destination buffer.
+ */
+char *strncpy(char *restrict dest, const char *restrict src, size_t n)
+{
+	stpncpy(dest, src, n);
+	return dest;
+}
+
+/**
+ * Copy a string.
+ *
+ * @param dest Destination pre-allocated buffer.
+ * @param src Source string to be copied.
+ * @return Pointer to the nul character in the destination string.
+ */
+char *stpcpy(char *restrict dest, const char *restrict src)
+{
+	assert(dest != NULL);
+	assert(src != NULL);
+
+	for (size_t i = 0; ; ++i) {
+		dest[i] = src[i];
+		
+		if (src[i] == '\0') {
+			/* pointer to the terminating nul character */
+			return &dest[i];
+		}
+	}
+	
+	/* unreachable */
+	return NULL;
+}
+
+/**
+ * Copy fixed length string.
+ *
+ * @param dest Destination pre-allocated buffer.
+ * @param src Source string to be copied.
+ * @param n Number of bytes to be stored into destination buffer.
+ * @return Pointer to the first written nul character or &dest[n].
+ */
+char *stpncpy(char *restrict dest, const char *restrict src, size_t n)
+{
+	assert(dest != NULL);
+	assert(src != NULL);
+
+	for (size_t i = 0; i < n; ++i) {
+		dest[i] = src[i];
+	
+		/* the standard requires that nul characters
+		 * are appended to the length of n, in case src is shorter
+		 */
+		if (src[i] == '\0') {
+			char *result = &dest[i];
+			for (++i; i < n; ++i) {
+				dest[i] = '\0';
+			}
+			return result;
+		}
+	}
+	
+	return &dest[n];
+}
+
+/**
+ * Concatenate two strings.
+ *
+ * @param dest String to which src shall be appended.
+ * @param src String to be appended after dest.
+ * @return Pointer to destination buffer.
+ */
+char *strcat(char *restrict dest, const char *restrict src)
+{
+	assert(dest != NULL);
+	assert(src != NULL);
+
+	strcpy(strchr(dest, '\0'), src);
+	return dest;
+}
+
+/**
+ * Concatenate a string with part of another.
+ *
+ * @param dest String to which part of src shall be appended.
+ * @param src String whose part shall be appended after dest.
+ * @param n Number of bytes to append after dest.
+ * @return Pointer to destination buffer.
+ */
+char *strncat(char *restrict dest, const char *restrict src, size_t n)
+{
+	assert(dest != NULL);
+	assert(src != NULL);
+
+	char *zeroptr = strncpy(strchr(dest, '\0'), src, n);
+	/* strncpy doesn't append the nul terminator, so we do it here */
+	zeroptr[n] = '\0';
+	return dest;
+}
+
+/**
+ * Copy limited number of bytes in memory.
+ *
+ * @param dest Destination buffer.
+ * @param src Source buffer.
+ * @param c Character after which the copying shall stop.
+ * @param n Number of bytes that shall be copied if not stopped earlier by c.
+ * @return Pointer to the first byte after c in dest if found, NULL otherwise.
+ */
+void *memccpy(void *restrict dest, const void *restrict src, int c, size_t n)
+{
+	assert(dest != NULL);
+	assert(src != NULL);
+	
+	unsigned char* bdest = dest;
+	const unsigned char* bsrc = src;
+	
+	for (size_t i = 0; i < n; ++i) {
+		bdest[i] = bsrc[i];
+	
+		if (bsrc[i] == (unsigned char) c) {
+			/* pointer to the next byte */
+			return &bdest[i + 1];
+		}
+	}
+	
+	return NULL;
+}
+
+/**
+ * Duplicate a string.
+ *
+ * @param s String to be duplicated.
+ * @return Newly allocated copy of the string.
+ */
+char *strdup(const char *s)
+{
+	return strndup(s, SIZE_MAX);
+}
+
+/**
+ * Duplicate a specific number of bytes from a string.
+ *
+ * @param s String to be duplicated.
+ * @param n Maximum length of the resulting string..
+ * @return Newly allocated string copy of length at most n.
+ */
+char *strndup(const char *s, size_t n)
+{
+	assert(s != NULL);
+
+	size_t len = strnlen(s, n);
+	char *dup = malloc(len + 1);
+	if (dup == NULL) {
+		return NULL;
+	}
+
+	memcpy(dup, s, len);
+	dup[len] = '\0';
+
+	return dup;
+}
+
+/**
+ * Compare two strings.
+ *
+ * @param s1 First string to be compared.
+ * @param s2 Second string to be compared.
+ * @return Difference of the first pair of inequal characters,
+ *     or 0 if strings have the same content.
+ */
+int strcmp(const char *s1, const char *s2)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	return strncmp(s1, s2, STR_NO_LIMIT);
+}
+
+/**
+ * Compare part of two strings.
+ *
+ * @param s1 First string to be compared.
+ * @param s2 Second string to be compared.
+ * @param n Maximum number of characters to be compared.
+ * @return Difference of the first pair of inequal characters,
+ *     or 0 if strings have the same content.
+ */
+int strncmp(const char *s1, const char *s2, size_t n)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	for (size_t i = 0; i < n; ++i) {
+		if (s1[i] != s2[i]) {
+			return s1[i] - s2[i];
+		}
+		if (s1[i] == '\0') {
+			break;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * Find byte in memory.
+ *
+ * @param mem Memory area in which to look for the byte.
+ * @param c Byte to look for.
+ * @param n Maximum number of bytes to be inspected.
+ * @return Pointer to the specified byte on success,
+ *     NULL pointer otherwise.
+ */
+void *memchr(const void *mem, int c, size_t n)
+{
+	assert(mem != NULL);
+	
+	const unsigned char *s = mem;
+	
+	for (size_t i = 0; i < n; ++i) {
+		if (s[i] == (unsigned char) c) {
+			return (void *) &s[i];
+		}
+	}
+	return NULL;
+}
+
+/**
+ * Scan string for a first occurence of a character.
+ *
+ * @param s String in which to look for the character.
+ * @param c Character to look for.
+ * @return Pointer to the specified character on success,
+ *     NULL pointer otherwise.
+ */
+char *strchr(const char *s, int c)
+{
+	assert(s != NULL);
+	
+	char *res = gnu_strchrnul(s, c);
+	return (*res == c) ? res : NULL;
+}
+
+/**
+ * Scan string for a last occurence of a character.
+ *
+ * @param s String in which to look for the character.
+ * @param c Character to look for.
+ * @return Pointer to the specified character on success,
+ *     NULL pointer otherwise.
+ */
+char *strrchr(const char *s, int c)
+{
+	assert(s != NULL);
+	
+	const char *ptr = strchr(s, '\0');
+	
+	/* the same as in strchr, except it loops in reverse direction */
+	while (*ptr != (char) c) {
+		if (ptr == s) {
+			return NULL;
+		}
+
+		ptr--;
+	}
+
+	return (char *) ptr;
+}
+
+/**
+ * Scan string for a first occurence of a character.
+ *
+ * @param s String in which to look for the character.
+ * @param c Character to look for.
+ * @return Pointer to the specified character on success, pointer to the
+ *     string terminator otherwise.
+ */
+char *gnu_strchrnul(const char *s, int c)
+{
+	assert(s != NULL);
+	
+	while (*s != c && *s != '\0') {
+		s++;
+	}
+	
+	return (char *) s;
+}
+
+/**
+ * Scan a string for a first occurence of one of provided bytes.
+ *
+ * @param s1 String in which to look for the bytes.
+ * @param s2 String of bytes to look for.
+ * @return Pointer to the found byte on success,
+ *     NULL pointer otherwise.
+ */
+char *strpbrk(const char *s1, const char *s2)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	char *ptr = strpbrk_null(s1, s2);
+	return (*ptr == '\0') ? NULL : ptr;
+}
+
+/**
+ * Get the length of a complementary substring.
+ *
+ * @param s1 String that shall be searched for complementary prefix.
+ * @param s2 String of bytes that shall not occur in the prefix.
+ * @return Length of the prefix.
+ */
+size_t strcspn(const char *s1, const char *s2)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	char *ptr = strpbrk_null(s1, s2);
+	return (size_t) (ptr - s1);
+}
+
+/**
+ * Get length of a substring.
+ *
+ * @param s1 String that shall be searched for prefix.
+ * @param s2 String of bytes that the prefix must consist of.
+ * @return Length of the prefix.
+ */
+size_t strspn(const char *s1, const char *s2)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	const char *ptr;
+	for (ptr = s1; *ptr != '\0'; ++ptr) {
+		if (!strchr(s2, *ptr)) {
+			break;
+		}
+	}
+	return ptr - s1;
+}
+
+/**
+ * Find a substring. Uses Knuth-Morris-Pratt algorithm.
+ *
+ * @param s1 String in which to look for a substring.
+ * @param s2 Substring to look for.
+ * @return Pointer to the first character of the substring in s1, or NULL if
+ *     not found.
+ */
+char *strstr(const char *haystack, const char *needle)
+{
+	assert(haystack != NULL);
+	assert(needle != NULL);
+	
+	/* Special case - needle is an empty string. */
+	if (needle[0] == '\0') {
+		return (char *) haystack;
+	}
+	
+	/* Preprocess needle. */
+	size_t nlen = strlen(needle);
+	size_t prefix_table[nlen + 1];
+	
+	{
+		size_t i = 0;
+		ssize_t j = -1;
+		
+		prefix_table[i] = j;
+		
+		while (i < nlen) {
+			while (j >= 0 && needle[i] != needle[j]) {
+				j = prefix_table[j];
+			}
+			i++; j++;
+			prefix_table[i] = j;
+		}
+	}
+	
+	/* Search needle using the precomputed table. */
+	size_t npos = 0;
+	
+	for (size_t hpos = 0; haystack[hpos] != '\0'; ++hpos) {
+		while (npos != 0 && haystack[hpos] != needle[npos]) {
+			npos = prefix_table[npos];
+		}
+		
+		if (haystack[hpos] == needle[npos]) {
+			npos++;
+			
+			if (npos == nlen) {
+				return (char *) (haystack + hpos - nlen + 1);
+			}
+		}
+	}
+	
+	return NULL;
+}
+
+/** Split string by delimiters.
+ *
+ * @param s             String to be tokenized. May not be NULL.
+ * @param delim		String with the delimiters.
+ * @return              Pointer to the prefix of @a s before the first
+ *                      delimiter character. NULL if no such prefix
+ *                      exists.
+ */
+char *strtok(char *s, const char *delim)
+{
+	static char *next;
+
+	return strtok_r(s, delim, &next);
+}
+
+
+/** Split string by delimiters.
+ *
+ * @param s             String to be tokenized. May not be NULL.
+ * @param delim		String with the delimiters.
+ * @param next		Variable which will receive the pointer to the
+ *                      continuation of the string following the first
+ *                      occurrence of any of the delimiter characters.
+ *                      May be NULL.
+ * @return              Pointer to the prefix of @a s before the first
+ *                      delimiter character. NULL if no such prefix
+ *                      exists.
+ */
+char *strtok_r(char *s, const char *delim, char **next)
+{
+	char *start, *end;
+
+	if (s == NULL)
+		s = *next;
+
+	/* Skip over leading delimiters. */
+	while (*s && (strchr(delim, *s) != NULL)) ++s;
+	start = s;
+
+	/* Skip over token characters. */
+	while (*s && (strchr(delim, *s) == NULL)) ++s;
+	end = s;
+	*next = (*s ? s + 1 : s);
+
+	if (start == end) {
+		return NULL;	/* No more tokens. */
+	}
+
+	/* Overwrite delimiter with NULL terminator. */
+	*end = '\0';
+	return start;
+}
+
+/**
+ * String comparison using collating information.
+ *
+ * Currently ignores locale and just calls strcmp.
+ *
+ * @param s1 First string to be compared.
+ * @param s2 Second string to be compared.
+ * @return Difference of the first pair of inequal characters,
+ *     or 0 if strings have the same content.
+ */
+int strcoll(const char *s1, const char *s2)
+{
+	assert(s1 != NULL);
+	assert(s2 != NULL);
+
+	return strcmp(s1, s2);
+}
+
+/**
+ * Transform a string in such a way that the resulting string yields the same
+ * results when passed to the strcmp as if the original string is passed to
+ * the strcoll.
+ *
+ * Since strcoll is equal to strcmp here, this just makes a copy.
+ *
+ * @param s1 Transformed string.
+ * @param s2 Original string.
+ * @param n Maximum length of the transformed string.
+ * @return Length of the transformed string.
+ */
+size_t strxfrm(char *restrict s1, const char *restrict s2, size_t n)
+{
+	assert(s1 != NULL || n == 0);
+	assert(s2 != NULL);
+
+	size_t len = strlen(s2);
+
+	if (n > len) {
+		strcpy(s1, s2);
+	}
+
+	return len;
+}
+
+/**
+ * Get error message string.
+ *
+ * @param errnum Error code for which to obtain human readable string.
+ * @return Error message.
+ */
+char *strerror(int errnum)
+{
+	// FIXME: move strerror() and strerror_r() to libc.
+	return (char *) str_error(errnum);
+}
+
+/**
+ * Get error message string.
+ *
+ * @param errnum Error code for which to obtain human readable string.
+ * @param buf Buffer to store a human readable string to.
+ * @param bufsz Size of buffer pointed to by buf.
+ * @return Zero on success, errno otherwise.
+ */
+int strerror_r(int errnum, char *buf, size_t bufsz)
+{
+	assert(buf != NULL);
+	
+	char *errstr = strerror(errnum);
+	
+	if (strlen(errstr) + 1 > bufsz) {
+		return ERANGE;
+	} else {
+		strcpy(buf, errstr);
+	}
+
+	return EOK;
+}
+
+/**
+ * Get length of the string.
+ *
+ * @param s String which length shall be determined.
+ * @return Length of the string.
+ */
+size_t strlen(const char *s)
+{
+	assert(s != NULL);
+	
+	return (size_t) (strchr(s, '\0') - s);
+}
+
+/**
+ * Get limited length of the string.
+ *
+ * @param s String which length shall be determined.
+ * @param n Maximum number of bytes that can be examined to determine length.
+ * @return The lower of either string length or n limit.
+ */
+size_t strnlen(const char *s, size_t n)
+{
+	assert(s != NULL);
+	
+	for (size_t sz = 0; sz < n; ++sz) {
+		
+		if (s[sz] == '\0') {
+			return sz;
+		}
+	}
+	
+	return n;
+}
+
+/**
+ * Get description of a signal.
+ *
+ * @param signum Signal number.
+ * @return Human readable signal description.
+ */
+char *strsignal(int signum)
+{
+	static const char *const sigstrings[] = {
+		[SIGABRT] = "SIGABRT (Process abort signal)",
+		[SIGALRM] = "SIGALRM (Alarm clock)",
+		[SIGBUS] = "SIGBUS (Access to an undefined portion of a memory object)",
+		[SIGCHLD] = "SIGCHLD (Child process terminated, stopped, or continued)",
+		[SIGCONT] = "SIGCONT (Continue executing, if stopped)",
+		[SIGFPE] = "SIGFPE (Erroneous arithmetic operation)",
+		[SIGHUP] = "SIGHUP (Hangup)",
+		[SIGILL] = "SIGILL (Illegal instruction)",
+		[SIGINT] = "SIGINT (Terminal interrupt signal)",
+		[SIGKILL] = "SIGKILL (Kill process)",
+		[SIGPIPE] = "SIGPIPE (Write on a pipe with no one to read it)",
+		[SIGQUIT] = "SIGQUIT (Terminal quit signal)",
+		[SIGSEGV] = "SIGSEGV (Invalid memory reference)",
+		[SIGSTOP] = "SIGSTOP (Stop executing)",
+		[SIGTERM] = "SIGTERM (Termination signal)",
+		[SIGTSTP] = "SIGTSTP (Terminal stop signal)",
+		[SIGTTIN] = "SIGTTIN (Background process attempting read)",
+		[SIGTTOU] = "SIGTTOU (Background process attempting write)",
+		[SIGUSR1] = "SIGUSR1 (User-defined signal 1)",
+		[SIGUSR2] = "SIGUSR2 (User-defined signal 2)",
+		[SIGPOLL] = "SIGPOLL (Pollable event)",
+		[SIGPROF] = "SIGPROF (Profiling timer expired)",
+		[SIGSYS] = "SIGSYS (Bad system call)",
+		[SIGTRAP] = "SIGTRAP (Trace/breakpoint trap)",
+		[SIGURG] = "SIGURG (High bandwidth data is available at a socket)",
+		[SIGVTALRM] = "SIGVTALRM (Virtual timer expired)",
+		[SIGXCPU] = "SIGXCPU (CPU time limit exceeded)",
+		[SIGXFSZ] = "SIGXFSZ (File size limit exceeded)"
+	};
+
+	if (signum <= _TOP_SIGNAL) {
+		return (char *) sigstrings[signum];
+	}
+
+	return (char *) "ERROR, Invalid signal number";
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/strings.c
===================================================================
--- uspace/lib/posix/src/strings.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/strings.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,186 @@
+/*
+ * Copyright (c) 2011 Jiri Zarevucky
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Additional string manipulation.
+ */
+
+#include "internal/common.h"
+#include "posix/strings.h"
+
+#include "posix/string.h"
+#include "posix/ctype.h"
+
+#include "libc/mem.h"
+#include "libc/str.h"
+
+/**
+ * Find first set bit (beginning with the least significant bit).
+ *
+ * @param i Integer in which to look for the first set bit.
+ * @return Index of first set bit. Bits are numbered starting at one.
+ */
+int ffs(int i)
+{
+	if (i == 0) {
+		return 0;
+	}
+
+	int result = 0;
+
+	// XXX: assumes at most 32-bit int
+	if (!(i & 0xFFFF)) {
+		result |= 16;
+		i >>= 16;
+	}
+	if (!(i & 0xFF)) {
+		result |= 8;
+		i >>= 8;
+	}
+	if (!(i & 0xF)) {
+		result |= 4;
+		i >>= 4;
+	}
+	if (!(i & 0x3)) {
+		result |= 2;
+		i >>= 2;
+	}
+	if (!(i & 0x1)) {
+		result |= 1;
+	}
+
+	return result + 1;
+}
+
+/**
+ * Compare two strings (case-insensitive).
+ *
+ * @param s1 First string to be compared.
+ * @param s2 Second string to be compared.
+ * @return Difference of the first pair of inequal characters,
+ *     or 0 if strings have the same content.
+ */
+int strcasecmp(const char *s1, const char *s2)
+{
+	return strncasecmp(s1, s2, STR_NO_LIMIT);
+}
+
+/**
+ * Compare part of two strings (case-insensitive).
+ *
+ * @param s1 First string to be compared.
+ * @param s2 Second string to be compared.
+ * @param n Maximum number of characters to be compared.
+ * @return Difference of the first pair of inequal characters,
+ *     or 0 if strings have the same content.
+ */
+int strncasecmp(const char *s1, const char *s2, size_t n)
+{
+	for (size_t i = 0; i < n; ++i) {
+		int cmp = tolower(s1[i]) - tolower(s2[i]);
+		if (cmp != 0) {
+			return cmp;
+		}
+		
+		if (s1[i] == 0) {
+			return 0;
+		}
+	}
+	
+	return 0;
+}
+
+/**
+ * Compare two memory areas.
+ *
+ * @param mem1 Pointer to the first area to compare.
+ * @param mem2 Pointer to the second area to compare.
+ * @param n Common size of both areas.
+ * @return If n is 0, return zero. If the areas match, return
+ *     zero. Otherwise return non-zero.
+ */
+int bcmp(const void *mem1, const void *mem2, size_t n)
+{
+	return memcmp(mem1, mem2, n);
+}
+
+/**
+ * Copy bytes in memory with overlapping areas.
+ *
+ * @param src Source area.
+ * @param dest Destination area.
+ * @param n Number of bytes to copy.
+ */
+void bcopy(const void *src, void *dest, size_t n)
+{
+	/* Note that memmove has different order of arguments. */
+	memmove(dest, src, n);
+}
+
+/**
+ * Reset bytes in memory area to zero.
+ *
+ * @param mem Memory area to be zeroed.
+ * @param n Number of bytes to reset.
+ */
+void bzero(void *mem, size_t n)
+{
+	memset(mem, 0, n);
+}
+
+/**
+ * Scan string for a first occurence of a character.
+ *
+ * @param s String in which to look for the character.
+ * @param c Character to look for.
+ * @return Pointer to the specified character on success,
+ *     NULL pointer otherwise.
+ */
+char *index(const char *s, int c)
+{
+	return strchr(s, c);
+}
+
+/**
+ * Scan string for a last occurence of a character.
+ *
+ * @param s String in which to look for the character.
+ * @param c Character to look for.
+ * @return Pointer to the specified character on success,
+ *     NULL pointer otherwise.
+ */
+char *rindex(const char *s, int c)
+{
+	return strrchr(s, c);
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/sys/mman.c
===================================================================
--- uspace/lib/posix/src/sys/mman.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/sys/mman.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2006 Ondrej Palkovsky
+ * 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
+ */
+
+#include "../internal/common.h"
+#include <posix/sys/mman.h>
+#include <posix/sys/types.h>
+#include <libc/as.h>
+#include <posix/unistd.h>
+
+void *mmap(void *start, size_t length, int prot, int flags, int fd,
+    off_t offset)
+{
+	if (!start)
+		start = AS_AREA_ANY;
+	
+//	if (!((flags & MAP_SHARED) ^ (flags & MAP_PRIVATE)))
+//		return MAP_FAILED;
+	
+	if (!(flags & MAP_ANONYMOUS))
+		return MAP_FAILED;
+	
+	return as_area_create(start, length, prot, AS_AREA_UNPAGED);
+}
+
+int munmap(void *start, size_t length)
+{
+	int rc = as_area_destroy(start);
+	if (rc != EOK) {
+		errno = rc;
+		return -1;
+	}
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/sys/stat.c
===================================================================
--- uspace/lib/posix/src/sys/stat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/sys/stat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,163 @@
+/*
+ * Copyright (c) 2011 Jiri Zarevucky
+ * Copyright (c) 2011 Petr Koupy
+ * 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 File status handling.
+ */
+
+#include "../internal/common.h"
+#include "posix/sys/stat.h"
+#include "libc/vfs/vfs.h"
+
+#include <errno.h>
+#include "libc/mem.h"
+
+/**
+ * Convert HelenOS stat struct into POSIX stat struct (if possible).
+ *
+ * @param dest POSIX stat struct.
+ * @param src HelenOS stat struct.
+ *
+ * @return 0 on success, -1 on error.
+ */
+static int stat_to_posix(struct stat *dest, vfs_stat_t *src)
+{
+	memset(dest, 0, sizeof(struct stat));
+	
+	dest->st_dev = src->service;
+	dest->st_ino = src->index;
+	
+	/* HelenOS doesn't support permissions, so we set them all */
+	dest->st_mode = S_IRWXU | S_IRWXG | S_IRWXO;
+	if (src->is_file) {
+		dest->st_mode |= S_IFREG;
+	}
+	if (src->is_directory) {
+		dest->st_mode |= S_IFDIR;
+	}
+	
+	dest->st_nlink = src->lnkcnt;
+	dest->st_size = src->size;
+
+	if (src->size > INT64_MAX) {
+		errno = ERANGE;
+		return -1;
+	}
+
+	return 0;
+}
+
+/**
+ * Retrieve file status for file associated with file descriptor.
+ *
+ * @param fd File descriptor of the opened file.
+ * @param st Status structure to be filled with information.
+ * @return Zero on success, -1 otherwise.
+ */
+int fstat(int fd, struct stat *st)
+{
+	vfs_stat_t hst;
+	if (failed(vfs_stat(fd, &hst)))
+		return -1;
+	return stat_to_posix(st, &hst);
+}
+
+/**
+ * Retrieve file status for symbolic link.
+ * 
+ * @param path Path to the symbolic link.
+ * @param st Status structure to be filled with information.
+ * @return Zero on success, -1 otherwise.
+ */
+int lstat(const char *restrict path, struct stat *restrict st)
+{
+	/* There are currently no symbolic links in HelenOS. */
+	return stat(path, st);
+}
+
+/**
+ * Retrieve file status for regular file (or symbolic link target).
+ *
+ * @param path Path to the file/link.
+ * @param st Status structure to be filled with information.
+ * @return Zero on success, -1 otherwise.
+ */
+int stat(const char *restrict path, struct stat *restrict st)
+{
+	vfs_stat_t hst;
+	if (failed(vfs_stat_path(path, &hst)))
+		return -1;
+	return stat_to_posix(st, &hst);
+}
+
+/**
+ * Change permission bits for the file if possible.
+ * 
+ * @param path Path to the file.
+ * @param mode Permission bits to be set.
+ * @return Zero on success, -1 otherwise.
+ */
+int chmod(const char *path, mode_t mode)
+{
+	/* HelenOS doesn't support permissions, return success. */
+	return 0;
+}
+
+/**
+ * Set the file mode creation mask of the process.
+ * 
+ * @param mask Set permission bits are cleared in the related creation
+ *     functions. Non-permission bits are ignored.
+ * @return Previous file mode creation mask.
+ */
+mode_t umask(mode_t mask)
+{
+	/* HelenOS doesn't support permissions, return empty mask. */
+	return 0;
+}
+
+/**
+ * Create a directory.
+ * 
+ * @param path Path to the new directory.
+ * @param mode Permission bits to be set.
+ * @return Zero on success, -1 otherwise.
+ */
+int mkdir(const char *path, mode_t mode)
+{
+	if (failed(vfs_link_path(path, KIND_DIRECTORY, NULL)))
+		return -1;
+	else
+		return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/sys/wait.c
===================================================================
--- uspace/lib/posix/src/sys/wait.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/sys/wait.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,119 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Support for waiting.
+ */
+
+#include "../internal/common.h"
+#include "posix/sys/wait.h"
+
+#include "libc/task.h"
+#include <assert.h>
+
+#include <errno.h>
+
+#include "posix/limits.h"
+#include "posix/signal.h"
+
+int __posix_wifexited(int status) {
+	return status != INT_MIN;
+}
+
+int __posix_wexitstatus(int status) {
+	assert(__posix_wifexited(status));
+	return status;
+}
+
+int __posix_wifsignaled(int status) {
+	return status == INT_MIN;
+}
+
+int __posix_wtermsig(int status) {
+	assert(__posix_wifsignaled(status));
+	/* There is no way to distinguish reason
+	 * for unexpected termination at the moment.
+	 */
+	return SIGABRT;
+}
+
+/**
+ * Wait for any child process to stop or terminate.
+ * 
+ * @param stat_ptr Location of the final status code of the child process.
+ * @return ID of the child process for which status is reported,
+ *     -1 on signal interrupt, (pid_t)-1 otherwise.
+ */
+pid_t wait(int *stat_ptr)
+{
+	/* HelenOS does not support this. */
+	errno = ENOSYS;
+	return (pid_t) -1;
+}
+
+/**
+ * Wait for a child process to stop or terminate.
+ * 
+ * @param pid What child process shall the caller wait for. See POSIX manual
+ *     for details.
+ * @param stat_ptr Location of the final status code of the child process.
+ * @param options Constraints of the waiting. See POSIX manual for details.
+ * @return ID of the child process for which status is reported,
+ *     -1 on signal interrupt, 0 if non-blocking wait is requested but there is
+ *     no child process whose status can be reported, (pid_t)-1 otherwise.
+ */
+pid_t waitpid(pid_t pid, int *stat_ptr, int options)
+{
+	assert(stat_ptr != NULL);
+	assert(options == 0 /* None of the options are supported. */);
+	
+	task_exit_t texit;
+	int retval;
+	
+	if (failed(task_wait_task_id((task_id_t) pid, &texit, &retval))) {
+		/* Unable to retrieve status. */
+		return (pid_t) -1;
+	}
+	
+	if (texit == TASK_EXIT_NORMAL) {
+		// FIXME: relies on application not returning this value
+		assert(retval != INT_MIN);
+		*stat_ptr = retval;
+	} else {
+		/* Reserve the lowest value for unexpected termination. */
+		*stat_ptr = INT_MIN;
+	}
+	
+	return pid;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/time.c
===================================================================
--- uspace/lib/posix/src/time.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/time.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,330 @@
+/*
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Time measurement support.
+ */
+
+#include "internal/common.h"
+#include "posix/time.h"
+
+#include "posix/ctype.h"
+
+#include <errno.h>
+
+#include "posix/signal.h"
+#include <assert.h>
+
+#include "libc/async.h"
+#include "libc/malloc.h"
+#include "libc/task.h"
+#include "libc/stats.h"
+#include "libc/stddef.h"
+#include "libc/sys/time.h"
+
+// TODO: test everything in this file
+
+/* In some places in this file, phrase "normalized broken-down time" is used.
+ * This means time broken down to components (year, month, day, hour, min, sec),
+ * in which every component is in its proper bounds. Non-normalized time could
+ * e.g. be 2011-54-5 29:13:-5, which would semantically mean start of year 2011
+ * + 53 months + 4 days + 29 hours + 13 minutes - 5 seconds.
+ */
+
+int posix_daylight;
+long posix_timezone;
+char *posix_tzname[2];
+
+/**
+ * Set timezone conversion information.
+ */
+void tzset(void)
+{
+	// TODO: read environment
+	posix_tzname[0] = (char *) "GMT";
+	posix_tzname[1] = (char *) "GMT";
+	posix_daylight = 0;
+	posix_timezone = 0;
+}
+
+/**
+ * Converts a time value to a broken-down UTC time.
+ * 
+ * @param timer Time to convert.
+ * @param result Structure to store the result to.
+ * @return Value of result on success, NULL on overflow.
+ */
+struct tm *gmtime_r(const time_t *restrict timer,
+    struct tm *restrict result)
+{
+	if (failed(time_utc2tm(*timer, result))) {
+		return NULL;
+	}
+
+	return result;
+}
+
+/**
+ * Converts a time value to a broken-down UTC time.
+ * (non reentrant version)
+ *
+ * @param timep  Time to convert
+ * @return       Pointer to a statically allocated structure that stores
+ *               the result, NULL in case of error.
+ */
+struct tm *gmtime(const time_t *restrict timep)
+{
+	static struct tm result;
+
+	return gmtime_r(timep, &result);
+}
+
+/**
+ * Converts a time value to a broken-down local time.
+ * 
+ * @param timer Time to convert.
+ * @param result Structure to store the result to.
+ * @return Value of result on success, NULL on overflow.
+ */
+struct tm *localtime_r(const time_t *restrict timer,
+    struct tm *restrict result)
+{
+	// TODO: deal with timezone
+	// currently assumes system and all times are in GMT
+	return gmtime_r(timer, result);
+}
+
+/**
+ * Converts a time value to a broken-down local time.
+ * (non reentrant version)
+ *
+ * @param timep    Time to convert.
+ * @return         Pointer to a statically allocated structure that stores
+ *                 the result, NULL in case of error.
+ */
+struct tm *localtime(const time_t *restrict timep)
+{
+	static struct tm result;
+
+	return localtime_r(timep, &result);
+}
+
+/**
+ * Converts broken-down time to a string in format
+ * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
+ *
+ * @param timeptr Broken-down time structure.
+ * @param buf Buffer to store string to, must be at least ASCTIME_BUF_LEN
+ *     bytes long.
+ * @return Value of buf.
+ */
+char *asctime_r(const struct tm *restrict timeptr,
+    char *restrict buf)
+{
+	time_tm2str(timeptr, buf);
+	return buf;
+}
+
+/**
+ * Convers broken-down time to a string in format
+ * "Sun Jan 1 00:00:00 1970\n". (Obsolete)
+ * (non reentrant version)
+ *
+ * @param timeptr    Broken-down time structure.
+ * @return           Pointer to a statically allocated buffer that stores
+ *                   the result, NULL in case of error.
+ */
+char *asctime(const struct tm *restrict timeptr)
+{
+	static char buf[ASCTIME_BUF_LEN];
+
+	return asctime_r(timeptr, buf);
+}
+
+/**
+ * Converts the calendar time to a string in format
+ * "Sun Jan 1 00:00:00 1970\n" (Obsolete)
+ * 
+ * @param timer Time to convert.
+ * @param buf Buffer to store string to. Must be at least ASCTIME_BUF_LEN
+ *     bytes long.
+ * @return Pointer to buf on success, NULL on failure.
+ */
+char *ctime_r(const time_t *timer, char *buf)
+{
+	if (failed(time_local2str(*timer, buf))) {
+		return NULL;
+	}
+
+	return buf;
+}
+
+/**
+ * Converts the calendar time to a string in format
+ * "Sun Jan 1 00:00:00 1970\n" (Obsolete)
+ * (non reentrant version)
+ *
+ * @param timep    Time to convert.
+ * @return         Pointer to a statically allocated buffer that stores
+ *                 the result, NULL in case of error.
+ */
+char *ctime(const time_t *timep)
+{
+	static char buf[ASCTIME_BUF_LEN];
+
+	return ctime_r(timep, buf);
+}
+
+/**
+ * Get clock resolution. Only CLOCK_REALTIME is supported.
+ *
+ * @param clock_id Clock ID.
+ * @param res Pointer to the variable where the resolution is to be written.
+ * @return 0 on success, -1 with errno set on failure.
+ */
+int clock_getres(clockid_t clock_id, struct timespec *res)
+{
+	assert(res != NULL);
+
+	switch (clock_id) {
+		case CLOCK_REALTIME:
+			res->tv_sec = 0;
+			res->tv_nsec = 1000; /* Microsecond resolution. */
+			return 0;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+}
+
+/**
+ * Get time. Only CLOCK_REALTIME is supported.
+ * 
+ * @param clock_id ID of the clock to query.
+ * @param tp Pointer to the variable where the time is to be written.
+ * @return 0 on success, -1 with errno on failure.
+ */
+int clock_gettime(clockid_t clock_id, struct timespec *tp)
+{
+	assert(tp != NULL);
+
+	switch (clock_id) {
+		case CLOCK_REALTIME:
+			;
+			struct timeval tv;
+			gettimeofday(&tv, NULL);
+			tp->tv_sec = tv.tv_sec;
+			tp->tv_nsec = tv.tv_usec * 1000;
+			return 0;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+}
+
+/**
+ * Set time on a specified clock. As HelenOS doesn't support this yet,
+ * this function always fails.
+ * 
+ * @param clock_id ID of the clock to set.
+ * @param tp Time to set.
+ * @return 0 on success, -1 with errno on failure.
+ */
+int clock_settime(clockid_t clock_id,
+    const struct timespec *tp)
+{
+	assert(tp != NULL);
+
+	switch (clock_id) {
+		case CLOCK_REALTIME:
+			// TODO: setting clock
+			// FIXME: HelenOS doesn't actually support hardware
+			//        clock yet
+			errno = EPERM;
+			return -1;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+}
+
+/**
+ * Sleep on a specified clock.
+ * 
+ * @param clock_id ID of the clock to sleep on (only CLOCK_REALTIME supported).
+ * @param flags Flags (none supported).
+ * @param rqtp Sleep time.
+ * @param rmtp Remaining time is written here if sleep is interrupted.
+ * @return 0 on success, -1 with errno set on failure.
+ */
+int clock_nanosleep(clockid_t clock_id, int flags,
+    const struct timespec *rqtp, struct timespec *rmtp)
+{
+	assert(rqtp != NULL);
+	assert(rmtp != NULL);
+
+	switch (clock_id) {
+		case CLOCK_REALTIME:
+			// TODO: interruptible sleep
+			if (rqtp->tv_sec != 0) {
+				async_sleep(rqtp->tv_sec);
+			}
+			if (rqtp->tv_nsec != 0) {
+				async_usleep(rqtp->tv_nsec / 1000);
+			}
+			return 0;
+		default:
+			errno = EINVAL;
+			return -1;
+	}
+}
+
+/**
+ * Get CPU time used since the process invocation.
+ *
+ * @return Consumed CPU cycles by this process or -1 if not available.
+ */
+clock_t clock(void)
+{
+	clock_t total_cycles = -1;
+	stats_task_t *task_stats = stats_get_task(task_get_id());
+	if (task_stats) {
+		total_cycles = (clock_t) (task_stats->kcycles +
+		    task_stats->ucycles);
+		free(task_stats);
+		task_stats = 0;
+	}
+
+	return total_cycles;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/src/unistd.c
===================================================================
--- uspace/lib/posix/src/unistd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/posix/src/unistd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,491 @@
+/*
+ * Copyright (c) 2011 Jiri Zarevucky
+ * Copyright (c) 2011 Petr Koupy
+ * 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 Miscellaneous standard definitions.
+ */
+
+#include "internal/common.h"
+#include "posix/unistd.h"
+
+#include <errno.h>
+
+#include "posix/string.h"
+#include "posix/fcntl.h"
+
+#include "libc/task.h"
+#include "libc/thread.h"
+#include "libc/stats.h"
+#include "libc/malloc.h"
+#include "libc/vfs/vfs.h"
+
+#include <libarch/config.h>
+
+// FIXME: replace with a hash table
+aoff64_t posix_pos[MAX_OPEN_FILES];
+
+/* Array of environment variable strings (NAME=VALUE). */
+char **environ = NULL;
+
+/**
+ * Sleep for the specified number of seconds.
+ *
+ * Note that POSIX allows this call to be interrupted and then the return
+ * value represents remaining seconds for the sleep. HelenOS does not offer
+ * such functionality and thus always the whole sleep is taken.
+ *
+ * @param seconds Number of seconds to sleep.
+ * @return Always 0 on HelenOS.
+ */
+unsigned int sleep(unsigned int seconds)
+{
+	return thread_sleep(seconds);
+}
+
+/**
+ * Get current user name.
+ *
+ * @return User name (static) string or NULL if not found.
+ */
+char *getlogin(void)
+{
+	/* There is currently no support for user accounts in HelenOS. */
+	return (char *) "user";
+}
+
+/**
+ * Get current user name.
+ *
+ * @param name Pointer to a user supplied buffer.
+ * @param namesize Length of the buffer.
+ * @return Zero on success, error code otherwise.
+ */
+int getlogin_r(char *name, size_t namesize)
+{
+	/* There is currently no support for user accounts in HelenOS. */
+	if (namesize >= 5) {
+		strcpy(name, (char *) "user");
+		return 0;
+	} else {
+		errno = ERANGE;
+		return -1;
+	}
+}
+
+/**
+ * Test whether open file descriptor is associated with a terminal.
+ *
+ * @param fd Open file descriptor to test.
+ * @return Boolean result of the test.
+ */
+int isatty(int fd)
+{
+	// TODO
+	/* Always returns false, because there is no easy way to find
+	 * out under HelenOS. */
+	return 0;
+}
+
+/**
+ * Get the pathname of the current working directory.
+ *
+ * @param buf Buffer into which the pathname shall be put.
+ * @param size Size of the buffer.
+ * @return Buffer pointer on success, NULL on failure.
+ */
+char *getcwd(char *buf, size_t size)
+{
+	if (failed(vfs_cwd_get(buf, size))) 
+		return NULL;
+	return buf;
+}
+
+/**
+ * Change the current working directory.
+ *
+ * @param path New working directory.
+ */
+int chdir(const char *path)
+{
+	if (failed(vfs_cwd_set(path)))
+		return -1;
+	return 0;
+}
+
+/**
+ * Determine the page size of the current run of the process.
+ *
+ * @return Page size of the process.
+ */
+int getpagesize(void)
+{
+	return PAGE_SIZE;
+}
+
+/**
+ * Get the process ID of the calling process.
+ *
+ * @return Process ID.
+ */
+pid_t getpid(void)
+{
+	return task_get_id();
+}
+
+/**
+ * Get the real user ID of the calling process.
+ *
+ * @return User ID.
+ */
+uid_t getuid(void)
+{
+	/* There is currently no support for user accounts in HelenOS. */
+	return 0;
+}
+
+/**
+ * Get the real group ID of the calling process.
+ * 
+ * @return Group ID.
+ */
+gid_t getgid(void)
+{
+	/* There is currently no support for user accounts in HelenOS. */
+	return 0;
+}
+
+/**
+ * Close a file.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @return 0 on success, -1 on error.
+ */
+int close(int fildes)
+{
+	posix_pos[fildes] = 0;
+	if (failed(vfs_put(fildes)))
+		return -1;
+	else
+		return 0;
+}
+
+/**
+ * Read from a file.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @param buf Buffer to which the read bytes shall be stored.
+ * @param nbyte Upper limit on the number of read bytes.
+ * @return Number of read bytes on success, -1 otherwise.
+ */
+ssize_t read(int fildes, void *buf, size_t nbyte)
+{
+	size_t nread;
+	if (failed(vfs_read(fildes, &posix_pos[fildes], buf, nbyte, &nread)))
+		return -1;
+	return (ssize_t) nread;
+}
+
+/**
+ * Write to a file.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @param buf Buffer to write.
+ * @param nbyte Size of the buffer.
+ * @return Number of written bytes on success, -1 otherwise.
+ */
+ssize_t write(int fildes, const void *buf, size_t nbyte)
+{
+	size_t nwr;
+	if (failed(vfs_write(fildes, &posix_pos[fildes], buf, nbyte, &nwr)))
+		return -1;
+	return nwr;
+}
+
+/**
+ * Reposition read/write file offset
+ *
+ * @param fildes File descriptor of the opened file.
+ * @param offset New offset in the file.
+ * @param whence The position from which the offset argument is specified.
+ * @return Upon successful completion, returns the resulting offset
+ *         as measured in bytes from the beginning of the file, -1 otherwise.
+ */
+off_t lseek(int fildes, off_t offset, int whence)
+{
+	vfs_stat_t st;
+
+	switch (whence) {
+	case SEEK_SET:
+		posix_pos[fildes] = offset;
+		break;
+	case SEEK_CUR:
+		posix_pos[fildes] += offset;
+		break;
+	case SEEK_END:
+		if (failed(vfs_stat(fildes, &st)))
+			return -1;
+		posix_pos[fildes] = st.size + offset;
+		break;
+	}
+	if (posix_pos[fildes] > INT64_MAX) {
+		/* The native width is too large for the POSIX interface. */
+		errno = ERANGE;
+		return -1;
+	}
+	return posix_pos[fildes];
+}
+
+/**
+ * Requests outstanding data to be written to the underlying storage device.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @return Zero on success, -1 otherwise.
+ */
+int fsync(int fildes)
+{
+	if (failed(vfs_sync(fildes)))
+		return -1;
+	else
+		return 0;
+}
+
+/**
+ * Truncate a file to a specified length.
+ *
+ * @param fildes File descriptor of the opened file.
+ * @param length New length of the file.
+ * @return Zero on success, -1 otherwise.
+ */
+int ftruncate(int fildes, off_t length)
+{
+	if (failed(vfs_resize(fildes, (aoff64_t) length)))
+		return -1;
+	else
+		return 0;
+}
+
+/**
+ * Remove a directory.
+ *
+ * @param path Directory pathname.
+ * @return Zero on success, -1 otherwise.
+ */
+int rmdir(const char *path)
+{
+	if (failed(vfs_unlink_path(path)))
+		return -1;
+	else
+		return 0;
+}
+
+/**
+ * Remove a link to a file.
+ * 
+ * @param path File pathname.
+ * @return Zero on success, -1 otherwise.
+ */
+int unlink(const char *path)
+{
+	if (failed(vfs_unlink_path(path)))
+		return -1;
+	else
+		return 0;
+}
+
+/**
+ * Duplicate an open file descriptor.
+ *
+ * @param fildes File descriptor to be duplicated.
+ * @return On success, new file descriptor for the same file, otherwise -1.
+ */
+int dup(int fildes)
+{
+	return fcntl(fildes, F_DUPFD, 0);
+}
+
+/**
+ * Duplicate an open file descriptor.
+ * 
+ * @param fildes File descriptor to be duplicated.
+ * @param fildes2 File descriptor to be paired with the same file description
+ *     as is paired fildes.
+ * @return fildes2 on success, -1 otherwise.
+ */
+int dup2(int fildes, int fildes2)
+{
+	int file;
+	if (failed(vfs_clone(fildes, fildes2, false, &file))) {
+		return -1;
+	}
+	return file;
+}
+
+/**
+ * Determine accessibility of a file.
+ *
+ * @param path File to check accessibility for.
+ * @param amode Either check for existence or intended access mode.
+ * @return Zero on success, -1 otherwise.
+ */
+int access(const char *path, int amode)
+{
+	if (amode == F_OK || (amode & (X_OK | W_OK | R_OK))) {
+		/* HelenOS doesn't support permissions, permission checks
+		 * are equal to existence check.
+		 *
+		 * Check file existence by attempting to open it.
+		 */
+		int fd = open(path, O_RDONLY);
+		if (fd < 0)
+			return -1;
+		close(fd);
+		return 0;
+	} else {
+		/* Invalid amode argument. */
+		errno = EINVAL;
+		return -1;
+	}
+}
+
+/**
+ * Get configurable system variables.
+ * 
+ * @param name Variable name.
+ * @return Variable value.
+ */
+long sysconf(int name)
+{
+	long clk_tck = 0;
+	size_t cpu_count = 0;
+	stats_cpu_t *cpu_stats = stats_get_cpus(&cpu_count);
+	if (cpu_stats && cpu_count > 0) {
+		clk_tck = ((long) cpu_stats[0].frequency_mhz) * 1000000L;
+	}
+	if (cpu_stats) {
+		free(cpu_stats);
+		cpu_stats = 0;
+	}
+
+	long phys_pages = 0;
+	long avphys_pages = 0;
+	stats_physmem_t *mem_stats = stats_get_physmem();
+	if (mem_stats) {
+		phys_pages = (long) (mem_stats->total / getpagesize());
+		avphys_pages = (long) (mem_stats->free / getpagesize());
+		free(mem_stats);
+		mem_stats = 0;
+	}
+
+	switch (name) {
+	case _SC_PHYS_PAGES:
+		return phys_pages;
+	case _SC_AVPHYS_PAGES:
+		return avphys_pages;
+	case _SC_PAGESIZE:
+		return getpagesize();
+	case _SC_CLK_TCK:
+		return clk_tck;
+	default:
+		errno = EINVAL;
+		return -1;
+	}
+}
+
+/**
+ * 
+ * @param path
+ * @param name
+ * @return
+ */
+long pathconf(const char *path, int name)
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return -1;
+}
+
+/**
+ * 
+ * @return
+ */
+pid_t fork(void)
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return -1;
+}
+
+/**
+ * 
+ * @param path
+ * @param argv
+ * @return
+ */
+int execv(const char *path, char *const argv[])
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return -1;
+}
+
+/**
+ * 
+ * @param file
+ * @param argv
+ * @return
+ */
+int execvp(const char *file, char *const argv[])
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return -1;
+}
+
+/**
+ * 
+ * @param fildes
+ * @return
+ */
+int pipe(int fildes[2])
+{
+	// TODO: low priority, just a compile-time dependency of binutils
+	not_implemented();
+	return -1;
+}
+
+unsigned int alarm(unsigned int seconds)
+{
+	not_implemented();
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/posix/test/scanf.c
===================================================================
--- uspace/lib/posix/test/scanf.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/posix/test/scanf.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -27,6 +27,5 @@
  */
 
-#define LIBPOSIX_INTERNAL
-#define __POSIX_DEF__(x) posix_##x
+
 
 #include <errno.h>
@@ -52,5 +51,5 @@
 PCUT_TEST(int_decimal) {
 	int number;
-	int rc = posix_sscanf("4242", "%d", &number);
+	int rc = sscanf("4242", "%d", &number);
 	PCUT_ASSERT_INT_EQUALS(1, rc);
 	PCUT_ASSERT_INT_EQUALS(4242, number);
@@ -59,5 +58,5 @@
 PCUT_TEST(int_negative_decimal) {
 	int number;
-	int rc = posix_sscanf("-53", "%d", &number);
+	int rc = sscanf("-53", "%d", &number);
 	PCUT_ASSERT_INT_EQUALS(1, rc);
 	PCUT_ASSERT_INT_EQUALS(-53, number);
@@ -83,5 +82,5 @@
 	void *p;
 
-	int rc = posix_sscanf(
+	int rc = sscanf(
 		"\n j tt % \t -121314 98765 aqw 0765 0x77 0xABCDEF88 -99 884",
 		" j tt %%%3hhd%1hhu%3hd %3hu%u aqw%n %lo%llx %p %li %lld",
@@ -108,5 +107,5 @@
 	long double ld;
 
-	int rc = posix_sscanf(
+	int rc = sscanf(
 		"\n \t\t1.0 -0x555.AP10 1234.5678e12",
 		"%f %lf %Lf",
@@ -124,5 +123,5 @@
 	char *pstr;
 
-	int rc = posix_sscanf(
+	int rc = sscanf(
 		"\n\n\thello world    \n",
 		"%5s %ms",
@@ -141,5 +140,5 @@
 	char *pscanset;
 
-	int rc = posix_sscanf(
+	int rc = sscanf(
 		"\n\n\th-e-l-l-o world-]    \n",
 		" %9[-eh-o] %m[^]-]",
@@ -158,5 +157,5 @@
 	char *pseq;
 
-	int rc = posix_sscanf(
+	int rc = sscanf(
 		"\n\n\thello world    \n",
 		" %5c %mc",
Index: uspace/lib/softint/include/lltype.h
===================================================================
--- uspace/lib/softint/include/lltype.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/softint/include/lltype.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,9 +43,9 @@
 
 #ifdef __BE__
-	#define LO 1
-	#define HI 0
+#define LO 1
+#define HI 0
 #else
-	#define LO 0
-	#define HI 1
+#define LO 0
+#define HI 1
 #endif
 
Index: pace/lib/uri/ctype.h
===================================================================
--- uspace/lib/uri/ctype.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ 	(revision )
@@ -1,95 +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 uri
- * @{
- */
-/**
- * @file
- */
-
-#ifndef URI_CTYPE_H_
-#define URI_CTYPE_H_
-
-static inline bool is_unreserved(char c)
-{
-	return isalpha(c) || isdigit(c) ||
-	    c == '-' || c == '.' || c == '_' || c == '~';
-}
-
-static inline bool is_hexdig(char c)
-{
-	return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
-	    (c >= 'A' && c <= 'F');
-}
-
-static inline bool is_subdelim(char c)
-{
-	switch (c) {
-	case '!':
-	case '$':
-	case '&':
-	case '\'':
-	case '(':
-	case ')':
-	case '*':
-	case '+':
-	case ',':
-	case ';':
-	case '=':
-		return true;
-	default:
-		return false;
-	}
-}
-
-static inline bool is_gendelim(char c)
-{
-	switch (c) {
-	case ':':
-	case '/':
-	case '?':
-	case '#':
-	case '[':
-	case ']':
-	case '@':
-		return true;
-	default:
-		return false;
-	}
-}
-
-static inline bool is_reserved(char c)
-{
-	return is_gendelim(c) || is_subdelim(c);
-}
-
-#endif
-
-/** @}
- */
Index: uspace/lib/uri/internal/ctype.h
===================================================================
--- uspace/lib/uri/internal/ctype.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
+++ uspace/lib/uri/internal/ctype.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -0,0 +1,95 @@
+/*
+ * 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 uri
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef URI_CTYPE_H_
+#define URI_CTYPE_H_
+
+static inline bool is_unreserved(char c)
+{
+	return isalpha(c) || isdigit(c) ||
+	    c == '-' || c == '.' || c == '_' || c == '~';
+}
+
+static inline bool is_hexdig(char c)
+{
+	return (c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') ||
+	    (c >= 'A' && c <= 'F');
+}
+
+static inline bool is_subdelim(char c)
+{
+	switch (c) {
+	case '!':
+	case '$':
+	case '&':
+	case '\'':
+	case '(':
+	case ')':
+	case '*':
+	case '+':
+	case ',':
+	case ';':
+	case '=':
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_gendelim(char c)
+{
+	switch (c) {
+	case ':':
+	case '/':
+	case '?':
+	case '#':
+	case '[':
+	case ']':
+	case '@':
+		return true;
+	default:
+		return false;
+	}
+}
+
+static inline bool is_reserved(char c)
+{
+	return is_gendelim(c) || is_subdelim(c);
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/uri/uri.c
===================================================================
--- uspace/lib/uri/uri.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/uri/uri.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,5 +42,5 @@
 
 #include "uri.h"
-#include "ctype.h"
+#include "internal/ctype.h"
 
 static char *cut_str(const char *start, const char *end)
Index: uspace/lib/usb/src/debug.c
===================================================================
--- uspace/lib/usb/src/debug.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usb/src/debug.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,5 @@
 #include <ddf/log.h>
 #include <usb/debug.h>
+#include <str.h>
 
 #define REMAINDER_STR_FMT " (%zu)..."
Index: uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbdev/include/usb/dev/alternate_ifaces.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -59,5 +59,5 @@
 typedef struct {
 	/** Array of alternate interfaces descriptions. */
-	const usb_alternate_interface_descriptors_t *alternatives;
+	usb_alternate_interface_descriptors_t *alternatives;
 	/** Size of @c alternatives array. */
 	size_t alternative_count;
Index: uspace/lib/usbdev/include/usb/dev/device.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/device.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbdev/include/usb/dev/device.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,5 +52,5 @@
 	usb_standard_device_descriptor_t device;
 	/** Full configuration descriptor of current configuration. */
-	const void *full_config;
+	void *full_config;
 	size_t full_config_size;
 } usb_device_descriptors_t;
Index: uspace/lib/usbdev/include/usb/dev/request.h
===================================================================
--- uspace/lib/usbdev/include/usb/dev/request.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbdev/include/usb/dev/request.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -70,5 +70,5 @@
     void *, size_t, size_t *);
 errno_t usb_request_get_full_configuration_descriptor_alloc(usb_pipe_t *,
-    int, const void **, size_t *);
+    int, void **, size_t *);
 errno_t usb_request_set_descriptor(usb_pipe_t *, usb_request_type_t,
     usb_request_recipient_t, uint8_t, uint8_t, uint16_t, const void *, size_t);
Index: uspace/lib/usbdev/src/recognise.c
===================================================================
--- uspace/lib/usbdev/src/recognise.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbdev/src/recognise.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -61,5 +61,5 @@
  */
 static errno_t usb_add_match_id(match_id_list_t *matches, int score,
-    const char *match_str)
+    char *match_str)
 {
 	assert(matches);
Index: uspace/lib/usbdev/src/request.c
===================================================================
--- uspace/lib/usbdev/src/request.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbdev/src/request.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -475,5 +475,5 @@
 errno_t usb_request_get_full_configuration_descriptor_alloc(
     usb_pipe_t *pipe, int index,
-    const void **descriptor_ptr, size_t *descriptor_size)
+    void **descriptor_ptr, size_t *descriptor_size)
 {
 	errno_t rc;
Index: uspace/lib/usbhid/include/usb/hid/hiddescriptor.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hiddescriptor.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbhid/include/usb/hid/hiddescriptor.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,5 +44,5 @@
 
 errno_t usb_hid_parse_report_descriptor(usb_hid_report_t *report,
-		const uint8_t *data, size_t size);
+    const uint8_t *data, size_t size);
 
 void usb_hid_descriptor_print(usb_hid_report_t *report);
@@ -53,25 +53,25 @@
 
 errno_t usb_hid_report_append_fields(usb_hid_report_t *report,
-		usb_hid_report_item_t *report_item);
+    usb_hid_report_item_t *report_item);
 
-usb_hid_report_description_t * usb_hid_report_find_description(
-		const usb_hid_report_t *report, uint8_t report_id,
-		usb_hid_report_type_t type);
+usb_hid_report_description_t *usb_hid_report_find_description(
+    const usb_hid_report_t *report, uint8_t report_id,
+    usb_hid_report_type_t type);
 
 int usb_hid_report_parse_tag(uint8_t tag, uint8_t class, const uint8_t *data,
-		size_t item_size, usb_hid_report_item_t *report_item,
-		usb_hid_report_path_t *usage_path);
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path);
 
-int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data, 
-		size_t item_size, usb_hid_report_item_t *report_item,
-		usb_hid_report_path_t *usage_path);
+int usb_hid_report_parse_main_tag(uint8_t tag, const uint8_t *data,
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path);
 
-int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data, 
-		size_t item_size, usb_hid_report_item_t *report_item,
-		usb_hid_report_path_t *usage_path);
+int usb_hid_report_parse_global_tag(uint8_t tag, const uint8_t *data,
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path);
 
-int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data, 
-		size_t item_size, usb_hid_report_item_t *report_item,
-		usb_hid_report_path_t *usage_path);
+int usb_hid_report_parse_local_tag(uint8_t tag, const uint8_t *data,
+    size_t item_size, usb_hid_report_item_t *report_item,
+    usb_hid_report_path_t *usage_path);
 
 void usb_hid_descriptor_print_list(list_t *list);
@@ -80,10 +80,10 @@
 
 usb_hid_report_item_t *usb_hid_report_item_clone(
-		const usb_hid_report_item_t *item);
+    const usb_hid_report_item_t *item);
 
 uint32_t usb_hid_report_tag_data_uint32(const uint8_t *data, size_t size);
 
-usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t*report,
-		usb_hid_report_path_t *cmp_path);
+usb_hid_report_path_t *usb_hid_report_path_try_insert(usb_hid_report_t *report,
+    usb_hid_report_path_t *cmp_path);
 
 
Index: uspace/lib/usbhid/include/usb/hid/hidparser.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hidparser.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbhid/include/usb/hid/hidparser.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,23 +48,23 @@
  */
 errno_t usb_hid_parse_report(const usb_hid_report_t *report, const uint8_t *data,
-		size_t size, uint8_t *report_id);
+    size_t size, uint8_t *report_id);
 
 /*
  * Output report parser functions
  */
-uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size, 
-		uint8_t report_id);
+uint8_t *usb_hid_report_output(usb_hid_report_t *report, size_t *size,
+    uint8_t report_id);
 
 void usb_hid_report_output_free(uint8_t *output);
 
 size_t usb_hid_report_size(usb_hid_report_t *report, uint8_t report_id,
-		usb_hid_report_type_t type);
+    usb_hid_report_type_t type);
 
 size_t usb_hid_report_byte_size(usb_hid_report_t *report, uint8_t report_id,
-		usb_hid_report_type_t type);
+    usb_hid_report_type_t type);
 
 
-errno_t usb_hid_report_output_translate(usb_hid_report_t *report, 
-		uint8_t report_id, uint8_t *buffer, size_t size);
+errno_t usb_hid_report_output_translate(usb_hid_report_t *report,
+    uint8_t report_id, uint8_t *buffer, size_t size);
 
 
@@ -73,9 +73,9 @@
  */
 usb_hid_report_field_t *usb_hid_report_get_sibling(usb_hid_report_t *report,
-		usb_hid_report_field_t *field, usb_hid_report_path_t *path,
-		int flags, usb_hid_report_type_t type);
+    usb_hid_report_field_t *field, usb_hid_report_path_t *path,
+    int flags, usb_hid_report_type_t type);
 
-uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report, 
-		uint8_t report_id, usb_hid_report_type_t type);
+uint8_t usb_hid_get_next_report_id(usb_hid_report_t *report,
+    uint8_t report_id, usb_hid_report_type_t type);
 
 #endif
Index: uspace/lib/usbhid/include/usb/hid/hidpath.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hidpath.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbhid/include/usb/hid/hidpath.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -83,5 +83,5 @@
 	/** Usage page of report item. Zero when usage page can be changed. */
 	uint32_t usage_page;
-	/** Usage of report item. Zero when usage can be changed. */	
+	/** Usage of report item. Zero when usage can be changed. */
 	uint32_t usage;
 
@@ -119,8 +119,8 @@
 
 errno_t usb_hid_report_path_set_report_id(usb_hid_report_path_t *usage_path,
-		uint8_t report_id);
+    uint8_t report_id);
 
-errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path, 
-		int32_t usage_page, int32_t usage);
+errno_t usb_hid_report_path_append_item(usb_hid_report_path_t *usage_path,
+    int32_t usage_page, int32_t usage);
 
 void usb_hid_report_remove_last_item(usb_hid_report_path_t *usage_path);
@@ -128,12 +128,12 @@
 void usb_hid_report_null_last_item(usb_hid_report_path_t *usage_path);
 
-void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path, 
-		int32_t tag, int32_t data);
+void usb_hid_report_set_last_item(usb_hid_report_path_t *usage_path,
+    int32_t tag, int32_t data);
 
 int usb_hid_report_compare_usage_path(usb_hid_report_path_t *report_path,
-		usb_hid_report_path_t *path, int flags);
+    usb_hid_report_path_t *path, int flags);
 
 usb_hid_report_path_t *usb_hid_report_path_clone(
-		usb_hid_report_path_t *usage_path);
+    usb_hid_report_path_t *usage_path);
 
 void usb_hid_print_usage_path(usb_hid_report_path_t *path);
Index: uspace/lib/usbhid/include/usb/hid/hidreport.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/hidreport.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbhid/include/usb/hid/hidreport.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -58,5 +58,5 @@
  *         usb_pipe_end_session() or usb_request_get_descriptor().
  */
-errno_t usb_hid_process_report_descriptor(usb_device_t *dev, 
+errno_t usb_hid_process_report_descriptor(usb_device_t *dev,
     usb_hid_report_t *report, uint8_t **report_desc, size_t *report_size);
 
Index: uspace/lib/usbhid/include/usb/hid/request.h
===================================================================
--- uspace/lib/usbhid/include/usb/hid/request.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbhid/include/usb/hid/request.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,14 +47,14 @@
     usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size);
 
-errno_t usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
+errno_t usbhid_req_set_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
     usb_hid_protocol_t protocol);
 
 errno_t usbhid_req_set_idle(usb_pipe_t *ctrl_pipe, int iface_no, uint8_t duration);
 
-errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no, 
-    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size, 
+errno_t usbhid_req_get_report(usb_pipe_t *ctrl_pipe, int iface_no,
+    usb_hid_report_type_t type, uint8_t *buffer, size_t buf_size,
     size_t *actual_size);
 
-errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no, 
+errno_t usbhid_req_get_protocol(usb_pipe_t *ctrl_pipe, int iface_no,
     usb_hid_protocol_t *protocol);
 
Index: uspace/lib/usbvirt/include/usbvirt/device.h
===================================================================
--- uspace/lib/usbvirt/include/usbvirt/device.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/lib/usbvirt/include/usbvirt/device.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -154,5 +154,5 @@
 	usb_standard_configuration_descriptor_t *descriptor;
 	/** Array of extra data. */
-	const usbvirt_device_configuration_extras_t *extra;
+	usbvirt_device_configuration_extras_t *extra;
 	/** Length of @c extra array. */
 	size_t extra_count;
Index: uspace/srv/audio/hound/audio_data.c
===================================================================
--- uspace/srv/audio/hound/audio_data.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/audio_data.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,5 @@
 #include <macros.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include "audio_data.h"
@@ -50,5 +51,5 @@
     pcm_format_t format)
 {
-	audio_data_t *adata = malloc(sizeof(audio_data_t));
+	audio_data_t *adata = malloc(sizeof(audio_data_t) + size);
 	if (adata) {
 		unsigned overflow = size % pcm_format_frame_size(&format);
@@ -56,6 +57,6 @@
 			log_warning("Data not a multiple of frame size, "
 			    "clipping.");
-
-		adata->data = data;
+		uint8_t *d = ((uint8_t *)adata) + offsetof(audio_data_t, data);
+		memcpy(d, data, size);
 		adata->size = size - overflow;
 		adata->format = format;
@@ -86,5 +87,4 @@
 	atomic_count_t refc = atomic_predec(&adata->refcount);
 	if (refc == 0) {
-		free(adata->data);
 		free(adata);
 	}
Index: uspace/srv/audio/hound/audio_data.h
===================================================================
--- uspace/srv/audio/hound/audio_data.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/audio_data.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,6 +45,4 @@
 /** Reference counted audio buffer */
 typedef struct {
-	/** Audio data */
-	const void *data;
 	/** Size of the buffer pointer to by data */
 	size_t size;
@@ -53,4 +51,6 @@
 	/** Reference counter */
 	atomic_t refcount;
+	/** Audio data */
+	const uint8_t data[];
 } audio_data_t;
 
Index: uspace/srv/audio/hound/audio_sink.h
===================================================================
--- uspace/srv/audio/hound/audio_sink.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/audio_sink.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -54,5 +54,5 @@
 	list_t connections;
 	/** Sink's name */
-	const char *name;
+	char *name;
 	/** Consumes data in this format */
 	pcm_format_t format;
Index: uspace/srv/audio/hound/audio_source.c
===================================================================
--- uspace/srv/audio/hound/audio_source.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/audio_source.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -96,5 +96,5 @@
  * @return Error code.
  */
-errno_t audio_source_push_data(audio_source_t *source, const void *data,
+errno_t audio_source_push_data(audio_source_t *source, void *data,
     size_t size)
 {
Index: uspace/srv/audio/hound/audio_source.h
===================================================================
--- uspace/srv/audio/hound/audio_source.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/audio_source.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,5 +49,5 @@
 	list_t connections;
 	/** String identifier */
-	const char *name;
+	char *name;
 	/** audio data format */
 	pcm_format_t format;
@@ -75,5 +75,5 @@
     const pcm_format_t *f);
 void audio_source_fini(audio_source_t *source);
-errno_t audio_source_push_data(audio_source_t *source, const void *data,
+errno_t audio_source_push_data(audio_source_t *source, void *data,
     size_t size);
 static inline const pcm_format_t *audio_source_format(const audio_source_t *s)
Index: uspace/srv/audio/hound/hound.c
===================================================================
--- uspace/srv/audio/hound/hound.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/hound.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -37,4 +37,5 @@
 #include <assert.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include "hound.h"
@@ -413,5 +414,5 @@
  * @return Error code.
  */
-errno_t hound_list_sources(hound_t *hound, const char ***list, size_t *size)
+errno_t hound_list_sources(hound_t *hound, char ***list, size_t *size)
 {
 	assert(hound);
@@ -427,5 +428,5 @@
 		return EOK;
 	}
-	const char **names = calloc(count, sizeof(char *));
+	char **names = calloc(count, sizeof(char *));
 	errno_t ret = names ? EOK : ENOMEM;
 	for (unsigned long i = 0; i < count && ret == EOK; ++i) {
@@ -455,5 +456,5 @@
  * @return Error code.
  */
-errno_t hound_list_sinks(hound_t *hound, const char ***list, size_t *size)
+errno_t hound_list_sinks(hound_t *hound, char ***list, size_t *size)
 {
 	assert(hound);
@@ -469,5 +470,5 @@
 		return EOK;
 	}
-	const char **names = calloc(count, sizeof(char *));
+	char **names = calloc(count, sizeof(char *));
 	errno_t ret = names ? EOK : ENOMEM;
 	for (size_t i = 0; i < count && ret == EOK; ++i) {
Index: uspace/srv/audio/hound/hound.h
===================================================================
--- uspace/srv/audio/hound/hound.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/hound.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -70,15 +70,15 @@
 hound_ctx_t *hound_get_ctx_by_id(hound_t *hound, hound_context_id_t id);
 
-errno_t hound_add_device(hound_t *hound, service_id_t id, const char* name);
+errno_t hound_add_device(hound_t *hound, service_id_t id, const char *name);
 errno_t hound_add_source(hound_t *hound, audio_source_t *source);
 errno_t hound_add_sink(hound_t *hound, audio_sink_t *sink);
-errno_t hound_list_sources(hound_t *hound, const char ***list, size_t *size);
-errno_t hound_list_sinks(hound_t *hound, const char ***list, size_t *size);
+errno_t hound_list_sources(hound_t *hound, char ***list, size_t *size);
+errno_t hound_list_sinks(hound_t *hound, char ***list, size_t *size);
 errno_t hound_list_connections(hound_t *hound, const char ***sources,
     const char ***sinks, size_t *size);
 errno_t hound_remove_source(hound_t *hound, audio_source_t *source);
 errno_t hound_remove_sink(hound_t *hound, audio_sink_t *sink);
-errno_t hound_connect(hound_t *hound, const char* source_name, const char* sink_name);
-errno_t hound_disconnect(hound_t *hound, const char* source_name, const char* sink_name);
+errno_t hound_connect(hound_t *hound, const char *source_name, const char *sink_name);
+errno_t hound_disconnect(hound_t *hound, const char *source_name, const char *sink_name);
 
 #endif
Index: uspace/srv/audio/hound/hound_ctx.h
===================================================================
--- uspace/srv/audio/hound/hound_ctx.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/hound_ctx.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -69,5 +69,5 @@
 
 hound_ctx_stream_t *hound_ctx_create_stream(hound_ctx_t *ctx, int flags,
-	pcm_format_t format, size_t buffer_size);
+    pcm_format_t format, size_t buffer_size);
 void hound_ctx_destroy_stream(hound_ctx_stream_t *stream);
 
Index: uspace/srv/audio/hound/iface.c
===================================================================
--- uspace/srv/audio/hound/iface.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/audio/hound/iface.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -86,5 +86,5 @@
 }
 
-static errno_t iface_get_list(void *server, const char ***list, size_t *size,
+static errno_t iface_get_list(void *server, char ***list, size_t *size,
     const char *connection, int flags)
 {
Index: uspace/srv/bd/file_bd/file_bd.c
===================================================================
--- uspace/srv/bd/file_bd/file_bd.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/bd/file_bd/file_bd.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,4 +52,5 @@
 #include <task.h>
 #include <macros.h>
+#include <str.h>
 
 #define NAME "file_bd"
Index: uspace/srv/bd/vbd/disk.h
===================================================================
--- uspace/srv/bd/vbd/disk.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/bd/vbd/disk.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -52,5 +52,5 @@
 extern errno_t vbds_label_delete(service_id_t);
 extern errno_t vbds_part_get_info(vbds_part_id_t, vbd_part_info_t *);
-extern errno_t vbds_part_create(service_id_t, vbd_part_spec_t *,vbds_part_id_t *);
+extern errno_t vbds_part_create(service_id_t, vbd_part_spec_t *, vbds_part_id_t *);
 extern errno_t vbds_part_delete(vbds_part_id_t);
 extern errno_t vbds_suggest_ptype(service_id_t, label_pcnt_t, label_ptype_t *);
Index: uspace/srv/devman/devman.h
===================================================================
--- uspace/srv/devman/devman.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/devman/devman.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -80,5 +80,5 @@
 	char *name;
 	/** Path to the driver's binary. */
-	const char *binary_path;
+	char *binary_path;
 	/** List of device ids for device-to-driver matching. */
 	match_id_list_t match_ids;
Index: uspace/srv/devman/driver.c
===================================================================
--- uspace/srv/devman/driver.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/devman/driver.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -140,5 +140,5 @@
 	
 	/* Check whether the driver's binary exists. */
-	struct stat s;
+	vfs_stat_t s;
 	if (vfs_stat_path(drv->binary_path, &s) != EOK) {
 		log_msg(LOG_DEFAULT, LVL_ERROR, "Driver not found at path `%s'.",
Index: uspace/srv/devman/match.c
===================================================================
--- uspace/srv/devman/match.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/devman/match.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -200,5 +200,5 @@
 	int fd;
 	size_t len = 0;
-	struct stat st;
+	vfs_stat_t st;
 	
 	errno_t rc = vfs_lookup_open(conf_path, WALK_REGULAR, MODE_READ, &fd);
Index: uspace/srv/fs/cdfs/cdfs.c
===================================================================
--- uspace/srv/fs/cdfs/cdfs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/cdfs/cdfs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -44,4 +44,5 @@
 #include <stdio.h>
 #include <libfs.h>
+#include <str.h>
 #include "cdfs.h"
 #include "cdfs_ops.h"
Index: uspace/srv/fs/exfat/exfat.c
===================================================================
--- uspace/srv/fs/exfat/exfat.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/exfat/exfat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <stdio.h>
 #include <libfs.h>
+#include <str.h>
 #include "../../vfs/vfs.h"
 
Index: uspace/srv/fs/exfat/exfat_bitmap.h
===================================================================
--- uspace/srv/fs/exfat/exfat_bitmap.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/exfat/exfat_bitmap.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,20 +42,20 @@
 struct exfat_bs;
 
-extern errno_t exfat_bitmap_alloc_clusters(struct exfat_bs *, service_id_t, 
+extern errno_t exfat_bitmap_alloc_clusters(struct exfat_bs *, service_id_t,
     exfat_cluster_t *, exfat_cluster_t);
-extern errno_t exfat_bitmap_append_clusters(struct exfat_bs *, struct exfat_node *, 
+extern errno_t exfat_bitmap_append_clusters(struct exfat_bs *, struct exfat_node *,
     exfat_cluster_t);
-extern errno_t exfat_bitmap_free_clusters(struct exfat_bs *, struct exfat_node *, 
+extern errno_t exfat_bitmap_free_clusters(struct exfat_bs *, struct exfat_node *,
     exfat_cluster_t);
-extern errno_t exfat_bitmap_replicate_clusters(struct exfat_bs *, struct exfat_node *); 
+extern errno_t exfat_bitmap_replicate_clusters(struct exfat_bs *, struct exfat_node *);
 
 extern errno_t exfat_bitmap_is_free(struct exfat_bs *, service_id_t, exfat_cluster_t);
 extern errno_t exfat_bitmap_set_cluster(struct exfat_bs *, service_id_t, exfat_cluster_t);
-extern errno_t exfat_bitmap_clear_cluster(struct exfat_bs *, service_id_t, 
+extern errno_t exfat_bitmap_clear_cluster(struct exfat_bs *, service_id_t,
     exfat_cluster_t);
 
-extern errno_t exfat_bitmap_set_clusters(struct exfat_bs *, service_id_t, 
+extern errno_t exfat_bitmap_set_clusters(struct exfat_bs *, service_id_t,
     exfat_cluster_t, exfat_cluster_t);
-extern errno_t exfat_bitmap_clear_clusters(struct exfat_bs *, service_id_t, 
+extern errno_t exfat_bitmap_clear_clusters(struct exfat_bs *, service_id_t,
     exfat_cluster_t, exfat_cluster_t);
 
Index: uspace/srv/fs/exfat/exfat_directory.h
===================================================================
--- uspace/srv/fs/exfat/exfat_directory.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/exfat/exfat_directory.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 #ifndef EXFAT_EXFAT_DIRECTORY_H_
@@ -66,5 +66,5 @@
 extern errno_t exfat_directory_find(exfat_directory_t *, exfat_dentry_clsf_t,
     exfat_dentry_t **);
-extern errno_t exfat_directory_find_continue(exfat_directory_t *, 
+extern errno_t exfat_directory_find_continue(exfat_directory_t *,
     exfat_dentry_clsf_t, exfat_dentry_t **);
 
Index: uspace/srv/fs/exfat/exfat_fat.h
===================================================================
--- uspace/srv/fs/exfat/exfat_fat.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/exfat/exfat_fat.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -61,5 +61,5 @@
     exfat_cluster_walk((bs), (sid), (fc), NULL, (numc), (uint32_t) -1)
 
-extern errno_t exfat_cluster_walk(struct exfat_bs *, service_id_t, 
+extern errno_t exfat_cluster_walk(struct exfat_bs *, service_id_t,
     exfat_cluster_t, exfat_cluster_t *, uint32_t *, uint32_t);
 extern errno_t exfat_block_get(block_t **, struct exfat_bs *, struct exfat_node *,
Index: uspace/srv/fs/ext4fs/ext4fs.c
===================================================================
--- uspace/srv/fs/ext4fs/ext4fs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/ext4fs/ext4fs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,4 +42,5 @@
 #include <task.h>
 #include <ipc/services.h>
+#include <str.h>
 #include "ext4/ops.h"
 #include "../../vfs/vfs.h"
Index: uspace/srv/fs/fat/fat.c
===================================================================
--- uspace/srv/fs/fat/fat.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/fat/fat.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <stdio.h>
 #include <libfs.h>
+#include <str.h>
 #include "../../vfs/vfs.h"
 
Index: uspace/srv/fs/fat/fat_directory.h
===================================================================
--- uspace/srv/fs/fat/fat_directory.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/fat/fat_directory.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 #ifndef FAT_FAT_DIRECTORY_H_
Index: uspace/srv/fs/locfs/locfs.c
===================================================================
--- uspace/srv/fs/locfs/locfs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/locfs/locfs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -47,4 +47,5 @@
 #include <task.h>
 #include <libfs.h>
+#include <str.h>
 #include "locfs.h"
 #include "locfs_ops.h"
Index: uspace/srv/fs/locfs/locfs.h
===================================================================
--- uspace/srv/fs/locfs/locfs.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/locfs/locfs.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -29,5 +29,5 @@
 /** @addtogroup fs
  * @{
- */ 
+ */
 
 #ifndef LOCFS_LOCFS_H_
Index: uspace/srv/fs/mfs/mfs_dentry.c
===================================================================
--- uspace/srv/fs/mfs/mfs_dentry.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/mfs/mfs_dentry.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -31,4 +31,5 @@
  */
 
+#include <str.h>
 #include "mfs.h"
 
Index: uspace/srv/fs/mfs/mfs_ops.c
===================================================================
--- uspace/srv/fs/mfs/mfs_ops.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/mfs/mfs_ops.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -36,4 +36,5 @@
 #include <adt/hash_table.h>
 #include <adt/hash.h>
+#include <str.h>
 #include "mfs.h"
 
Index: uspace/srv/fs/tmpfs/tmpfs.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/fs/tmpfs/tmpfs.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -50,4 +50,5 @@
 #include <task.h>
 #include <libfs.h>
+#include <str.h>
 #include "../../vfs/vfs.h"
 
Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/console/console.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -51,4 +51,5 @@
 #include <fibril_synch.h>
 #include <stdlib.h>
+#include <str.h>
 #include "console.h"
 
Index: uspace/srv/hid/input/input.c
===================================================================
--- uspace/srv/hid/input/input.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/input/input.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -54,4 +54,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <str_error.h>
 
Index: uspace/srv/hid/isdv4_tablet/isdv4.h
===================================================================
--- uspace/srv/hid/isdv4_tablet/isdv4.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/isdv4_tablet/isdv4.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -74,9 +74,16 @@
 
 typedef enum {
-	UNKNOWN, PRESS, RELEASE, PROXIMITY_IN, PROXIMITY_OUT, MOVE
+	UNKNOWN,
+	PRESS,
+	RELEASE,
+	PROXIMITY_IN,
+	PROXIMITY_OUT,
+	MOVE
 } isdv4_event_type_t;
 
 typedef enum {
-	STYLUS_TIP, STYLUS_ERASER, TOUCH
+	STYLUS_TIP,
+	STYLUS_ERASER,
+	TOUCH
 } isdv4_source_type_t;
 
Index: uspace/srv/hid/isdv4_tablet/main.c
===================================================================
--- uspace/srv/hid/isdv4_tablet/main.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/isdv4_tablet/main.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,4 +35,5 @@
 #include <stddef.h>
 #include <stdio.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/hid/output/output.h
===================================================================
--- uspace/srv/hid/output/output.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/output/output.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -42,15 +42,15 @@
 
 typedef struct {
-	errno_t (* yield)(struct outdev *dev);
-	errno_t (* claim)(struct outdev *dev);
+	errno_t (*yield)(struct outdev *dev);
+	errno_t (*claim)(struct outdev *dev);
 	
-	void (* get_dimensions)(struct outdev *dev, sysarg_t *cols,
+	void (*get_dimensions)(struct outdev *dev, sysarg_t *cols,
 	    sysarg_t *rows);
-	console_caps_t (* get_caps)(struct outdev *dev);
+	console_caps_t (*get_caps)(struct outdev *dev);
 	
-	void (* cursor_update)(struct outdev *dev, sysarg_t prev_col,
+	void (*cursor_update)(struct outdev *dev, sysarg_t prev_col,
 	    sysarg_t prev_row, sysarg_t col, sysarg_t row, bool visible);
-	void (* char_update)(struct outdev *dev, sysarg_t col, sysarg_t row);
-	void (* flush)(struct outdev *dev);
+	void (*char_update)(struct outdev *dev, sysarg_t col, sysarg_t row);
+	void (*flush)(struct outdev *dev);
 } outdev_ops_t;
 
Index: uspace/srv/hid/output/proto/vt100.h
===================================================================
--- uspace/srv/hid/output/proto/vt100.h	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/output/proto/vt100.h	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,7 +35,7 @@
 #include <io/charfield.h>
 
-typedef void (* vt100_putchar_t)(wchar_t ch);
-typedef void (* vt100_control_puts_t)(const char *str);
-typedef void (* vt100_flush_t)(void);
+typedef void (*vt100_putchar_t)(wchar_t ch);
+typedef void (*vt100_control_puts_t)(const char *str);
+typedef void (*vt100_flush_t)(void);
 
 typedef struct {
Index: uspace/srv/hid/remcons/remcons.c
===================================================================
--- uspace/srv/hid/remcons/remcons.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/remcons/remcons.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -49,4 +49,5 @@
 #include <io/console.h>
 #include <inttypes.h>
+#include <str.h>
 #include "telnet.h"
 #include "user.h"
Index: uspace/srv/hid/rfb/main.c
===================================================================
--- uspace/srv/hid/rfb/main.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/hid/rfb/main.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -35,4 +35,5 @@
 #include <inttypes.h>
 #include <io/log.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/net/dhcp/dhcp.c
===================================================================
--- uspace/srv/net/dhcp/dhcp.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/net/dhcp/dhcp.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -48,4 +48,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 
 #include "dhcp.h"
Index: uspace/srv/net/dnsrsrv/dnsrsrv.c
===================================================================
--- uspace/srv/net/dnsrsrv/dnsrsrv.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/net/dnsrsrv/dnsrsrv.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -43,4 +43,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/net/loopip/loopip.c
===================================================================
--- uspace/srv/net/loopip/loopip.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/net/loopip/loopip.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -45,4 +45,5 @@
 #include <stdio.h>
 #include <stdlib.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/net/tcp/ncsim.c
===================================================================
--- uspace/srv/net/tcp/ncsim.c	(revision a0a9cc249adce31c755defdb6b74a991ebbf55ea)
+++ uspace/srv/net/tcp/ncsim.c	(revision 2b3dd78e52704a51e22b71513327373cf8f6a614)
@@ -81,5 +81,5 @@
 	return;
 
-	if (0 /*random() % 4 == 3*/) {
+	if (0 /*rand() % 4 == 3*/) {
 		/* Drop segment */
 		log_msg(LOG_DEFAULT, LVL_ERROR, "NCSim dropping segment");
@@ -94,5 +94,5 @@
 	}
 
-	sqe->delay = random() % (1000 * 1000);
+	sqe->delay = rand() % (1000 * 1000);
 	sqe->epp = *epp;
 	sqe->seg = seg;
