[libc] Add new libc
This new libc is mostly from scratch, with *printf() functions provided by Marco Paland and Eyal Rozenberg's tiny printf library, and malloc and friends provided by dlmalloc.
This commit is contained in:
27
src/libraries/libc/string/strncat.cpp
Normal file
27
src/libraries/libc/string/strncat.cpp
Normal file
@@ -0,0 +1,27 @@
|
||||
/** \file strncat.cpp
|
||||
*
|
||||
* This file is part of the C standard library for the jsix operating
|
||||
* system.
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stddef.h>
|
||||
#include <__j6libc/copy.h>
|
||||
|
||||
char *strncat(char * restrict s1, const char * restrict s2, size_t n) {
|
||||
if (!s1 || !s2 || !n)
|
||||
return s1;
|
||||
|
||||
char *dest = s1;
|
||||
char const *src = s2;
|
||||
while (*dest++);
|
||||
while (*src && n--) *dest++ = *src++;
|
||||
*dest = 0;
|
||||
|
||||
return s1;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user