annotate lib/calloc.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 96c32553b4c6
children a4f83e0e605c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5464
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
1 /* calloc() function that is glibc compatible.
5081
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
2 This wrapper function is required at least on Tru64 UNIX 5.1.
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
3 Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc.
5081
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
4
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
6 it under the terms of the GNU General Public License as published by
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
7 the Free Software Foundation; either version 2, or (at your option)
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
8 any later version.
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
9
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
13 GNU General Public License for more details.
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
14
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
15 You should have received a copy of the GNU General Public License
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
16 along with this program; if not, write to the Free Software Foundation,
5848
a48fb0e98c8c *** empty log message ***
Paul Eggert <eggert@cs.ucla.edu>
parents: 5464
diff changeset
17 Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
5081
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
18
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
19 /* written by Jim Meyering */
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
20
7302
8a1a9361108c * _fpending.c: Include <config.h> unconditionally, since we no
Paul Eggert <eggert@cs.ucla.edu>
parents: 6259
diff changeset
21 #include <config.h>
5081
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
22 #undef calloc
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
23
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
24 #include <stdlib.h>
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
25
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
26 /* Allocate and zero-fill an NxS-byte block of memory from the heap.
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
27 If N or S is zero, allocate and zero-fill a 1-byte block. */
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
28
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
29 void *
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
30 rpl_calloc (size_t n, size_t s)
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
31 {
5464
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
32 size_t bytes;
5927
cb13c1ad85d5 (rpl_calloc): Allocate a 1-byte buffer (not 1xS or Nx1)
Jim Meyering <jim@meyering.net>
parents: 5848
diff changeset
33
cb13c1ad85d5 (rpl_calloc): Allocate a 1-byte buffer (not 1xS or Nx1)
Jim Meyering <jim@meyering.net>
parents: 5848
diff changeset
34 if (n == 0 || s == 0)
cb13c1ad85d5 (rpl_calloc): Allocate a 1-byte buffer (not 1xS or Nx1)
Jim Meyering <jim@meyering.net>
parents: 5848
diff changeset
35 return calloc (1, 1);
5464
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
36
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
37 /* Defend against buggy calloc implementations that mishandle
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
38 size_t overflow. */
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
39 bytes = n * s;
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
40 if (bytes / s != n)
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
41 return NULL;
f7677662318c (rpl_calloc): Defend against buggy calloc implementations
Paul Eggert <eggert@cs.ucla.edu>
parents: 5081
diff changeset
42
5081
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
43 return calloc (n, s);
af4fd5060a09 * modules/calloc: New file.
Jim Meyering <jim@meyering.net>
parents:
diff changeset
44 }