Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strdup.c @ 3997:c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
author | Jim Meyering <jim@meyering.net> |
---|---|
date | Thu, 21 Nov 2002 13:33:10 +0000 |
parents | 3e25885877b3 |
children | 7158a1db8695 |
rev | line source |
---|---|
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
1 /* Copyright (C) 1991, 1996, 1997, 1998, 2002 Free Software Foundation, Inc. |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
2 This file is part of the GNU C Library. |
5 | 3 |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
4 The GNU C Library is free software; you can redistribute it and/or |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
5 modify it under the terms of the GNU Lesser General Public |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
6 License as published by the Free Software Foundation; either |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
7 version 2.1 of the License, or (at your option) any later version. |
5 | 8 |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
9 The GNU C Library is distributed in the hope that it will be useful, |
5 | 10 but WITHOUT ANY WARRANTY; without even the implied warranty of |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
12 Lesser General Public License for more details. |
5 | 13 |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
14 You should have received a copy of the GNU Lesser General Public |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
15 License along with the GNU C Library; if not, write to the Free |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
16 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
17 02111-1307 USA. */ |
647 | 18 |
3997
c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
Jim Meyering <jim@meyering.net>
parents:
3943
diff
changeset
|
19 #if HAVE_CONFIG_H |
c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
Jim Meyering <jim@meyering.net>
parents:
3943
diff
changeset
|
20 # include <config.h> |
647 | 21 #endif |
5 | 22 |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
23 #if defined _LIBC || defined STDC_HEADERS |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
24 # include <stdlib.h> |
1278
9ad625a30b7d
Use #if, not #ifdef with HAVE_ macros
Jim Meyering <jim@meyering.net>
parents:
647
diff
changeset
|
25 # include <string.h> |
5 | 26 #else |
27 char *malloc (); | |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
28 char *memcpy (); |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
29 #endif |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
30 |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
31 #undef __strdup |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
32 #undef strdup |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
33 |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
34 #ifndef weak_alias |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
35 # define __strdup strdup |
5 | 36 #endif |
37 | |
3997
c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
Jim Meyering <jim@meyering.net>
parents:
3943
diff
changeset
|
38 /* Duplicate S, returning an identical malloc'd string. |
c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
Jim Meyering <jim@meyering.net>
parents:
3943
diff
changeset
|
39 Return NULL if out of memory. */ |
c1f0c85e44eb
(strdup): Tweak comment and initial #if/#include.
Jim Meyering <jim@meyering.net>
parents:
3943
diff
changeset
|
40 |
5 | 41 char * |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
42 __strdup (const char *s) |
5 | 43 { |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
44 size_t len = strlen (s) + 1; |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
45 void *new = malloc (len); |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
46 |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
47 if (new == NULL) |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
48 return NULL; |
5 | 49 |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
50 return (char *) memcpy (new, s, len); |
5 | 51 } |
3943
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
52 #ifdef libc_hidden_def |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
53 libc_hidden_def (__strdup) |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
54 #endif |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
55 #ifdef weak_alias |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
56 weak_alias (__strdup, strdup) |
3e25885877b3
copy from libc/string (via ../config/srclist*).
Karl Berry <karl@freefriends.org>
parents:
2807
diff
changeset
|
57 #endif |