• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* Copyright (C) 2000, 2002 Free Software Foundation, Inc.
2 
3    This program is Open Source software; you can redistribute it and/or
4    modify it under the terms of the Open Software License version 1.0 as
5    published by the Open Source Initiative.
6 
7    You should have received a copy of the Open Software License along
8    with this program; if not, you may obtain a copy of the Open Software
9    License version 1.0 from http://www.opensource.org/licenses/osl.php or
10    by writing the Open Source Initiative c/o Lawrence Rosen, Esq.,
11    3001 King Ranch Road, Ukiah, CA 95482.   */
12 
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16 
17 #include <string.h>
18 #include "system.h"
19 
20 
21 /* Return a newly allocated copy of STRING.  */
22 char *
xstrndup(string,n)23 xstrndup (string, n)
24      const char *string;
25      size_t n;
26 {
27   char *res;
28   size_t len = strnlen (string, n);
29   *((char *) mempcpy ((res = xmalloc (len + 1)), string, len)) = '\0';
30   return res;
31 }
32