1997-11-12 16:11:17 +00:00
|
|
|
/* Copyright (C) 1996, 1997 Free Software Foundation, Inc.
|
1996-06-23 17:58:15 +00:00
|
|
|
|
1996-06-25 05:06:53 +00:00
|
|
|
NOTE: The canonical source of this file is maintained with the GNU C Library.
|
|
|
|
|
Bugs can be reported to bug-glibc@prep.ai.mit.edu.
|
1996-06-23 17:58:15 +00:00
|
|
|
|
1996-06-25 05:06:53 +00:00
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
|
under the terms of the GNU General Public License as published by the
|
|
|
|
|
Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
|
later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
1996-06-23 17:58:15 +00:00
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
1996-06-25 05:06:53 +00:00
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
1996-06-23 17:58:15 +00:00
|
|
|
|
1996-06-25 05:06:53 +00:00
|
|
|
You should have received a copy of the GNU General Public License
|
1996-07-15 03:36:16 +00:00
|
|
|
along with this program; if not, write to the Free Software Foundation,
|
|
|
|
|
Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
|
1996-06-23 17:58:15 +00:00
|
|
|
|
1996-06-25 05:06:53 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
|
# include "config.h"
|
|
|
|
|
#endif
|
1996-06-23 17:58:15 +00:00
|
|
|
|
1996-07-03 03:59:02 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
1996-06-25 05:06:53 +00:00
|
|
|
#ifdef STDC_HEADERS
|
|
|
|
|
# include <string.h>
|
|
|
|
|
# include <stdlib.h>
|
|
|
|
|
#else
|
|
|
|
|
char *malloc ();
|
|
|
|
|
#endif
|
1996-06-23 17:58:15 +00:00
|
|
|
|
|
|
|
|
/* Duplicate S, returning an identical malloc'd string. */
|
|
|
|
|
char *
|
1996-06-25 05:06:53 +00:00
|
|
|
strndup (s, n)
|
|
|
|
|
const char *s;
|
|
|
|
|
size_t n;
|
1996-06-23 17:58:15 +00:00
|
|
|
{
|
1996-06-25 05:06:53 +00:00
|
|
|
char *new = malloc (n + 1);
|
1996-06-23 17:58:15 +00:00
|
|
|
|
|
|
|
|
if (new == NULL)
|
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
|
|
new[n] = '\0';
|
1997-12-14 15:12:29 +00:00
|
|
|
return (char *) memcpy (new, s, n);
|
1996-06-23 17:58:15 +00:00
|
|
|
}
|