Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strndup.c @ 7379:3ee6e46a13c3
[lib/ChangeLog]
This function could end up with a definition for a function
named __strndup, rather than rpl_strndup on a system with
incomplete weak_alias support.
* strndup.c (strndup): Rename from __strndup.
Remove #defines that used to map __strndup to strndup.
Don't use K&R prototypes.
Remove LIBC-related code, since this file is not sync'd with glibc.
* strndup.h: Revamp, accordingly.
[m4/ChangeLog]
* strndup.m4: Modernize.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Thu, 28 Sep 2006 11:16:05 +0000 |
parents | 8a1a9361108c |
children | a1d177cd9523 |
rev | line source |
---|---|
7379 | 1 /* A replacement function, for systems that lack strndup. |
627 | 2 |
7379 | 3 Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free |
4 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> |
21 #include "strndup.h" | |
627 | 22 |
4685 | 23 #include <stdlib.h> |
24 #include <string.h> | |
627 | 25 |
7379 | 26 #include "strnlen.h" |
2469 | 27 |
627 | 28 char * |
7379 | 29 strndup (char const *s, size_t n) |
627 | 30 { |
7379 | 31 size_t len = strnlen (s, n); |
2469 | 32 char *new = malloc (len + 1); |
627 | 33 |
34 if (new == NULL) | |
35 return NULL; | |
36 | |
2469 | 37 new[len] = '\0'; |
4685 | 38 return memcpy (new, s, len); |
627 | 39 } |