Blame lib/strdup.c

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