Skip to content

Commit bd9de5e

Browse files
committed
lib/libc/string0: Add strncpy() implementation.
1 parent 5302c3e commit bd9de5e

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

lib/libc/string0.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ char *strcpy(char *dest, const char *src) {
169169
return dest;
170170
}
171171

172+
char *strncpy(char *dest, const char *src, size_t dest_sz) {
173+
char *d = dest;
174+
while (*src && --dest_sz) {
175+
*d++ = *src++;
176+
}
177+
*d = '\0';
178+
return dest;
179+
}
180+
172181
// needed because gcc optimises strcpy + strcat to this
173182
char *stpcpy(char *dest, const char *src) {
174183
while (*src) {

0 commit comments

Comments
 (0)