src/common.[ch]: Implement "strtolower" and "strtolower_copy".
[collection4.git] / src / common.c
index 2b6b5eb..4916b3c 100644 (file)
@@ -3,6 +3,7 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <string.h>
+#include <ctype.h>
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -190,4 +191,25 @@ int print_debug (const char *format, ...) /* {{{ */
   return (status);
 } /* }}} int print_debug */
 
+char *strtolower (char *str) /* {{{ */
+{
+  unsigned int i;
+
+  if (str == NULL)
+    return (NULL);
+
+  for (i = 0; str[i] != 0; i++)
+    str[i] = (char) tolower ((int) str[i]);
+
+  return (str);
+} /* }}} char *strtolower */
+
+char *strtolower_copy (const char *str)
+{
+  if (str == NULL)
+    return (NULL);
+
+  return (strdup (str));
+}
+
 /* vim: set sw=2 sts=2 et fdm=marker : */