Blame lib/strdup.c

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