Index: boot/arch/arm32/meson.build
===================================================================
--- boot/arch/arm32/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/arm32/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -70,5 +70,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/arch/arm64/meson.build
===================================================================
--- boot/arch/arm64/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/arm64/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -56,5 +56,5 @@
 	'../../generic/src/printf.c',
 	'../../generic/src/printf_core.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/tar.c',
 	'../../generic/src/version.c',
Index: boot/arch/ia64/meson.build
===================================================================
--- boot/arch/ia64/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/ia64/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -48,5 +48,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/arch/mips32/meson.build
===================================================================
--- boot/arch/mips32/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/mips32/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -48,5 +48,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/arch/ppc32/meson.build
===================================================================
--- boot/arch/ppc32/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/ppc32/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -46,5 +46,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/arch/riscv64/meson.build
===================================================================
--- boot/arch/riscv64/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/riscv64/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -42,5 +42,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/arch/sparc64/meson.build
===================================================================
--- boot/arch/sparc64/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/arch/sparc64/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -44,5 +44,5 @@
 	'../../generic/src/vprintf.c',
 	'../../generic/src/printf.c',
-	'../../generic/src/str.c',
+	'../../../common/str.c',
 	'../../generic/src/version.c',
 	'../../generic/src/inflate.c',
Index: boot/generic/include/assert.h
===================================================================
--- boot/generic/include/assert.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ boot/generic/include/assert.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,34 @@
+/*
+ * Copyright (c) 2023 Jiří Zárevúcky
+ * 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.
+ */
+
+#ifndef BOOT_ASSERT_H_
+#define BOOT_ASSERT_H_
+
+#define assert(expr) ((void) (expr))
+
+#endif /* BOOT_ASSERT_H_ */
Index: boot/generic/include/errno.h
===================================================================
--- boot/generic/include/errno.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ boot/generic/include/errno.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -39,4 +39,5 @@
 #define EINVAL     -14  /* Invalid value. */
 #define EOVERFLOW  -16  /* The result does not fit its size. */
+#define EIO        -17
 
 typedef int errno_t;
