Blame gnu/strdup.c

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