Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strndup.c @ 10780:5c7a68d31801
Add support for Haiku.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Mon, 10 Nov 2008 12:37:32 +0100 |
parents | a1d177cd9523 |
children | b5e42ef33b49 |
rev | line source |
---|---|
7379 | 1 /* A replacement function, for systems that lack strndup. |
627 | 2 |
7944
a1d177cd9523
* doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents:
7379
diff
changeset
|
3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006, 2007 |
a1d177cd9523
* doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents:
7379
diff
changeset
|
4 Free Software Foundation, Inc. |
627 | 5 |
2469 | 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. | |
630 | 10 |
2469 | 11 This program is distributed in the hope that it will be useful, |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
627 | 15 |
2469 | 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 Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4685
diff
changeset
|
18 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
627 | 19 |
7379 | 20 #include <config.h> |
7944
a1d177cd9523
* doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents:
7379
diff
changeset
|
21 |
a1d177cd9523
* doc/gnulib-tool.texi (Initial import): Update to match current
Paul Eggert <eggert@cs.ucla.edu>
parents:
7379
diff
changeset
|
22 #include <string.h> |
627 | 23 |
4685 | 24 #include <stdlib.h> |
2469 | 25 |
627 | 26 char * |
7379 | 27 strndup (char const *s, size_t n) |
627 | 28 { |
7379 | 29 size_t len = strnlen (s, n); |
2469 | 30 char *new = malloc (len + 1); |
627 | 31 |
32 if (new == NULL) | |
33 return NULL; | |
34 | |
2469 | 35 new[len] = '\0'; |
4685 | 36 return memcpy (new, s, len); |
627 | 37 } |