Blame lib/strdup.c

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