Index: boot/generic/include/errno.h
===================================================================
--- boot/generic/include/errno.h	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ boot/generic/include/errno.h	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -40,4 +40,6 @@
 #define EOVERFLOW  -16  /* The result does not fit its size. */
 
+typedef int errno_t;
+
 #endif
 
Index: boot/generic/include/str.h
===================================================================
--- boot/generic/include/str.h	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ boot/generic/include/str.h	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,4 +1,6 @@
 /*
- * Copyright (c) 2010 Martin Decky
+ * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2011 Oleg Romanenko
  * All rights reserved.
  *
@@ -33,25 +35,26 @@
 #define BOOT_STR_H_
 
+#include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
 
-/**< Common Unicode characters */
-#define U_SPECIAL  '?'
+/* Common Unicode characters */
+#define U_SPECIAL      '?'
 
-/**< No size limit constant */
+/** No size limit constant */
 #define STR_NO_LIMIT  ((size_t) -1)
 
-extern wchar_t str_decode(const char *, size_t *, size_t);
-extern int chr_encode(wchar_t, char *, size_t *, size_t);
+extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
+extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
 
-extern size_t str_size(const char *);
-extern size_t str_lsize(const char *, size_t);
-extern size_t str_length(const char *);
+extern size_t str_size(const char *str);
+extern size_t str_lsize(const char *str, size_t max_len);
+extern size_t str_length(const char *str);
 
-extern bool ascii_check(wchar_t);
-extern bool chr_check(wchar_t);
+extern bool ascii_check(wchar_t ch);
+extern bool chr_check(wchar_t ch);
 
-extern int str_cmp(const char *, const char *);
-extern void str_cpy(char *, size_t, const char *);
+extern int str_cmp(const char *s1, const char *s2);
+extern void str_cpy(char *dest, size_t size, const char *src);
 
 #endif
Index: boot/generic/src/str.c
===================================================================
--- boot/generic/src/str.c	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ boot/generic/src/str.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,4 +1,8 @@
 /*
  * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2008 Jiri Svoboda
+ * Copyright (c) 2011 Martin Sucha
+ * Copyright (c) 2011 Oleg Romanenko
  * All rights reserved.
  *
@@ -98,9 +102,10 @@
  */
 
+#include <str.h>
+
 #include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
-#include <str.h>
 
 /** Check the condition if wchar_t is signed */
@@ -208,5 +213,5 @@
  *         code was invalid.
  */
-int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
+errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size)
 {
 	if (*offset >= size)
@@ -392,5 +397,5 @@
 			return 1;
 
-		if ((c1 == 0) || (c2 == 0))
+		if (c1 == 0 || c2 == 0)
 			break;
 	}
Index: kernel/generic/include/str.h
===================================================================
--- kernel/generic/include/str.h	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ kernel/generic/include/str.h	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,4 +1,6 @@
 /*
  * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2011 Oleg Romanenko
  * All rights reserved.
  *
@@ -36,10 +38,10 @@
 #define KERN_STR_H_
 
+#include <errno.h>
 #include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
-#include <errno.h>
 
-/**< Common Unicode characters */
+/* Common Unicode characters */
 #define U_SPECIAL      '?'
 
@@ -61,9 +63,9 @@
 #define U_CURSOR       0x2588
 
