]> git.saurik.com Git - bison.git/blame - lib/xstrndup.c
* data/bison.simple (yyr1): Its type is that of a token number.
[bison.git] / lib / xstrndup.c
CommitLineData
a4b36db4 1/* Copyright (C) 2001 Free Software Foundation, Inc.
18569462
AD
2
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
6 later version.
7
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.
12
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. */
16
a4b36db4
AD
17#if HAVE_CONFIG_H
18# include <config.h>
18569462
AD
19#endif
20
a4b36db4 21#if STDC_HEADERS || HAVE_STRING_H
18569462
AD
22# include <string.h>
23#else
a4b36db4 24# include <strings.h>
18569462
AD
25#endif
26
a4b36db4
AD
27#include <sys/types.h>
28
29#include "xalloc.h"
30
18569462
AD
31#ifndef HAVE_DECL_STRNLEN
32"this configure-time declaration test was not run"
33#endif
34#if !HAVE_DECL_STRNLEN
35size_t strnlen ();
36#endif
37
a4b36db4 38char *xstrndup (const char *s, size_t n);
18569462
AD
39
40char *
a4b36db4 41xstrndup (const char *s, size_t n)
18569462
AD
42{
43 size_t len = strnlen (s, n);
a4b36db4 44 char *new = xmalloc (len + 1);
18569462
AD
45
46 if (new == NULL)
47 return NULL;
48
49 new[len] = '\0';
50 return (char *) memcpy (new, s, len);
51}