627
|
1 /* Copyright (C) 1996 Free Software Foundation, Inc. |
|
2 |
630
|
3 NOTE: The canonical source of this file is maintained with the GNU C Library. |
|
4 Bugs can be reported to bug-glibc@prep.ai.mit.edu. |
627
|
5 |
630
|
6 This program is free software; you can redistribute it and/or modify it |
|
7 under the terms of the GNU General Public License as published by the |
|
8 Free Software Foundation; either version 2, or (at your option) any |
|
9 later version. |
|
10 |
|
11 This program is distributed in the hope that it will be useful, |
627
|
12 but WITHOUT ANY WARRANTY; without even the implied warranty of |
630
|
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 GNU General Public License for more details. |
627
|
15 |
630
|
16 You should have received a copy of the GNU General Public License |
|
17 along with this program; if not, write to the Free Software |
|
18 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ |
627
|
19 |
630
|
20 #ifdef HAVE_CONFIG_H |
|
21 # include "config.h" |
|
22 #endif |
627
|
23 |
630
|
24 #ifdef STDC_HEADERS |
|
25 # include <string.h> |
|
26 # include <stdlib.h> |
|
27 #else |
|
28 char *malloc (); |
|
29 #endif |
627
|
30 |
|
31 /* Duplicate S, returning an identical malloc'd string. */ |
|
32 char * |
630
|
33 strndup (s, n) |
|
34 const char *s; |
|
35 size_t n; |
627
|
36 { |
630
|
37 char *new = malloc (n + 1); |
627
|
38 |
|
39 if (new == NULL) |
|
40 return NULL; |
|
41 |
|
42 memcpy (new, s, n); |
|
43 new[n] = '\0'; |
|
44 |
|
45 return new; |
|
46 } |