-/**< No size limit constant */
+/** 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)
+/** 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);
@@ -92,7 +94,4 @@
 extern void wstr_to_str(char *dest, size_t size, const wchar_t *src);
 
-extern char *str_dup(const char *src);
-extern char *str_ndup(const char *src, size_t n);
-
 extern char *str_chr(const char *str, wchar_t ch);
 
@@ -100,5 +99,9 @@
 extern bool wstr_remove(wchar_t *str, size_t pos);
 
-extern errno_t str_uint64_t(const char *, char **, unsigned int, bool, uint64_t *);
+extern char *str_dup(const char *src);
+extern char *str_ndup(const char *src, size_t n);
+
+extern errno_t str_uint64_t(const char *, char **, unsigned int, bool,
+    uint64_t *);
 
 extern void order_suffix(const uint64_t, uint64_t *, char *);
Index: kernel/generic/src/lib/str.c
===================================================================
--- kernel/generic/src/lib/str.c	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ kernel/generic/src/lib/str.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,4 +1,8 @@
 /*
  * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2008 Jiri Svoboda
+ * Copyright (c) 2011 Martin Sucha
+ * Copyright (c) 2011 Oleg Romanenko
  * All rights reserved.
  *
@@ -103,12 +107,14 @@
 
 #include <str.h>
-#include <cpu.h>
-#include <arch/asm.h>
-#include <arch.h>
+
+#include <assert.h>
 #include <errno.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+#include <stdlib.h>
+
 #include <align.h>
-#include <assert.h>
 #include <macros.h>
-#include <stdlib.h>
 
 /** Check the condition if wchar_t is signed */
@@ -616,4 +622,112 @@
 }
 
+/** 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;
+}
+
 /** Duplicate string.
  *
@@ -675,113 +789,4 @@
 	str_ncpy(dest, size + 1, src, size);
 	return dest;
-}
-
-/** 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: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ uspace/lib/c/generic/str.c	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,3 +1,4 @@
 /*
+ * Copyright (c) 2001-2004 Jakub Jermar
  * Copyright (c) 2005 Martin Decky
  * Copyright (c) 2008 Jiri Svoboda
@@ -33,17 +34,88 @@
  * @{
  */
-/** @file
+
+/**
+ * @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 <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
 #include <stdlib.h>
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
+
 #include <align.h>
 #include <mem.h>
-#include <limits.h>
 
 /** Check the condition if wchar_t is signed */
@@ -747,4 +819,5 @@
 	/* There must be space for a null terminator in the buffer. */
 	assert(size > 0);
+	assert(src != NULL);
 
 	size_t src_off = 0;
@@ -1311,7 +1384,7 @@
 {
 	size_t size = str_size(src) + 1;
-	char *dest = (char *) malloc(size);
-	if (dest == NULL)
-		return (char *) NULL;
+	char *dest = malloc(size);
+	if (!dest)
+		return NULL;
 
 	str_cpy(dest, size, src);
@@ -1345,7 +1418,7 @@
 		size = n;
 
-	char *dest = (char *) malloc(size + 1);
-	if (dest == NULL)
-		return (char *) NULL;
+	char *dest = malloc(size + 1);
+	if (!dest)
+		return NULL;
 
 	str_ncpy(dest, size + 1, src, size);
Index: uspace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision cca2d93bbd7935b85a50e403eb614eb5885365c3)
+++ uspace/lib/c/include/str.h	(revision d066259279e2e85ad364d7828aa3db232f394ec4)
@@ -1,3 +1,4 @@
 /*
+ * Copyright (c) 2001-2004 Jakub Jermar
  * Copyright (c) 2005 Martin Decky
  * Copyright (c) 2011 Oleg Romanenko
@@ -42,10 +43,12 @@
 
 #include <errno.h>
-#include <mem.h>
+#include <stdbool.h>
 #include <stddef.h>
 #include <stdint.h>
-#include <stdbool.h>
 
-#define U_SPECIAL  '?'
+#include <mem.h>
+
+/* Common Unicode characters */
+#define U_SPECIAL      '?'
 
 /** No size limit constant */
@@ -63,5 +66,5 @@
 extern wchar_t str_decode(const char *str, size_t *offset, size_t sz);
 extern wchar_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
-extern errno_t chr_encode(const wchar_t ch, char *str, size_t *offset, size_t sz);
+extern errno_t chr_encode(wchar_t ch, char *str, size_t *offset, size_t sz);
 
 extern size_t str_size(const char *str);
@@ -116,6 +119,6 @@
 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);
+extern char *str_dup(const char *src);
+extern char *str_ndup(const char *src, size_t n);
 
 extern char *str_tok(char *, const char *, char **);
