Index: uspace/lib/c/Makefile
===================================================================
--- uspace/lib/c/Makefile	(revision 838ea8aa268ce5aa4f3d613a136463c7e1e46857)
+++ uspace/lib/c/Makefile	(revision 6c34be69eef6e892de7663ec0a2bacb932d8c72d)
@@ -176,5 +176,6 @@
 	test/main.c \
 	test/odict.c \
-	test/sprintf.c
+	test/sprintf.c \
+	test/str.c
 
 include $(USPACE_PREFIX)/Makefile.common
Index: uspace/lib/c/generic/str.c
===================================================================
--- uspace/lib/c/generic/str.c	(revision 838ea8aa268ce5aa4f3d613a136463c7e1e46857)
+++ uspace/lib/c/generic/str.c	(revision 6c34be69eef6e892de7663ec0a2bacb932d8c72d)
@@ -1157,5 +1157,5 @@
 		memmove(str, &str[pos], str_sz - pos);
 		pos = str_sz - pos;
-		str[str_sz - pos] = '\0';
+		str[pos] = '\0';
 	}
 }
@@ -1250,5 +1250,5 @@
 }
 
-/** Convert string to a number. 
+/** Convert string to a number.
  * Core of strtol and strtoul functions.
  *
@@ -1296,5 +1296,5 @@
 				str += 2;
 			}
-		} 
+		}
 	}
 	
@@ -1335,5 +1335,5 @@
 		*endptr = (char *) str;
 
-	if (nptr == str) { 
+	if (nptr == str) {
 		/*FIXME: errno = EINVAL*/
 		return 0;
@@ -1366,8 +1366,8 @@
 		if ((sgn) && (number == (unsigned long) (LONG_MAX) + 1)) {
 			/* FIXME: set 0 to errno */
-			return number;		
+			return number;
 		}
 		/* FIXME: set ERANGE to errno */
-		return (sgn ? LONG_MIN : LONG_MAX);	
+		return (sgn ? LONG_MIN : LONG_MAX);
 	}
 	
Index: uspace/lib/c/test/main.c
===================================================================
--- uspace/lib/c/test/main.c	(revision 838ea8aa268ce5aa4f3d613a136463c7e1e46857)
+++ uspace/lib/c/test/main.c	(revision 6c34be69eef6e892de7663ec0a2bacb932d8c72d)
@@ -34,4 +34,5 @@
 PCUT_IMPORT(odict);
 PCUT_IMPORT(sprintf);
+PCUT_IMPORT(str);
 
 PCUT_MAIN()
Index: uspace/lib/c/test/str.c
===================================================================
--- uspace/lib/c/test/str.c	(revision 6c34be69eef6e892de7663ec0a2bacb932d8c72d)
+++ uspace/lib/c/test/str.c	(revision 6c34be69eef6e892de7663ec0a2bacb932d8c72d)
@@ -0,0 +1,88 @@
+/*
+ * Copyright (c) 2015 Michal Koutny
+ * 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 <stdio.h>
+#include <str.h>
+#include <pcut/pcut.h>
+
+#define BUFFER_SIZE 256
+
+#define SET_BUFFER(str) snprintf(buffer, BUFFER_SIZE, "%s", str)
+#define EQ(expected, value) PCUT_ASSERT_STR_EQUALS(expected, value)
+
+
+
+PCUT_INIT
+
+PCUT_TEST_SUITE(str);
+
+static char buffer[BUFFER_SIZE];
+
+PCUT_TEST_BEFORE {
+	memset(buffer, 0, BUFFER_SIZE);
+}
+
+
+PCUT_TEST(rtrim) {
+	SET_BUFFER("foobar");
+	str_rtrim(buffer, ' ');
+	EQ("foobar", buffer);
+
+	SET_BUFFER("  foobar  ");
+	str_rtrim(buffer, ' ');
+	EQ("  foobar", buffer);
+
+	SET_BUFFER("  ššš  ");
+	str_rtrim(buffer, ' ');
+	EQ("  ššš", buffer);
+
+	SET_BUFFER("ššAAAšš");
+	str_rtrim(buffer, L'š');
+	EQ("ššAAA", buffer);
+}
+
+PCUT_TEST(ltrim) {
+	SET_BUFFER("foobar");
+	str_ltrim(buffer, ' ');
+	EQ("foobar", buffer);
+
+	SET_BUFFER("  foobar  ");
+	str_ltrim(buffer, ' ');
+	EQ("foobar  ", buffer);
+
+	SET_BUFFER("  ššš  ");
+	str_ltrim(buffer, ' ');
+	EQ("ššš  ", buffer);
+
+	SET_BUFFER("ššAAAšš");
+	str_ltrim(buffer, L'š');
+	EQ("AAAšš", buffer);
+}
+
+
+PCUT_EXPORT(str);
