Mercurial > hg > octave-kai > gnulib-hg
annotate lib/strndup.c @ 7302:8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
longer worry about uses that don't define HAVE_CONFIG_H.
* acl.c, alloca.c, argmatch.c, atexit.c, backupfile.c:
* basename.c, c-stack.c, c-strtod.c, calloc.c, canon-host.c:
* canonicalize.c, chdir-long.c, chdir-safer.c, chown.c:
* cloexec.c, close-stream.c, closeout.c, creat-safer.c:
* cycle-check.c, diacrit.c, dirchownmod.c, dirfd.c, dirname.c:
* dup-safer.c, dup2.c, error.c, euidaccess.c, exclude.c:
* exitfail.c, fchmodat.c, fchown-stub.c, fd-safer.c:
* file-type.c, fileblocks.c, filemode.c, filenamecat.c:
* fnmatch.c, fopen-safer.c, fprintftime.c, free.c, fsusage.c:
* ftruncate.c, fts-cycle.c, fts.c, full-write.c, gai_strerror.c:
* getcwd.c, getdate.y, getdomainname.c, getgroups.c:
* gethostname.c, gethrxtime.c, getloadavg.c, getlogin_r.c:
* getndelim2.c, getnline.c, getopt.c, getopt1.c, getpass.c:
* gettime.c, gettimeofday.c, getugroups.c, getusershell.c:
* glob.c, group-member.c, hard-locale.c, hash-pjw.c, hash.c:
* human.c, idcache.c, inet_ntop.c, inet_pton.c, inttostr.c:
* isdir.c, lchown.c, linebuffer.c, long-options.c, lstat.c:
* malloc.c, md5.c, memcasecmp.c, memchr.c, memcmp.c, memcoll.c:
* memcpy.c, memmove.c, memrchr.c, mkancesdirs.c, mkdir-p.c:
* mkdir.c, mkdirat.c, mkstemp-safer.c, mkstemp.c, modechange.c:
* mountlist.c, nanosleep.c, obstack.c, open-safer.c:
* openat-die.c, openat.c, pagealign_alloc.c, physmem.c:
* pipe-safer.c, posixtm.c, posixver.c, putenv.c, quote.c:
* quotearg.c, raise.c, readtokens.c, readtokens0.c, readutmp.c:
* realloc.c, regex.c, rename.c, rmdir.c, rpmatch.c, safe-read.c:
* same.c, save-cwd.c, savedir.c, setenv.c, settime.c, sha1.c:
* sig2str.c, snprintf.c, strdup.c, strerror.c, strftime.c:
* stripslash.c, strndup.c, strnlen.c, strpbrk.c, strtod.c:
* strtoimax.c, strtol.c, strverscmp.c, tempname.c, time_r.c:
* timegm.c, tmpfile-safer.c, unlinkdir.c, userspec.c, utime.c:
* utimecmp.c, utimens.c, version-etc-fsf.c, version-etc.c:
* xalloc-die.c, xgetcwd.c, xgethostname.c, xmalloc.c:
* xmemcoll.c, xnanosleep.c, xreadlink.c, xstrtod.c:
* xstrtoimax.c, xstrtol.c, xstrtoumax.c, yesno.c:
Likewise.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Wed, 13 Sep 2006 22:38:14 +0000 |
parents | f63adaadabfa |
children | 3ee6e46a13c3 |
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 |
7302
8a1a9361108c
* _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents:
6812
diff
changeset
|
21 #if !_LIBC |
6259
96c32553b4c6
Use a consistent style for including <config.h>.
Paul Eggert <eggert@cs.ucla.edu>
parents:
6020
diff
changeset
|
22 # include <config.h> |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
23 # include "strndup.h" |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
24 #endif |
627 | 25 |
4685 | 26 #include <stdlib.h> |
27 #include <string.h> | |
627 | 28 |
6587
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
29 #if !_LIBC |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
30 # include "strnlen.h" |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
31 # ifndef __strnlen |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
32 # define __strnlen strnlen |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
33 # endif |
453776fca04b
Work around porting bugs reported by Dieter in
Paul Eggert <eggert@cs.ucla.edu>
parents:
6259
diff
changeset
|
34 #endif |
2705
e17209e9562d
[!HAVE_DECL_STRNLEN]: Declare strnlen.
Jim Meyering <jim@meyering.net>
parents:
2469
diff
changeset
|
35 |
2469 | 36 #undef __strndup |
6812
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
37 #if _LIBC |
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
38 # undef strndup |
f63adaadabfa
Work around broken AIX 5.1 strndup function.
Bruno Haible <bruno@clisp.org>
parents:
6587
diff
changeset
|
39 #endif |
2469 | 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 |