1 /* PSPP - computes sample statistics.
2 Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
3 Written by Ben Pfaff <blp@gnu.org>.
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
27 /* Public functions. */
29 /* Allocates a block of SIZE bytes and returns it.
30 If SIZE is 0, returns a null pointer.
31 Aborts if unsuccessful. */
47 /* Allocates a continous block of N_MEMB by SIZE elements, with all
49 Aborts if unsuccessful.
52 xcalloc (size_t n_memb, size_t size)
54 const size_t prod = size * n_memb;
60 /* Trap overflow errors */
61 assert ( prod >= size );
62 assert ( prod >= n_memb ) ;
64 vp = xmalloc ( prod );
71 /* If SIZE is 0, then block PTR is freed and a null pointer is
73 Otherwise, if PTR is a null pointer, then a new block is allocated
75 Otherwise, block PTR is reallocated to be SIZE bytes in size and
76 the new location of the block is returned.
77 Aborts if unsuccessful. */
79 xrealloc (void *ptr, size_t size)
91 vp = realloc (ptr, size);
101 /* Makes a copy of string S in malloc()'d memory and returns the copy.
102 S must not be a null pointer. */
104 xstrdup (const char *s)
111 size = strlen (s) + 1;
121 /* Report an out-of-memory condition and abort execution. */
125 fprintf (stderr, "virtual memory exhausted\n");