Index: ot/generic/include/str.h
===================================================================
--- boot/generic/include/str.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,64 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Jakub Jermar
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2011 Oleg Romanenko
- * 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.
- */
-
-/** @file
- */
-
-#ifndef BOOT_STR_H_
-#define BOOT_STR_H_
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <uchar.h>
-
-/* Common Unicode characters */
-#define U_SPECIAL  '?'
-
-/** No size limit constant */
-#define STR_NO_LIMIT  ((size_t) -1)
-
-extern char32_t str_decode(const char *str, size_t *offset, size_t sz);
-extern errno_t chr_encode(char32_t ch, char *str, size_t *offset, size_t sz);
-
-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(char32_t ch);
-extern bool chr_check(char32_t ch);
-
-extern int str_cmp(const char *s1, const char *s2);
-extern void str_cpy(char *dest, size_t size, const char *src);
-
-#endif
-
-/** @}
- */
Index: ot/generic/src/str.c
===================================================================
--- boot/generic/src/str.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,426 +1,0 @@
-/*
- * 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.
- *
- * 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.
- */
-
-/**
- * @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 char32_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 char32_t
- *                        (unsigned 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,
- *                        char32_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 *, char32_t *)
- *  byte offset (size_t)
- *  character index (size_t)
- *
- */
-
-#include <str.h>
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.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.
- *
- */
-char32_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;
-
-	char32_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) | (char32_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.
- */
-errno_t chr_encode(const char32_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 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 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;
-}
-
-/** Check whether character is plain ASCII.
- *
- * @return True if character is plain ASCII.
- *
- */
-bool ascii_check(char32_t ch)
-{
-	if (ch <= 127)
-		return true;
-
-	return false;
-}
-
-/** Check whether character is valid
- *
- * @return True if character is a valid Unicode code point.
- *
- */
-bool chr_check(char32_t ch)
-{
-	if (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 their length is equal
- * and both strings consist of the same sequence of characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_cmp(const char *s1, const char *s2)
-{
-	char32_t c1 = 0;
-	char32_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;
-}
-
-/** 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)
-{
-	size_t src_off = 0;
-	size_t dest_off = 0;
-
-	char32_t ch;
-	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';
-}
-
-/** @}
- */
Index: common/include/ctype.h
===================================================================
--- common/include/ctype.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/include/ctype.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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.
+ */
+
+#ifndef _LIBC_CTYPE_H_
+#define _LIBC_CTYPE_H_
+
+#include <_bits/decls.h>
+
+__C_DECLS_BEGIN;
+int islower(int);
+int isupper(int);
+int isalpha(int);
+int isdigit(int);
+int isalnum(int);
+int isblank(int);
+int iscntrl(int);
+int isprint(int);
+int isgraph(int);
+int isspace(int);
+int ispunct(int);
+int isxdigit(int);
+int tolower(int);
+int toupper(int);
+__C_DECLS_END;
+
+#endif
Index: common/include/str.h
===================================================================
--- common/include/str.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/include/str.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,176 @@
+/*
+ * Copyright (c) 2001-2004 Jakub Jermar
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2011 Oleg Romanenko
+ * 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 <errno.h>
+#include <stdbool.h>
+#include <stddef.h>
+#include <stdint.h>
+
+#include <mem.h>
+#include <_bits/decls.h>
+#include <_bits/uchar.h>
+
+#ifndef __cplusplus
+
+/* 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 @c length characters */
+#define STR_BOUNDS(length)  ((length) << 2)
+
+/**
+ * Maximum size of a buffer needed to a string converted from space-padded
+ * ASCII of size @a spa_size using spascii_to_str().
+ */
+#define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
+
+#endif
+
+__HELENOS_DECLS_BEGIN;
+
+extern char32_t str_decode(const char *str, size_t *offset, size_t sz);
+extern char32_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
+extern errno_t chr_encode(char32_t ch, char *str, size_t *offset, size_t sz);
+
+extern size_t str_size(const char *str);
+extern size_t wstr_size(const char32_t *str);
+
+extern size_t str_nsize(const char *str, size_t max_size);
+extern size_t wstr_nsize(const char32_t *str, size_t max_size);
+
+extern size_t str_lsize(const char *str, size_t max_len);
+extern size_t wstr_lsize(const char32_t *str, size_t max_len);
+
+extern size_t str_length(const char *str);
+extern size_t wstr_length(const char32_t *wstr);
+
+extern size_t str_nlength(const char *str, size_t size);
+extern size_t wstr_nlength(const char32_t *str, size_t size);
+
+extern size_t chr_width(char32_t ch);
+extern size_t str_width(const char *str);
+
+extern bool ascii_check(char32_t ch);
+extern bool chr_check(char32_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 int str_casecmp(const char *s1, const char *s2);
+extern int str_lcasecmp(const char *s1, const char *s2, size_t max_len);
+
+extern bool str_test_prefix(const char *s, const char *p);
+extern const char *str_suffix(const char *s, size_t prefix_length);
+
+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 errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
+extern void wstr_to_str(char *dest, size_t size, const char32_t *src);
+extern char *wstr_to_astr(const char32_t *src);
+extern void str_to_wstr(char32_t *dest, size_t dlen, const char *src);
+extern char32_t *str_to_awstr(const char *src);
+extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
+extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
+extern size_t utf16_wsize(const uint16_t *ustr);
+
+extern char *str_chr(const char *str, char32_t ch);
+extern char *str_rchr(const char *str, char32_t ch);
+extern char *str_str(const char *hs, const char *n);
+
+extern void str_rtrim(char *str, char32_t ch);
+extern void str_ltrim(char *str, char32_t ch);
+
+extern bool wstr_linsert(char32_t *str, char32_t ch, size_t pos, size_t max_pos);
+extern bool wstr_remove(char32_t *str, size_t pos);
+
+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 **);
+
+extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
+    uint8_t *);
+extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
+    uint16_t *);
+extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
+    uint32_t *);
+extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
+    uint64_t *);
+extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
+    size_t *);
+extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
+    int64_t *);
+
+extern void order_suffix(const uint64_t, uint64_t *, char *);
+extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
+
+/*
+ * TODO: Get rid of this.
+ */
+
+extern long int strtol(const char *, char **, int);
+extern unsigned long strtoul(const char *, char **, int);
+
+__HELENOS_DECLS_END;
+
+#endif
+
+/** @}
+ */
Index: common/include/str_error.h
===================================================================
--- common/include/str_error.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/include/str_error.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2010 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_STRERROR_H_
+#define _LIBC_STRERROR_H_
+
+#include <errno.h>
+
+const char *str_error(errno_t);
+const char *str_error_name(errno_t);
+
+#endif
+
+/** @}
+ */
Index: common/stdc/ctype.c
===================================================================
--- common/stdc/ctype.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/stdc/ctype.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2006 Josef Cejka
+ * 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 <ctype.h>
+
+int islower(int c)
+{
+	return ((c >= 'a') && (c <= 'z'));
+}
+
+int isupper(int c)
+{
+	return ((c >= 'A') && (c <= 'Z'));
+}
+
+int isalpha(int c)
+{
+	return (islower(c) || isupper(c));
+}
+
+int isdigit(int c)
+{
+	return ((c >= '0') && (c <= '9'));
+}
+
+int isalnum(int c)
+{
+	return (isalpha(c) || isdigit(c));
+}
+
+int isblank(int c)
+{
+	return c == ' ' || c == '\t';
+}
+
+int iscntrl(int c)
+{
+	return (c >= 0 && c < 0x20) || c == 0x7E;
+}
+
+int isprint(int c)
+{
+	return c >= 0 && c < 0x80 && !iscntrl(c);
+}
+
+int isgraph(int c)
+{
+	return isprint(c) && c != ' ';
+}
+
+int isspace(int c)
+{
+	switch (c) {
+	case ' ':
+	case '\n':
+	case '\t':
+	case '\f':
+	case '\r':
+	case '\v':
+		return 1;
+	default:
+		return 0;
+	}
+}
+
+int ispunct(int c)
+{
+	return !isspace(c) && !isalnum(c) && isprint(c);
+}
+
+int isxdigit(int c)
+{
+	return isdigit(c) ||
+	    (c >= 'a' && c <= 'f') ||
+	    (c >= 'A' && c <= 'F');
+}
+
+int tolower(int c)
+{
+	if (isupper(c))
+		return (c + ('a' - 'A'));
+	else
+		return c;
+}
+
+int toupper(int c)
+{
+	if (islower(c))
+		return (c + ('A' - 'a'));
+	else
+		return c;
+}
+
+/** @}
+ */
Index: common/str.c
===================================================================
--- common/str.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/str.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,1548 @@
+/*
+ * 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.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+
+/**
+ * @file
+ * @brief 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 char32_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 char32_t
+ *                        (unsigned 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,
+ *                        char32_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 *, char32_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 <align.h>
+#include <mem.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.
+ *
+ */
+char32_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;
+
+	char32_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) | (char32_t) (b & LO_MASK_8(CONT_BITS));
+		cbytes--;
+	}
+
+	return ch;
+}
+
+/** Decode a single character from a string to the left.
+ *
+ * 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 previous
+ * character. In case of decoding error, offset generally decreases at least
+ * by one. However, offset is never moved before 0.
+ *
+ * @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 start of str.
+ *
+ */
+char32_t str_decode_reverse(const char *str, size_t *offset, size_t size)
+{
+	if (*offset == 0)
+		return 0;
+
+	size_t processed = 0;
+	/* Continue while continuation bytes found */
+	while (*offset > 0 && processed < 4) {
+		uint8_t b = (uint8_t) str[--(*offset)];
+
+		if (processed == 0 && (b & 0x80) == 0) {
+			/* 0xxxxxxx (Plain ASCII) */
+			return b & 0x7f;
+		} else if ((b & 0xe0) == 0xc0 || (b & 0xf0) == 0xe0 ||
+		    (b & 0xf8) == 0xf0) {
+			/* Start byte */
+			size_t start_offset = *offset;
+			return str_decode(str, &start_offset, size);
+		} else if ((b & 0xc0) != 0x80) {
+			/* Not a continuation byte */
+			return U_SPECIAL;
+		}
+		processed++;
+	}
+	/* Too many continuation bytes */
+	return U_SPECIAL;
+}
+
+/** 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.
+ */
+errno_t chr_encode(const char32_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 char32_t *str)
+{
+	return (wstr_length(str) * sizeof(char32_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 string with size limit.
+ *
+ * Get the number of bytes which are used by the string @a str
+ * (excluding the NULL-terminator), but no more than @max_size bytes.
+ *
+ * @param str      String to consider.
+ * @param max_size Maximum number of bytes to measure.
+ *
+ * @return Number of bytes used by the string
+ *
+ */
+size_t str_nsize(const char *str, size_t max_size)
+{
+	size_t size = 0;
+
+	while ((*str++ != 0) && (size < max_size))
+		size++;
+
+	return size;
+}
+
+/** Get size of wide string with size limit.
+ *
+ * Get the number of bytes which are used by the wide string @a str
+ * (excluding the NULL-terminator), but no more than @max_size bytes.
+ *
+ * @param str      Wide string to consider.
+ * @param max_size Maximum number of bytes to measure.
+ *
+ * @return Number of bytes used by the wide string
+ *
+ */
+size_t wstr_nsize(const char32_t *str, size_t max_size)
+{
+	return (wstr_nlength(str, max_size) * sizeof(char32_t));
+}
+
+/** 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 char32_t *str, size_t max_len)
+{
+	return (wstr_nlength(str, max_len * sizeof(char32_t)) * sizeof(char32_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 char32_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 char32_t *str, size_t size)
+{
+	size_t len = 0;
+	size_t limit = ALIGN_DOWN(size, sizeof(char32_t));
+	size_t offset = 0;
+
+	while ((offset < limit) && (*str++ != 0)) {
+		len++;
+		offset += sizeof(char32_t);
+	}
+
+	return len;
+}
+
+/** Get character display width on a character cell display.
+ *
+ * @param ch	Character
+ * @return	Width of character in cells.
+ */
+size_t chr_width(char32_t ch)
+{
+	return 1;
+}
+
+/** Get string display width on a character cell display.
+ *
+ * @param str	String
+ * @return	Width of string in cells.
+ */
+size_t str_width(const char *str)
+{
+	size_t width = 0;
+	size_t offset = 0;
+	char32_t ch;
+
+	while ((ch = str_decode(str, &offset, STR_NO_LIMIT)) != 0)
+		width += chr_width(ch);
+
+	return width;
+}
+
+/** Check whether character is plain ASCII.
+ *
+ * @return True if character is plain ASCII.
+ *
+ */
+bool ascii_check(char32_t ch)
+{
+	if (ch <= 127)
+		return true;
+
+	return false;
+}
+
+/** Check whether character is valid
+ *
+ * @return True if character is a valid Unicode code point.
+ *
+ */
+bool chr_check(char32_t ch)
+{
+	if (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 their length is equal
+ * and both strings consist of the same sequence of characters.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero.
+ *
+ * @param s1 First string to compare.
+ * @param s2 Second string to compare.
+ *
+ * @return 0 if the strings are equal, -1 if the first is less than the second,
+ *         1 if the second is less than the first.
+ *
+ */
+int str_cmp(const char *s1, const char *s2)
+{
+	char32_t c1 = 0;
+	char32_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
+ * min(str_length(s1), max_len) == min(str_length(s2), max_len)
+ * and both strings consist of the same sequence of characters,
+ * up to max_len characters.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero. Only the first max_len
+ * characters are considered.
+ *
+ * @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 the first is less than the second,
+ *         1 if the second is less than the first.
+ *
+ */
+int str_lcmp(const char *s1, const char *s2, size_t max_len)
+{
+	char32_t c1 = 0;
+	char32_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;
+
+}
+
+/** Compare two NULL terminated strings in case-insensitive manner.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff their length is equal
+ * and both strings consist of the same sequence of characters
+ * when converted to lower case.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero.
+ *
+ * @param s1 First string to compare.
+ * @param s2 Second string to compare.
+ *
+ * @return 0 if the strings are equal, -1 if the first is less than the second,
+ *         1 if the second is less than the first.
+ *
+ */
+int str_casecmp(const char *s1, const char *s2)
+{
+	char32_t c1 = 0;
+	char32_t c2 = 0;
+
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	while (true) {
+		c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
+		c2 = tolower(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 in case-insensitive
+ * manner.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings.
+ * The strings are considered equal iff
+ * min(str_length(s1), max_len) == min(str_length(s2), max_len)
+ * and both strings consist of the same sequence of characters,
+ * up to max_len characters.
+ *
+ * A string S1 is less than another string S2 if it has a character with
+ * lower value at the first character position where the strings differ.
+ * If the strings differ in length, the shorter one is treated as if
+ * padded by characters with a value of zero. Only the first max_len
+ * characters are considered.
+ *
+ * @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 the first is less than the second,
+ *         1 if the second is less than the first.
+ *
+ */
+int str_lcasecmp(const char *s1, const char *s2, size_t max_len)
+{
+	char32_t c1 = 0;
+	char32_t c2 = 0;
+
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	size_t len = 0;
+
+	while (true) {
+		if (len >= max_len)
+			break;
+
+		c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
+		c2 = tolower(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;
+
+}
+
+/** Test whether p is a prefix of s.
+ *
+ * Do a char-by-char comparison of two NULL-terminated strings
+ * and determine if p is a prefix of s.
+ *
+ * @param s The string in which to look
+ * @param p The string to check if it is a prefix of s
+ *
+ * @return true iff p is prefix of s else false
+ *
+ */
+bool str_test_prefix(const char *s, const char *p)
+{
+	char32_t c1 = 0;
+	char32_t c2 = 0;
+
+	size_t off1 = 0;
+	size_t off2 = 0;
+
+	while (true) {
+		c1 = str_decode(s, &off1, STR_NO_LIMIT);
+		c2 = str_decode(p, &off2, STR_NO_LIMIT);
+
+		if (c2 == 0)
+			return true;
+
+		if (c1 != c2)
+			return false;
+
+		if (c1 == 0)
+			break;
+	}
+
+	return false;
+}
+
+/** Get a string suffix.
+ *
+ * Return a string suffix defined by the prefix length.
+ *
+ * @param s             The string to get the suffix from.
+ * @param prefix_length Number of prefix characters to ignore.
+ *
+ * @return String suffix.
+ *
+ */
+const char *str_suffix(const char *s, size_t prefix_length)
+{
+	size_t off = 0;
+	size_t i = 0;
+
+	while (true) {
+		str_decode(s, &off, STR_NO_LIMIT);
+		i++;
+
+		if (i >= prefix_length)
+			break;
+	}
+
+	return s + off;
+}
+
+/** 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)
+{
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	assert(src != NULL);
+
+	size_t src_off = 0;
+	size_t dest_off = 0;
+
+	char32_t ch;
+	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)
+{
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+
+	size_t src_off = 0;
+	size_t dest_off = 0;
+
+	char32_t ch;
+	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);
+	if (dstr_size >= size)
+		return;
+
+	str_cpy(dest + dstr_size, size - dstr_size, src);
+}
+
+/** Convert space-padded ASCII to string.
+ *
+ * Common legacy text encoding in hardware is 7-bit ASCII fitted into
+ * a fixed-width byte buffer (bit 7 always zero), right-padded with spaces
+ * (ASCII 0x20). Convert space-padded ascii to string representation.
+ *
+ * If the text does not fit into the destination buffer, the function converts
+ * as many characters as possible and returns EOVERFLOW.
+ *
+ * If the text contains non-ASCII bytes (with bit 7 set), the whole string is
+ * converted anyway and invalid characters are replaced with question marks
+ * (U_SPECIAL) and the function returns EIO.
+ *
+ * Regardless of return value upon return @a dest will always be well-formed.
+ *
+ * @param dest		Destination buffer
+ * @param size		Size of destination buffer
+ * @param src		Space-padded ASCII.
+ * @param n		Size of the source buffer in bytes.
+ *
+ * @return		EOK on success, EOVERFLOW if the text does not fit
+ *			destination buffer, EIO if the text contains
+ *			non-ASCII bytes.
+ */
+errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n)
+{
+	size_t sidx;
+	size_t didx;
+	size_t dlast;
+	uint8_t byte;
+	errno_t rc;
+	errno_t result;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+	result = EOK;
+
+	didx = 0;
+	dlast = 0;
+	for (sidx = 0; sidx < n; ++sidx) {
+		byte = src[sidx];
+		if (!ascii_check(byte)) {
+			byte = U_SPECIAL;
+			result = EIO;
+		}
+
+		rc = chr_encode(byte, dest, &didx, size - 1);
+		if (rc != EOK) {
+			assert(rc == EOVERFLOW);
+			dest[didx] = '\0';
+			return rc;
+		}
+
+		/* Remember dest index after last non-empty character */
+		if (byte != 0x20)
+			dlast = didx;
+	}
+
+	/* Terminate string after last non-empty character */
+	dest[dlast] = '\0';
+	return result;
+}
+
+/** 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 char32_t *src)
+{
+	char32_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 UTF16 string to string.
+ *
+ * Convert utf16 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. Surrogate pairs also supported.
+ *
+ * @param dest	Destination buffer.
+ * @param size	Size of the destination buffer.
+ * @param src	Source utf16 string.
+ *
+ * @return EOK, if success, an error code otherwise.
+ */
+errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src)
+{
+	size_t idx = 0, dest_off = 0;
+	char32_t ch;
+	errno_t rc = EOK;
+
+	/* There must be space for a null terminator in the buffer. */
+	assert(size > 0);
+
+	while (src[idx]) {
+		if ((src[idx] & 0xfc00) == 0xd800) {
+			if (src[idx + 1] && (src[idx + 1] & 0xfc00) == 0xdc00) {
+				ch = 0x10000;
+				ch += (src[idx] & 0x03FF) << 10;
+				ch += (src[idx + 1] & 0x03FF);
+				idx += 2;
+			} else
+				break;
+		} else {
+			ch = src[idx];
+			idx++;
+		}
+		rc = chr_encode(ch, dest, &dest_off, size - 1);
+		if (rc != EOK)
+			break;
+	}
+	dest[dest_off] = '\0';
+	return rc;
+}
+
+/** Convert string to UTF16 string.
+ *
+ * Convert string @a src to utf16 string. The output is written to the buffer
+ * specified by @a dest and @a dlen. @a dlen must be non-zero and the string
+ * written will always be well-formed. Surrogate pairs also supported.
+ *
+ * @param dest	Destination buffer.
+ * @param dlen	Number of utf16 characters that fit in the destination buffer.
+ * @param src	Source string.
+ *
+ * @return EOK, if success, an error code otherwise.
+ */
+errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
+{
+	errno_t rc = EOK;
+	size_t offset = 0;
+	size_t idx = 0;
+	char32_t c;
+
+	assert(dlen > 0);
+
+	while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) {
+		if (c > 0x10000) {
+			if (idx + 2 >= dlen - 1) {
+				rc = EOVERFLOW;
+				break;
+			}
+			c = (c - 0x10000);
+			dest[idx] = 0xD800 | (c >> 10);
+			dest[idx + 1] = 0xDC00 | (c & 0x3FF);
+			idx++;
+		} else {
+			dest[idx] = c;
+		}
+
+		idx++;
+		if (idx >= dlen - 1) {
+			rc = EOVERFLOW;
+			break;
+		}
+	}
+
+	dest[idx] = '\0';
+	return rc;
+}
+
+/** Get size of UTF-16 string.
+ *
+ * Get the number of words which are used by the UTF-16 string @a ustr
+ * (excluding the NULL-terminator).
+ *
+ * @param ustr UTF-16 string to consider.
+ *
+ * @return Number of words used by the UTF-16 string
+ *
+ */
+size_t utf16_wsize(const uint16_t *ustr)
+{
+	size_t wsize = 0;
+
+	while (*ustr++ != 0)
+		wsize++;
+
+	return wsize;
+}
+
+/** 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 char32_t *src)
+{
+	char dbuf[STR_BOUNDS(1)];
+	char *str;
+	char32_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(char32_t *dest, size_t dlen, const char *src)
+{
+	size_t offset;
+	size_t di;
+	char32_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';
+}
+
+/** Convert string to wide string.
+ *
+ * Convert string @a src to wide string. A new wide NULL-terminated
+ * string will be allocated on the heap.
+ *
+ * @param src	Source string.
+ */
+char32_t *str_to_awstr(const char *str)
+{
+	size_t len = str_length(str);
+
+	char32_t *wstr = calloc(len + 1, sizeof(char32_t));
+	if (wstr == NULL)
+		return NULL;
+
+	str_to_wstr(wstr, len + 1, str);
+	return wstr;
+}
+
+/** 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, char32_t ch)
+{
+	char32_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 first occurence of substring in string.
+ *
+ * @param hs  Haystack (string)
+ * @param n   Needle (substring to look for)
+ *
+ * @return Pointer to character in @a hs or @c NULL if not found.
+ */
+char *str_str(const char *hs, const char *n)
+{
+	size_t off = 0;
+
+	if (str_lcmp(hs, n, str_length(n)) == 0)
+		return (char *)hs;
+
+	while (str_decode(hs, &off, STR_NO_LIMIT) != 0) {
+		if (str_lcmp(hs + off, n, str_length(n)) == 0)
+			return (char *)(hs + off);
+	}
+
+	return NULL;
+}
+
+/** Removes specified trailing characters from a string.
+ *
+ * @param str String to remove from.
+ * @param ch  Character to remove.
+ */
+void str_rtrim(char *str, char32_t ch)
+{
+	size_t off = 0;
+	size_t pos = 0;
+	char32_t c;
+	bool update_last_chunk = true;
+	char *last_chunk = NULL;
+
+	while ((c = str_decode(str, &off, STR_NO_LIMIT))) {
+		if (c != ch) {
+			update_last_chunk = true;
+			last_chunk = NULL;
+		} else if (update_last_chunk) {
+			update_last_chunk = false;
+			last_chunk = (str + pos);
+		}
+		pos = off;
+	}
+
+	if (last_chunk)
+		*last_chunk = '\0';
+}
+
+/** Removes specified leading characters from a string.
+ *
+ * @param str String to remove from.
+ * @param ch  Character to remove.
+ */
+void str_ltrim(char *str, char32_t ch)
+{
+	char32_t acc;
+	size_t off = 0;
+	size_t pos = 0;
+	size_t str_sz = str_size(str);
+
+	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
+		if (acc != ch)
+			break;
+		else
+			pos = off;
+	}
+
+	if (pos > 0) {
+		memmove(str, &str[pos], str_sz - pos);
+		pos = str_sz - pos;
+		str[pos] = '\0';
+	}
+}
+
+/** 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, char32_t ch)
+{
+	char32_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(char32_t *str, char32_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(char32_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.
+ *
+ * Allocate a new string and copy characters from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ *
+ * @return Duplicate string.
+ *
+ */
+char *str_dup(const char *src)
+{
+	size_t size = str_size(src) + 1;
+	char *dest = malloc(size);
+	if (!dest)
+		return NULL;
+
+	str_cpy(dest, size, src);
+	return dest;
+}
+
+/** Duplicate string with size limit.
+ *
+ * Allocate a new string and copy up to @max_size bytes from the source
+ * string into it. The duplicate string is allocated via sleeping
+ * malloc(), thus this function can sleep in no memory conditions.
+ * No more than @max_size + 1 bytes is allocated, but if the size
+ * occupied by the source string is smaller than @max_size + 1,
+ * less is allocated.
+ *
+ * The allocation cannot fail and the return value is always
+ * a valid pointer. The duplicate string is always a well-formed
+ * null-terminated UTF-8 string, but it can differ from the source
+ * string on the byte level.
+ *
+ * @param src Source string.
+ * @param n   Maximum number of bytes to duplicate.
+ *
+ * @return Duplicate string.
+ *
+ */
+char *str_ndup(const char *src, size_t n)
+{
+	size_t size = str_size(src);
+	if (size > n)
+		size = n;
+
+	char *dest = malloc(size + 1);
+	if (!dest)
+		return NULL;
+
+	str_ncpy(dest, size + 1, src, size);
+	return dest;
+}
+
+/** Split string by delimiters.
+ *
+ * @param s             String to be tokenized. May not be NULL.
+ * @param delim		String with the delimiters.
+ * @param next		Variable which will receive the pointer to the
+ *                      continuation of the string following the first
+ *                      occurrence of any of the delimiter characters.
+ *                      May be NULL.
+ * @return              Pointer to the prefix of @a s before the first
+ *                      delimiter character. NULL if no such prefix
+ *                      exists.
+ */
+char *str_tok(char *s, const char *delim, char **next)
+{
+	char *start, *end;
+
+	if (!s)
+		return NULL;
+
+	size_t len = str_size(s);
+	size_t cur;
+	size_t tmp;
+	char32_t ch;
+
+	/* Skip over leading delimiters. */
+	tmp = 0;
+	cur = 0;
+	while ((ch = str_decode(s, &tmp, len)) && str_chr(delim, ch))
+		cur = tmp;
+	start = &s[cur];
+
+	/* Skip over token characters. */
+	tmp = cur;
+	while ((ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch))
+		cur = tmp;
+	end = &s[cur];
+	if (next)
+		*next = (ch ? &s[tmp] : &s[cur]);
+
+	if (start == end)
+		return NULL;	/* No more tokens. */
+
+	/* Overwrite delimiter with NULL terminator. */
+	*end = '\0';
+	return start;
+}
+
+void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
+{
+	if (val > UINT64_C(10000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000000);
+		*suffix = 'Z';
+	} else if (val > UINT64_C(1000000000000000000)) {
+		*rv = val / UINT64_C(1000000000000000);
+		*suffix = 'E';
+	} else if (val > UINT64_C(1000000000000000)) {
+		*rv = val / UINT64_C(1000000000000);
+		*suffix = 'T';
+	} else if (val > UINT64_C(1000000000000)) {
+		*rv = val / UINT64_C(1000000000);
+		*suffix = 'G';
+	} else if (val > UINT64_C(1000000000)) {
+		*rv = val / UINT64_C(1000000);
+		*suffix = 'M';
+	} else if (val > UINT64_C(1000000)) {
+		*rv = val / UINT64_C(1000);
+		*suffix = 'k';
+	} else {
+		*rv = val;
+		*suffix = ' ';
+	}
+}
+
+void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
+    bool fixed)
+{
+	if (val > UINT64_C(1152921504606846976)) {
+		*rv = val / UINT64_C(1125899906842624);
+		*suffix = "EiB";
+	} else if (val > UINT64_C(1125899906842624)) {
+		*rv = val / UINT64_C(1099511627776);
+		*suffix = "TiB";
+	} else if (val > UINT64_C(1099511627776)) {
+		*rv = val / UINT64_C(1073741824);
+		*suffix = "GiB";
+	} else if (val > UINT64_C(1073741824)) {
+		*rv = val / UINT64_C(1048576);
+		*suffix = "MiB";
+	} else if (val > UINT64_C(1048576)) {
+		*rv = val / UINT64_C(1024);
+		*suffix = "KiB";
+	} else {
+		*rv = val;
+		if (fixed)
+			*suffix = "B  ";
+		else
+			*suffix = "B";
+	}
+}
+
+/** @}
+ */
Index: common/str_error.c
===================================================================
--- common/str_error.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/str_error.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2010 Martin Decky
+ * Copyright (c) 2017 CZ.NIC, z.s.p.o.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <str_error.h>
+
+#include <errno.h>
+#include <stddef.h>
+
+
+/*
+ * The arrays below are automatically generated from the same file that
+ * errno.h constants are generated from. Triple-include of the same list
+ * with redefinitions of __errno() macro are used to ensure that the
+ * information cannot get out of synch. This is inpired by musl libc.
+ */
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) name,
+
+static const errno_t err_num[] = {
+#include <abi/errno.in>
+};
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) #name,
+
+static const char *err_name[] = {
+#include <abi/errno.in>
+};
+
+#undef __errno_entry
+#define __errno_entry(name, num, desc) "[" #name "] " desc,
+
+static const char *err_desc[] = {
+#include <abi/errno.in>
+};
+
+/* Returns index corresponding to the given errno, or -1 if not found. */
+static int find_errno(errno_t e)
+{
+	/*
+	 * Just a dumb linear search.
+	 * There are too few entries to warrant anything smarter.
+	 */
+
+	int len = sizeof(err_num) / sizeof(errno_t);
+
+	for (int i = 0; i < len; i++) {
+		if (err_num[i] == e) {
+			return i;
+		}
+	}
+
+	return -1;
+}
+
+const char *str_error_name(errno_t e)
+{
+	int i = find_errno(e);
+
+	if (i >= 0) {
+		return err_name[i];
+	}
+
+	return NULL;
+}
+
+const char *str_error(errno_t e)
+{
+	int i = find_errno(e);
+
+	if (i >= 0) {
+		return err_desc[i];
+	}
+
+	return NULL;
+}
Index: common/strtol.c
===================================================================
--- common/strtol.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
+++ common/strtol.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -0,0 +1,562 @@
+/*
+ * Copyright (c) 2005 Martin Decky
+ * Copyright (c) 2008 Jiri Svoboda
+ * Copyright (c) 2011 Martin Sucha
+ * Copyright (c) 2011 Oleg Romanenko
+ * Copyright (c) 2011 Jiri Zarevucky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/** @file
+ */
+
+#include <assert.h>
+#include <ctype.h>
+#include <errno.h>
+#include <inttypes.h>
+#include <limits.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <str.h>
+
+// FIXME: The original HelenOS functions return EOVERFLOW instead
+//        of ERANGE. It's a pointless distinction from standard functions,
+//        so we should change that. Beware the callers though.
+
+// TODO: more unit tests
+
+static inline int _digit_value(int c)
+{
+	if (isdigit(c)) {
+		return c - '0';
+	} else if (islower(c)) {
+		return c - 'a' + 10;
+	} else if (isupper(c)) {
+		return c - 'A' + 10;
+	}
+	return INT_MAX;
+}
+
+/*
+ * FIXME: workaround for GCC "optimizing" the overflow check
+ * into soft-emulated 128b multiplication using `__multi3`,
+ * which we don't currently implement.
+ */
+__attribute__((noinline)) static uintmax_t _max_value(int base)
+{
+	return UINTMAX_MAX / base;
+}
+
+static inline int _prefixbase(const char *restrict *nptrptr, bool nonstd)
+{
+	const char *nptr = *nptrptr;
+
+	if (nptr[0] != '0')
+		return 10;
+
+	if (nptr[1] == 'x' || nptr[1] == 'X') {
+		if (_digit_value(nptr[2]) < 16) {
+			*nptrptr += 2;
+			return 16;
+		}
+	}
+
+	if (nonstd) {
+		switch (nptr[1]) {
+		case 'b':
+		case 'B':
+			if (_digit_value(nptr[2]) < 2) {
+				*nptrptr += 2;
+				return 2;
+			}
+			break;
+		case 'o':
+		case 'O':
+			if (_digit_value(nptr[2]) < 8) {
+				*nptrptr += 2;
+				return 8;
+			}
+			break;
+		case 'd':
+		case 'D':
+		case 't':
+		case 'T':
+			if (_digit_value(nptr[2]) < 10) {
+				*nptrptr += 2;
+				return 10;
+			}
+			break;
+		}
+	}
+
+	return 8;
+}
+
+static inline uintmax_t _strtoumax(
+    const char *restrict nptr, char **restrict endptr, int base,
+    bool *restrict sgn, errno_t *err, bool nonstd)
+{
+	assert(nptr != NULL);
+	assert(sgn != NULL);
+
+	const char *first = nptr;
+
+	/* Skip leading whitespace. */
+
+	while (isspace(*nptr)) {
+		nptr++;
+	}
+
+	/* Parse sign, if any. */
+
+	switch (*nptr) {
+	case '-':
+		*sgn = true;
+		nptr++;
+		break;
+	case '+':
+		nptr++;
+		break;
+	}
+
+	/* Figure out the base. */
+
+	if (base == 0)
+		base = _prefixbase(&nptr, nonstd);
+
+	if (base == 16 && !nonstd) {
+		/*
+		 * Standard strto* functions allow hexadecimal prefix to be
+		 * present when base is explicitly set to 16.
+		 * Our nonstandard str_* functions don't allow it.
+		 * I don't know if that is intended, just matching the original
+		 * functionality here.
+		 */
+
+		if (nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X') &&
+		    _digit_value(nptr[2]) < base)
+			nptr += 2;
+	}
+
+	if (base < 2 || base > 36) {
+		*err = EINVAL;
+		return 0;
+	}
+
+	/* Must be at least one digit. */
+
+	if (_digit_value(*nptr) >= base) {
+		/* No digits on input. */
+		if (endptr != NULL)
+			*endptr = (char *) first;
+		return 0;
+	}
+
+	/* Read the value.  */
+
+	uintmax_t result = 0;
+	uintmax_t max = _max_value(base);
+	int digit;
+
+	while (digit = _digit_value(*nptr), digit < base) {
+		if (result > max ||
+		    __builtin_add_overflow(result * base, digit, &result)) {
+
+			*err = nonstd ? EOVERFLOW : ERANGE;
+			result = UINTMAX_MAX;
+			break;
+		}
+
+		nptr++;
+	}
+
+	/* Set endptr. */
+
+	if (endptr != NULL) {
+		/*
+		 * Move the pointer to the end of the number,
+		 * in case it isn't there already.
+		 * This can happen when the number has legal formatting,
+		 * but is out of range of the target type.
+		 */
+		while (_digit_value(*nptr) < base) {
+			nptr++;
+		}
+
+		*endptr = (char *) nptr;
+	}
+
+	return result;
+}
+
+static inline intmax_t _strtosigned(const char *nptr, char **endptr, int base,
+    intmax_t min, intmax_t max, errno_t *err, bool nonstd)
+{
+	bool sgn = false;
+	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn, err, nonstd);
+
+	if (number > (uintmax_t) max) {
+		if (sgn && (number - 1 == (uintmax_t) max)) {
+			return min;
+		}
+
+		*err = nonstd ? EOVERFLOW : ERANGE;
+		return (sgn ? min : max);
+	}
+
+	return (sgn ? -number : number);
+}
+
+static inline uintmax_t _strtounsigned(const char *nptr, char **endptr, int base,
+    uintmax_t max, errno_t *err, bool nonstd)
+{
+	bool sgn = false;
+	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn, err, nonstd);
+
+	if (nonstd && sgn) {
+		/* Do not allow negative values */
+		*err = EINVAL;
+		return 0;
+	}
+
+	if (number > max) {
+		*err = nonstd ? EOVERFLOW : ERANGE;
+		return max;
+	}
+
+	return (sgn ? -number : number);
+}
+
+/** Convert initial part of string to long int according to given base.
+ * The number may begin with an arbitrary number of whitespaces followed by
+ * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
+ * inserted and the number will be taken as hexadecimal one. If the base is 0
+ * and the number begin with a zero, number will be taken as octal one (as with
+ * base 8). Otherwise the base 0 is taken as decimal.
+ *
+ * @param nptr		Pointer to string.
+ * @param[out] endptr	If not NULL, function stores here pointer to the first
+ * 			invalid character.
+ * @param base		Zero or number between 2 and 36 inclusive.
+ * @return		Result of conversion.
+ */
+long strtol(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtosigned(nptr, endptr, base, LONG_MIN, LONG_MAX, &errno, false);
+}
+
+/** Convert initial part of string to unsigned long according to given base.
+ * The number may begin with an arbitrary number of whitespaces followed by
+ * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
+ * inserted and the number will be taken as hexadecimal one. If the base is 0
+ * and the number begin with a zero, number will be taken as octal one (as with
+ * base 8). Otherwise the base 0 is taken as decimal.
+ *
+ * @param nptr		Pointer to string.
+ * @param[out] endptr	If not NULL, function stores here pointer to the first
+ * 			invalid character
+ * @param base		Zero or number between 2 and 36 inclusive.
+ * @return		Result of conversion.
+ */
+unsigned long strtoul(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtounsigned(nptr, endptr, base, ULONG_MAX, &errno, false);
+}
+
+long long strtoll(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtosigned(nptr, endptr, base, LLONG_MIN, LLONG_MAX, &errno, false);
+}
+
+unsigned long long strtoull(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtounsigned(nptr, endptr, base, ULLONG_MAX, &errno, false);
+}
+
+intmax_t strtoimax(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtosigned(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX, &errno, false);
+}
+
+uintmax_t strtoumax(const char *nptr, char **endptr, int base)
+{
+#if !__STDC_HOSTED__
+	errno_t errno;
+#endif
+
+	return _strtounsigned(nptr, endptr, base, UINTMAX_MAX, &errno, false);
+}
+
+int atoi(const char *nptr)
+{
+	return (int)strtol(nptr, NULL, 10);
+}
+
+long atol(const char *nptr)
+{
+	return strtol(nptr, NULL, 10);
+}
+
+long long atoll(const char *nptr)
+{
+	return strtoll(nptr, NULL, 10);
+}
+
+/** Convert string to uint8_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_uint8_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, uint8_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT8_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** Convert string to uint16_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_uint16_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, uint16_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT16_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** Convert string to uint32_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_uint32_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, uint32_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT32_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** Convert string to uint64_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_uint64_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, uint64_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT64_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** Convert string to int64_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_int64_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, int64_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	intmax_t r = _strtosigned(nptr, &lendptr, base, INT64_MIN, INT64_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** Convert string to size_t.
+ *
+ * @param nptr   Pointer to string.
+ * @param endptr If not NULL, pointer to the first invalid character
+ *               is stored here.
+ * @param base   Zero or number between 2 and 36 inclusive.
+ * @param strict Do not allow any trailing characters.
+ * @param result Result of the conversion.
+ *
+ * @return EOK if conversion was successful.
+ *
+ */
+errno_t str_size_t(const char *nptr, const char **endptr, unsigned int base,
+    bool strict, size_t *result)
+{
+	assert(result != NULL);
+
+	errno_t rc = EOK;
+	char *lendptr = (char *) nptr;
+
+	uintmax_t r = _strtounsigned(nptr, &lendptr, base, SIZE_MAX, &rc, true);
+
+	if (endptr)
+		*endptr = lendptr;
+
+	if (rc != EOK)
+		return rc;
+
+	if (strict && *lendptr != '\0')
+		return EINVAL;
+
+	*result = r;
+	return EOK;
+}
+
+/** @}
+ */
Index: rnel/generic/include/str.h
===================================================================
--- kernel/generic/include/str.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,116 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Jakub Jermar
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2011 Oleg Romanenko
- * 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 kernel_generic
- * @{
- */
-/** @file
- */
-
-#ifndef KERN_STR_H_
-#define KERN_STR_H_
-
-#include <errno.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.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 @c length characters */
-#define STR_BOUNDS(length)  ((length) << 2)
-
-extern char32_t str_decode(const char *, size_t *, size_t);
-extern errno_t chr_encode(char32_t, char *, size_t *, size_t);
-
-extern size_t str_size(const char *);
-extern size_t wstr_size(const char32_t *);
-
-extern size_t str_lsize(const char *, size_t);
-extern size_t wstr_lsize(const char32_t *, size_t);
-
-extern size_t str_length(const char *);
-extern size_t wstr_length(const char32_t *);
-
-extern size_t str_nlength(const char *, size_t);
-extern size_t wstr_nlength(const char32_t *, size_t);
-
-extern bool ascii_check(char32_t);
-extern bool chr_check(char32_t);
-
-extern int str_cmp(const char *, const char *);
-extern int str_lcmp(const char *, const char *, size_t);
-
-extern void str_cpy(char *, size_t, const char *);
-extern void str_ncpy(char *, size_t, const char *, size_t);
-extern void wstr_to_str(char *, size_t, const char32_t *);
-
-extern char *str_chr(const char *, char32_t);
-
-extern bool wstr_linsert(char32_t *, char32_t, size_t, size_t);
-extern bool wstr_remove(char32_t *, size_t);
-
-extern char *str_dup(const char *);
-extern char *str_ndup(const char *, size_t);
-
-extern errno_t str_uint64_t(const char *, char **, unsigned int, bool,
-    uint64_t *);
-
-extern void order_suffix(const uint64_t, uint64_t *, char *);
-extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
-
-extern const char *str_error(errno_t);
-extern const char *str_error_name(errno_t);
-
-#endif
-
-/** @}
- */
Index: kernel/generic/meson.build
===================================================================
--- kernel/generic/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ kernel/generic/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -36,5 +36,10 @@
 
 generic_src += files(
+	'common/stdc/calloc.c',
+	'common/stdc/ctype.c',
 	'common/stdc/mem.c',
+	'common/str.c',
+	'common/str_error.c',
+	'common/strtol.c',
 
 	'src/adt/bitmap.c',
@@ -77,7 +82,4 @@
 	'src/lib/ra.c',
 	'src/lib/rd.c',
-	'src/lib/str.c',
-	'src/lib/strtol.c',
-	'src/lib/str_error.c',
 	'src/lib/ubsan.c',
 	'src/log/log.c',
Index: kernel/generic/src/console/kconsole.c
===================================================================
--- kernel/generic/src/console/kconsole.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ kernel/generic/src/console/kconsole.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -599,5 +599,5 @@
 		/* It's a number - convert it */
 		uint64_t value;
-		char *end;
+		const char *end;
 		errno_t rc = str_uint64_t(text, &end, 0, false, &value);
 		if (end != text + len)
Index: rnel/generic/src/lib/str.c
===================================================================
--- kernel/generic/src/lib/str.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,840 +1,0 @@
-/*
- * 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.
- *
- * 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 kernel_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 char32_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 char32_t
- *                        (unsigned 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,
- *                        char32_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 *, char32_t *)
- *  byte offset (size_t)
- *  character index (size_t)
- *
- */
-
-#include <str.h>
-
-#include <assert.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-#include <align.h>
-#include <macros.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.
- *
- */
-char32_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;
-
-	char32_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) | (char32_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.
- */
-errno_t chr_encode(const char32_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 char32_t *str)
-{
-	return (wstr_length(str) * sizeof(char32_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 char32_t *str, size_t max_len)
-{
-	return (wstr_nlength(str, max_len * sizeof(char32_t)) * sizeof(char32_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 char32_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 char32_t *str, size_t size)
-{
-	size_t len = 0;
-	size_t limit = ALIGN_DOWN(size, sizeof(char32_t));
-	size_t offset = 0;
-
-	while ((offset < limit) && (*str++ != 0)) {
-		len++;
-		offset += sizeof(char32_t);
-	}
-
-	return len;
-}
-
-/** Check whether character is plain ASCII.
- *
- * @return True if character is plain ASCII.
- *
- */
-bool ascii_check(char32_t ch)
-{
-	if (ch <= 127)
-		return true;
-
-	return false;
-}
-
-/** Check whether character is valid
- *
- * @return True if character is a valid Unicode code point.
- *
- */
-bool chr_check(char32_t ch)
-{
-	if (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 their length is equal
- * and both strings consist of the same sequence of characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_cmp(const char *s1, const char *s2)
-{
-	char32_t c1 = 0;
-	char32_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
- * min(str_length(s1), max_len) == min(str_length(s2), max_len)
- * and both strings consist of the same sequence of characters,
- * up to max_len characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero. Only the first max_len
- * characters are considered.
- *
- * @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 the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_lcmp(const char *s1, const char *s2, size_t max_len)
-{
-	char32_t c1 = 0;
-	char32_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)
-{
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	assert(src != NULL);
-
-	size_t src_off = 0;
-	size_t dest_off = 0;
-
-	char32_t ch;
-	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)
-{
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-
-	size_t src_off = 0;
-	size_t dest_off = 0;
-
-	char32_t ch;
-	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 char32_t *src)
-{
-	char32_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, char32_t ch)
-{
-	char32_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(char32_t *str, char32_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(char32_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.
- *
- * Allocate a new string and copy characters from the source
- * string into it. The duplicate string is allocated via sleeping
- * malloc(), thus this function can sleep in no memory conditions.
- *
- * The allocation cannot fail and the return value is always
- * a valid pointer. The duplicate string is always a well-formed
- * null-terminated UTF-8 string, but it can differ from the source
- * string on the byte level.
- *
- * @param src Source string.
- *
- * @return Duplicate string.
- *
- */
-char *str_dup(const char *src)
-{
-	size_t size = str_size(src) + 1;
-	char *dest = malloc(size);
-	if (!dest)
-		return NULL;
-
-	str_cpy(dest, size, src);
-	return dest;
-}
-
-/** Duplicate string with size limit.
- *
- * Allocate a new string and copy up to @max_size bytes from the source
- * string into it. The duplicate string is allocated via sleeping
- * malloc(), thus this function can sleep in no memory conditions.
- * No more than @max_size + 1 bytes is allocated, but if the size
- * occupied by the source string is smaller than @max_size + 1,
- * less is allocated.
- *
- * The allocation cannot fail and the return value is always
- * a valid pointer. The duplicate string is always a well-formed
- * null-terminated UTF-8 string, but it can differ from the source
- * string on the byte level.
- *
- * @param src Source string.
- * @param n   Maximum number of bytes to duplicate.
- *
- * @return Duplicate string.
- *
- */
-char *str_ndup(const char *src, size_t n)
-{
-	size_t size = str_size(src);
-	if (size > n)
-		size = n;
-
-	char *dest = malloc(size + 1);
-	if (!dest)
-		return NULL;
-
-	str_ncpy(dest, size + 1, src, size);
-	return dest;
-}
-
-void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
-{
-	if (val > UINT64_C(10000000000000000000)) {
-		*rv = val / UINT64_C(1000000000000000000);
-		*suffix = 'Z';
-	} else if (val > UINT64_C(1000000000000000000)) {
-		*rv = val / UINT64_C(1000000000000000);
-		*suffix = 'E';
-	} else if (val > UINT64_C(1000000000000000)) {
-		*rv = val / UINT64_C(1000000000000);
-		*suffix = 'T';
-	} else if (val > UINT64_C(1000000000000)) {
-		*rv = val / UINT64_C(1000000000);
-		*suffix = 'G';
-	} else if (val > UINT64_C(1000000000)) {
-		*rv = val / UINT64_C(1000000);
-		*suffix = 'M';
-	} else if (val > UINT64_C(1000000)) {
-		*rv = val / UINT64_C(1000);
-		*suffix = 'k';
-	} else {
-		*rv = val;
-		*suffix = ' ';
-	}
-}
-
-void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
-    bool fixed)
-{
-	if (val > UINT64_C(1152921504606846976)) {
-		*rv = val / UINT64_C(1125899906842624);
-		*suffix = "EiB";
-	} else if (val > UINT64_C(1125899906842624)) {
-		*rv = val / UINT64_C(1099511627776);
-		*suffix = "TiB";
-	} else if (val > UINT64_C(1099511627776)) {
-		*rv = val / UINT64_C(1073741824);
-		*suffix = "GiB";
-	} else if (val > UINT64_C(1073741824)) {
-		*rv = val / UINT64_C(1048576);
-		*suffix = "MiB";
-	} else if (val > UINT64_C(1048576)) {
-		*rv = val / UINT64_C(1024);
-		*suffix = "KiB";
-	} else {
-		*rv = val;
-		if (fixed)
-			*suffix = "B  ";
-		else
-			*suffix = "B";
-	}
-}
-
-/** @}
- */
Index: rnel/generic/src/lib/str_error.c
===================================================================
--- kernel/generic/src/lib/str_error.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,100 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * Copyright (c) 2017 CZ.NIC, z.s.p.o.
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include <errno.h>
-#include <str.h>
-
-/*
- * The arrays below are automatically generated from the same file that
- * errno.h constants are generated from. Triple-include of the same list
- * with redefinitions of __errno() macro are used to ensure that the
- * information cannot get out of synch. This is inpired by musl libc.
- */
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) name,
-
-static const errno_t err_num[] = {
-#include <abi/errno.in>
-};
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) #name,
-
-static const char *err_name[] = {
-#include <abi/errno.in>
-};
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) "[" #name "] " desc,
-
-static const char *err_desc[] = {
-#include <abi/errno.in>
-};
-
-/* Returns index corresponding to the given errno, or -1 if not found. */
-static int find_errno(errno_t e)
-{
-	/*
-	 * Just a dumb linear search.
-	 * There too few entries to warrant anything smarter.
-	 */
-
-	int len = sizeof(err_num) / sizeof(errno_t);
-
-	for (int i = 0; i < len; i++) {
-		if (err_num[i] == e) {
-			return i;
-		}
-	}
-
-	return -1;
-}
-
-const char *str_error_name(errno_t e)
-{
-	int i = find_errno(e);
-
-	if (i >= 0) {
-		return err_name[i];
-	}
-
-	return "(unknown)";
-}
-
-const char *str_error(errno_t e)
-{
-	int i = find_errno(e);
-
-	if (i >= 0) {
-		return err_desc[i];
-	}
-
-	return "Unknown error code";
-}
Index: rnel/generic/src/lib/strtol.c
===================================================================
--- kernel/generic/src/lib/strtol.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,303 +1,0 @@
-/*
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2008 Jiri Svoboda
- * Copyright (c) 2011 Martin Sucha
- * Copyright (c) 2011 Oleg Romanenko
- * Copyright (c) 2011 Jiri Zarevucky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup kernel_generic
- * @{
- */
-/** @file
- */
-
-#include <assert.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <str.h>
-
-// FIXME: The original HelenOS functions return EOVERFLOW instead
-//        of ERANGE. It's a pointless distinction from standard functions,
-//        so we should change that. Beware the callers though.
-
-// TODO: more unit tests
-
-static inline int isdigit(int c)
-{
-	return c >= '0' && c <= '9';
-}
-
-static inline int islower(int c)
-{
-	return c >= 'a' && c <= 'z';
-}
-
-static inline int isupper(int c)
-{
-	return c >= 'A' && c <= 'Z';
-}
-
-static inline int isspace(int c)
-{
-	switch (c) {
-	case ' ':
-	case '\n':
-	case '\t':
-	case '\f':
-	case '\r':
-	case '\v':
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-static inline int _digit_value(int c)
-{
-	if (isdigit(c)) {
-		return c - '0';
-	} else if (islower(c)) {
-		return c - 'a' + 10;
-	} else if (isupper(c)) {
-		return c - 'A' + 10;
-	}
-	return INT_MAX;
-}
-
-/*
- * FIXME: workaround for GCC "optimizing" the overflow check
- * into soft-emulated 128b multiplication using `__multi3`,
- * which we don't currently implement.
- */
-__attribute__((noinline)) static uintmax_t _max_value(int base)
-{
-	return UINTMAX_MAX / base;
-}
-
-static inline int _prefixbase(const char *restrict *nptrptr, bool nonstd)
-{
-	const char *nptr = *nptrptr;
-
-	if (nptr[0] != '0')
-		return 10;
-
-	if (nptr[1] == 'x' || nptr[1] == 'X') {
-		if (_digit_value(nptr[2]) < 16) {
-			*nptrptr += 2;
-			return 16;
-		}
-	}
-
-	if (nonstd) {
-		switch (nptr[1]) {
-		case 'b':
-		case 'B':
-			if (_digit_value(nptr[2]) < 2) {
-				*nptrptr += 2;
-				return 2;
-			}
-			break;
-		case 'o':
-		case 'O':
-			if (_digit_value(nptr[2]) < 8) {
-				*nptrptr += 2;
-				return 8;
-			}
-			break;
-		case 'd':
-		case 'D':
-		case 't':
-		case 'T':
-			if (_digit_value(nptr[2]) < 10) {
-				*nptrptr += 2;
-				return 10;
-			}
-			break;
-		}
-	}
-
-	return 8;
-}
-
-static inline uintmax_t _strtoumax(
-    const char *restrict nptr, char **restrict endptr, int base,
-    bool *restrict sgn, errno_t *err, bool nonstd)
-{
-	assert(nptr != NULL);
-	assert(sgn != NULL);
-
-	const char *first = nptr;
-
-	/* Skip leading whitespace. */
-
-	while (isspace(*nptr)) {
-		nptr++;
-	}
-
-	/* Parse sign, if any. */
-
-	switch (*nptr) {
-	case '-':
-		*sgn = true;
-		nptr++;
-		break;
-	case '+':
-		nptr++;
-		break;
-	}
-
-	/* Figure out the base. */
-
-	if (base == 0)
-		base = _prefixbase(&nptr, nonstd);
-
-	if (base == 16 && !nonstd) {
-		/*
-		 * Standard strto* functions allow hexadecimal prefix to be
-		 * present when base is explicitly set to 16.
-		 * Our nonstandard str_* functions don't allow it.
-		 * I don't know if that is intended, just matching the original
-		 * functionality here.
-		 */
-
-		if (nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X') &&
-		    _digit_value(nptr[2]) < base)
-			nptr += 2;
-	}
-
-	if (base < 2 || base > 36) {
-		*err = EINVAL;
-		return 0;
-	}
-
-	/* Must be at least one digit. */
-
-	if (_digit_value(*nptr) >= base) {
-		/* No digits on input. */
-		if (endptr != NULL)
-			*endptr = (char *) first;
-		return 0;
-	}
-
-	/* Read the value.  */
-
-	uintmax_t result = 0;
-	uintmax_t max = _max_value(base);
-	int digit;
-
-	while (digit = _digit_value(*nptr), digit < base) {
-		if (result > max ||
-		    __builtin_add_overflow(result * base, digit, &result)) {
-
-			*err = nonstd ? EOVERFLOW : ERANGE;
-			result = UINTMAX_MAX;
-			break;
-		}
-
-		nptr++;
-	}
-
-	/* Set endptr. */
-
-	if (endptr != NULL) {
-		/*
-		 * Move the pointer to the end of the number,
-		 * in case it isn't there already.
-		 * This can happen when the number has legal formatting,
-		 * but is out of range of the target type.
-		 */
-		while (_digit_value(*nptr) < base) {
-			nptr++;
-		}
-
-		*endptr = (char *) nptr;
-	}
-
-	return result;
-}
-
-static inline uintmax_t _strtounsigned(const char *nptr, char **endptr, int base,
-    uintmax_t max, errno_t *err, bool nonstd)
-{
-	bool sgn = false;
-	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn, err, nonstd);
-
-	if (nonstd && sgn) {
-		/* Do not allow negative values */
-		*err = EINVAL;
-		return 0;
-	}
-
-	if (number > max) {
-		*err = nonstd ? EOVERFLOW : ERANGE;
-		return max;
-	}
-
-	return (sgn ? -number : number);
-}
-
-/** Convert string to uint64_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_uint64_t(const char *nptr, char **endptr, unsigned int base,
-    bool strict, uint64_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT64_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** @}
- */
Index: kernel/generic/src/main/kinit.c
===================================================================
--- kernel/generic/src/main/kinit.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ kernel/generic/src/main/kinit.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -69,4 +69,5 @@
 #include <ipc/ipc.h>
 #include <str.h>
+#include <str_error.h>
 #include <sysinfo/stats.h>
 #include <sysinfo/sysinfo.h>
Index: kernel/generic/src/mm/backend_user.c
===================================================================
--- kernel/generic/src/mm/backend_user.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ kernel/generic/src/mm/backend_user.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -50,4 +50,5 @@
 #include <log.h>
 #include <str.h>
+#include <str_error.h>
 
 static bool user_create(as_area_t *);
Index: kernel/generic/src/proc/program.c
===================================================================
--- kernel/generic/src/proc/program.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ kernel/generic/src/proc/program.c	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -49,4 +49,5 @@
 #include <lib/elf_load.h>
 #include <str.h>
+#include <str_error.h>
 #include <log.h>
 #include <syscall/copy.h>
Index: pace/lib/c/generic/ctype.c
===================================================================
--- uspace/lib/c/generic/ctype.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,126 +1,0 @@
-/*
- * Copyright (c) 2006 Josef Cejka
- * 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 <ctype.h>
-
-int islower(int c)
-{
-	return ((c >= 'a') && (c <= 'z'));
-}
-
-int isupper(int c)
-{
-	return ((c >= 'A') && (c <= 'Z'));
-}
-
-int isalpha(int c)
-{
-	return (islower(c) || isupper(c));
-}
-
-int isdigit(int c)
-{
-	return ((c >= '0') && (c <= '9'));
-}
-
-int isalnum(int c)
-{
-	return (isalpha(c) || isdigit(c));
-}
-
-int isblank(int c)
-{
-	return c == ' ' || c == '\t';
-}
-
-int iscntrl(int c)
-{
-	return (c >= 0 && c < 0x20) || c == 0x7E;
-}
-
-int isprint(int c)
-{
-	return c >= 0 && c < 0x80 && !iscntrl(c);
-}
-
-int isgraph(int c)
-{
-	return isprint(c) && c != ' ';
-}
-
-int isspace(int c)
-{
-	switch (c) {
-	case ' ':
-	case '\n':
-	case '\t':
-	case '\f':
-	case '\r':
-	case '\v':
-		return 1;
-	default:
-		return 0;
-	}
-}
-
-int ispunct(int c)
-{
-	return !isspace(c) && !isalnum(c) && isprint(c);
-}
-
-int isxdigit(int c)
-{
-	return isdigit(c) ||
-	    (c >= 'a' && c <= 'f') ||
-	    (c >= 'A' && c <= 'F');
-}
-
-int tolower(int c)
-{
-	if (isupper(c))
-		return (c + ('a' - 'A'));
-	else
-		return c;
-}
-
-int toupper(int c)
-{
-	if (islower(c))
-		return (c + ('A' - 'a'));
-	else
-		return c;
-}
-
-/** @}
- */
Index: pace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,1548 +1,0 @@
-/*
- * 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.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-
-/**
- * @file
- * @brief 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 char32_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 char32_t
- *                        (unsigned 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,
- *                        char32_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 *, char32_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 <align.h>
-#include <mem.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.
- *
- */
-char32_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;
-
-	char32_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) | (char32_t) (b & LO_MASK_8(CONT_BITS));
-		cbytes--;
-	}
-
-	return ch;
-}
-
-/** Decode a single character from a string to the left.
- *
- * 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 previous
- * character. In case of decoding error, offset generally decreases at least
- * by one. However, offset is never moved before 0.
- *
- * @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 start of str.
- *
- */
-char32_t str_decode_reverse(const char *str, size_t *offset, size_t size)
-{
-	if (*offset == 0)
-		return 0;
-
-	size_t processed = 0;
-	/* Continue while continuation bytes found */
-	while (*offset > 0 && processed < 4) {
-		uint8_t b = (uint8_t) str[--(*offset)];
-
-		if (processed == 0 && (b & 0x80) == 0) {
-			/* 0xxxxxxx (Plain ASCII) */
-			return b & 0x7f;
-		} else if ((b & 0xe0) == 0xc0 || (b & 0xf0) == 0xe0 ||
-		    (b & 0xf8) == 0xf0) {
-			/* Start byte */
-			size_t start_offset = *offset;
-			return str_decode(str, &start_offset, size);
-		} else if ((b & 0xc0) != 0x80) {
-			/* Not a continuation byte */
-			return U_SPECIAL;
-		}
-		processed++;
-	}
-	/* Too many continuation bytes */
-	return U_SPECIAL;
-}
-
-/** 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.
- */
-errno_t chr_encode(const char32_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 char32_t *str)
-{
-	return (wstr_length(str) * sizeof(char32_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 string with size limit.
- *
- * Get the number of bytes which are used by the string @a str
- * (excluding the NULL-terminator), but no more than @max_size bytes.
- *
- * @param str      String to consider.
- * @param max_size Maximum number of bytes to measure.
- *
- * @return Number of bytes used by the string
- *
- */
-size_t str_nsize(const char *str, size_t max_size)
-{
-	size_t size = 0;
-
-	while ((*str++ != 0) && (size < max_size))
-		size++;
-
-	return size;
-}
-
-/** Get size of wide string with size limit.
- *
- * Get the number of bytes which are used by the wide string @a str
- * (excluding the NULL-terminator), but no more than @max_size bytes.
- *
- * @param str      Wide string to consider.
- * @param max_size Maximum number of bytes to measure.
- *
- * @return Number of bytes used by the wide string
- *
- */
-size_t wstr_nsize(const char32_t *str, size_t max_size)
-{
-	return (wstr_nlength(str, max_size) * sizeof(char32_t));
-}
-
-/** 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 char32_t *str, size_t max_len)
-{
-	return (wstr_nlength(str, max_len * sizeof(char32_t)) * sizeof(char32_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 char32_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 char32_t *str, size_t size)
-{
-	size_t len = 0;
-	size_t limit = ALIGN_DOWN(size, sizeof(char32_t));
-	size_t offset = 0;
-
-	while ((offset < limit) && (*str++ != 0)) {
-		len++;
-		offset += sizeof(char32_t);
-	}
-
-	return len;
-}
-
-/** Get character display width on a character cell display.
- *
- * @param ch	Character
- * @return	Width of character in cells.
- */
-size_t chr_width(char32_t ch)
-{
-	return 1;
-}
-
-/** Get string display width on a character cell display.
- *
- * @param str	String
- * @return	Width of string in cells.
- */
-size_t str_width(const char *str)
-{
-	size_t width = 0;
-	size_t offset = 0;
-	char32_t ch;
-
-	while ((ch = str_decode(str, &offset, STR_NO_LIMIT)) != 0)
-		width += chr_width(ch);
-
-	return width;
-}
-
-/** Check whether character is plain ASCII.
- *
- * @return True if character is plain ASCII.
- *
- */
-bool ascii_check(char32_t ch)
-{
-	if (ch <= 127)
-		return true;
-
-	return false;
-}
-
-/** Check whether character is valid
- *
- * @return True if character is a valid Unicode code point.
- *
- */
-bool chr_check(char32_t ch)
-{
-	if (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 their length is equal
- * and both strings consist of the same sequence of characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_cmp(const char *s1, const char *s2)
-{
-	char32_t c1 = 0;
-	char32_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
- * min(str_length(s1), max_len) == min(str_length(s2), max_len)
- * and both strings consist of the same sequence of characters,
- * up to max_len characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero. Only the first max_len
- * characters are considered.
- *
- * @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 the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_lcmp(const char *s1, const char *s2, size_t max_len)
-{
-	char32_t c1 = 0;
-	char32_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;
-
-}
-
-/** Compare two NULL terminated strings in case-insensitive manner.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff their length is equal
- * and both strings consist of the same sequence of characters
- * when converted to lower case.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero.
- *
- * @param s1 First string to compare.
- * @param s2 Second string to compare.
- *
- * @return 0 if the strings are equal, -1 if the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_casecmp(const char *s1, const char *s2)
-{
-	char32_t c1 = 0;
-	char32_t c2 = 0;
-
-	size_t off1 = 0;
-	size_t off2 = 0;
-
-	while (true) {
-		c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
-		c2 = tolower(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 in case-insensitive
- * manner.
- *
- * Do a char-by-char comparison of two NULL-terminated strings.
- * The strings are considered equal iff
- * min(str_length(s1), max_len) == min(str_length(s2), max_len)
- * and both strings consist of the same sequence of characters,
- * up to max_len characters.
- *
- * A string S1 is less than another string S2 if it has a character with
- * lower value at the first character position where the strings differ.
- * If the strings differ in length, the shorter one is treated as if
- * padded by characters with a value of zero. Only the first max_len
- * characters are considered.
- *
- * @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 the first is less than the second,
- *         1 if the second is less than the first.
- *
- */
-int str_lcasecmp(const char *s1, const char *s2, size_t max_len)
-{
-	char32_t c1 = 0;
-	char32_t c2 = 0;
-
-	size_t off1 = 0;
-	size_t off2 = 0;
-
-	size_t len = 0;
-
-	while (true) {
-		if (len >= max_len)
-			break;
-
-		c1 = tolower(str_decode(s1, &off1, STR_NO_LIMIT));
-		c2 = tolower(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;
-
-}
-
-/** Test whether p is a prefix of s.
- *
- * Do a char-by-char comparison of two NULL-terminated strings
- * and determine if p is a prefix of s.
- *
- * @param s The string in which to look
- * @param p The string to check if it is a prefix of s
- *
- * @return true iff p is prefix of s else false
- *
- */
-bool str_test_prefix(const char *s, const char *p)
-{
-	char32_t c1 = 0;
-	char32_t c2 = 0;
-
-	size_t off1 = 0;
-	size_t off2 = 0;
-
-	while (true) {
-		c1 = str_decode(s, &off1, STR_NO_LIMIT);
-		c2 = str_decode(p, &off2, STR_NO_LIMIT);
-
-		if (c2 == 0)
-			return true;
-
-		if (c1 != c2)
-			return false;
-
-		if (c1 == 0)
-			break;
-	}
-
-	return false;
-}
-
-/** Get a string suffix.
- *
- * Return a string suffix defined by the prefix length.
- *
- * @param s             The string to get the suffix from.
- * @param prefix_length Number of prefix characters to ignore.
- *
- * @return String suffix.
- *
- */
-const char *str_suffix(const char *s, size_t prefix_length)
-{
-	size_t off = 0;
-	size_t i = 0;
-
-	while (true) {
-		str_decode(s, &off, STR_NO_LIMIT);
-		i++;
-
-		if (i >= prefix_length)
-			break;
-	}
-
-	return s + off;
-}
-
-/** 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)
-{
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	assert(src != NULL);
-
-	size_t src_off = 0;
-	size_t dest_off = 0;
-
-	char32_t ch;
-	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)
-{
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-
-	size_t src_off = 0;
-	size_t dest_off = 0;
-
-	char32_t ch;
-	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);
-	if (dstr_size >= size)
-		return;
-
-	str_cpy(dest + dstr_size, size - dstr_size, src);
-}
-
-/** Convert space-padded ASCII to string.
- *
- * Common legacy text encoding in hardware is 7-bit ASCII fitted into
- * a fixed-width byte buffer (bit 7 always zero), right-padded with spaces
- * (ASCII 0x20). Convert space-padded ascii to string representation.
- *
- * If the text does not fit into the destination buffer, the function converts
- * as many characters as possible and returns EOVERFLOW.
- *
- * If the text contains non-ASCII bytes (with bit 7 set), the whole string is
- * converted anyway and invalid characters are replaced with question marks
- * (U_SPECIAL) and the function returns EIO.
- *
- * Regardless of return value upon return @a dest will always be well-formed.
- *
- * @param dest		Destination buffer
- * @param size		Size of destination buffer
- * @param src		Space-padded ASCII.
- * @param n		Size of the source buffer in bytes.
- *
- * @return		EOK on success, EOVERFLOW if the text does not fit
- *			destination buffer, EIO if the text contains
- *			non-ASCII bytes.
- */
-errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n)
-{
-	size_t sidx;
-	size_t didx;
-	size_t dlast;
-	uint8_t byte;
-	errno_t rc;
-	errno_t result;
-
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-	result = EOK;
-
-	didx = 0;
-	dlast = 0;
-	for (sidx = 0; sidx < n; ++sidx) {
-		byte = src[sidx];
-		if (!ascii_check(byte)) {
-			byte = U_SPECIAL;
-			result = EIO;
-		}
-
-		rc = chr_encode(byte, dest, &didx, size - 1);
-		if (rc != EOK) {
-			assert(rc == EOVERFLOW);
-			dest[didx] = '\0';
-			return rc;
-		}
-
-		/* Remember dest index after last non-empty character */
-		if (byte != 0x20)
-			dlast = didx;
-	}
-
-	/* Terminate string after last non-empty character */
-	dest[dlast] = '\0';
-	return result;
-}
-
-/** 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 char32_t *src)
-{
-	char32_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 UTF16 string to string.
- *
- * Convert utf16 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. Surrogate pairs also supported.
- *
- * @param dest	Destination buffer.
- * @param size	Size of the destination buffer.
- * @param src	Source utf16 string.
- *
- * @return EOK, if success, an error code otherwise.
- */
-errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src)
-{
-	size_t idx = 0, dest_off = 0;
-	char32_t ch;
-	errno_t rc = EOK;
-
-	/* There must be space for a null terminator in the buffer. */
-	assert(size > 0);
-
-	while (src[idx]) {
-		if ((src[idx] & 0xfc00) == 0xd800) {
-			if (src[idx + 1] && (src[idx + 1] & 0xfc00) == 0xdc00) {
-				ch = 0x10000;
-				ch += (src[idx] & 0x03FF) << 10;
-				ch += (src[idx + 1] & 0x03FF);
-				idx += 2;
-			} else
-				break;
-		} else {
-			ch = src[idx];
-			idx++;
-		}
-		rc = chr_encode(ch, dest, &dest_off, size - 1);
-		if (rc != EOK)
-			break;
-	}
-	dest[dest_off] = '\0';
-	return rc;
-}
-
-/** Convert string to UTF16 string.
- *
- * Convert string @a src to utf16 string. The output is written to the buffer
- * specified by @a dest and @a dlen. @a dlen must be non-zero and the string
- * written will always be well-formed. Surrogate pairs also supported.
- *
- * @param dest	Destination buffer.
- * @param dlen	Number of utf16 characters that fit in the destination buffer.
- * @param src	Source string.
- *
- * @return EOK, if success, an error code otherwise.
- */
-errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src)
-{
-	errno_t rc = EOK;
-	size_t offset = 0;
-	size_t idx = 0;
-	char32_t c;
-
-	assert(dlen > 0);
-
-	while ((c = str_decode(src, &offset, STR_NO_LIMIT)) != 0) {
-		if (c > 0x10000) {
-			if (idx + 2 >= dlen - 1) {
-				rc = EOVERFLOW;
-				break;
-			}
-			c = (c - 0x10000);
-			dest[idx] = 0xD800 | (c >> 10);
-			dest[idx + 1] = 0xDC00 | (c & 0x3FF);
-			idx++;
-		} else {
-			dest[idx] = c;
-		}
-
-		idx++;
-		if (idx >= dlen - 1) {
-			rc = EOVERFLOW;
-			break;
-		}
-	}
-
-	dest[idx] = '\0';
-	return rc;
-}
-
-/** Get size of UTF-16 string.
- *
- * Get the number of words which are used by the UTF-16 string @a ustr
- * (excluding the NULL-terminator).
- *
- * @param ustr UTF-16 string to consider.
- *
- * @return Number of words used by the UTF-16 string
- *
- */
-size_t utf16_wsize(const uint16_t *ustr)
-{
-	size_t wsize = 0;
-
-	while (*ustr++ != 0)
-		wsize++;
-
-	return wsize;
-}
-
-/** 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 char32_t *src)
-{
-	char dbuf[STR_BOUNDS(1)];
-	char *str;
-	char32_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(char32_t *dest, size_t dlen, const char *src)
-{
-	size_t offset;
-	size_t di;
-	char32_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';
-}
-
-/** Convert string to wide string.
- *
- * Convert string @a src to wide string. A new wide NULL-terminated
- * string will be allocated on the heap.
- *
- * @param src	Source string.
- */
-char32_t *str_to_awstr(const char *str)
-{
-	size_t len = str_length(str);
-
-	char32_t *wstr = calloc(len + 1, sizeof(char32_t));
-	if (wstr == NULL)
-		return NULL;
-
-	str_to_wstr(wstr, len + 1, str);
-	return wstr;
-}
-
-/** 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, char32_t ch)
-{
-	char32_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 first occurence of substring in string.
- *
- * @param hs  Haystack (string)
- * @param n   Needle (substring to look for)
- *
- * @return Pointer to character in @a hs or @c NULL if not found.
- */
-char *str_str(const char *hs, const char *n)
-{
-	size_t off = 0;
-
-	if (str_lcmp(hs, n, str_length(n)) == 0)
-		return (char *)hs;
-
-	while (str_decode(hs, &off, STR_NO_LIMIT) != 0) {
-		if (str_lcmp(hs + off, n, str_length(n)) == 0)
-			return (char *)(hs + off);
-	}
-
-	return NULL;
-}
-
-/** Removes specified trailing characters from a string.
- *
- * @param str String to remove from.
- * @param ch  Character to remove.
- */
-void str_rtrim(char *str, char32_t ch)
-{
-	size_t off = 0;
-	size_t pos = 0;
-	char32_t c;
-	bool update_last_chunk = true;
-	char *last_chunk = NULL;
-
-	while ((c = str_decode(str, &off, STR_NO_LIMIT))) {
-		if (c != ch) {
-			update_last_chunk = true;
-			last_chunk = NULL;
-		} else if (update_last_chunk) {
-			update_last_chunk = false;
-			last_chunk = (str + pos);
-		}
-		pos = off;
-	}
-
-	if (last_chunk)
-		*last_chunk = '\0';
-}
-
-/** Removes specified leading characters from a string.
- *
- * @param str String to remove from.
- * @param ch  Character to remove.
- */
-void str_ltrim(char *str, char32_t ch)
-{
-	char32_t acc;
-	size_t off = 0;
-	size_t pos = 0;
-	size_t str_sz = str_size(str);
-
-	while ((acc = str_decode(str, &off, STR_NO_LIMIT)) != 0) {
-		if (acc != ch)
-			break;
-		else
-			pos = off;
-	}
-
-	if (pos > 0) {
-		memmove(str, &str[pos], str_sz - pos);
-		pos = str_sz - pos;
-		str[pos] = '\0';
-	}
-}
-
-/** 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, char32_t ch)
-{
-	char32_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(char32_t *str, char32_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(char32_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.
- *
- * Allocate a new string and copy characters from the source
- * string into it. The duplicate string is allocated via sleeping
- * malloc(), thus this function can sleep in no memory conditions.
- *
- * The allocation cannot fail and the return value is always
- * a valid pointer. The duplicate string is always a well-formed
- * null-terminated UTF-8 string, but it can differ from the source
- * string on the byte level.
- *
- * @param src Source string.
- *
- * @return Duplicate string.
- *
- */
-char *str_dup(const char *src)
-{
-	size_t size = str_size(src) + 1;
-	char *dest = malloc(size);
-	if (!dest)
-		return NULL;
-
-	str_cpy(dest, size, src);
-	return dest;
-}
-
-/** Duplicate string with size limit.
- *
- * Allocate a new string and copy up to @max_size bytes from the source
- * string into it. The duplicate string is allocated via sleeping
- * malloc(), thus this function can sleep in no memory conditions.
- * No more than @max_size + 1 bytes is allocated, but if the size
- * occupied by the source string is smaller than @max_size + 1,
- * less is allocated.
- *
- * The allocation cannot fail and the return value is always
- * a valid pointer. The duplicate string is always a well-formed
- * null-terminated UTF-8 string, but it can differ from the source
- * string on the byte level.
- *
- * @param src Source string.
- * @param n   Maximum number of bytes to duplicate.
- *
- * @return Duplicate string.
- *
- */
-char *str_ndup(const char *src, size_t n)
-{
-	size_t size = str_size(src);
-	if (size > n)
-		size = n;
-
-	char *dest = malloc(size + 1);
-	if (!dest)
-		return NULL;
-
-	str_ncpy(dest, size + 1, src, size);
-	return dest;
-}
-
-/** Split string by delimiters.
- *
- * @param s             String to be tokenized. May not be NULL.
- * @param delim		String with the delimiters.
- * @param next		Variable which will receive the pointer to the
- *                      continuation of the string following the first
- *                      occurrence of any of the delimiter characters.
- *                      May be NULL.
- * @return              Pointer to the prefix of @a s before the first
- *                      delimiter character. NULL if no such prefix
- *                      exists.
- */
-char *str_tok(char *s, const char *delim, char **next)
-{
-	char *start, *end;
-
-	if (!s)
-		return NULL;
-
-	size_t len = str_size(s);
-	size_t cur;
-	size_t tmp;
-	char32_t ch;
-
-	/* Skip over leading delimiters. */
-	tmp = 0;
-	cur = 0;
-	while ((ch = str_decode(s, &tmp, len)) && str_chr(delim, ch))
-		cur = tmp;
-	start = &s[cur];
-
-	/* Skip over token characters. */
-	tmp = cur;
-	while ((ch = str_decode(s, &tmp, len)) && !str_chr(delim, ch))
-		cur = tmp;
-	end = &s[cur];
-	if (next)
-		*next = (ch ? &s[tmp] : &s[cur]);
-
-	if (start == end)
-		return NULL;	/* No more tokens. */
-
-	/* Overwrite delimiter with NULL terminator. */
-	*end = '\0';
-	return start;
-}
-
-void order_suffix(const uint64_t val, uint64_t *rv, char *suffix)
-{
-	if (val > UINT64_C(10000000000000000000)) {
-		*rv = val / UINT64_C(1000000000000000000);
-		*suffix = 'Z';
-	} else if (val > UINT64_C(1000000000000000000)) {
-		*rv = val / UINT64_C(1000000000000000);
-		*suffix = 'E';
-	} else if (val > UINT64_C(1000000000000000)) {
-		*rv = val / UINT64_C(1000000000000);
-		*suffix = 'T';
-	} else if (val > UINT64_C(1000000000000)) {
-		*rv = val / UINT64_C(1000000000);
-		*suffix = 'G';
-	} else if (val > UINT64_C(1000000000)) {
-		*rv = val / UINT64_C(1000000);
-		*suffix = 'M';
-	} else if (val > UINT64_C(1000000)) {
-		*rv = val / UINT64_C(1000);
-		*suffix = 'k';
-	} else {
-		*rv = val;
-		*suffix = ' ';
-	}
-}
-
-void bin_order_suffix(const uint64_t val, uint64_t *rv, const char **suffix,
-    bool fixed)
-{
-	if (val > UINT64_C(1152921504606846976)) {
-		*rv = val / UINT64_C(1125899906842624);
-		*suffix = "EiB";
-	} else if (val > UINT64_C(1125899906842624)) {
-		*rv = val / UINT64_C(1099511627776);
-		*suffix = "TiB";
-	} else if (val > UINT64_C(1099511627776)) {
-		*rv = val / UINT64_C(1073741824);
-		*suffix = "GiB";
-	} else if (val > UINT64_C(1073741824)) {
-		*rv = val / UINT64_C(1048576);
-		*suffix = "MiB";
-	} else if (val > UINT64_C(1048576)) {
-		*rv = val / UINT64_C(1024);
-		*suffix = "KiB";
-	} else {
-		*rv = val;
-		if (fixed)
-			*suffix = "B  ";
-		else
-			*suffix = "B";
-	}
-}
-
-/** @}
- */
Index: pace/lib/c/generic/str_error.c
===================================================================
--- uspace/lib/c/generic/str_error.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,117 +1,0 @@
-/*
- * Copyright (c) 2010 Martin Decky
- * Copyright (c) 2017 CZ.NIC, z.s.p.o.
- * 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 <errno.h>
-#include <str_error.h>
-#include <stdio.h>
-#include <fibril.h>
-
-#define NOERR_LEN  64
-
-/*
- * The arrays below are automatically generated from the same file that
- * errno.h constants are generated from. Triple-include of the same list
- * with redefinitions of __errno() macro are used to ensure that the
- * information cannot get out of synch. This is inpired by musl libc.
- */
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) name,
-
-static const errno_t err_num[] = {
-#include <abi/errno.in>
-};
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) #name,
-
-static const char *err_name[] = {
-#include <abi/errno.in>
-};
-
-#undef __errno_entry
-#define __errno_entry(name, num, desc) "[" #name "] " desc,
-
-static const char *err_desc[] = {
-#include <abi/errno.in>
-};
-
-static fibril_local char noerr[NOERR_LEN];
-
-/* Returns index corresponding to the given errno, or -1 if not found. */
-static int find_errno(errno_t e)
-{
-	/*
-	 * Just a dumb linear search.
-	 * There are too few entries to warrant anything smarter.
-	 */
-
-	int len = sizeof(err_num) / sizeof(errno_t);
-
-	for (int i = 0; i < len; i++) {
-		if (err_num[i] == e) {
-			return i;
-		}
-	}
-
-	return -1;
-}
-
-const char *str_error_name(errno_t e)
-{
-	int i = find_errno(e);
-
-	if (i >= 0) {
-		return err_name[i];
-	}
-
-	snprintf(noerr, NOERR_LEN, "(%d)", (int)e);
-	return noerr;
-}
-
-const char *str_error(errno_t e)
-{
-	int i = find_errno(e);
-
-	if (i >= 0) {
-		return err_desc[i];
-	}
-
-	snprintf(noerr, NOERR_LEN, "Unknown error code (%d)", (int)e);
-	return noerr;
-}
-
-/** @}
- */
Index: pace/lib/c/generic/strtol.c
===================================================================
--- uspace/lib/c/generic/strtol.c	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,538 +1,0 @@
-/*
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2008 Jiri Svoboda
- * Copyright (c) 2011 Martin Sucha
- * Copyright (c) 2011 Oleg Romanenko
- * Copyright (c) 2011 Jiri Zarevucky
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * - Redistributions of source code must retain the above copyright
- *   notice, this list of conditions and the following disclaimer.
- * - Redistributions in binary form must reproduce the above copyright
- *   notice, this list of conditions and the following disclaimer in the
- *   documentation and/or other materials provided with the distribution.
- * - The name of the author may not be used to endorse or promote products
- *   derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-/** @addtogroup libc
- * @{
- */
-/** @file
- */
-
-#include <assert.h>
-#include <ctype.h>
-#include <errno.h>
-#include <inttypes.h>
-#include <limits.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <str.h>
-
-// FIXME: The original HelenOS functions return EOVERFLOW instead
-//        of ERANGE. It's a pointless distinction from standard functions,
-//        so we should change that. Beware the callers though.
-
-// TODO: more unit tests
-
-static inline int _digit_value(int c)
-{
-	if (isdigit(c)) {
-		return c - '0';
-	} else if (islower(c)) {
-		return c - 'a' + 10;
-	} else if (isupper(c)) {
-		return c - 'A' + 10;
-	}
-	return INT_MAX;
-}
-
-/*
- * FIXME: workaround for GCC "optimizing" the overflow check
- * into soft-emulated 128b multiplication using `__multi3`,
- * which we don't currently implement.
- */
-__attribute__((noinline)) static uintmax_t _max_value(int base)
-{
-	return UINTMAX_MAX / base;
-}
-
-static inline int _prefixbase(const char *restrict *nptrptr, bool nonstd)
-{
-	const char *nptr = *nptrptr;
-
-	if (nptr[0] != '0')
-		return 10;
-
-	if (nptr[1] == 'x' || nptr[1] == 'X') {
-		if (_digit_value(nptr[2]) < 16) {
-			*nptrptr += 2;
-			return 16;
-		}
-	}
-
-	if (nonstd) {
-		switch (nptr[1]) {
-		case 'b':
-		case 'B':
-			if (_digit_value(nptr[2]) < 2) {
-				*nptrptr += 2;
-				return 2;
-			}
-			break;
-		case 'o':
-		case 'O':
-			if (_digit_value(nptr[2]) < 8) {
-				*nptrptr += 2;
-				return 8;
-			}
-			break;
-		case 'd':
-		case 'D':
-		case 't':
-		case 'T':
-			if (_digit_value(nptr[2]) < 10) {
-				*nptrptr += 2;
-				return 10;
-			}
-			break;
-		}
-	}
-
-	return 8;
-}
-
-static inline uintmax_t _strtoumax(
-    const char *restrict nptr, char **restrict endptr, int base,
-    bool *restrict sgn, errno_t *err, bool nonstd)
-{
-	assert(nptr != NULL);
-	assert(sgn != NULL);
-
-	const char *first = nptr;
-
-	/* Skip leading whitespace. */
-
-	while (isspace(*nptr)) {
-		nptr++;
-	}
-
-	/* Parse sign, if any. */
-
-	switch (*nptr) {
-	case '-':
-		*sgn = true;
-		nptr++;
-		break;
-	case '+':
-		nptr++;
-		break;
-	}
-
-	/* Figure out the base. */
-
-	if (base == 0)
-		base = _prefixbase(&nptr, nonstd);
-
-	if (base == 16 && !nonstd) {
-		/*
-		 * Standard strto* functions allow hexadecimal prefix to be
-		 * present when base is explicitly set to 16.
-		 * Our nonstandard str_* functions don't allow it.
-		 * I don't know if that is intended, just matching the original
-		 * functionality here.
-		 */
-
-		if (nptr[0] == '0' && (nptr[1] == 'x' || nptr[1] == 'X') &&
-		    _digit_value(nptr[2]) < base)
-			nptr += 2;
-	}
-
-	if (base < 2 || base > 36) {
-		*err = EINVAL;
-		return 0;
-	}
-
-	/* Must be at least one digit. */
-
-	if (_digit_value(*nptr) >= base) {
-		/* No digits on input. */
-		if (endptr != NULL)
-			*endptr = (char *) first;
-		return 0;
-	}
-
-	/* Read the value.  */
-
-	uintmax_t result = 0;
-	uintmax_t max = _max_value(base);
-	int digit;
-
-	while (digit = _digit_value(*nptr), digit < base) {
-		if (result > max ||
-		    __builtin_add_overflow(result * base, digit, &result)) {
-
-			*err = nonstd ? EOVERFLOW : ERANGE;
-			result = UINTMAX_MAX;
-			break;
-		}
-
-		nptr++;
-	}
-
-	/* Set endptr. */
-
-	if (endptr != NULL) {
-		/*
-		 * Move the pointer to the end of the number,
-		 * in case it isn't there already.
-		 * This can happen when the number has legal formatting,
-		 * but is out of range of the target type.
-		 */
-		while (_digit_value(*nptr) < base) {
-			nptr++;
-		}
-
-		*endptr = (char *) nptr;
-	}
-
-	return result;
-}
-
-static inline intmax_t _strtosigned(const char *nptr, char **endptr, int base,
-    intmax_t min, intmax_t max, errno_t *err, bool nonstd)
-{
-	bool sgn = false;
-	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn, err, nonstd);
-
-	if (number > (uintmax_t) max) {
-		if (sgn && (number - 1 == (uintmax_t) max)) {
-			return min;
-		}
-
-		*err = nonstd ? EOVERFLOW : ERANGE;
-		return (sgn ? min : max);
-	}
-
-	return (sgn ? -number : number);
-}
-
-static inline uintmax_t _strtounsigned(const char *nptr, char **endptr, int base,
-    uintmax_t max, errno_t *err, bool nonstd)
-{
-	bool sgn = false;
-	uintmax_t number = _strtoumax(nptr, endptr, base, &sgn, err, nonstd);
-
-	if (nonstd && sgn) {
-		/* Do not allow negative values */
-		*err = EINVAL;
-		return 0;
-	}
-
-	if (number > max) {
-		*err = nonstd ? EOVERFLOW : ERANGE;
-		return max;
-	}
-
-	return (sgn ? -number : number);
-}
-
-/** Convert initial part of string to long int according to given base.
- * The number may begin with an arbitrary number of whitespaces followed by
- * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
- * inserted and the number will be taken as hexadecimal one. If the base is 0
- * and the number begin with a zero, number will be taken as octal one (as with
- * base 8). Otherwise the base 0 is taken as decimal.
- *
- * @param nptr		Pointer to string.
- * @param[out] endptr	If not NULL, function stores here pointer to the first
- * 			invalid character.
- * @param base		Zero or number between 2 and 36 inclusive.
- * @return		Result of conversion.
- */
-long strtol(const char *nptr, char **endptr, int base)
-{
-	return _strtosigned(nptr, endptr, base, LONG_MIN, LONG_MAX, &errno, false);
-}
-
-/** Convert initial part of string to unsigned long according to given base.
- * The number may begin with an arbitrary number of whitespaces followed by
- * optional sign (`+' or `-'). If the base is 0 or 16, the prefix `0x' may be
- * inserted and the number will be taken as hexadecimal one. If the base is 0
- * and the number begin with a zero, number will be taken as octal one (as with
- * base 8). Otherwise the base 0 is taken as decimal.
- *
- * @param nptr		Pointer to string.
- * @param[out] endptr	If not NULL, function stores here pointer to the first
- * 			invalid character
- * @param base		Zero or number between 2 and 36 inclusive.
- * @return		Result of conversion.
- */
-unsigned long strtoul(const char *nptr, char **endptr, int base)
-{
-	return _strtounsigned(nptr, endptr, base, ULONG_MAX, &errno, false);
-}
-
-long long strtoll(const char *nptr, char **endptr, int base)
-{
-	return _strtosigned(nptr, endptr, base, LLONG_MIN, LLONG_MAX, &errno, false);
-}
-
-unsigned long long strtoull(const char *nptr, char **endptr, int base)
-{
-	return _strtounsigned(nptr, endptr, base, ULLONG_MAX, &errno, false);
-}
-
-intmax_t strtoimax(const char *nptr, char **endptr, int base)
-{
-	return _strtosigned(nptr, endptr, base, INTMAX_MIN, INTMAX_MAX, &errno, false);
-}
-
-uintmax_t strtoumax(const char *nptr, char **endptr, int base)
-{
-	return _strtounsigned(nptr, endptr, base, UINTMAX_MAX, &errno, false);
-}
-
-int atoi(const char *nptr)
-{
-	return (int)strtol(nptr, NULL, 10);
-}
-
-long atol(const char *nptr)
-{
-	return strtol(nptr, NULL, 10);
-}
-
-long long atoll(const char *nptr)
-{
-	return strtoll(nptr, NULL, 10);
-}
-
-/** Convert string to uint8_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_uint8_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, uint8_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT8_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** Convert string to uint16_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_uint16_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, uint16_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT16_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** Convert string to uint32_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_uint32_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, uint32_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT32_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** Convert string to uint64_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_uint64_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, uint64_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, UINT64_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** Convert string to int64_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_int64_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, int64_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	intmax_t r = _strtosigned(nptr, &lendptr, base, INT64_MIN, INT64_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** Convert string to size_t.
- *
- * @param nptr   Pointer to string.
- * @param endptr If not NULL, pointer to the first invalid character
- *               is stored here.
- * @param base   Zero or number between 2 and 36 inclusive.
- * @param strict Do not allow any trailing characters.
- * @param result Result of the conversion.
- *
- * @return EOK if conversion was successful.
- *
- */
-errno_t str_size_t(const char *nptr, const char **endptr, unsigned int base,
-    bool strict, size_t *result)
-{
-	assert(result != NULL);
-
-	errno_t rc = EOK;
-	char *lendptr = (char *) nptr;
-
-	uintmax_t r = _strtounsigned(nptr, &lendptr, base, SIZE_MAX, &rc, true);
-
-	if (endptr)
-		*endptr = lendptr;
-
-	if (rc != EOK)
-		return rc;
-
-	if (strict && *lendptr != '\0')
-		return EINVAL;
-
-	*result = r;
-	return EOK;
-}
-
-/** @}
- */
Index: pace/lib/c/include/ctype.h
===================================================================
--- uspace/lib/c/include/ctype.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,51 +1,0 @@
-/*
- * Copyright (c) 2006 Josef Cejka
- * 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.
- */
-
-#ifndef _LIBC_CTYPE_H_
-#define _LIBC_CTYPE_H_
-
-#include <_bits/decls.h>
-
-__C_DECLS_BEGIN;
-int islower(int);
-int isupper(int);
-int isalpha(int);
-int isdigit(int);
-int isalnum(int);
-int isblank(int);
-int iscntrl(int);
-int isprint(int);
-int isgraph(int);
-int isspace(int);
-int ispunct(int);
-int isxdigit(int);
-int tolower(int);
-int toupper(int);
-__C_DECLS_END;
-
-#endif
Index: pace/lib/c/include/str.h
===================================================================
--- uspace/lib/c/include/str.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,158 +1,0 @@
-/*
- * Copyright (c) 2001-2004 Jakub Jermar
- * Copyright (c) 2005 Martin Decky
- * Copyright (c) 2011 Oleg Romanenko
- * 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 <errno.h>
-#include <stdbool.h>
-#include <stddef.h>
-#include <stdint.h>
-
-#include <mem.h>
-#include <_bits/decls.h>
-
-#ifndef __cplusplus
-
-/* Common Unicode characters */
-#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)
-
-/**
- * Maximum size of a buffer needed to a string converted from space-padded
- * ASCII of size @a spa_size using spascii_to_str().
- */
-#define SPASCII_STR_BUFSIZE(spa_size) ((spa_size) + 1)
-
-#endif
-
-__HELENOS_DECLS_BEGIN;
-
-extern char32_t str_decode(const char *str, size_t *offset, size_t sz);
-extern char32_t str_decode_reverse(const char *str, size_t *offset, size_t sz);
-extern errno_t chr_encode(char32_t ch, char *str, size_t *offset, size_t sz);
-
-extern size_t str_size(const char *str);
-extern size_t wstr_size(const char32_t *str);
-
-extern size_t str_nsize(const char *str, size_t max_size);
-extern size_t wstr_nsize(const char32_t *str, size_t max_size);
-
-extern size_t str_lsize(const char *str, size_t max_len);
-extern size_t wstr_lsize(const char32_t *str, size_t max_len);
-
-extern size_t str_length(const char *str);
-extern size_t wstr_length(const char32_t *wstr);
-
-extern size_t str_nlength(const char *str, size_t size);
-extern size_t wstr_nlength(const char32_t *str, size_t size);
-
-extern size_t chr_width(char32_t ch);
-extern size_t str_width(const char *str);
-
-extern bool ascii_check(char32_t ch);
-extern bool chr_check(char32_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 int str_casecmp(const char *s1, const char *s2);
-extern int str_lcasecmp(const char *s1, const char *s2, size_t max_len);
-
-extern bool str_test_prefix(const char *s, const char *p);
-extern const char *str_suffix(const char *s, size_t prefix_length);
-
-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 errno_t spascii_to_str(char *dest, size_t size, const uint8_t *src, size_t n);
-extern void wstr_to_str(char *dest, size_t size, const char32_t *src);
-extern char *wstr_to_astr(const char32_t *src);
-extern void str_to_wstr(char32_t *dest, size_t dlen, const char *src);
-extern char32_t *str_to_awstr(const char *src);
-extern errno_t utf16_to_str(char *dest, size_t size, const uint16_t *src);
-extern errno_t str_to_utf16(uint16_t *dest, size_t dlen, const char *src);
-extern size_t utf16_wsize(const uint16_t *ustr);
-
-extern char *str_chr(const char *str, char32_t ch);
-extern char *str_rchr(const char *str, char32_t ch);
-extern char *str_str(const char *hs, const char *n);
-
-extern void str_rtrim(char *str, char32_t ch);
-extern void str_ltrim(char *str, char32_t ch);
-
-extern bool wstr_linsert(char32_t *str, char32_t ch, size_t pos, size_t max_pos);
-extern bool wstr_remove(char32_t *str, size_t pos);
-
-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 **);
-
-extern errno_t str_uint8_t(const char *, const char **, unsigned int, bool,
-    uint8_t *);
-extern errno_t str_uint16_t(const char *, const char **, unsigned int, bool,
-    uint16_t *);
-extern errno_t str_uint32_t(const char *, const char **, unsigned int, bool,
-    uint32_t *);
-extern errno_t str_uint64_t(const char *, const char **, unsigned int, bool,
-    uint64_t *);
-extern errno_t str_size_t(const char *, const char **, unsigned int, bool,
-    size_t *);
-extern errno_t str_int64_t(const char *, const char **, unsigned int, bool,
-    int64_t *);
-
-extern void order_suffix(const uint64_t, uint64_t *, char *);
-extern void bin_order_suffix(const uint64_t, uint64_t *, const char **, bool);
-
-/*
- * TODO: Get rid of this.
- */
-
-extern long int strtol(const char *, char **, int);
-extern unsigned long strtoul(const char *, char **, int);
-
-__HELENOS_DECLS_END;
-
-#endif
-
-/** @}
- */
Index: pace/lib/c/include/str_error.h
===================================================================
--- uspace/lib/c/include/str_error.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ 	(revision )
@@ -1,46 +1,0 @@
-/*
- * Copyright (c) 2010 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_STRERROR_H_
-#define _LIBC_STRERROR_H_
-
-#include <errno.h>
-
-const char *str_error(errno_t);
-const char *str_error_name(errno_t);
-
-#endif
-
-/** @}
- */
Index: uspace/lib/c/meson.build
===================================================================
--- uspace/lib/c/meson.build	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ uspace/lib/c/meson.build	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -61,8 +61,12 @@
 
 src += files(
+	'common/stdc/ctype.c',
 	'common/stdc/mem.c',
 	'common/stdc/bsearch.c',
 	'common/stdc/qsort.c',
 	'common/stdc/calloc.c',
+	'common/str.c',
+	'common/str_error.c',
+	'common/strtol.c',
 
 	'generic/libc.c',
@@ -75,5 +79,4 @@
 	'generic/context.c',
 	'generic/corecfg.c',
-	'generic/ctype.c',
 	'generic/device/clock_dev.c',
 	'generic/device/hw_res.c',
@@ -91,8 +94,5 @@
 	'generic/ipc_test.c',
 	'generic/loc.c',
-	'generic/str.c',
 	'generic/string.c',
-	'generic/str_error.c',
-	'generic/strtol.c',
 	'generic/l18n/langs.c',
 	'generic/pcb.c',
Index: uspace/lib/posix/include/posix/ctype.h
===================================================================
--- uspace/lib/posix/include/posix/ctype.h	(revision 44e85413b5db9e8d690890c835ecbdf8ec078d8e)
+++ uspace/lib/posix/include/posix/ctype.h	(revision fdfb24eeffcfac57ce3048026b204ef70bf13003)
@@ -37,5 +37,5 @@
 #define POSIX_CTYPE_H_
 
-#include <libc/ctype.h>
+#include <common/ctype.h>
 
 __C_DECLS_BEGIN;
