~ubuntu-branches/ubuntu/maverick/texinfo/maverick

« back to all changes in this revision

Viewing changes to lib/strdup.c

  • Committer: Bazaar Package Importer
  • Author(s): Norbert Preining
  • Date: 2005-10-28 15:10:30 UTC
  • mto: (2.1.1 dapper) (3.1.4 hardy)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20051028151030-9nsf2s2k2z3fktjt
Tags: upstream-4.8
ImportĀ upstreamĀ versionĀ 4.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* strdup.c -- return a newly allocated copy of a string
2
 
   Copyright (C) 1990, 1998 Free Software Foundation, Inc.
 
1
/* Copyright (C) 1991, 1996, 1997, 1998, 2002, 2003, 2004 Free Software
 
2
   Foundation, Inc.
 
3
 
 
4
   This file is part of the GNU C Library.
3
5
 
4
6
   This program is free software; you can redistribute it and/or modify
5
7
   it under the terms of the GNU General Public License as published by
11
13
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
14
   GNU General Public License for more details.
13
15
 
14
 
   You should have received a copy of the GNU General Public License
15
 
   along with this program; if not, write to the Free Software Foundation,
 
16
   You should have received a copy of the GNU General Public License along
 
17
   with this program; if not, write to the Free Software Foundation,
16
18
   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
17
19
 
18
 
#if HAVE_CONFIG_H
 
20
#ifdef HAVE_CONFIG_H
19
21
# include <config.h>
20
22
#endif
21
23
 
22
 
#ifdef STDC_HEADERS
23
 
# include <string.h>
24
 
# include <stdlib.h>
25
 
#else
26
 
char *malloc ();
27
 
char *strcpy ();
28
 
#endif
29
 
 
30
 
/* Return a newly allocated copy of STR,
31
 
   or 0 if out of memory. */
32
 
 
 
24
#ifndef _LIBC
 
25
/* Get specification.  */
 
26
# include "strdup.h"
 
27
#endif
 
28
 
 
29
#include <stdlib.h>
 
30
#include <string.h>
 
31
 
 
32
#undef __strdup
 
33
#undef strdup
 
34
 
 
35
#ifndef weak_alias
 
36
# define __strdup strdup
 
37
#endif
 
38
 
 
39
/* Duplicate S, returning an identical malloc'd string.  */
33
40
char *
34
 
strdup (const char *str)
 
41
__strdup (const char *s)
35
42
{
36
 
  char *newstr;
37
 
 
38
 
  newstr = (char *) malloc (strlen (str) + 1);
39
 
  if (newstr)
40
 
    strcpy (newstr, str);
41
 
  return newstr;
 
43
  size_t len = strlen (s) + 1;
 
44
  void *new = malloc (len);
 
45
 
 
46
  if (new == NULL)
 
47
    return NULL;
 
48
 
 
49
  return (char *) memcpy (new, s, len);
42
50
}
 
51
#ifdef libc_hidden_def
 
52
libc_hidden_def (__strdup)
 
53
#endif
 
54
#ifdef weak_alias
 
55
weak_alias (__strdup, strdup)
 
56
#endif