rewrite the device subsystem interfaces (#48)
[lunaix-os.git] / lunaix-os / libs / klibc / string / trim.c
index 82f29bd717ead44bcaddd5dd4c9fc6927a211a4c..82fbacc8622b85b642fe414874af3738d82a3a29 100644 (file)
@@ -1,13 +1,14 @@
 #include <klibc/string.h>
+#include <lunaix/compiler.h>
 
 #define WS_CHAR(c)                                                             \
     (c == ' ' || c == '\t' || c == '\n' || c == '\f' || c == '\v' || c == '\r')
 
-void
+void _weak
 strrtrim(char* str)
 {
-    size_t l = strlen(str);
-    while (l < (size_t)-1) {
+    unsigned long l = strlen(str);
+    while (l < (unsigned long)-1) {
         char c = str[l];
         if (!c || WS_CHAR(c)) {
             l--;
@@ -18,12 +19,16 @@ strrtrim(char* str)
     str[l + 1] = '\0';
 }
 
-void*
+char* _weak
 strltrim_safe(char* str)
 {
-    size_t l = 0;
+    unsigned long l = 0;
     char c = 0;
-    while ((c = str[l++]) && WS_CHAR(c))
-        ;
-    return strcpy(str, str + l);
+    while ((c = str[l]) && WS_CHAR(c)) {
+        l++;
+    }
+
+    if (l)
+        strcpy(str, str + l);
+    return str;
 }
\ No newline at end of file