taskfs fix up, minor refactoring
[lunaix-os.git] / lunaix-os / libs / klibc / string / strcpy.c
index 86032d91ec03dbceab54e2e3ecc5bb14258c19c8..400aeec4ae1c52ade64a890db2a41ab5ebdd5a48 100644 (file)
@@ -1,6 +1,7 @@
 #include <klibc/string.h>
 #include <klibc/string.h>
+#include <lunaix/compiler.h>
 
 
-char*
+char* _weak
 strcpy(char* dest, const char* src)
 {
     char c;
 strcpy(char* dest, const char* src)
 {
     char c;
@@ -13,14 +14,26 @@ strcpy(char* dest, const char* src)
     return &dest[i];
 }
 
     return &dest[i];
 }
 
-char*
+/**
+ * @brief strcpy with constrain on numbers of character.
+ *        this version is smarter than stdc, it will automatically
+ *        handle the null-terminator.
+ * 
+ * @param dest 
+ * @param src 
+ * @param n 
+ * @return char* 
+ */
+char* _weak
 strncpy(char* dest, const char* src, unsigned long n)
 {
 strncpy(char* dest, const char* src, unsigned long n)
 {
-    char c;
+    char c = '\0';
     unsigned int i = 0;
     unsigned int i = 0;
-    while ((c = src[i]) && i <= n)
+    while (i < n && (c = src[i]))
         dest[i++] = c;
         dest[i++] = c;
-    while (i <= n)
+
+    while (i < n)
         dest[i++] = 0;
         dest[i++] = 0;
+    
     return dest;
 }
\ No newline at end of file
     return dest;
 }
\ No newline at end of file