Blame lib/strdup.c

Packit d6cc65
/* Copyright (C) 1991, 1996-1998, 2002-2004, 2006-2007, 2009-2015 Free Software
Packit d6cc65
   Foundation, Inc.
Packit d6cc65
Packit d6cc65
   This file is part of the GNU C Library.
Packit d6cc65
Packit d6cc65
   This program is free software; you can redistribute it and/or modify
Packit d6cc65
   it under the terms of the GNU General Public License as published by
Packit d6cc65
   the Free Software Foundation; either version 3, or (at your option)
Packit d6cc65
   any later version.
Packit d6cc65
Packit d6cc65
   This program is distributed in the hope that it will be useful,
Packit d6cc65
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d6cc65
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit d6cc65
   GNU General Public License for more details.
Packit d6cc65
Packit d6cc65
   You should have received a copy of the GNU General Public License along
Packit d6cc65
   with this program; if not, see <http://www.gnu.org/licenses/>.  */
Packit d6cc65
Packit d6cc65
#ifndef _LIBC
Packit d6cc65
# include <config.h>
Packit d6cc65
#endif
Packit d6cc65
Packit d6cc65
/* Get specification.  */
Packit d6cc65
#include <string.h>
Packit d6cc65
Packit d6cc65
#include <stdlib.h>
Packit d6cc65
Packit d6cc65
#undef __strdup
Packit d6cc65
#ifdef _LIBC
Packit d6cc65
# undef strdup
Packit d6cc65
#endif
Packit d6cc65
Packit d6cc65
#ifndef weak_alias
Packit d6cc65
# define __strdup strdup
Packit d6cc65
#endif
Packit d6cc65
Packit d6cc65
/* Duplicate S, returning an identical malloc'd string.  */
Packit d6cc65
char *
Packit d6cc65
__strdup (const char *s)
Packit d6cc65
{
Packit d6cc65
  size_t len = strlen (s) + 1;
Packit d6cc65
  void *new = malloc (len);
Packit d6cc65
Packit d6cc65
  if (new == NULL)
Packit d6cc65
    return NULL;
Packit d6cc65
Packit d6cc65
  return (char *) memcpy (new, s, len);
Packit d6cc65
}
Packit d6cc65
#ifdef libc_hidden_def
Packit d6cc65
libc_hidden_def (__strdup)
Packit d6cc65
#endif
Packit d6cc65
#ifdef weak_alias
Packit d6cc65
weak_alias (__strdup, strdup)
Packit d6cc65
#endif