Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strndup.c @ 6587:453776fca04b
Work around porting bugs reported by Dieter in
<http://lists.gnu.org/archive/html/bug-bison/2006-01/msg00049.html>.
* lib/getopt.c (_NOPROTO): Remove; no longer needed.
Include <stdlib.h> and <unistd.h> in all environments; it's safe now.
Include "getopt.h" first, to check interface.
(getenv): Declare only if defined HAVE_DECL_GETENV &&
!HAVE_DECL_GETENV.
* lib/strndup.c [!_LIBC]: Include "strndup.h" to get prototype.
(__strndup): Revert to K&R-style function dfns, the glibc style.
* lib/strnlen.c: Don't claim it's taken from glibc; it's not.
(strnlen, __strnlen): Remove #defines and #undefs; not needed.
Include strnlen.h first, to get prototype properly.
(strnlen): Renamed from __strnlen.
Remove weak alias.
* m4/getopt.m4 (gl_PREREQ_GETOPT): Check for getenv decl.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Tue, 24 Jan 2006 07:40:58 +0000 |
parents | 96c32553b4c6 |
children | f63adaadabfa |
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 |
39 #undef strndup | |
40 | |
41 #ifndef weak_alias | |
42 # define __strndup strndup | |
43 #endif | |
44 | |
627 | 45 char * |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
46 __strndup (s, n) |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
47 const char *s; |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
48 size_t n; |
627 | 49 { |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
50 size_t len = __strnlen (s, n); |
2469 | 51 char *new = malloc (len + 1); |
627 | 52 |
53 if (new == NULL) | |
54 return NULL; | |
55 | |
2469 | 56 new[len] = '\0'; |
4685 | 57 return memcpy (new, s, len); |
627 | 58 } |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
59 #ifdef libc_hidden_def |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
60 libc_hidden_def (__strndup) |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
61 #endif |
2469 | 62 #ifdef weak_alias |
63 weak_alias (__strndup, strndup) | |
64 #endif |