We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9aa2140 commit 98e5834Copy full SHA for 98e5834
lib/libc/string0.c
@@ -169,6 +169,23 @@ char *strcpy(char *dest, const char *src) {
169
return dest;
170
}
171
172
+// Public Domain implementation of strncpy from:
173
+// http://en.wikibooks.org/wiki/C_Programming/Strings#The_strncpy_function
174
+char *strncpy(char *s1, const char *s2, size_t n) {
175
+ char *dst = s1;
176
+ const char *src = s2;
177
+ /* Copy bytes, one at a time. */
178
+ while (n > 0) {
179
+ n--;
180
+ if ((*dst++ = *src++) == '\0') {
181
+ /* If we get here, we found a null character at the end of s2 */
182
+ *dst = '\0';
183
+ break;
184
+ }
185
186
+ return s1;
187
188
+
189
// needed because gcc optimises strcpy + strcat to this
190
char *stpcpy(char *dest, const char *src) {
191
while (*src) {
0 commit comments