git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rewrite the device subsystem interfaces (#48)
[lunaix-os.git]
/
lunaix-os
/
libs
/
klibc
/
string
/
strcpy.c
diff --git
a/lunaix-os/libs/klibc/string/strcpy.c
b/lunaix-os/libs/klibc/string/strcpy.c
index 88b5cb1ca2a02ab298e6f8b8a0532e59bcd0b454..7a3b430faad8a4cc673073ee752b7de6f099691c 100644
(file)
--- a/
lunaix-os/libs/klibc/string/strcpy.c
+++ b/
lunaix-os/libs/klibc/string/strcpy.c
@@
-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;
@@
-9,18
+10,35
@@
strcpy(char* dest, const char* src)
dest[i] = c;
i++;
}
dest[i] = c;
i++;
}
- dest[i] = '\0';
- return
dest
;
+ dest[i
++
] = '\0';
+ 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)
{
char c;
unsigned int i = 0;
strncpy(char* dest, const char* src, unsigned long n)
{
char c;
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)
- dest[i++] = 0;
+
+ if (!(n < i && src[i - 1])) {
+ while (i <= n)
+ dest[i++] = 0;
+ }
+ else {
+ dest[i - 1] = 0;
+ }
+
return dest;
}
\ No newline at end of file
return dest;
}
\ No newline at end of file