Index: kernel/Makefile
===================================================================
--- kernel/Makefile	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/Makefile	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -204,5 +204,5 @@
 	generic/src/lib/memstr.c \
 	generic/src/lib/sort.c \
-	generic/src/lib/string.c \
+	generic/src/lib/str.c \
 	generic/src/lib/elf.c \
 	generic/src/lib/rd.c \
Index: kernel/arch/arm32/src/arm32.c
===================================================================
--- kernel/arch/arm32/src/arm32.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/arm32/src/arm32.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -47,5 +47,5 @@
 #include <userspace.h>
 #include <macros.h>
-#include <string.h>
+#include <str.h>
 #include <arch/ras.h>
 
Index: kernel/arch/ia64/src/drivers/ski.c
===================================================================
--- kernel/arch/ia64/src/drivers/ski.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/ia64/src/drivers/ski.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -42,5 +42,5 @@
 #include <arch/asm.h>
 #include <arch/drivers/kbd.h>
-#include <string.h>
+#include <str.h>
 #include <arch.h>
 
Index: kernel/arch/ia64/src/ia64.c
===================================================================
--- kernel/arch/ia64/src/ia64.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/ia64/src/ia64.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -66,5 +66,5 @@
 #include <print.h>
 #include <sysinfo/sysinfo.h>
-#include <string.h>
+#include <str.h>
 
 /* NS16550 as a COM 1 */
Index: kernel/arch/mips32/src/mips32.c
===================================================================
--- kernel/arch/mips32/src/mips32.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/mips32/src/mips32.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -57,5 +57,5 @@
 #include <macros.h>
 #include <config.h>
-#include <string.h>
+#include <str.h>
 #include <arch/drivers/msim.h>
 #include <arch/asm/regname.h>
Index: kernel/arch/ppc32/src/ppc32.c
===================================================================
--- kernel/arch/ppc32/src/ppc32.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/ppc32/src/ppc32.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -53,5 +53,5 @@
 #include <align.h>
 #include <macros.h>
-#include <string.h>
+#include <str.h>
 #include <print.h>
 
Index: kernel/arch/sparc64/src/console.c
===================================================================
--- kernel/arch/sparc64/src/console.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/console.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -49,5 +49,5 @@
 #include <arch.h>
 #include <panic.h>
-#include <string.h>
+#include <str.h>
 #include <print.h>
 
Index: kernel/arch/sparc64/src/drivers/kbd.c
===================================================================
--- kernel/arch/sparc64/src/drivers/kbd.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/drivers/kbd.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -43,5 +43,5 @@
 #include <arch/types.h>
 #include <align.h>
-#include <string.h>
+#include <str.h>
 #include <print.h>
 #include <sysinfo/sysinfo.h>
Index: kernel/arch/sparc64/src/drivers/pci.c
===================================================================
--- kernel/arch/sparc64/src/drivers/pci.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/drivers/pci.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -44,10 +44,10 @@
 #include <debug.h>
 #include <print.h>
-#include <string.h>
+#include <str.h>
 #include <arch/asm.h>
 #include <sysinfo/sysinfo.h>
 
 #define SABRE_INTERNAL_REG	0
-#define PSYCHO_INTERNAL_REG	2	
+#define PSYCHO_INTERNAL_REG	2
 
 #define OBIO_IMR_BASE	0x200
Index: kernel/arch/sparc64/src/drivers/scr.c
===================================================================
--- kernel/arch/sparc64/src/drivers/scr.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/drivers/scr.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -43,5 +43,5 @@
 #include <console/console.h>
 #include <arch/types.h>
-#include <string.h>
+#include <str.h>
 #include <align.h>
 #include <print.h>
Index: kernel/arch/sparc64/src/drivers/sgcn.c
===================================================================
--- kernel/arch/sparc64/src/drivers/sgcn.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/drivers/sgcn.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <genarch/ofw/ofw_tree.h>
 #include <debug.h>
-#include <string.h>
+#include <str.h>
 #include <print.h>
 #include <mm/page.h>
Index: kernel/arch/sparc64/src/smp/sun4v/smp.c
===================================================================
--- kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/smp/sun4v/smp.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -53,5 +53,5 @@
 #include <time/delay.h>
 #include <arch/smp/sun4v/smp.h>
-#include <string.h>
+#include <str.h>
 
 /** hypervisor code of the "running" state of the CPU */
Index: kernel/arch/sparc64/src/sun4u/sparc64.c
===================================================================
--- kernel/arch/sparc64/src/sun4u/sparc64.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/sun4u/sparc64.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -48,5 +48,5 @@
 #include <userspace.h>
 #include <ddi/irq.h>
-#include <string.h>
+#include <str.h>
 
 bootinfo_t bootinfo;
Index: kernel/arch/sparc64/src/sun4v/md.c
===================================================================
--- kernel/arch/sparc64/src/sun4v/md.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/sun4v/md.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <func.h>
 #include <print.h>
-#include <string.h>
+#include <str.h>
 #include <arch/sun4v/md.h>
 #include <arch/sun4v/hypercall.h>
Index: kernel/arch/sparc64/src/sun4v/sparc64.c
===================================================================
--- kernel/arch/sparc64/src/sun4v/sparc64.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/arch/sparc64/src/sun4v/sparc64.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -49,5 +49,5 @@
 #include <userspace.h>
 #include <ddi/irq.h>
-#include <string.h>
+#include <str.h>
 #include <arch/drivers/niagara.h>
 
Index: kernel/genarch/src/drivers/dsrln/dsrlnout.c
===================================================================
--- kernel/genarch/src/drivers/dsrln/dsrlnout.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/drivers/dsrln/dsrlnout.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <console/console.h>
 #include <sysinfo/sysinfo.h>
