strdup.c revision cea198a11f15a2eb071d98491ca9a8bc8cebfbc4
1cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software
2cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   Foundation, Inc.
3cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
4cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   This file is part of the GNU C Library.
5cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
6cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   This program is free software; you can redistribute it and/or modify
7cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   it under the terms of the GNU General Public License as published by
8cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   the Free Software Foundation; either version 2, or (at your option)
9cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   any later version.
10cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
11cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   This program is distributed in the hope that it will be useful,
12cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   but WITHOUT ANY WARRANTY; without even the implied warranty of
13cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   GNU General Public License for more details.
15cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
16cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   You should have received a copy of the GNU General Public License along
17cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   with this program; if not, write to the Free Software Foundation,
18cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project   Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.  */
19cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
20cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifdef HAVE_CONFIG_H
21cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# include <config.h>
22cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif
23cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
24cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifndef _LIBC
25cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Get specification.  */
26cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# include "strdup.h"
27cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif
28cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
29cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#include <stdlib.h>
30cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#include <string.h>
31cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
32cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#undef __strdup
33cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#undef strdup
34cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
35cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifndef weak_alias
36cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project# define __strdup strdup
37cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif
38cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
39cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project/* Duplicate S, returning an identical malloc'd string.  */
40cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectchar *
41cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project__strdup (const char *s)
42cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project{
43cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project  size_t len = strlen (s) + 1;
44cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project  void *new = malloc (len);
45cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
46cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project  if (new == NULL)
47cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project    return NULL;
48cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project
49cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project  return (char *) memcpy (new, s, len);
50cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project}
51cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifdef libc_hidden_def
52cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectlibc_hidden_def (__strdup)
53cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif
54cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#ifdef weak_alias
55cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Projectweak_alias (__strdup, strdup)
56cea198a11f15a2eb071d98491ca9a8bc8cebfbc4The Android Open Source Project#endif
57