MCPcopy Create free account
hub / github.com/coreboot/coreboot / strndup

Function strndup

payloads/libpayload/libc/string.c:247–257  ·  view source on GitHub ↗

* Duplicate a string with a max length of size * * @param s The string to duplicate. * @param size The max length of the string * @return A pointer to the copy of the original string. */

Source from the content-addressed store, hash-verified

245 * @return A pointer to the copy of the original string.
246 */
247char *strndup(const char *s, size_t size)
248{
249 size_t n = strnlen(s, size);
250 char *p = malloc(n + 1);
251
252 if (p != NULL) {
253 strncpy(p, s, n);
254 p[n] = 0;
255 }
256 return p;
257}
258
259/**
260 * Find a substring within a string.

Callers 1

xstrndupFunction · 0.85

Calls 3

strnlenFunction · 0.85
mallocFunction · 0.70
strncpyFunction · 0.70

Tested by

no test coverage detected