-#include <string.h>
+#include <str.h>
 
 typedef struct {
Index: kernel/genarch/src/drivers/ega/ega.c
===================================================================
--- kernel/genarch/src/drivers/ega/ega.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/drivers/ega/ega.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -45,5 +45,5 @@
 #include <arch/asm.h>
 #include <memstr.h>
-#include <string.h>
+#include <str.h>
 #include <console/chardev.h>
 #include <console/console.h>
Index: kernel/genarch/src/fb/fb.c
===================================================================
--- kernel/genarch/src/fb/fb.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/fb/fb.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -49,5 +49,5 @@
 #include <bitops.h>
 #include <print.h>
-#include <string.h>
+#include <str.h>
 #include <ddi/ddi.h>
 #include <arch/types.h>
Index: kernel/genarch/src/kbrd/scanc_mac.c
===================================================================
--- kernel/genarch/src/kbrd/scanc_mac.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/kbrd/scanc_mac.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <genarch/kbrd/scanc.h>
 #include <typedefs.h>
-#include <string.h>
+#include <str.h>
 
 /** Primary meaning of scancodes. */
Index: kernel/genarch/src/kbrd/scanc_pc.c
===================================================================
--- kernel/genarch/src/kbrd/scanc_pc.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/kbrd/scanc_pc.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <genarch/kbrd/scanc.h>
 #include <typedefs.h>
-#include <string.h>
+#include <str.h>
 
 /** Primary meaning of scancodes. */
Index: kernel/genarch/src/kbrd/scanc_pl050.c
===================================================================
--- kernel/genarch/src/kbrd/scanc_pl050.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/kbrd/scanc_pl050.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -36,5 +36,5 @@
 #include <genarch/kbrd/scanc.h>
 #include <typedefs.h>
-#include <string.h>
+#include <str.h>
 
 
Index: kernel/genarch/src/kbrd/scanc_sun.c
===================================================================
--- kernel/genarch/src/kbrd/scanc_sun.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/kbrd/scanc_sun.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <genarch/kbrd/scanc.h>
 #include <typedefs.h>
-#include <string.h>
+#include <str.h>
 
 /** Primary meaning of scancodes. */
Index: kernel/genarch/src/multiboot/multiboot.c
===================================================================
--- kernel/genarch/src/multiboot/multiboot.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/multiboot/multiboot.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <typedefs.h>
 #include <config.h>
-#include <string.h>
+#include <str.h>
 #include <macros.h>
 
Index: kernel/genarch/src/ofw/ebus.c
===================================================================
--- kernel/genarch/src/ofw/ebus.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/ofw/ebus.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <genarch/ofw/pci.h>
 #include <arch/memstr.h>
-#include <string.h>
+#include <str.h>
 #include <panic.h>
 #include <debug.h>
Index: kernel/genarch/src/ofw/fhc.c
===================================================================
--- kernel/genarch/src/ofw/fhc.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/ofw/fhc.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <arch/drivers/fhc.h>
 #include <arch/memstr.h>
-#include <string.h>
+#include <str.h>
 #include <panic.h>
 #include <macros.h>
Index: kernel/genarch/src/ofw/ofw_tree.c
===================================================================
--- kernel/genarch/src/ofw/ofw_tree.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/ofw/ofw_tree.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include <arch/memstr.h>
 #include <mm/slab.h>
-#include <string.h>
+#include <str.h>
 #include <panic.h>
 #include <print.h>
Index: kernel/genarch/src/ofw/pci.c
===================================================================
--- kernel/genarch/src/ofw/pci.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/ofw/pci.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,10 +41,10 @@
 #include <arch/trap/interrupt.h>
 #include <arch/memstr.h>
-#include <string.h>
+#include <str.h>
 #include <panic.h>
 #include <macros.h>
 
 #define PCI_SPACE_MASK		0x03000000
-#define PCI_ABS_MASK		0x80000000	
+#define PCI_ABS_MASK		0x80000000
 #define PCI_REG_MASK		0x000000ff
 
Index: kernel/genarch/src/srln/srln.c
===================================================================
--- kernel/genarch/src/srln/srln.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/genarch/src/srln/srln.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <proc/thread.h>
 #include <arch.h>
-#include <string.h>
+#include <str.h>
 
 static indev_operations_t srln_raw_ops = {
Index: kernel/generic/include/str.h
===================================================================
--- kernel/generic/include/str.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ kernel/generic/include/str.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -0,0 +1,99 @@
+/*
+ * 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_STR_H_
+#define KERN_STR_H_
+
+#include <typedefs.h>
+
+/**< Common Unicode characters */
+#define U_SPECIAL      '?'
+
+#define U_LEFT_ARROW   0x2190
+#define U_UP_ARROW     0x2191
+#define U_RIGHT_ARROW  0x2192
+#define U_DOWN_ARROW   0x2193
+
+#define U_PAGE_UP      0x21de
+#define U_PAGE_DOWN    0x21df
+
+#define U_HOME_ARROW   0x21f1
+#define U_END_ARROW    0x21f2
+
+#define U_NULL         0x2400
+#define U_ESCAPE       0x241b
+#define U_DELETE       0x2421
+
+#define U_CURSOR       0x2588
+
+/**< No size limit constant */
+#define STR_NO_LIMIT  ((size_t) -1)
+
+/**< Maximum size of a string containing cnt characters */
+#define STR_BOUNDS(cnt)  (cnt << 2)
+
+extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
+extern int chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
+
+extern size_t str_size(const char *str);
+extern size_t wstr_size(const wchar_t *str);
+
+extern size_t str_lsize(const char *str, size_t max_len);
+extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
+
+extern size_t str_length(const char *str);
+extern size_t wstr_length(const wchar_t *wstr);
+
+extern size_t str_nlength(const char *str, size_t size);
+extern size_t wstr_nlength(const wchar_t *str, size_t size);
+
+extern bool ascii_check(wchar_t ch);
+extern bool chr_check(wchar_t ch);
+
+extern int str_cmp(const char *s1, const char *s2);
+extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
+
+extern void str_cpy(char *dest, size_t size, const char *src);
+extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
+extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
+
+extern char *str_chr(const char *str, wchar_t ch);
+
+extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
+extern bool wstr_remove(wchar_t *str, size_t pos);
+
+#endif
+
+/** @}
+ */
Index: rnel/generic/include/string.h
===================================================================
--- kernel/generic/include/string.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ 	(revision )
@@ -1,99 +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_STRING_H_
-#define KERN_STRING_H_
-
-#include <typedefs.h>
-
-/**< Common Unicode characters */
-#define U_SPECIAL      '?'
-
-#define U_LEFT_ARROW   0x2190
-#define U_UP_ARROW     0x2191
-#define U_RIGHT_ARROW  0x2192
-#define U_DOWN_ARROW   0x2193
-
-#define U_PAGE_UP      0x21de
-#define U_PAGE_DOWN    0x21df
-
-#define U_HOME_ARROW   0x21f1
-#define U_END_ARROW    0x21f2
-
-#define U_NULL         0x2400
-#define U_ESCAPE       0x241b
-#define U_DELETE       0x2421
-
-#define U_CURSOR       0x2588
-
-/**< No size limit constant */
-#define STR_NO_LIMIT  ((size_t) -1)
-
-/**< Maximum size of a string containing cnt characters */
-#define STR_BOUNDS(cnt)  (cnt << 2)
-
-extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
-extern int chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
-
-extern size_t str_size(const char *str);
-extern size_t wstr_size(const wchar_t *str);
-
-extern size_t str_lsize(const char *str, size_t max_len);
-extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
-
-extern size_t str_length(const char *str);
-extern size_t wstr_length(const wchar_t *wstr);
-
-extern size_t str_nlength(const char *str, size_t size);
-extern size_t wstr_nlength(const wchar_t *str, size_t size);
-
-extern bool ascii_check(wchar_t ch);
-extern bool chr_check(wchar_t ch);
-
-extern int str_cmp(const char *s1, const char *s2);
-extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
-
-extern void str_cpy(char *dest, size_t size, const char *src);
-extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
-extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
-
-extern char *str_chr(const char *str, wchar_t ch);
-
-extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
-extern bool wstr_remove(wchar_t *str, size_t pos);
-
-#endif
-
-/** @}
- */
Index: kernel/generic/include/sysinfo/sysinfo.h
===================================================================
--- kernel/generic/include/sysinfo/sysinfo.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/include/sysinfo/sysinfo.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 
 #include <arch/types.h>
-#include <string.h>
+#include <str.h>
 
 extern bool fb_exported;
Index: kernel/generic/src/console/cmd.c
===================================================================
--- kernel/generic/src/console/cmd.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/console/cmd.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -51,5 +51,5 @@
 #include <config.h>
 #include <func.h>
-#include <string.h>
+#include <str.h>
 #include <macros.h>
 #include <debug.h>
Index: kernel/generic/src/console/console.c
===================================================================
--- kernel/generic/src/console/console.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/console/console.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -51,5 +51,5 @@
 #include <syscall/copy.h>
 #include <errno.h>
-#include <string.h>
+#include <str.h>
 
 #define KLOG_PAGES    4
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/console/kconsole.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -51,5 +51,5 @@
 #include <debug.h>
 #include <func.h>
-#include <string.h>
+#include <str.h>
 #include <macros.h>
 #include <sysinfo/sysinfo.h>
@@ -58,5 +58,5 @@
 #include <errno.h>
 #include <putchar.h>
-#include <string.h>
+#include <str.h>
 
 /** Simple kernel console.
Index: kernel/generic/src/debug/symtab.c
===================================================================
--- kernel/generic/src/debug/symtab.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/debug/symtab.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <symtab.h>
 #include <byteorder.h>
-#include <string.h>
+#include <str.h>
 #include <print.h>
 #include <arch/types.h>
Index: kernel/generic/src/lib/str.c
===================================================================
--- kernel/generic/src/lib/str.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ kernel/generic/src/lib/str.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -0,0 +1,708 @@
+/*
+ * 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 String functions.
+ *
+ * Strings and characters use the Universal Character Set (UCS). The standard
+ * strings, called just strings are encoded in UTF-8. Wide strings (encoded
+ * in UTF-32) are supported to a limited degree. A single character is
+ * represented as wchar_t.@n
+ *
+ * Overview of the terminology:@n
+ *
+ *  Term                  Meaning
+ *  --------------------  ----------------------------------------------------
+ *  byte                  8 bits stored in uint8_t (unsigned 8 bit integer)
+ *
+ *  character             UTF-32 encoded Unicode character, stored in wchar_t
+ *                        (signed 32 bit integer), code points 0 .. 1114111
+ *                        are valid
+ *
+ *  ASCII character       7 bit encoded ASCII character, stored in char
+ *                        (usually signed 8 bit integer), code points 0 .. 127
+ *                        are valid
+ *
+ *  string                UTF-8 encoded NULL-terminated Unicode string, char *
+ *
+ *  wide string           UTF-32 encoded NULL-terminated Unicode string,
+ *                        wchar_t *
+ *
+ *  [wide] string size    number of BYTES in a [wide] string (excluding
+ *                        the NULL-terminator), size_t
+ *
+ *  [wide] string length  number of CHARACTERS in a [wide] string (excluding
+ *                        the NULL-terminator), size_t
+ *
+ *  [wide] string width   number of display cells on a monospace display taken
+ *                        by a [wide] string, size_t
+ *
+ *
+ * Overview of string metrics:@n
+ *
+ *  Metric  Abbrev.  Type     Meaning
+ *  ------  ------   ------   -------------------------------------------------
+ *  size    n        size_t   number of BYTES in a string (excluding the
+ *                            NULL-terminator)
+ *
+ *  length  l        size_t   number of CHARACTERS in a string (excluding the
+ *                            null terminator)
+ *
+ *  width  w         size_t   number of display cells on a monospace display
+ *                            taken by a string
+ *
+ *
+ * Function naming prefixes:@n
+ *
+ *  chr_    operate on characters
+ *  ascii_  operate on ASCII characters
+ *  str_    operate on strings
+ *  wstr_   operate on wide strings
+ *
+ *  [w]str_[n|l|w]  operate on a prefix limited by size, length
+ *                  or width
+ *
+ *
+ * A specific character inside a [wide] string can be referred to by:@n
+ *
+ *  pointer (char *, wchar_t *)
+ *  byte offset (size_t)
+ *  character index (size_t)
+ *
+ */
+
+#include <str.h>
+#include <print.h>
+#include <cpu.h>
+#include <arch/asm.h>
+#include <arch.h>
+#include <errno.h>
+#include <align.h>
+#include <debug.h>
+
+/** Byte mask consisting of lowest @n bits (out of 8) */
+#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
+
+/** Byte mask consisting of lowest @n bits (out of 32) */
+#define LO_MASK_32(n)  ((uint32_t) ((1 << (n)) - 1))
+
+/** Byte mask consisting of highest @n bits (out of 8) */
+#define HI_MASK_8(n)  (~LO_MASK_8(8 - (n)))
+
+/** Number of data bits in a UTF-8 continuation byte */
+#define CONT_BITS  6
+
+/** Decode a single character from a string.
+ *
+ * Decode a single character from a string of size @a size. Decoding starts
+ * at @a offset and this offset is moved to the beginning of the next
+ * character. In case of decoding error, offset generally advances at least
+ * by one. However, offset is never moved beyond size.
+ *
+ * @param str    String (not necessarily NULL-terminated).
+ * @param offset Byte offset in string where to start decoding.
+ * @param size   Size of the string (in bytes).
+ *
+ * @return Value of decoded character, U_SPECIAL on decoding error or
+ *         NULL if attempt to decode beyond @a size.
+ *
+ */
+wchar_t str_decode(const char *str, size_t *offset, size_t size)
+{
+	if (*offset + 1 > size)
+		return 0;
+	
+	/* First byte read from string */
+	uint8_t b0 = (uint8_t) str[(*offset)++];
+	
+	/* Determine code length */
+	
+	unsigned int b0_bits;  /* Data bits in first byte */
+	unsigned int cbytes;   /* Number of continuation bytes */
+	
+	if ((b0 & 0x80) == 0) {
+		/* 0xxxxxxx (Plain ASCII) */
+		b0_bits = 7;
+		cbytes = 0;
+	} else if ((b0 & 0xe0) == 0xc0) {
+		/* 110xxxxx 10xxxxxx */
+		b0_bits = 5;
+		cbytes = 1;
+	} else if ((b0 & 0xf0) == 0xe0) {
+		/* 1110xxxx 10xxxxxx 10xxxxxx */
+		b0_bits = 4;
+		cbytes = 2;
+	} else if ((b0 & 0xf8) == 0xf0) {
+		/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
+		b0_bits = 3;
+		cbytes = 3;
+	} else {
+		/* 10xxxxxx -- unexpected continuation byte */
+		return U_SPECIAL;
+	}
+	
+	if (*offset + cbytes > size)
+		return U_SPECIAL;
+	
+	wchar_t ch = b0 & LO_MASK_8(b0_bits);
+	
+	/* Decode continuation bytes */
+	while (cbytes > 0) {
+		uint8_t b = (uint8_t) str[(*offset)++];
+		
+		/* Must be 10xxxxxx */
+		if ((b & 0xc0) != 0x80)
+			return U_SPECIAL;
+		
+		/* Shift data bits to ch */
+		ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
+		cbytes--;
+	}
+	
+	return ch;
+}
+
+/** Encode a single character to string representation.
+ *
+ * Encode a single character to string representation (i.e. UTF-8) and store
+ * it into a buffer at @a offset. Encoding starts at @a offset and this offset
+ * is moved to the position where the next character can be written to.
+ *
+ * @param ch     Input character.
+ * @param str    Output buffer.
+ * @param offset Byte offset where to start writing.
+ * @param size   Size of the output buffer (in bytes).
+ *
+ * @return EOK if the character was encoded successfully, EOVERFLOW if there
+ *	   was not enough space in the output buffer or EINVAL if the character
+ *	   code was invalid.
+ */
+int chr_encode(wchar_t ch, char *str, size_t *offset, size_t size)
+{
+	if (*offset >= size)
+		return EOVERFLOW;
+	
+	if (!chr_check(ch))
+		return EINVAL;
+	
+	/* Unsigned version of ch (bit operations should only be done
+	   on unsigned types). */
+	uint32_t cc = (uint32_t) ch;
+	
+	/* Determine how many continuation bytes are needed */
+	
+	unsigned int b0_bits;  /* Data bits in first byte */
+	unsigned int cbytes;   /* Number of continuation bytes */
+	
+	if ((cc & ~LO_MASK_32(7)) == 0) {
+		b0_bits = 7;
+		cbytes = 0;
+	} else if ((cc & ~LO_MASK_32(11)) == 0) {
+		b0_bits = 5;
+		cbytes = 1;
+	} else if ((cc & ~LO_MASK_32(16)) == 0) {
+		b0_bits = 4;
+		cbytes = 2;
+	} else if ((cc & ~LO_MASK_32(21)) == 0) {
+		b0_bits = 3;
+		cbytes = 3;
+	} else {
+		/* Codes longer than 21 bits are not supported */
+		return EINVAL;
+	}
+	
+	/* Check for available space in buffer */
+	if (*offset + cbytes >= size)
+		return EOVERFLOW;
+	
+	/* Encode continuation bytes */
+	unsigned int i;
+	for (i = cbytes; i > 0; i--) {
+		str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
+		cc = cc >> CONT_BITS;
+	}
+	
+	/* Encode first byte */
+	str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
+	
+	/* Advance offset */
+	*offset += cbytes + 1;
+	
+	return EOK;
+}
+
+/** Get size of string.
+ *
+ * Get the number of bytes which are used by the string @a str (excluding the
+ * NULL-terminator).
+ *
+ * @param str String to consider.
+ *
+ * @return Number of bytes used by the string
+ *
+ */
+size_t str_size(const char *str)
+{
+	size_t size = 0;
+	
+	while (*str++ != 0)
+		size++;
+	
+	return size;
+}
+
+/** Get size of wide string.
+ *
+ * Get the number of bytes which are used by the wide string @a str (excluding the
+ * NULL-terminator).
+ *
+ * @param str Wide string to consider.
+ *
+ * @return Number of bytes used by the wide string
+ *
+ */
+size_t wstr_size(const wchar_t *str)
+{
+	return (wstr_length(str) * sizeof(wchar_t));
+}
+
+/** Get size of string with length limit.
+ *
+ * Get the number of bytes which are used by up to @a max_len first
+ * characters in the string @a str. If @a max_len is greater than
+ * the length of @a str, the entire string is measured (excluding the
+ * NULL-terminator).
+ *
+ * @param str     String to consider.
+ * @param max_len Maximum number of characters to measure.
+ *
+ * @return Number of bytes used by the characters.
+ *
+ */
+size_t str_lsize(const char *str, size_t max_len)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (len < max_len) {
+		if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
+			break;
+		
+		len++;
+	}
+	
+	return offset;
+}
+
+/** Get size of wide string with length limit.
+ *
+ * Get the number of bytes which are used by up to @a max_len first
+ * wide characters in the wide string @a str. If @a max_len is greater than
+ * the length of @a str, the entire wide string is measured (excluding the
+ * NULL-terminator).
+ *
+ * @param str     Wide string to consider.
+ * @param max_len Maximum number of wide characters to measure.
+ *
+ * @return Number of bytes used by the wide characters.
+ *
+ */
+size_t wstr_lsize(const wchar_t *str, size_t max_len)
+{
+	return (wstr_nlength(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
+}
+
+/** Get number of characters in a string.
+ *
+ * @param str NULL-terminated string.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t str_length(const char *str)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a wide string.
+ *
+ * @param str NULL-terminated wide string.
+ *
+ * @return Number of characters in @a str.
+ *
+ */
+size_t wstr_length(const wchar_t *wstr)
+{
+	size_t len = 0;
+	
+	while (*wstr++ != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a string with size limit.
+ *
+ * @param str  NULL-terminated string.
+ * @param size Maximum number of bytes to consider.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t str_nlength(const char *str, size_t size)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (str_decode(str, &offset, size) != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a string with size limit.
+ *
+ * @param str  NULL-terminated string.
+ * @param size Maximum number of bytes to consider.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t wstr_nlength(const wchar_t *str, size_t size)
+{
+	size_t len = 0;
+	size_t limit = ALIGN_DOWN(size, sizeof(wchar_t));
+	size_t offset = 0;
+	
+	while ((offset < limit) && (*str++ != 0)) {
+		len++;
+		offset += sizeof(wchar_t);
+	}
+	
+	return len;
+}
+
+/** Check whether character is plain ASCII.
+ *
+ * @return True if character is plain ASCII.
+ *
+ */
+bool ascii_check(wchar_t ch)
+{
+	if ((ch >= 0) && (ch <= 127))
+		return true;
+	
+	return false;
+}
+
+/** Check whether character is valid
+ *
+ * @return True if character is a valid Unicode code point.
+ *
+ */
+bool chr_check(wchar_t ch)
+{
+	if ((ch >= 0) && (ch <= 1114111))
+		return true;
+	
+	return false;
+}
+
+/** Compare two NULL terminated strings.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff they consist of the same
+ * characters on the minimum of their lengths.
+ *
+ * @param s1 First string to compare.
+ * @param s2 Second string to compare.
+ *
+ * @return 0 if the strings are equal, -1 if first is smaller,
+ *         1 if second smaller.
+ *
+ */
+int str_cmp(const char *s1, const char *s2)
+{
+	wchar_t c1 = 0;
+	wchar_t c2 = 0;
+	
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	while (true) {
+		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
+		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
+
+		if (c1 < c2)
+			return -1;
+		
+		if (c1 > c2)
+			return 1;
+
+		if (c1 == 0 || c2 == 0)
+			break;		
+	}
+
+	return 0;
+}
+
+/** Compare two NULL terminated strings with length limit.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff they consist of the same
+ * characters on the minimum of their lengths and the length limit.
+ *
+ * @param s1      First string to compare.
+ * @param s2      Second string to compare.
+ * @param max_len Maximum number of characters to consider.
+ *
+ * @return 0 if the strings are equal, -1 if first is smaller,
+ *         1 if second smaller.
+ *
+ */
+int str_lcmp(const char *s1, const char *s2, size_t max_len)
+{
+	wchar_t c1 = 0;
+	wchar_t c2 = 0;
+	
+	size_t off1 = 0;
+	size_t off2 = 0;
+	
+	size_t len = 0;
+
+	while (true) {
+		if (len >= max_len)
+			break;
+
+		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
+		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
+
+		if (c1 < c2)
+			return -1;
+
+		if (c1 > c2)
+			return 1;
+
+		if (c1 == 0 || c2 == 0)
+			break;
+
+		++len;	
+	}
+
+	return 0;
+
+}
+
+/** Copy string.
+ *
+ * Copy source string @a src to destination buffer @a dest.
+ * No more than @a size bytes are written. If the size of the output buffer
+ * is at least one byte, the output string will always be well-formed, i.e.
+ * null-terminated and containing only complete characters.
+ *
+ * @param dest   Destination buffer.
+ * @param count Size of the destination buffer (must be > 0).
+ * @param src   Source string.
+ */
+void str_cpy(char *dest, size_t size, const char *src)
+{
+	wchar_t ch;
+	size_t src_off;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	ASSERT(size > 0);
+	
+	src_off = 0;
+	dest_off = 0;
+
+	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Copy size-limited substring.
+ *
+ * Copy prefix of string @a src of max. size @a size to destination buffer
+ * @a dest. No more than @a size bytes are written. The output string will
+ * always be well-formed, i.e. null-terminated and containing only complete
+ * characters.
+ *
+ * No more than @a n bytes are read from the input string, so it does not
+ * have to be null-terminated.
+ *
+ * @param dest   Destination buffer.
+ * @param count Size of the destination buffer (must be > 0).
+ * @param src   Source string.
+ * @param n	Maximum number of bytes to read from @a src.
+ */
+void str_ncpy(char *dest, size_t size, const char *src, size_t n)
+{
+	wchar_t ch;
+	size_t src_off;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	ASSERT(size > 0);
+	
+	src_off = 0;
+	dest_off = 0;
+
+	while ((ch = str_decode(src, &src_off, n)) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Convert wide string to string.
+ *
+ * Convert wide string @a src to string. The output is written to the buffer
+ * specified by @a dest and @a size. @a size must be non-zero and the string
+ * written will always be well-formed.
+ *
+ * @param dest	Destination buffer.
+ * @param size	Size of the destination buffer.
+ * @param src	Source wide string.
+ */
+void wstr_to_str(char *dest, size_t size, const wchar_t *src)
+{
+	wchar_t ch;
+	size_t src_idx;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	ASSERT(size > 0);
+
+	src_idx = 0;
+	dest_off = 0;
+	
+	while ((ch = src[src_idx++]) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Find first occurence of character in string.
+ *
+ * @param str String to search.
+ * @param ch  Character to look for.
+ *
+ * @return Pointer to character in @a str or NULL if not found.
+ *
+ */
+char *str_chr(const char *str, wchar_t ch)
+{
+	wchar_t acc;
+	size_t off = 0;
+	size_t last = 0;
+	
+	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
+		if (acc == ch)
+			return (char *) (str + last);
+		last = off;
+	}
+	
+	return NULL;
+}
+
+/** Insert a wide character into a wide string.
+ *
+ * Insert a wide character into a wide string at position
+ * @a pos. The characters after the position are shifted.
+ *
+ * @param str     String to insert to.
+ * @param ch      Character to insert to.
+ * @param pos     Character index where to insert.
+ @ @param max_pos Characters in the buffer.
+ *
+ * @return True if the insertion was sucessful, false if the position
+ *         is out of bounds.
+ *
+ */
+bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos)
+{
+	size_t len = wstr_length(str);
+	
+	if ((pos > len) || (pos + 1 > max_pos))
+		return false;
+	
+	size_t i;
+	for (i = len; i + 1 > pos; i--)
+		str[i + 1] = str[i];
+	
+	str[pos] = ch;
+	
+	return true;
+}
+
+/** Remove a wide character from a wide string.
+ *
+ * Remove a wide character from a wide string at position
+ * @a pos. The characters after the position are shifted.
+ *
+ * @param str String to remove from.
+ * @param pos Character index to remove.
+ *
+ * @return True if the removal was sucessful, false if the position
+ *         is out of bounds.
+ *
+ */
+bool wstr_remove(wchar_t *str, size_t pos)
+{
+	size_t len = wstr_length(str);
+	
+	if (pos >= len)
+		return false;
+	
+	size_t i;
+	for (i = pos + 1; i <= len; i++)
+		str[i - 1] = str[i];
+	
+	return true;
+}
+
+/** @}
+ */
Index: rnel/generic/src/lib/string.c
===================================================================
--- kernel/generic/src/lib/string.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ 	(revision )
@@ -1,708 +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 String functions.
- *
- * Strings and characters use the Universal Character Set (UCS). The standard
- * strings, called just strings are encoded in UTF-8. Wide strings (encoded
- * in UTF-32) are supported to a limited degree. A single character is
- * represented as wchar_t.@n
- *
- * Overview of the terminology:@n
- *
- *  Term                  Meaning
- *  --------------------  ----------------------------------------------------
- *  byte                  8 bits stored in uint8_t (unsigned 8 bit integer)
- *
- *  character             UTF-32 encoded Unicode character, stored in wchar_t
- *                        (signed 32 bit integer), code points 0 .. 1114111
- *                        are valid
- *
- *  ASCII character       7 bit encoded ASCII character, stored in char
- *                        (usually signed 8 bit integer), code points 0 .. 127
- *                        are valid
- *
- *  string                UTF-8 encoded NULL-terminated Unicode string, char *
- *
- *  wide string           UTF-32 encoded NULL-terminated Unicode string,
- *                        wchar_t *
- *
- *  [wide] string size    number of BYTES in a [wide] string (excluding
- *                        the NULL-terminator), size_t
- *
- *  [wide] string length  number of CHARACTERS in a [wide] string (excluding
- *                        the NULL-terminator), size_t
- *
- *  [wide] string width   number of display cells on a monospace display taken
- *                        by a [wide] string, size_t
- *
- *
- * Overview of string metrics:@n
- *
- *  Metric  Abbrev.  Type     Meaning
- *  ------  ------   ------   -------------------------------------------------
- *  size    n        size_t   number of BYTES in a string (excluding the
- *                            NULL-terminator)
- *
- *  length  l        size_t   number of CHARACTERS in a string (excluding the
- *                            null terminator)
- *
- *  width  w         size_t   number of display cells on a monospace display
- *                            taken by a string
- *
- *
- * Function naming prefixes:@n
- *
- *  chr_    operate on characters
- *  ascii_  operate on ASCII characters
- *  str_    operate on strings
- *  wstr_   operate on wide strings
- *
- *  [w]str_[n|l|w]  operate on a prefix limited by size, length
- *                  or width
- *
- *
- * A specific character inside a [wide] string can be referred to by:@n
- *
- *  pointer (char *, wchar_t *)
- *  byte offset (size_t)
- *  character index (size_t)
- *
- */
-
-#include <string.h>
-#include <print.h>
-#include <cpu.h>
-#include <arch/asm.h>
-#include <arch.h>
-#include <errno.h>
-#include <align.h>
-#include <debug.h>
-
-/** Byte mask consisting of lowest @n bits (out of 8) */
-#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
-
-/** Byte mask consisting of lowest @n bits (out of 32) */
-#define LO_MASK_32(n)  ((uint32_t) ((1 << (n)) - 1))
-
-/** Byte mask consisting of highest @n bits (out of 8) */
-#define HI_MASK_8(n)  (~LO_MASK_8(8 - (n)))
-
-/** Number of data bits in a UTF-8 continuation byte */
-#define CONT_BITS  6
-
-/** Decode a single character from a string.
- *
- * Decode a single character from a string of size @a size. Decoding starts
- * at @a offset and this offset is moved to the beginning of the next
- * character. In case of decoding error, offset generally advances at least
- * by one. However, offset is never moved beyond size.
- *
- * @param str    String (not necessarily NULL-terminated).
- * @param offset Byte offset in string where to start decoding.
- * @param size   Size of the string (in bytes).
- *
- * @return Value of decoded character, U_SPECIAL on decoding error or
- *         NULL if attempt to decode beyond @a size.
- *
- */
-wchar_t str_decode(const char *str, size_t *offset, size_t size)
-{
-	if (*offset + 1 > size)
-		return 0;
-	
-	/* First byte read from string */
-	uint8_t b0 = (uint8_t) str[(*offset)++];
-	
-	/* Determine code length */
-	
-	unsigned int b0_bits;  /* Data bits in first byte */
-	unsigned int cbytes;   /* Number of continuation bytes */
-	
-	if ((b0 & 0x80) == 0) {
-		/* 0xxxxxxx (Plain ASCII) */
-		b0_bits = 7;
-		cbytes = 0;
-	} else if ((b0 & 0xe0) == 0xc0) {
-		/* 110xxxxx 10xxxxxx */
-		b0_bits = 5;
-		cbytes = 1;
-	} else if ((b0 & 0xf0) == 0xe0) {
-		/* 1110xxxx 10xxxxxx 10xxxxxx */
-		b0_bits = 4;
-		cbytes = 2;
-	} else if ((b0 & 0xf8) == 0xf0) {
-		/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
-		b0_bits = 3;
-		cbytes = 3;
-	} else {
-		/* 10xxxxxx -- unexpected continuation byte */
-		return U_SPECIAL;
-	}
-	
-	if (*offset + cbytes > size)
-		return U_SPECIAL;
-	
-	wchar_t ch = b0 & LO_MASK_8(b0_bits);
-	
-	/* Decode continuation bytes */
-	while (cbytes > 0) {
-		uint8_t b = (uint8_t) str[(*offset)++];
-		
-		/* Must be 10xxxxxx */
-		if ((b & 0xc0) != 0x80)
-			return U_SPECIAL;
-		
-		/* Shift data bits to ch */
-		ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
-		cbytes--;
-	}
-	
-	return ch;
-}
-
-/** Encode a single character to string representation.
- *
- * Encode a single character to string representation (i.e. UTF-8) and store
- * it into a buffer at @a offset. Encoding starts at @a offset and this offset
- * is moved to the position where the next character can be written to.
- *
- * @param ch     Input character.
- * @param str    Output buffer.
- * @param offset Byte offset where to start writing.
- * @param size   Size of the output buffer (in bytes).
- *
- * @return EOK if the character was encoded successfully, EOVERFLOW if there
- *	   was not enough space in the output buffer or EINVAL if the character
- *	   code was invalid.
- */
-int chr_encode(wchar_t ch, char *str, size_t *offset, size_t size)
-{
-	if (*offset >= size)
-		return EOVERFLOW;
-	
-	if (!chr_check(ch))
-		return EINVAL;
-	
-	/* Unsigned version of ch (bit operations should only be done
-	   on unsigned types). */
-	uint32_t cc = (uint32_t) ch;
-	
-	/* Determine how many continuation bytes are needed */
-	
-	unsigned int b0_bits;  /* Data bits in first byte */
-	unsigned int cbytes;   /* Number of continuation bytes */
-	
-	if ((cc & ~LO_MASK_32(7)) == 0) {
-		b0_bits = 7;
-		cbytes = 0;
-	} else if ((cc & ~LO_MASK_32(11)) == 0) {
-		b0_bits = 5;
-		cbytes = 1;
-	} else if ((cc & ~LO_MASK_32(16)) == 0) {
-		b0_bits = 4;
-		cbytes = 2;
-	} else if ((cc & ~LO_MASK_32(21)) == 0) {
-		b0_bits = 3;
-		cbytes = 3;
-	} else {
-		/* Codes longer than 21 bits are not supported */
-		return EINVAL;
-	}
-	
-	/* Check for available space in buffer */
-	if (*offset + cbytes >= size)
-		return EOVERFLOW;
-	
-	/* Encode continuation bytes */
-	unsigned int i;
-	for (i = cbytes; i > 0; i--) {
-		str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
-		cc = cc >> CONT_BITS;
-	}
-	
-	/* Encode first byte */
-	str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
-	
-	/* Advance offset */
-	*offset += cbytes + 1;
-	
-	return EOK;
-}
-
-/** Get size of string.
- *
- * Get the number of bytes which are used by the string @a str (excluding the
- * NULL-terminator).
- *
- * @param str String to consider.
- *
- * @return Number of bytes used by the string
- *
- */
-size_t str_size(const char *str)
-{
-	size_t size = 0;
-	
-	while (*str++ != 0)
-		size++;
-	
-	return size;
-}
-
-/** Get size of wide string.
- *
- * Get the number of bytes which are used by the wide string @a str (excluding the
- * NULL-terminator).
- *
- * @param str Wide string to consider.
- *
- * @return Number of bytes used by the wide string
- *
- */
-size_t wstr_size(const wchar_t *str)
-{
-	return (wstr_length(str) * sizeof(wchar_t));
-}
-
-/** Get size of string with length limit.
- *
- * Get the number of bytes which are used by up to @a max_len first
- * characters in the string @a str. If @a max_len is greater than
- * the length of @a str, the entire string is measured (excluding the
- * NULL-terminator).
- *
- * @param str     String to consider.
- * @param max_len Maximum number of characters to measure.
- *
- * @return Number of bytes used by the characters.
- *
- */
-size_t str_lsize(const char *str, size_t max_len)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (len < max_len) {
-		if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
-			break;
-		
-		len++;
-	}
-	
-	return offset;
-}
-
-/** Get size of wide string with length limit.
- *
- * Get the number of bytes which are used by up to @a max_len first
- * wide characters in the wide string @a str. If @a max_len is greater than
- * the length of @a str, the entire wide string is measured (excluding the
- * NULL-terminator).
- *
- * @param str     Wide string to consider.
- * @param max_len Maximum number of wide characters to measure.
- *
- * @return Number of bytes used by the wide characters.
- *
- */
-size_t wstr_lsize(const wchar_t *str, size_t max_len)
-{
-	return (wstr_nlength(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
-}
-
-/** Get number of characters in a string.
- *
- * @param str NULL-terminated string.
- *
- * @return Number of characters in string.
- *
- */
-size_t str_length(const char *str)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a wide string.
- *
- * @param str NULL-terminated wide string.
- *
- * @return Number of characters in @a str.
- *
- */
-size_t wstr_length(const wchar_t *wstr)
-{
-	size_t len = 0;
-	
-	while (*wstr++ != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a string with size limit.
- *
- * @param str  NULL-terminated string.
- * @param size Maximum number of bytes to consider.
- *
- * @return Number of characters in string.
- *
- */
-size_t str_nlength(const char *str, size_t size)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (str_decode(str, &offset, size) != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a string with size limit.
- *
- * @param str  NULL-terminated string.
- * @param size Maximum number of bytes to consider.
- *
- * @return Number of characters in string.
- *
- */
-size_t wstr_nlength(const wchar_t *str, size_t size)
-{
-	size_t len = 0;
-	size_t limit = ALIGN_DOWN(size, sizeof(wchar_t));
-	size_t offset = 0;
-	
-	while ((offset < limit) && (*str++ != 0)) {
-		len++;
-		offset += sizeof(wchar_t);
-	}
-	
-	return len;
-}
-
-/** Check whether character is plain ASCII.
- *
- * @return True if character is plain ASCII.
- *
- */
-bool ascii_check(wchar_t ch)
-{
-	if ((ch >= 0) && (ch <= 127))
-		return true;
-	
-	return false;
-}
-
-/** Check whether character is valid
- *
- * @return True if character is a valid Unicode code point.
- *
- */
-bool chr_check(wchar_t ch)
-{
-	if ((ch >= 0) && (ch <= 1114111))
-		return true;
-	
-	return false;
-}
-
-/** Compare two NULL terminated strings.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
- *
- */
-int str_cmp(const char *s1, const char *s2)
-{
-	wchar_t c1 = 0;
-	wchar_t c2 = 0;
-	
-	size_t off1 = 0;
-	size_t off2 = 0;
-
-	while (true) {
-		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
-		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
-
-		if (c1 < c2)
-			return -1;
-		
-		if (c1 > c2)
-			return 1;
-
-		if (c1 == 0 || c2 == 0)
-			break;		
-	}
-
-	return 0;
-}
-
-/** Compare two NULL terminated strings with length limit.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths and the length limit.
- *
- * @param s1      First string to compare.
- * @param s2      Second string to compare.
- * @param max_len Maximum number of characters to consider.
- *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
- *
- */
-int str_lcmp(const char *s1, const char *s2, size_t max_len)
-{
-	wchar_t c1 = 0;
-	wchar_t c2 = 0;
-	
-	size_t off1 = 0;
-	size_t off2 = 0;
-	
-	size_t len = 0;
-
-	while (true) {
-		if (len >= max_len)
-			break;
-
-		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
-		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
-
-		if (c1 < c2)
-			return -1;
-
-		if (c1 > c2)
-			return 1;
-
-		if (c1 == 0 || c2 == 0)
-			break;
-
-		++len;	
-	}
-
-	return 0;
-
-}
-
-/** Copy string.
- *
- * Copy source string @a src to destination buffer @a dest.
- * No more than @a size bytes are written. If the size of the output buffer
- * is at least one byte, the output string will always be well-formed, i.e.
- * null-terminated and containing only complete characters.
- *
- * @param dest   Destination buffer.
- * @param count Size of the destination buffer (must be > 0).
- * @param src   Source string.
- */
-void str_cpy(char *dest, size_t size, const char *src)
-{
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	ASSERT(size > 0);
-	
-	src_off = 0;
-	dest_off = 0;
-
-	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Copy size-limited substring.
- *
- * Copy prefix of string @a src of max. size @a size to destination buffer
- * @a dest. No more than @a size bytes are written. The output string will
- * always be well-formed, i.e. null-terminated and containing only complete
- * characters.
- *
- * No more than @a n bytes are read from the input string, so it does not
- * have to be null-terminated.
- *
- * @param dest   Destination buffer.
- * @param count Size of the destination buffer (must be > 0).
- * @param src   Source string.
- * @param n	Maximum number of bytes to read from @a src.
- */
-void str_ncpy(char *dest, size_t size, const char *src, size_t n)
-{
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	ASSERT(size > 0);
-	
-	src_off = 0;
-	dest_off = 0;
-
-	while ((ch = str_decode(src, &src_off, n)) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Convert wide string to string.
- *
- * Convert wide string @a src to string. The output is written to the buffer
- * specified by @a dest and @a size. @a size must be non-zero and the string
- * written will always be well-formed.
- *
- * @param dest	Destination buffer.
- * @param size	Size of the destination buffer.
- * @param src	Source wide string.
- */
-void wstr_to_str(char *dest, size_t size, const wchar_t *src)
-{
-	wchar_t ch;
-	size_t src_idx;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	ASSERT(size > 0);
-
-	src_idx = 0;
-	dest_off = 0;
-	
-	while ((ch = src[src_idx++]) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Find first occurence of character in string.
- *
- * @param str String to search.
- * @param ch  Character to look for.
- *
- * @return Pointer to character in @a str or NULL if not found.
- *
- */
-char *str_chr(const char *str, wchar_t ch)
-{
-	wchar_t acc;
-	size_t off = 0;
-	size_t last = 0;
-	
-	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
-		if (acc == ch)
-			return (char *) (str + last);
-		last = off;
-	}
-	
-	return NULL;
-}
-
-/** Insert a wide character into a wide string.
- *
- * Insert a wide character into a wide string at position
- * @a pos. The characters after the position are shifted.
- *
- * @param str     String to insert to.
- * @param ch      Character to insert to.
- * @param pos     Character index where to insert.
- @ @param max_pos Characters in the buffer.
- *
- * @return True if the insertion was sucessful, false if the position
- *         is out of bounds.
- *
- */
-bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos)
-{
-	size_t len = wstr_length(str);
-	
-	if ((pos > len) || (pos + 1 > max_pos))
-		return false;
-	
-	size_t i;
-	for (i = len; i + 1 > pos; i--)
-		str[i + 1] = str[i];
-	
-	str[pos] = ch;
-	
-	return true;
-}
-
-/** Remove a wide character from a wide string.
- *
- * Remove a wide character from a wide string at position
- * @a pos. The characters after the position are shifted.
- *
- * @param str String to remove from.
- * @param pos Character index to remove.
- *
- * @return True if the removal was sucessful, false if the position
- *         is out of bounds.
- *
- */
-bool wstr_remove(wchar_t *str, size_t pos)
-{
-	size_t len = wstr_length(str);
-	
-	if (pos >= len)
-		return false;
-	
-	size_t i;
-	for (i = pos + 1; i <= len; i++)
-		str[i - 1] = str[i];
-	
-	return true;
-}
-
-/** @}
- */
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/main/kinit.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -66,5 +66,5 @@
 #include <ipc/ipc.h>
 #include <debug.h>
-#include <string.h>
+#include <str.h>
 
 #ifdef CONFIG_SMP
Index: kernel/generic/src/printf/printf_core.c
===================================================================
--- kernel/generic/src/printf/printf_core.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/printf/printf_core.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <stdarg.h>
 #include <macros.h>
-#include <string.h>
+#include <str.h>
 #include <arch.h>
 
Index: kernel/generic/src/printf/vprintf.c
===================================================================
--- kernel/generic/src/printf/vprintf.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/printf/vprintf.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <arch/types.h>
 #include <typedefs.h>
-#include <string.h>
+#include <str.h>
 
 SPINLOCK_STATIC_INITIALIZE_NAME(printf_lock, "*printf_lock");
Index: kernel/generic/src/printf/vsnprintf.c
===================================================================
--- kernel/generic/src/printf/vsnprintf.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/printf/vsnprintf.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -35,5 +35,5 @@
 #include <print.h>
 #include <printf/printf_core.h>
-#include <string.h>
+#include <str.h>
 #include <memstr.h>
 #include <errno.h>
Index: kernel/generic/src/proc/task.c
===================================================================
--- kernel/generic/src/proc/task.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/proc/task.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -53,5 +53,5 @@
 #include <errno.h>
 #include <func.h>
-#include <string.h>
+#include <str.h>
 #include <memstr.h>
 #include <syscall/copy.h>
Index: kernel/generic/src/udebug/udebug_ops.c
===================================================================
--- kernel/generic/src/udebug/udebug_ops.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ kernel/generic/src/udebug/udebug_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -46,5 +46,5 @@
 #include <errno.h>
 #include <print.h>
-#include <string.h>
+#include <str.h>
 #include <syscall/copy.h>
 #include <ipc/ipc.h>
Index: uspace/app/bdsh/cmds/builtin_cmds.c
===================================================================
--- uspace/app/bdsh/cmds/builtin_cmds.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/builtin_cmds.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -34,5 +34,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include "errors.h"
 #include "cmds.h"
Index: uspace/app/bdsh/cmds/builtins/cd/cd.c
===================================================================
--- uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/builtins/cd/cd.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -32,5 +32,5 @@
 #include <stdlib.h>
 #include <unistd.h>
-#include <string.h>
+#include <str.h>
 #include <errno.h>
 
Index: uspace/app/bdsh/cmds/mod_cmds.c
===================================================================
--- uspace/app/bdsh/cmds/mod_cmds.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/mod_cmds.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -47,5 +47,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include "errors.h"
 #include "cmds.h"
Index: uspace/app/bdsh/cmds/modules/bdd/bdd.c
===================================================================
--- uspace/app/bdsh/cmds/modules/bdd/bdd.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/bdd/bdd.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -29,5 +29,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.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 e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/cat/cat.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -33,5 +33,5 @@
 #include <unistd.h>
 #include <getopt.h>
-#include <string.h>
+#include <str.h>
 #include <fcntl.h>
 
Index: uspace/app/bdsh/cmds/modules/cp/cp.c
===================================================================
--- uspace/app/bdsh/cmds/modules/cp/cp.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/cp/cp.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -33,5 +33,5 @@
 #include <unistd.h>
 #include <getopt.h>
-#include <string.h>
+#include <str.h>
 #include <fcntl.h>
 #include "config.h"
Index: uspace/app/bdsh/cmds/modules/help/help.c
===================================================================
--- uspace/app/bdsh/cmds/modules/help/help.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/help/help.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -31,5 +31,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 
 #include "config.h"
Index: uspace/app/bdsh/cmds/modules/ls/ls.c
===================================================================
--- uspace/app/bdsh/cmds/modules/ls/ls.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/ls/ls.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <string.h>
+#include <str.h>
 
 #include "errors.h"
Index: uspace/app/bdsh/cmds/modules/mkdir/mkdir.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/mkdir/mkdir.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <getopt.h>
 #include <stdarg.h>
-#include <string.h>
+#include <str.h>
 
 #include "config.h"
Index: uspace/app/bdsh/cmds/modules/mkfile/mkfile.c
===================================================================
--- uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/mkfile/mkfile.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <getopt.h>
 #include <stdarg.h>
-#include <string.h>
+#include <str.h>
 #include <ctype.h>
 
Index: uspace/app/bdsh/cmds/modules/rm/rm.c
===================================================================
--- uspace/app/bdsh/cmds/modules/rm/rm.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/rm/rm.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -36,5 +36,5 @@
 #include <getopt.h>
 #include <mem.h>
-#include <string.h>
+#include <str.h>
 
 #include "config.h"
Index: uspace/app/bdsh/cmds/modules/touch/touch.c
===================================================================
--- uspace/app/bdsh/cmds/modules/touch/touch.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/cmds/modules/touch/touch.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <dirent.h>
 #include <sys/types.h>
-#include <string.h>
+#include <str.h>
 
 #include "config.h"
Index: uspace/app/bdsh/errors.c
===================================================================
--- uspace/app/bdsh/errors.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/errors.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -30,5 +30,5 @@
 
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <stdlib.h>
 #include <unistd.h>
Index: uspace/app/bdsh/exec.c
===================================================================
--- uspace/app/bdsh/exec.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/exec.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <stdlib.h>
 #include <unistd.h>
-#include <string.h>
+#include <str.h>
 #include <fcntl.h>
 
Index: uspace/app/bdsh/input.c
===================================================================
--- uspace/app/bdsh/input.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/input.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -32,5 +32,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <io/console.h>
 #include <io/keycode.h>
Index: uspace/app/bdsh/scli.c
===================================================================
--- uspace/app/bdsh/scli.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/scli.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -31,5 +31,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <unistd.h>
 #include "config.h"
Index: uspace/app/bdsh/util.c
===================================================================
--- uspace/app/bdsh/util.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/bdsh/util.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -29,5 +29,5 @@
 
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <stdarg.h>
 #include <stdlib.h>
Index: uspace/app/edit/sheet.c
===================================================================
--- uspace/app/edit/sheet.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/edit/sheet.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -50,5 +50,5 @@
 
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <errno.h>
 #include <adt/list.h>
Index: uspace/app/init/init.c
===================================================================
--- uspace/app/init/init.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/init/init.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -46,5 +46,5 @@
 #include <malloc.h>
 #include <macros.h>
-#include <string.h>
+#include <str.h>
 #include <devmap.h>
 #include "init.h"
Index: uspace/app/redir/redir.c
===================================================================
--- uspace/app/redir/redir.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/redir/redir.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include <fcntl.h>
 #include <unistd.h>
-#include <string.h>
+#include <str.h>
 #include <stdio.h>
 #include <task.h>
Index: uspace/app/tester/tester.c
===================================================================
--- uspace/app/tester/tester.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tester/tester.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <unistd.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include "tester.h"
 
Index: uspace/app/tester/vfs/vfs1.c
===================================================================
--- uspace/app/tester/vfs/vfs1.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tester/vfs/vfs1.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -30,5 +30,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <vfs/vfs.h>
 #include <unistd.h>
Index: uspace/app/tetris/input.c
===================================================================
--- uspace/app/tetris/input.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tetris/input.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -52,5 +52,5 @@
 #include <errno.h>
 #include <unistd.h>
-#include <string.h>
+#include <str.h>
 
 #include "input.h"
Index: uspace/app/tetris/scores.c
===================================================================
--- uspace/app/tetris/scores.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tetris/scores.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -52,5 +52,5 @@
 #include <errno.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <io/console.h>
 #include <io/keycode.h>
Index: uspace/app/tetris/scores.h
===================================================================
--- uspace/app/tetris/scores.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tetris/scores.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -48,5 +48,5 @@
 
 #include <sys/time.h>
-#include <string.h>
+#include <str.h>
 
 #define MAXLOGNAME   16
Index: uspace/app/tetris/screen.c
===================================================================
--- uspace/app/tetris/screen.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tetris/screen.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -49,5 +49,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <unistd.h>
 #include <vfs/vfs.h>
Index: uspace/app/tetris/tetris.c
===================================================================
--- uspace/app/tetris/tetris.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/tetris/tetris.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -53,5 +53,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <unistd.h>
 #include <getopt.h>
Index: uspace/app/trace/trace.c
===================================================================
--- uspace/app/trace/trace.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/app/trace/trace.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -43,5 +43,5 @@
 #include <task.h>
 #include <mem.h>
-#include <string.h>
+#include <str.h>
 #include <bool.h>
 #include <loader/loader.h>
Index: uspace/lib/libc/Makefile
===================================================================
--- uspace/lib/libc/Makefile	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/Makefile	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -56,5 +56,5 @@
 	generic/errno.c \
 	generic/mem.c \
-	generic/string.c \
+	generic/str.c \
 	generic/fibril.c \
 	generic/fibril_synch.c \
Index: uspace/lib/libc/generic/adt/hash_table.c
===================================================================
--- uspace/lib/libc/generic/adt/hash_table.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/adt/hash_table.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -43,5 +43,5 @@
 #include <assert.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 /** Create chained hash table.
Index: uspace/lib/libc/generic/clipboard.c
===================================================================
--- uspace/lib/libc/generic/clipboard.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/clipboard.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -42,5 +42,5 @@
 #include <ipc/clipboard.h>
 #include <async.h>
-#include <string.h>
+#include <str.h>
 #include <errno.h>
 #include <malloc.h>
Index: uspace/lib/libc/generic/devmap.c
===================================================================
--- uspace/lib/libc/generic/devmap.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/devmap.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -28,5 +28,5 @@
  */
 
-#include <string.h>
+#include <str.h>
 #include <ipc/ipc.h>
 #include <ipc/services.h>
Index: uspace/lib/libc/generic/getopt.c
===================================================================
--- uspace/lib/libc/generic/getopt.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/getopt.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <getopt.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 
 /* HelenOS Port : We're incorporating only the modern getopt_long with wrappers
Index: uspace/lib/libc/generic/io/asprintf.c
===================================================================
--- uspace/lib/libc/generic/io/asprintf.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/asprintf.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <io/printf_core.h>
 
Index: uspace/lib/libc/generic/io/io.c
===================================================================
--- uspace/lib/libc/generic/io/io.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/io.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <fcntl.h>
 #include <assert.h>
-#include <string.h>
+#include <str.h>
 #include <errno.h>
 #include <bool.h>
Index: uspace/lib/libc/generic/io/klog.c
===================================================================
--- uspace/lib/libc/generic/io/klog.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/klog.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -35,5 +35,5 @@
 
 #include <libc.h>
-#include <string.h>
+#include <str.h>
 #include <sys/types.h>
 #include <unistd.h>
Index: uspace/lib/libc/generic/io/printf_core.c
===================================================================
--- uspace/lib/libc/generic/io/printf_core.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/printf_core.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <io/printf_core.h>
 #include <ctype.h>
-#include <string.h>
+#include <str.h>
 
 /** show prefixes 0x or 0 */
Index: uspace/lib/libc/generic/io/vprintf.c
===================================================================
--- uspace/lib/libc/generic/io/vprintf.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/vprintf.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include <futex.h>
 #include <async.h>
-#include <string.h>
+#include <str.h>
 
 static atomic_t printf_futex = FUTEX_INITIALIZER;
Index: uspace/lib/libc/generic/io/vsnprintf.c
===================================================================
--- uspace/lib/libc/generic/io/vsnprintf.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/io/vsnprintf.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -35,5 +35,5 @@
 #include <stdarg.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <io/printf_core.h>
 #include <errno.h>
Index: uspace/lib/libc/generic/loader.c
===================================================================
--- uspace/lib/libc/generic/loader.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/loader.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <libc.h>
 #include <task.h>
-#include <string.h>
+#include <str.h>
 #include <stdlib.h>
 #include <async.h>
Index: uspace/lib/libc/generic/str.c
===================================================================
--- uspace/lib/libc/generic/str.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ uspace/lib/libc/generic/str.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -0,0 +1,982 @@
+/*
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2008 Jiri Svoboda
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <str.h>
+#include <stdlib.h>
+#include <assert.h>
+#include <limits.h>
+#include <ctype.h>
+#include <malloc.h>
+#include <errno.h>
+#include <align.h>
+#include <mem.h>
+#include <str.h>
+
+/** Byte mask consisting of lowest @n bits (out of 8) */
+#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
+
+/** Byte mask consisting of lowest @n bits (out of 32) */
+#define LO_MASK_32(n)  ((uint32_t) ((1 << (n)) - 1))
+
+/** Byte mask consisting of highest @n bits (out of 8) */
+#define HI_MASK_8(n)  (~LO_MASK_8(8 - (n)))
+
+/** Number of data bits in a UTF-8 continuation byte */
+#define CONT_BITS  6
+
+/** Decode a single character from a string.
+ *
+ * Decode a single character from a string of size @a size. Decoding starts
+ * at @a offset and this offset is moved to the beginning of the next
+ * character. In case of decoding error, offset generally advances at least
+ * by one. However, offset is never moved beyond size.
+ *
+ * @param str    String (not necessarily NULL-terminated).
+ * @param offset Byte offset in string where to start decoding.
+ * @param size   Size of the string (in bytes).
+ *
+ * @return Value of decoded character, U_SPECIAL on decoding error or
+ *         NULL if attempt to decode beyond @a size.
+ *
+ */
+wchar_t str_decode(const char *str, size_t *offset, size_t size)
+{
+	if (*offset + 1 > size)
+		return 0;
+	
+	/* First byte read from string */
+	uint8_t b0 = (uint8_t) str[(*offset)++];
+	
+	/* Determine code length */
+	
+	unsigned int b0_bits;  /* Data bits in first byte */
+	unsigned int cbytes;   /* Number of continuation bytes */
+	
+	if ((b0 & 0x80) == 0) {
+		/* 0xxxxxxx (Plain ASCII) */
+		b0_bits = 7;
+		cbytes = 0;
+	} else if ((b0 & 0xe0) == 0xc0) {
+		/* 110xxxxx 10xxxxxx */
+		b0_bits = 5;
+		cbytes = 1;
+	} else if ((b0 & 0xf0) == 0xe0) {
+		/* 1110xxxx 10xxxxxx 10xxxxxx */
+		b0_bits = 4;
+		cbytes = 2;
+	} else if ((b0 & 0xf8) == 0xf0) {
+		/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
+		b0_bits = 3;
+		cbytes = 3;
+	} else {
+		/* 10xxxxxx -- unexpected continuation byte */
+		return U_SPECIAL;
+	}
+	
+	if (*offset + cbytes > size)
+		return U_SPECIAL;
+	
+	wchar_t ch = b0 & LO_MASK_8(b0_bits);
+	
+	/* Decode continuation bytes */
+	while (cbytes > 0) {
+		uint8_t b = (uint8_t) str[(*offset)++];
+		
+		/* Must be 10xxxxxx */
+		if ((b & 0xc0) != 0x80)
+			return U_SPECIAL;
+		
+		/* Shift data bits to ch */
+		ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
+		cbytes--;
+	}
+	
+	return ch;
+}
+
+/** Encode a single character to string representation.
+ *
+ * Encode a single character to string representation (i.e. UTF-8) and store
+ * it into a buffer at @a offset. Encoding starts at @a offset and this offset
+ * is moved to the position where the next character can be written to.
+ *
+ * @param ch     Input character.
+ * @param str    Output buffer.
+ * @param offset Byte offset where to start writing.
+ * @param size   Size of the output buffer (in bytes).
+ *
+ * @return EOK if the character was encoded successfully, EOVERFLOW if there
+ *         was not enough space in the output buffer or EINVAL if the character
+ *         code was invalid.
+ */
+int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
+{
+	if (*offset >= size)
+		return EOVERFLOW;
+	
+	if (!chr_check(ch))
+		return EINVAL;
+	
+	/* Unsigned version of ch (bit operations should only be done
+	   on unsigned types). */
+	uint32_t cc = (uint32_t) ch;
+	
+	/* Determine how many continuation bytes are needed */
+	
+	unsigned int b0_bits;  /* Data bits in first byte */
+	unsigned int cbytes;   /* Number of continuation bytes */
+	
+	if ((cc & ~LO_MASK_32(7)) == 0) {
+		b0_bits = 7;
+		cbytes = 0;
+	} else if ((cc & ~LO_MASK_32(11)) == 0) {
+		b0_bits = 5;
+		cbytes = 1;
+	} else if ((cc & ~LO_MASK_32(16)) == 0) {
+		b0_bits = 4;
+		cbytes = 2;
+	} else if ((cc & ~LO_MASK_32(21)) == 0) {
+		b0_bits = 3;
+		cbytes = 3;
+	} else {
+		/* Codes longer than 21 bits are not supported */
+		return EINVAL;
+	}
+	
+	/* Check for available space in buffer */
+	if (*offset + cbytes >= size)
+		return EOVERFLOW;
+	
+	/* Encode continuation bytes */
+	unsigned int i;
+	for (i = cbytes; i > 0; i--) {
+		str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
+		cc = cc >> CONT_BITS;
+	}
+	
+	/* Encode first byte */
+	str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
+	
+	/* Advance offset */
+	*offset += cbytes + 1;
+	
+	return EOK;
+}
+
+/** Get size of string.
+ *
+ * Get the number of bytes which are used by the string @a str (excluding the
+ * NULL-terminator).
+ *
+ * @param str String to consider.
+ *
+ * @return Number of bytes used by the string
+ *
+ */
+size_t str_size(const char *str)
+{
+	size_t size = 0;
+	
+	while (*str++ != 0)
+		size++;
+	
+	return size;
+}
+
+/** Get size of wide string.
+ *
+ * Get the number of bytes which are used by the wide string @a str (excluding the
+ * NULL-terminator).
+ *
+ * @param str Wide string to consider.
+ *
+ * @return Number of bytes used by the wide string
+ *
+ */
+size_t wstr_size(const wchar_t *str)
+{
+	return (wstr_length(str) * sizeof(wchar_t));
+}
+
+/** Get size of string with length limit.
+ *
+ * Get the number of bytes which are used by up to @a max_len first
+ * characters in the string @a str. If @a max_len is greater than
+ * the length of @a str, the entire string is measured (excluding the
+ * NULL-terminator).
+ *
+ * @param str     String to consider.
+ * @param max_len Maximum number of characters to measure.
+ *
+ * @return Number of bytes used by the characters.
+ *
+ */
+size_t str_lsize(const char *str, size_t max_len)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (len < max_len) {
+		if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
+			break;
+		
+		len++;
+	}
+	
+	return offset;
+}
+
+/** Get size of wide string with length limit.
+ *
+ * Get the number of bytes which are used by up to @a max_len first
+ * wide characters in the wide string @a str. If @a max_len is greater than
+ * the length of @a str, the entire wide string is measured (excluding the
+ * NULL-terminator).
+ *
+ * @param str     Wide string to consider.
+ * @param max_len Maximum number of wide characters to measure.
+ *
+ * @return Number of bytes used by the wide characters.
+ *
+ */
+size_t wstr_lsize(const wchar_t *str, size_t max_len)
+{
+	return (wstr_nlength(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
+}
+
+/** Get number of characters in a string.
+ *
+ * @param str NULL-terminated string.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t str_length(const char *str)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a wide string.
+ *
+ * @param str NULL-terminated wide string.
+ *
+ * @return Number of characters in @a str.
+ *
+ */
+size_t wstr_length(const wchar_t *wstr)
+{
+	size_t len = 0;
+	
+	while (*wstr++ != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a string with size limit.
+ *
+ * @param str  NULL-terminated string.
+ * @param size Maximum number of bytes to consider.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t str_nlength(const char *str, size_t size)
+{
+	size_t len = 0;
+	size_t offset = 0;
+	
+	while (str_decode(str, &offset, size) != 0)
+		len++;
+	
+	return len;
+}
+
+/** Get number of characters in a string with size limit.
+ *
+ * @param str  NULL-terminated string.
+ * @param size Maximum number of bytes to consider.
+ *
+ * @return Number of characters in string.
+ *
+ */
+size_t wstr_nlength(const wchar_t *str, size_t size)
+{
+	size_t len = 0;
+	size_t limit = ALIGN_DOWN(size, sizeof(wchar_t));
+	size_t offset = 0;
+	
+	while ((offset < limit) && (*str++ != 0)) {
+		len++;
+		offset += sizeof(wchar_t);
+	}
+	
+	return len;
+}
+
+/** Check whether character is plain ASCII.
+ *
+ * @return True if character is plain ASCII.
+ *
+ */
+bool ascii_check(wchar_t ch)
+{
+	if ((ch >= 0) && (ch <= 127))
+		return true;
+	
+	return false;
+}
+
+/** Check whether character is valid
+ *
+ * @return True if character is a valid Unicode code point.
+ *
+ */
+bool chr_check(wchar_t ch)
+{
+	if ((ch >= 0) && (ch <= 1114111))
+		return true;
+	
+	return false;
+}
+
+/** Compare two NULL terminated strings.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff they consist of the same
+ * characters on the minimum of their lengths.
+ *
+ * @param s1 First string to compare.
+ * @param s2 Second string to compare.
+ *
+ * @return 0 if the strings are equal, -1 if first is smaller,
+ *         1 if second smaller.
+ *
+ */
+int str_cmp(const char *s1, const char *s2)
+{
+	wchar_t c1 = 0;
+	wchar_t c2 = 0;
+	
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	while (true) {
+		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
+		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
+
+		if (c1 < c2)
+			return -1;
+		
+		if (c1 > c2)
+			return 1;
+
+		if (c1 == 0 || c2 == 0)
+			break;		
+	}
+
+	return 0;
+}
+
+/** Compare two NULL terminated strings with length limit.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff they consist of the same
+ * characters on the minimum of their lengths and the length limit.
+ *
+ * @param s1      First string to compare.
+ * @param s2      Second string to compare.
+ * @param max_len Maximum number of characters to consider.
+ *
+ * @return 0 if the strings are equal, -1 if first is smaller,
+ *         1 if second smaller.
+ *
+ */
+int str_lcmp(const char *s1, const char *s2, size_t max_len)
+{
+	wchar_t c1 = 0;
+	wchar_t c2 = 0;
+	
+	size_t off1 = 0;
+	size_t off2 = 0;
+	
+	size_t len = 0;
+
+	while (true) {
+		if (len >= max_len)
+			break;
+
+		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
+		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
+
+		if (c1 < c2)
+			return -1;
+
+		if (c1 > c2)
+			return 1;
+
+		if (c1 == 0 || c2 == 0)
+			break;
+
+		++len;	
+	}
+
+	return 0;
+
+}
+
+/** Copy string.
+ *
+ * Copy source string @a src to destination buffer @a dest.
+ * No more than @a size bytes are written. If the size of the output buffer
+ * is at least one byte, the output string will always be well-formed, i.e.
+ * null-terminated and containing only complete characters.
+ *
+ * @param dest   Destination buffer.
+ * @param count Size of the destination buffer (must be > 0).
+ * @param src   Source string.
+ */
+void str_cpy(char *dest, size_t size, const char *src)
+{
+	wchar_t ch;
+	size_t src_off;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	
+	src_off = 0;
+	dest_off = 0;
+
+	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Copy size-limited substring.
+ *
+ * Copy prefix of string @a src of max. size @a size to destination buffer
+ * @a dest. No more than @a size bytes are written. The output string will
+ * always be well-formed, i.e. null-terminated and containing only complete
+ * characters.
+ *
+ * No more than @a n bytes are read from the input string, so it does not
+ * have to be null-terminated.
+ *
+ * @param dest   Destination buffer.
+ * @param count Size of the destination buffer (must be > 0).
+ * @param src   Source string.
+ * @param n	Maximum number of bytes to read from @a src.
+ */
+void str_ncpy(char *dest, size_t size, const char *src, size_t n)
+{
+	wchar_t ch;
+	size_t src_off;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	
+	src_off = 0;
+	dest_off = 0;
+
+	while ((ch = str_decode(src, &src_off, n)) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Append one string to another.
+ *
+ * Append source string @a src to string in destination buffer @a dest.
+ * Size of the destination buffer is @a dest. If the size of the output buffer
+ * is at least one byte, the output string will always be well-formed, i.e.
+ * null-terminated and containing only complete characters.
+ *
+ * @param dest   Destination buffer.
+ * @param count Size of the destination buffer.
+ * @param src   Source string.
+ */
+void str_append(char *dest, size_t size, const char *src)
+{
+	size_t dstr_size;
+
+	dstr_size = str_size(dest);
+	str_cpy(dest + dstr_size, size - dstr_size, src);
+}
+
+/** Convert wide string to string.
+ *
+ * Convert wide string @a src to string. The output is written to the buffer
+ * specified by @a dest and @a size. @a size must be non-zero and the string
+ * written will always be well-formed.
+ *
+ * @param dest	Destination buffer.
+ * @param size	Size of the destination buffer.
+ * @param src	Source wide string.
+ */
+void wstr_to_str(char *dest, size_t size, const wchar_t *src)
+{
+	wchar_t ch;
+	size_t src_idx;
+	size_t dest_off;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	
+	src_idx = 0;
+	dest_off = 0;
+
+	while ((ch = src[src_idx++]) != 0) {
+		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
+			break;
+	}
+
+	dest[dest_off] = '\0';
+}
+
+/** Convert wide string to new string.
+ *
+ * Convert wide string @a src to string. Space for the new string is allocated
+ * on the heap.
+ *
+ * @param src	Source wide string.
+ * @return	New string.
+ */
+char *wstr_to_astr(const wchar_t *src)
+{
+	char dbuf[STR_BOUNDS(1)];
+	char *str;
+	wchar_t ch;
+
+	size_t src_idx;
+	size_t dest_off;
+	size_t dest_size;
+
+	/* Compute size of encoded string. */
+
+	src_idx = 0;
+	dest_size = 0;
+
+	while ((ch = src[src_idx++]) != 0) {
+		dest_off = 0;
+		if (chr_encode(ch, dbuf, &dest_off, STR_BOUNDS(1)) != EOK)
+			break;
+		dest_size += dest_off;
+	}
+
+	str = malloc(dest_size + 1);
+	if (str == NULL)
+		return NULL;
+
+	/* Encode string. */
+
+	src_idx = 0;
+	dest_off = 0;
+
+	while ((ch = src[src_idx++]) != 0) {
+		if (chr_encode(ch, str, &dest_off, dest_size) != EOK)
+			break;
+	}
+
+	str[dest_size] = '\0';
+	return str;
+}
+
+
+/** Convert string to wide string.
+ *
+ * Convert string @a src to wide string. The output is written to the
+ * buffer specified by @a dest and @a dlen. @a dlen must be non-zero
+ * and the wide string written will always be null-terminated.
+ *
+ * @param dest	Destination buffer.
+ * @param dlen	Length of destination buffer (number of wchars).
+ * @param src	Source string.
+ */
+void str_to_wstr(wchar_t *dest, size_t dlen, const char *src)
+{
+	size_t offset;
+	size_t di;
+	wchar_t c;
+
+	assert(dlen > 0);
+
+	offset = 0;
+	di = 0;
+
+	do {
+		if (di >= dlen - 1)
+			break;
+
+		c = str_decode(src, &offset, STR_NO_LIMIT);
+		dest[di++] = c;
+	} while (c != '\0');
+
+	dest[dlen - 1] = '\0';
+}
+
+/** Find first occurence of character in string.
+ *
+ * @param str String to search.
+ * @param ch  Character to look for.
+ *
+ * @return Pointer to character in @a str or NULL if not found.
+ */
+char *str_chr(const char *str, wchar_t ch)
+{
+	wchar_t acc;
+	size_t off = 0;
+	size_t last = 0;
+	
+	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
+		if (acc == ch)
+			return (char *) (str + last);
+		last = off;
+	}
+	
+	return NULL;
+}
+
+/** Find last occurence of character in string.
+ *
+ * @param str String to search.
+ * @param ch  Character to look for.
+ *
+ * @return Pointer to character in @a str or NULL if not found.
+ */
+char *str_rchr(const char *str, wchar_t ch)
+{
+	wchar_t acc;
+	size_t off = 0;
+	size_t last = 0;
+	const char *res = NULL;
+	
+	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
+		if (acc == ch)
+			res = (str + last);
+		last = off;
+	}
+	
+	return (char *) res;
+}
+
+/** Insert a wide character into a wide string.
+ *
+ * Insert a wide character into a wide string at position
+ * @a pos. The characters after the position are shifted.
+ *
+ * @param str     String to insert to.
+ * @param ch      Character to insert to.
+ * @param pos     Character index where to insert.
+ @ @param max_pos Characters in the buffer.
+ *
+ * @return True if the insertion was sucessful, false if the position
+ *         is out of bounds.
+ *
+ */
+bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos)
+{
+	size_t len = wstr_length(str);
+	
+	if ((pos > len) || (pos + 1 > max_pos))
+		return false;
+	
+	size_t i;
+	for (i = len; i + 1 > pos; i--)
+		str[i + 1] = str[i];
+	
+	str[pos] = ch;
+	
+	return true;
+}
+
+/** Remove a wide character from a wide string.
+ *
+ * Remove a wide character from a wide string at position
+ * @a pos. The characters after the position are shifted.
+ *
+ * @param str String to remove from.
+ * @param pos Character index to remove.
+ *
+ * @return True if the removal was sucessful, false if the position
+ *         is out of bounds.
+ *
+ */
+bool wstr_remove(wchar_t *str, size_t pos)
+{
+	size_t len = wstr_length(str);
+	
+	if (pos >= len)
+		return false;
+	
+	size_t i;
+	for (i = pos + 1; i <= len; i++)
+		str[i - 1] = str[i];
+	
+	return true;
+}
+
+int stricmp(const char *a, const char *b)
+{
+	int c = 0;
+	
+	while (a[c] && b[c] && (!(tolower(a[c]) - tolower(b[c]))))
+		c++;
+	
+	return (tolower(a[c]) - tolower(b[c]));
+}
+
+/** 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);
+}
+
+char *str_dup(const char *src)
+{
+	size_t size = str_size(src);
+	void *dest = malloc(size + 1);
+	
+	if (dest == NULL)
+		return (char *) NULL;
+	
+	return (char *) memcpy(dest, src, size + 1);
+}
+
+char *str_ndup(const char *src, size_t max_size)
+{
+	size_t size = str_size(src);
+	if (size > max_size)
+		size = max_size;
+	
+	char *dest = (char *) malloc(size + 1);
+	
+	if (dest == NULL)
+		return (char *) NULL;
+	
+	memcpy(dest, src, size);
+	dest[size] = 0;
+	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);
+}
+
+char *strtok(char *s, const char *delim)
+{
+	static char *next;
+
+	return strtok_r(s, delim, &next);
+}
+
+char *strtok_r(char *s, const char *delim, char **next)
+{
+	char *start, *end;
+
+	if (s == NULL)
+		s = *next;
+
+	/* Skip over leading delimiters. */
+	while (*s && (str_chr(delim, *s) != NULL)) ++s;
+	start = s;
+
+	/* Skip over token characters. */
+	while (*s && (str_chr(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;
+}
+
+/** @}
+ */
Index: pace/lib/libc/generic/string.c
===================================================================
--- uspace/lib/libc/generic/string.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ 	(revision )
@@ -1,982 +1,0 @@
-/*
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2008 Jiri Svoboda
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <string.h>
-#include <stdlib.h>
-#include <assert.h>
-#include <limits.h>
-#include <ctype.h>
-#include <malloc.h>
-#include <errno.h>
-#include <align.h>
-#include <mem.h>
-#include <string.h>
-
-/** Byte mask consisting of lowest @n bits (out of 8) */
-#define LO_MASK_8(n)  ((uint8_t) ((1 << (n)) - 1))
-
-/** Byte mask consisting of lowest @n bits (out of 32) */
-#define LO_MASK_32(n)  ((uint32_t) ((1 << (n)) - 1))
-
-/** Byte mask consisting of highest @n bits (out of 8) */
-#define HI_MASK_8(n)  (~LO_MASK_8(8 - (n)))
-
-/** Number of data bits in a UTF-8 continuation byte */
-#define CONT_BITS  6
-
-/** Decode a single character from a string.
- *
- * Decode a single character from a string of size @a size. Decoding starts
- * at @a offset and this offset is moved to the beginning of the next
- * character. In case of decoding error, offset generally advances at least
- * by one. However, offset is never moved beyond size.
- *
- * @param str    String (not necessarily NULL-terminated).
- * @param offset Byte offset in string where to start decoding.
- * @param size   Size of the string (in bytes).
- *
- * @return Value of decoded character, U_SPECIAL on decoding error or
- *         NULL if attempt to decode beyond @a size.
- *
- */
-wchar_t str_decode(const char *str, size_t *offset, size_t size)
-{
-	if (*offset + 1 > size)
-		return 0;
-	
-	/* First byte read from string */
-	uint8_t b0 = (uint8_t) str[(*offset)++];
-	
-	/* Determine code length */
-	
-	unsigned int b0_bits;  /* Data bits in first byte */
-	unsigned int cbytes;   /* Number of continuation bytes */
-	
-	if ((b0 & 0x80) == 0) {
-		/* 0xxxxxxx (Plain ASCII) */
-		b0_bits = 7;
-		cbytes = 0;
-	} else if ((b0 & 0xe0) == 0xc0) {
-		/* 110xxxxx 10xxxxxx */
-		b0_bits = 5;
-		cbytes = 1;
-	} else if ((b0 & 0xf0) == 0xe0) {
-		/* 1110xxxx 10xxxxxx 10xxxxxx */
-		b0_bits = 4;
-		cbytes = 2;
-	} else if ((b0 & 0xf8) == 0xf0) {
-		/* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
-		b0_bits = 3;
-		cbytes = 3;
-	} else {
-		/* 10xxxxxx -- unexpected continuation byte */
-		return U_SPECIAL;
-	}
-	
-	if (*offset + cbytes > size)
-		return U_SPECIAL;
-	
-	wchar_t ch = b0 & LO_MASK_8(b0_bits);
-	
-	/* Decode continuation bytes */
-	while (cbytes > 0) {
-		uint8_t b = (uint8_t) str[(*offset)++];
-		
-		/* Must be 10xxxxxx */
-		if ((b & 0xc0) != 0x80)
-			return U_SPECIAL;
-		
-		/* Shift data bits to ch */
-		ch = (ch << CONT_BITS) | (wchar_t) (b & LO_MASK_8(CONT_BITS));
-		cbytes--;
-	}
-	
-	return ch;
-}
-
-/** Encode a single character to string representation.
- *
- * Encode a single character to string representation (i.e. UTF-8) and store
- * it into a buffer at @a offset. Encoding starts at @a offset and this offset
- * is moved to the position where the next character can be written to.
- *
- * @param ch     Input character.
- * @param str    Output buffer.
- * @param offset Byte offset where to start writing.
- * @param size   Size of the output buffer (in bytes).
- *
- * @return EOK if the character was encoded successfully, EOVERFLOW if there
- *         was not enough space in the output buffer or EINVAL if the character
- *         code was invalid.
- */
-int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
-{
-	if (*offset >= size)
-		return EOVERFLOW;
-	
-	if (!chr_check(ch))
-		return EINVAL;
-	
-	/* Unsigned version of ch (bit operations should only be done
-	   on unsigned types). */
-	uint32_t cc = (uint32_t) ch;
-	
-	/* Determine how many continuation bytes are needed */
-	
-	unsigned int b0_bits;  /* Data bits in first byte */
-	unsigned int cbytes;   /* Number of continuation bytes */
-	
-	if ((cc & ~LO_MASK_32(7)) == 0) {
-		b0_bits = 7;
-		cbytes = 0;
-	} else if ((cc & ~LO_MASK_32(11)) == 0) {
-		b0_bits = 5;
-		cbytes = 1;
-	} else if ((cc & ~LO_MASK_32(16)) == 0) {
-		b0_bits = 4;
-		cbytes = 2;
-	} else if ((cc & ~LO_MASK_32(21)) == 0) {
-		b0_bits = 3;
-		cbytes = 3;
-	} else {
-		/* Codes longer than 21 bits are not supported */
-		return EINVAL;
-	}
-	
-	/* Check for available space in buffer */
-	if (*offset + cbytes >= size)
-		return EOVERFLOW;
-	
-	/* Encode continuation bytes */
-	unsigned int i;
-	for (i = cbytes; i > 0; i--) {
-		str[*offset + i] = 0x80 | (cc & LO_MASK_32(CONT_BITS));
-		cc = cc >> CONT_BITS;
-	}
-	
-	/* Encode first byte */
-	str[*offset] = (cc & LO_MASK_32(b0_bits)) | HI_MASK_8(8 - b0_bits - 1);
-	
-	/* Advance offset */
-	*offset += cbytes + 1;
-	
-	return EOK;
-}
-
-/** Get size of string.
- *
- * Get the number of bytes which are used by the string @a str (excluding the
- * NULL-terminator).
- *
- * @param str String to consider.
- *
- * @return Number of bytes used by the string
- *
- */
-size_t str_size(const char *str)
-{
-	size_t size = 0;
-	
-	while (*str++ != 0)
-		size++;
-	
-	return size;
-}
-
-/** Get size of wide string.
- *
- * Get the number of bytes which are used by the wide string @a str (excluding the
- * NULL-terminator).
- *
- * @param str Wide string to consider.
- *
- * @return Number of bytes used by the wide string
- *
- */
-size_t wstr_size(const wchar_t *str)
-{
-	return (wstr_length(str) * sizeof(wchar_t));
-}
-
-/** Get size of string with length limit.
- *
- * Get the number of bytes which are used by up to @a max_len first
- * characters in the string @a str. If @a max_len is greater than
- * the length of @a str, the entire string is measured (excluding the
- * NULL-terminator).
- *
- * @param str     String to consider.
- * @param max_len Maximum number of characters to measure.
- *
- * @return Number of bytes used by the characters.
- *
- */
-size_t str_lsize(const char *str, size_t max_len)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (len < max_len) {
-		if (str_decode(str, &offset, STR_NO_LIMIT) == 0)
-			break;
-		
-		len++;
-	}
-	
-	return offset;
-}
-
-/** Get size of wide string with length limit.
- *
- * Get the number of bytes which are used by up to @a max_len first
- * wide characters in the wide string @a str. If @a max_len is greater than
- * the length of @a str, the entire wide string is measured (excluding the
- * NULL-terminator).
- *
- * @param str     Wide string to consider.
- * @param max_len Maximum number of wide characters to measure.
- *
- * @return Number of bytes used by the wide characters.
- *
- */
-size_t wstr_lsize(const wchar_t *str, size_t max_len)
-{
-	return (wstr_nlength(str, max_len * sizeof(wchar_t)) * sizeof(wchar_t));
-}
-
-/** Get number of characters in a string.
- *
- * @param str NULL-terminated string.
- *
- * @return Number of characters in string.
- *
- */
-size_t str_length(const char *str)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (str_decode(str, &offset, STR_NO_LIMIT) != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a wide string.
- *
- * @param str NULL-terminated wide string.
- *
- * @return Number of characters in @a str.
- *
- */
-size_t wstr_length(const wchar_t *wstr)
-{
-	size_t len = 0;
-	
-	while (*wstr++ != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a string with size limit.
- *
- * @param str  NULL-terminated string.
- * @param size Maximum number of bytes to consider.
- *
- * @return Number of characters in string.
- *
- */
-size_t str_nlength(const char *str, size_t size)
-{
-	size_t len = 0;
-	size_t offset = 0;
-	
-	while (str_decode(str, &offset, size) != 0)
-		len++;
-	
-	return len;
-}
-
-/** Get number of characters in a string with size limit.
- *
- * @param str  NULL-terminated string.
- * @param size Maximum number of bytes to consider.
- *
- * @return Number of characters in string.
- *
- */
-size_t wstr_nlength(const wchar_t *str, size_t size)
-{
-	size_t len = 0;
-	size_t limit = ALIGN_DOWN(size, sizeof(wchar_t));
-	size_t offset = 0;
-	
-	while ((offset < limit) && (*str++ != 0)) {
-		len++;
-		offset += sizeof(wchar_t);
-	}
-	
-	return len;
-}
-
-/** Check whether character is plain ASCII.
- *
- * @return True if character is plain ASCII.
- *
- */
-bool ascii_check(wchar_t ch)
-{
-	if ((ch >= 0) && (ch <= 127))
-		return true;
-	
-	return false;
-}
-
-/** Check whether character is valid
- *
- * @return True if character is a valid Unicode code point.
- *
- */
-bool chr_check(wchar_t ch)
-{
-	if ((ch >= 0) && (ch <= 1114111))
-		return true;
-	
-	return false;
-}
-
-/** Compare two NULL terminated strings.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
- *
- */
-int str_cmp(const char *s1, const char *s2)
-{
-	wchar_t c1 = 0;
-	wchar_t c2 = 0;
-	
-	size_t off1 = 0;
-	size_t off2 = 0;
-
-	while (true) {
-		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
-		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
-
-		if (c1 < c2)
-			return -1;
-		
-		if (c1 > c2)
-			return 1;
-
-		if (c1 == 0 || c2 == 0)
-			break;		
-	}
-
-	return 0;
-}
-
-/** Compare two NULL terminated strings with length limit.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff they consist of the same
- * characters on the minimum of their lengths and the length limit.
- *
- * @param s1      First string to compare.
- * @param s2      Second string to compare.
- * @param max_len Maximum number of characters to consider.
- *
- * @return 0 if the strings are equal, -1 if first is smaller,
- *         1 if second smaller.
- *
- */
-int str_lcmp(const char *s1, const char *s2, size_t max_len)
-{
-	wchar_t c1 = 0;
-	wchar_t c2 = 0;
-	
-	size_t off1 = 0;
-	size_t off2 = 0;
-	
-	size_t len = 0;
-
-	while (true) {
-		if (len >= max_len)
-			break;
-
-		c1 = str_decode(s1, &off1, STR_NO_LIMIT);
-		c2 = str_decode(s2, &off2, STR_NO_LIMIT);
-
-		if (c1 < c2)
-			return -1;
-
-		if (c1 > c2)
-			return 1;
-
-		if (c1 == 0 || c2 == 0)
-			break;
-
-		++len;	
-	}
-
-	return 0;
-
-}
-
-/** Copy string.
- *
- * Copy source string @a src to destination buffer @a dest.
- * No more than @a size bytes are written. If the size of the output buffer
- * is at least one byte, the output string will always be well-formed, i.e.
- * null-terminated and containing only complete characters.
- *
- * @param dest   Destination buffer.
- * @param count Size of the destination buffer (must be > 0).
- * @param src   Source string.
- */
-void str_cpy(char *dest, size_t size, const char *src)
-{
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	
-	src_off = 0;
-	dest_off = 0;
-
-	while ((ch = str_decode(src, &src_off, STR_NO_LIMIT)) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Copy size-limited substring.
- *
- * Copy prefix of string @a src of max. size @a size to destination buffer
- * @a dest. No more than @a size bytes are written. The output string will
- * always be well-formed, i.e. null-terminated and containing only complete
- * characters.
- *
- * No more than @a n bytes are read from the input string, so it does not
- * have to be null-terminated.
- *
- * @param dest   Destination buffer.
- * @param count Size of the destination buffer (must be > 0).
- * @param src   Source string.
- * @param n	Maximum number of bytes to read from @a src.
- */
-void str_ncpy(char *dest, size_t size, const char *src, size_t n)
-{
-	wchar_t ch;
-	size_t src_off;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	
-	src_off = 0;
-	dest_off = 0;
-
-	while ((ch = str_decode(src, &src_off, n)) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Append one string to another.
- *
- * Append source string @a src to string in destination buffer @a dest.
- * Size of the destination buffer is @a dest. If the size of the output buffer
- * is at least one byte, the output string will always be well-formed, i.e.
- * null-terminated and containing only complete characters.
- *
- * @param dest   Destination buffer.
- * @param count Size of the destination buffer.
- * @param src   Source string.
- */
-void str_append(char *dest, size_t size, const char *src)
-{
-	size_t dstr_size;
-
-	dstr_size = str_size(dest);
-	str_cpy(dest + dstr_size, size - dstr_size, src);
-}
-
-/** Convert wide string to string.
- *
- * Convert wide string @a src to string. The output is written to the buffer
- * specified by @a dest and @a size. @a size must be non-zero and the string
- * written will always be well-formed.
- *
- * @param dest	Destination buffer.
- * @param size	Size of the destination buffer.
- * @param src	Source wide string.
- */
-void wstr_to_str(char *dest, size_t size, const wchar_t *src)
-{
-	wchar_t ch;
-	size_t src_idx;
-	size_t dest_off;
-
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	
-	src_idx = 0;
-	dest_off = 0;
-
-	while ((ch = src[src_idx++]) != 0) {
-		if (chr_encode(ch, dest, &dest_off, size - 1) != EOK)
-			break;
-	}
-
-	dest[dest_off] = '\0';
-}
-
-/** Convert wide string to new string.
- *
- * Convert wide string @a src to string. Space for the new string is allocated
- * on the heap.
- *
- * @param src	Source wide string.
- * @return	New string.
- */
-char *wstr_to_astr(const wchar_t *src)
-{
-	char dbuf[STR_BOUNDS(1)];
-	char *str;
-	wchar_t ch;
-
-	size_t src_idx;
-	size_t dest_off;
-	size_t dest_size;
-
-	/* Compute size of encoded string. */
-
-	src_idx = 0;
-	dest_size = 0;
-
-	while ((ch = src[src_idx++]) != 0) {
-		dest_off = 0;
-		if (chr_encode(ch, dbuf, &dest_off, STR_BOUNDS(1)) != EOK)
-			break;
-		dest_size += dest_off;
-	}
-
-	str = malloc(dest_size + 1);
-	if (str == NULL)
-		return NULL;
-
-	/* Encode string. */
-
-	src_idx = 0;
-	dest_off = 0;
-
-	while ((ch = src[src_idx++]) != 0) {
-		if (chr_encode(ch, str, &dest_off, dest_size) != EOK)
-			break;
-	}
-
-	str[dest_size] = '\0';
-	return str;
-}
-
-
-/** Convert string to wide string.
- *
- * Convert string @a src to wide string. The output is written to the
- * buffer specified by @a dest and @a dlen. @a dlen must be non-zero
- * and the wide string written will always be null-terminated.
- *
- * @param dest	Destination buffer.
- * @param dlen	Length of destination buffer (number of wchars).
- * @param src	Source string.
- */
-void str_to_wstr(wchar_t *dest, size_t dlen, const char *src)
-{
-	size_t offset;
-	size_t di;
-	wchar_t c;
-
-	assert(dlen > 0);
-
-	offset = 0;
-	di = 0;
-
-	do {
-		if (di >= dlen - 1)
-			break;
-
-		c = str_decode(src, &offset, STR_NO_LIMIT);
-		dest[di++] = c;
-	} while (c != '\0');
-
-	dest[dlen - 1] = '\0';
-}
-
-/** Find first occurence of character in string.
- *
- * @param str String to search.
- * @param ch  Character to look for.
- *
- * @return Pointer to character in @a str or NULL if not found.
- */
-char *str_chr(const char *str, wchar_t ch)
-{
-	wchar_t acc;
-	size_t off = 0;
-	size_t last = 0;
-	
-	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
-		if (acc == ch)
-			return (char *) (str + last);
-		last = off;
-	}
-	
-	return NULL;
-}
-
-/** Find last occurence of character in string.
- *
- * @param str String to search.
- * @param ch  Character to look for.
- *
- * @return Pointer to character in @a str or NULL if not found.
- */
-char *str_rchr(const char *str, wchar_t ch)
-{
-	wchar_t acc;
-	size_t off = 0;
-	size_t last = 0;
-	const char *res = NULL;
-	
-	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
-		if (acc == ch)
-			res = (str + last);
-		last = off;
-	}
-	
-	return (char *) res;
-}
-
-/** Insert a wide character into a wide string.
- *
- * Insert a wide character into a wide string at position
- * @a pos. The characters after the position are shifted.
- *
- * @param str     String to insert to.
- * @param ch      Character to insert to.
- * @param pos     Character index where to insert.
- @ @param max_pos Characters in the buffer.
- *
- * @return True if the insertion was sucessful, false if the position
- *         is out of bounds.
- *
- */
-bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos)
-{
-	size_t len = wstr_length(str);
-	
-	if ((pos > len) || (pos + 1 > max_pos))
-		return false;
-	
-	size_t i;
-	for (i = len; i + 1 > pos; i--)
-		str[i + 1] = str[i];
-	
-	str[pos] = ch;
-	
-	return true;
-}
-
-/** Remove a wide character from a wide string.
- *
- * Remove a wide character from a wide string at position
- * @a pos. The characters after the position are shifted.
- *
- * @param str String to remove from.
- * @param pos Character index to remove.
- *
- * @return True if the removal was sucessful, false if the position
- *         is out of bounds.
- *
- */
-bool wstr_remove(wchar_t *str, size_t pos)
-{
-	size_t len = wstr_length(str);
-	
-	if (pos >= len)
-		return false;
-	
-	size_t i;
-	for (i = pos + 1; i <= len; i++)
-		str[i - 1] = str[i];
-	
-	return true;
-}
-
-int stricmp(const char *a, const char *b)
-{
-	int c = 0;
-	
-	while (a[c] && b[c] && (!(tolower(a[c]) - tolower(b[c]))))
-		c++;
-	
-	return (tolower(a[c]) - tolower(b[c]));
-}
-
-/** 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);
-}
-
-char *str_dup(const char *src)
-{
-	size_t size = str_size(src);
-	void *dest = malloc(size + 1);
-	
-	if (dest == NULL)
-		return (char *) NULL;
-	
-	return (char *) memcpy(dest, src, size + 1);
-}
-
-char *str_ndup(const char *src, size_t max_size)
-{
-	size_t size = str_size(src);
-	if (size > max_size)
-		size = max_size;
-	
-	char *dest = (char *) malloc(size + 1);
-	
-	if (dest == NULL)
-		return (char *) NULL;
-	
-	memcpy(dest, src, size);
-	dest[size] = 0;
-	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);
-}
-
-char *strtok(char *s, const char *delim)
-{
-	static char *next;
-
-	return strtok_r(s, delim, &next);
-}
-
-char *strtok_r(char *s, const char *delim, char **next)
-{
-	char *start, *end;
-
-	if (s == NULL)
-		s = *next;
-
-	/* Skip over leading delimiters. */
-	while (*s && (str_chr(delim, *s) != NULL)) ++s;
-	start = s;
-
-	/* Skip over token characters. */
-	while (*s && (str_chr(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;
-}
-
-/** @}
- */
Index: uspace/lib/libc/generic/sysinfo.c
===================================================================
--- uspace/lib/libc/generic/sysinfo.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/sysinfo.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -35,5 +35,5 @@
 #include <libc.h>
 #include <sysinfo.h>
-#include <string.h>
+#include <str.h>
 
 sysarg_t sysinfo_value(const char *name)
Index: uspace/lib/libc/generic/task.c
===================================================================
--- uspace/lib/libc/generic/task.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/task.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include <errno.h>
 #include <loader/loader.h>
-#include <string.h>
+#include <str.h>
 #include <ipc/ns.h>
 #include <macros.h>
Index: uspace/lib/libc/generic/thread.c
===================================================================
--- uspace/lib/libc/generic/thread.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/thread.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include <kernel/proc/uarg.h>
 #include <fibril.h>
-#include <string.h>
+#include <str.h>
 #include <async.h>
 
Index: uspace/lib/libc/generic/tls.c
===================================================================
--- uspace/lib/libc/generic/tls.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/tls.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <tls.h>
 #include <malloc.h>
-#include <string.h>
+#include <str.h>
 #include <align.h>
 
Index: uspace/lib/libc/generic/vfs/vfs.c
===================================================================
--- uspace/lib/libc/generic/vfs/vfs.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/generic/vfs/vfs.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -49,5 +49,5 @@
 #include <futex.h>
 #include <errno.h>
-#include <string.h>
+#include <str.h>
 #include <devmap.h>
 #include <ipc/vfs.h>
Index: uspace/lib/libc/include/stdio.h
===================================================================
--- uspace/lib/libc/include/stdio.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/include/stdio.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <sys/types.h>
 #include <stdarg.h>
-#include <string.h>
+#include <str.h>
 #include <adt/list.h>
 
Index: uspace/lib/libc/include/str.h
===================================================================
--- uspace/lib/libc/include/str.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
+++ uspace/lib/libc/include/str.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2005 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_STR_H_
+#define LIBC_STR_H_
+
+#include <mem.h>
+#include <sys/types.h>
+#include <bool.h>
+
+#define U_SPECIAL  '?'
+
+/** No size limit constant */
+#define STR_NO_LIMIT  ((size_t) -1)
+
+/** Maximum size of a string containing @c length characters */
+#define STR_BOUNDS(length)  ((length) << 2)
+
+extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
+extern int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz);
+
+extern size_t str_size(const char *str);
+extern size_t wstr_size(const wchar_t *str);
+
+extern size_t str_lsize(const char *str, size_t max_len);
+extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
+
+extern size_t str_length(const char *str);
+extern size_t wstr_length(const wchar_t *wstr);
+
+extern size_t str_nlength(const char *str, size_t size);
+extern size_t wstr_nlength(const wchar_t *str, size_t size);
+
+extern bool ascii_check(wchar_t ch);
+extern bool chr_check(wchar_t ch);
+
+extern int str_cmp(const char *s1, const char *s2);
+extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
+
+extern void str_cpy(char *dest, size_t size, const char *src);
+extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
+extern void str_append(char *dest, size_t size, const char *src);
+
+extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
+extern char *wstr_to_astr(const wchar_t *src);
+extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
+
+extern char *str_chr(const char *str, wchar_t ch);
+extern char *str_rchr(const char *str, wchar_t ch);
+
+extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
+extern bool wstr_remove(wchar_t *str, size_t pos);
+
+extern char *str_dup(const char *);
+extern char *str_ndup(const char *, size_t max_size);
+
+/*
+ * TODO: Get rid of this.
+ */
+
+extern int stricmp(const char *, const char *);
+
+extern long int strtol(const char *, char **, int);
+extern unsigned long strtoul(const char *, char **, int);
+
+extern char * strtok_r(char *, const char *, char **);
+extern char * strtok(char *, const char *);
+
+#endif
+
+/** @}
+ */
Index: pace/lib/libc/include/string.h
===================================================================
--- uspace/lib/libc/include/string.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ 	(revision )
@@ -1,103 +1,0 @@
-/*
- * Copyright (c) 2005 Martin Decky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#ifndef LIBC_STRING_H_
-#define LIBC_STRING_H_
-
-#include <mem.h>
-#include <sys/types.h>
-#include <bool.h>
-
-#define U_SPECIAL  '?'
-
-/** No size limit constant */
-#define STR_NO_LIMIT  ((size_t) -1)
-
-/** Maximum size of a string containing @c length characters */
-#define STR_BOUNDS(length)  ((length) << 2)
-
-extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
-extern int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz);
-
-extern size_t str_size(const char *str);
-extern size_t wstr_size(const wchar_t *str);
-
-extern size_t str_lsize(const char *str, size_t max_len);
-extern size_t wstr_lsize(const wchar_t *str, size_t max_len);
-
-extern size_t str_length(const char *str);
-extern size_t wstr_length(const wchar_t *wstr);
-
-extern size_t str_nlength(const char *str, size_t size);
-extern size_t wstr_nlength(const wchar_t *str, size_t size);
-
-extern bool ascii_check(wchar_t ch);
-extern bool chr_check(wchar_t ch);
-
-extern int str_cmp(const char *s1, const char *s2);
-extern int str_lcmp(const char *s1, const char *s2, size_t max_len);
-
-extern void str_cpy(char *dest, size_t size, const char *src);
-extern void str_ncpy(char *dest, size_t size, const char *src, size_t n);
-extern void str_append(char *dest, size_t size, const char *src);
-
-extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
-extern char *wstr_to_astr(const wchar_t *src);
-extern void str_to_wstr(wchar_t *dest, size_t dlen, const char *src);
-
-extern char *str_chr(const char *str, wchar_t ch);
-extern char *str_rchr(const char *str, wchar_t ch);
-
-extern bool wstr_linsert(wchar_t *str, wchar_t ch, size_t pos, size_t max_pos);
-extern bool wstr_remove(wchar_t *str, size_t pos);
-
-extern char *str_dup(const char *);
-extern char *str_ndup(const char *, size_t max_size);
-
-/*
- * TODO: Get rid of this.
- */
-
-extern int stricmp(const char *, const char *);
-
-extern long int strtol(const char *, char **, int);
-extern unsigned long strtoul(const char *, char **, int);
-
-extern char * strtok_r(char *, const char *, char **);
-extern char * strtok(char *, const char *);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/libc/include/sysinfo.h
===================================================================
--- uspace/lib/libc/include/sysinfo.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libc/include/sysinfo.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <libc.h>
 #include <sysinfo.h>
-#include <string.h>
+#include <str.h>
 
 sysarg_t sysinfo_value(const char *name);
Index: uspace/lib/libpci/access.c
===================================================================
--- uspace/lib/libpci/access.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libpci/access.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -12,5 +12,5 @@
 #include <stdlib.h>
 #include <stdarg.h>
-#include <string.h>
+#include <str.h>
 
 #include "internal.h"
Index: uspace/lib/libpci/generic.c
===================================================================
--- uspace/lib/libpci/generic.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libpci/generic.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -9,5 +9,5 @@
  */
 
-#include <string.h>
+#include <str.h>
 
 #include "internal.h"
Index: uspace/lib/libpci/names.c
===================================================================
--- uspace/lib/libpci/names.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/lib/libpci/names.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -12,5 +12,5 @@
 #include <stdlib.h>
 #include <stdarg.h>
-#include <string.h>
+#include <str.h>
 #include <errno.h>
 
Index: uspace/srv/bd/ata_bd/ata_bd.c
===================================================================
--- uspace/srv/bd/ata_bd/ata_bd.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/bd/ata_bd/ata_bd.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -56,5 +56,5 @@
 #include <as.h>
 #include <fibril_synch.h>
-#include <string.h>
+#include <str.h>
 #include <devmap.h>
 #include <sys/types.h>
Index: uspace/srv/bd/ata_bd/ata_bd.h
===================================================================
--- uspace/srv/bd/ata_bd/ata_bd.h	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/bd/ata_bd/ata_bd.h	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <sys/types.h>
 #include <fibril_synch.h>
-#include <string.h>
+#include <str.h>
 
 enum {
Index: uspace/srv/devmap/devmap.c
===================================================================
--- uspace/srv/devmap/devmap.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/devmap/devmap.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -44,5 +44,5 @@
 #include <fibril_synch.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <ipc/devmap.h>
 
Index: uspace/srv/fs/devfs/devfs_ops.c
===================================================================
--- uspace/srv/fs/devfs/devfs_ops.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/devfs/devfs_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <errno.h>
 #include <malloc.h>
-#include <string.h>
+#include <str.h>
 #include <libfs.h>
 #include <fibril_synch.h>
Index: uspace/srv/fs/fat/fat_dentry.c
===================================================================
--- uspace/srv/fs/fat/fat_dentry.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/fat/fat_dentry.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include "fat_dentry.h"
 #include <ctype.h>
-#include <string.h>
+#include <str.h>
 
 static bool is_d_char(const char ch)
Index: uspace/srv/fs/fat/fat_idx.c
===================================================================
--- uspace/srv/fs/fat/fat_idx.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/fat/fat_idx.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -39,5 +39,5 @@
 #include "../../vfs/vfs.h"
 #include <errno.h>
-#include <string.h>
+#include <str.h>
 #include <adt/hash_table.h>
 #include <adt/list.h>
Index: uspace/srv/fs/fat/fat_ops.c
===================================================================
--- uspace/srv/fs/fat/fat_ops.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/fat/fat_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -48,5 +48,5 @@
 #include <async.h>
 #include <errno.h>
-#include <string.h>
+#include <str.h>
 #include <byteorder.h>
 #include <adt/hash_table.h>
Index: uspace/srv/fs/tmpfs/tmpfs_dump.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/tmpfs/tmpfs_dump.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <errno.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <sys/types.h>
 #include <as.h>
Index: uspace/srv/fs/tmpfs/tmpfs_ops.c
===================================================================
--- uspace/srv/fs/tmpfs/tmpfs_ops.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/fs/tmpfs/tmpfs_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -46,5 +46,5 @@
 #include <atomic.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <stdio.h>
 #include <assert.h>
Index: uspace/srv/hid/console/console.c
===================================================================
--- uspace/srv/hid/console/console.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/hid/console/console.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -47,5 +47,5 @@
 #include <sys/mman.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <sysinfo.h>
 #include <event.h>
Index: uspace/srv/hid/console/gcons.c
===================================================================
--- uspace/srv/hid/console/gcons.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/hid/console/gcons.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <stdio.h>
 #include <sys/mman.h>
-#include <string.h>
+#include <str.h>
 #include <align.h>
 #include <bool.h>
Index: uspace/srv/hid/fb/fb.c
===================================================================
--- uspace/srv/hid/fb/fb.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/hid/fb/fb.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <stdlib.h>
 #include <unistd.h>
-#include <string.h>
+#include <str.h>
 #include <ddi.h>
 #include <sysinfo.h>
Index: uspace/srv/hid/fb/serial_console.c
===================================================================
--- uspace/srv/hid/fb/serial_console.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/hid/fb/serial_console.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -46,5 +46,5 @@
 #include <io/color.h>
 #include <io/style.h>
-#include <string.h>
+#include <str.h>
 
 #include "../console/screenbuffer.h"
Index: uspace/srv/loader/main.c
===================================================================
--- uspace/srv/loader/main.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/loader/main.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -58,5 +58,5 @@
 #include <errno.h>
 #include <async.h>
-#include <string.h>
+#include <str.h>
 #include <as.h>
 
Index: uspace/srv/net/app/echo/echo.c
===================================================================
--- uspace/srv/net/app/echo/echo.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/app/echo/echo.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <malloc.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/net/app/nettest1/nettest1.c
===================================================================
--- uspace/srv/net/app/nettest1/nettest1.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/app/nettest1/nettest1.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <malloc.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <task.h>
 #include <time.h>
Index: uspace/srv/net/app/nettest2/nettest2.c
===================================================================
--- uspace/srv/net/app/nettest2/nettest2.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/app/nettest2/nettest2.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -37,5 +37,5 @@
 #include <malloc.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <task.h>
 #include <time.h>
Index: uspace/srv/net/app/parse.c
===================================================================
--- uspace/srv/net/app/parse.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/app/parse.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -36,5 +36,5 @@
 
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include "../include/socket.h"
Index: uspace/srv/net/app/ping/ping.c
===================================================================
--- uspace/srv/net/app/ping/ping.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/app/ping/ping.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -36,5 +36,5 @@
 
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <task.h>
 #include <time.h>
Index: uspace/srv/net/il/arp/arp.c
===================================================================
--- uspace/srv/net/il/arp/arp.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/il/arp/arp.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <fibril_synch.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 #include <task.h>
 
Index: uspace/srv/net/il/ip/ip.c
===================================================================
--- uspace/srv/net/il/ip/ip.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/il/ip/ip.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <fibril_synch.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/inet.c
===================================================================
--- uspace/srv/net/inet.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/inet.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <mem.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include "include/in.h"
Index: uspace/srv/net/net/net.c
===================================================================
--- uspace/srv/net/net/net.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/net/net.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <malloc.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/net/net_bundle.c
===================================================================
--- uspace/srv/net/net/net_bundle.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/net/net_bundle.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -36,5 +36,5 @@
  */
 
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/net/net_standalone.c
===================================================================
--- uspace/srv/net/net/net_standalone.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/net/net_standalone.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -35,5 +35,5 @@
  */
 
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/netif/lo/lo.c
===================================================================
--- uspace/srv/net/netif/lo/lo.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/netif/lo/lo.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <errno.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/nil/eth/eth.c
===================================================================
--- uspace/srv/net/nil/eth/eth.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/nil/eth/eth.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <mem.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/nil/nildummy/nildummy.c
===================================================================
--- uspace/srv/net/nil/nildummy/nildummy.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/nil/nildummy/nildummy.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -40,5 +40,5 @@
 #include <mem.h>
 #include <stdio.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/net/tl/icmp/icmp.c
===================================================================
--- uspace/srv/net/tl/icmp/icmp.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/net/tl/icmp/icmp.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <fibril_synch.h>
 #include <stdint.h>
-#include <string.h>
+#include <str.h>
 
 #include <ipc/ipc.h>
Index: uspace/srv/vfs/vfs.c
===================================================================
--- uspace/srv/vfs/vfs.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -42,5 +42,5 @@
 #include <stdio.h>
 #include <bool.h>
-#include <string.h>
+#include <str.h>
 #include <as.h>
 #include <atomic.h>
Index: uspace/srv/vfs/vfs_file.c
===================================================================
--- uspace/srv/vfs/vfs_file.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs_file.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include <errno.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <assert.h>
 #include <bool.h>
Index: uspace/srv/vfs/vfs_lookup.c
===================================================================
--- uspace/srv/vfs/vfs_lookup.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs_lookup.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -41,5 +41,5 @@
 #include <async.h>
 #include <errno.h>
-#include <string.h>
+#include <str.h>
 #include <stdarg.h>
 #include <bool.h>
Index: uspace/srv/vfs/vfs_node.c
===================================================================
--- uspace/srv/vfs/vfs_node.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs_node.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -38,5 +38,5 @@
 #include "vfs.h"
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <fibril_synch.h>
 #include <adt/hash_table.h>
Index: uspace/srv/vfs/vfs_ops.c
===================================================================
--- uspace/srv/vfs/vfs_ops.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs_ops.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -44,5 +44,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <bool.h>
 #include <fibril_synch.h>
Index: uspace/srv/vfs/vfs_register.c
===================================================================
--- uspace/srv/vfs/vfs_register.c	(revision e2b73d4fff709707005b78cde1d4a38ed96c6209)
+++ uspace/srv/vfs/vfs_register.c	(revision 19f857a3b361739b06d4f547174ae4ac1b99c651)
@@ -43,5 +43,5 @@
 #include <stdio.h>
 #include <stdlib.h>
-#include <string.h>
+#include <str.h>
 #include <ctype.h>
 #include <bool.h>
