OSDN Git Service

hidden_def/hidden_proto: convert all users (I hope) termios split, add some missing...
[uclinux-h8/uClibc.git] / libc / string / strndup.c
1 /*
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 libc_hidden_proto(strndup)
12 libc_hidden_proto(strnlen)
13 libc_hidden_proto(memcpy)
14
15 char *strndup(register const char *s1, size_t n)
16 {
17         register char *s;
18
19         n = strnlen(s1,n);                      /* Avoid problems if s1 not nul-terminated. */
20
21     if ((s = malloc(n + 1)) != NULL) {
22                 memcpy(s, s1, n);
23                 s[n] = 0;
24         }
25
26         return s;
27 }
28 libc_hidden_def(strndup)