blob: 8e608669c6359bd79ac52fd06590f676345b5697 [file] [log] [blame]
lh9ed821d2023-04-07 01:36:19 -07001/*
2 * Copyright (C) 2002 Manuel Novoa III
3 * Copyright (C) 2000-2005 Erik Andersen <andersen@uclibc.org>
4 *
5 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
6 */
7
8#include "_string.h"
9#include <stdlib.h>
10
11
12char *strndup(register const char *s1, size_t n)
13{
14 register char *s;
15
16 n = strnlen(s1,n); /* Avoid problems if s1 not nul-terminated. */
17
18 if ((s = malloc(n + 1)) != NULL) {
19 memcpy(s, s1, n);
20 s[n] = 0;
21 }
22
23 return s;
24}
25libc_hidden_def(strndup)