1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-13 23:36:10 +02:00
Files
coreutils/lib/strdup.c

43 lines
1.2 KiB
C
Raw Normal View History

1992-10-31 20:42:48 +00:00
/* strdup.c -- return a newly allocated copy of a string
Copyright (C) 1990, 1998 Free Software Foundation, Inc.
1992-10-31 20:42:48 +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,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
1996-07-15 00:04:51 +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. */
1998-03-15 11:09:10 +00:00
#if HAVE_CONFIG_H
# include <config.h>
1996-07-15 00:04:51 +00:00
#endif
1992-10-31 20:42:48 +00:00
#ifdef STDC_HEADERS
1998-03-15 11:09:10 +00:00
# include <string.h>
# include <stdlib.h>
1992-10-31 20:42:48 +00:00
#else
char *malloc ();
char *strcpy ();
#endif
/* Return a newly allocated copy of STR,
or 0 if out of memory. */
char *
1998-12-07 03:12:10 +00:00
strdup (const char *str)
1992-10-31 20:42:48 +00:00
{
char *newstr;
newstr = (char *) malloc (strlen (str) + 1);
if (newstr)
strcpy (newstr, str);
return newstr;
}