Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strndup.c @ 6812:f63adaadabfa
Work around broken AIX 5.1 strndup function.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Tue, 30 May 2006 19:14:05 +0000 |
parents | 453776fca04b |
children | 8a1a9361108c |
rev | line source |
---|---|
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
1 /* Copyright (C) 1996, 1997, 1998, 2001, 2002, 2003, 2005, 2006 Free |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
2 Software Foundation, Inc. |
627 | 3 |
2469 | 4 NOTE: The canonical source of this file is maintained with the GNU C Library. |
5 Bugs can be reported to bug-glibc@prep.ai.mit.edu. | |
627 | 6 |
2469 | 7 This program is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | |
9 Free Software Foundation; either version 2, or (at your option) any | |
10 later version. | |
630 | 11 |
2469 | 12 This program is distributed in the hope that it will be useful, |
13 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 GNU General Public License for more details. | |
627 | 16 |
2469 | 17 You should have received a copy of the GNU General Public License |
18 along with this program; if not, write to the Free Software Foundation, | |
5848
a48fb0e98c8c
*** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents:
4685
diff
changeset
|
19 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ |
627 | 20 |
630 | 21 #ifdef HAVE_CONFIG_H |
6259
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6020
diff
changeset
|
22 # include <config.h> |
630 | 23 #endif |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
24 #if !_LIBC |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
25 # include "strndup.h" |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
26 #endif |
627 | 27 |
4685 | 28 #include <stdlib.h> |
29 #include <string.h> | |
627 | 30 |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
31 #if !_LIBC |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
32 # include "strnlen.h" |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
33 # ifndef __strnlen |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
34 # define __strnlen strnlen |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
35 # endif |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
36 #endif |
2705
e17209e9562d
[!HAVE_DECL_STRNLEN]: Declare strnlen.
Jim Meyering <jim@meyering.net>
parents:
2469
diff
changeset
|
37 |
2469 | 38 #undef __strndup |
6812
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
39 #if _LIBC |
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
40 # undef strndup |
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
41 #endif |
2469 | 42 |
43 #ifndef weak_alias | |
44 # define __strndup strndup | |
45 #endif | |
46 | |
627 | 47 char * |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
48 __strndup (s, n) |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
49 const char *s; |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
50 size_t n; |
627 | 51 { |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
52 size_t len = __strnlen (s, n); |
2469 | 53 char *new = malloc (len + 1); |
627 | 54 |
55 if (new == NULL) | |
56 return NULL; | |
57 | |
2469 | 58 new[len] = '\0'; |
4685 | 59 return memcpy (new, s, len); |
627 | 60 } |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
61 #ifdef libc_hidden_def |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
62 libc_hidden_def (__strndup) |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
63 #endif |
2469 | 64 #ifdef weak_alias |
65 weak_alias (__strndup, strndup) | |
66 #endif |