]>
git.saurik.com Git - bison.git/blob - lib/xstrndup.c
1 /* Copyright (C) 2001 Free Software Foundation, Inc.
3 This program is free software; you can redistribute it and/or modify it
4 under the terms of the GNU General Public License as published by the
5 Free Software Foundation; either version 2, or (at your option) any
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program; if not, write to the Free Software Foundation,
15 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
21 #if STDC_HEADERS || HAVE_STRING_H
27 #include <sys/types.h>
31 #ifndef HAVE_DECL_STRNLEN
32 "this configure-time declaration test was not run"
34 #if !HAVE_DECL_STRNLEN
38 char *xstrndup (const char *s
, size_t n
);
41 xstrndup (const char *s
, size_t n
)
43 size_t len
= strnlen (s
, n
);
44 char *new = xmalloc (len
+ 1);
50 return (char *) memcpy (new, s
, len
);