Mercurial > hg > octave-kai > gnulib-hg
annotate lib/xalloc.h @ 4783:d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Mon, 13 Oct 2003 06:07:10 +0000 |
parents | fd6696a97000 |
children | 7c67f04e1c19 |
rev | line source |
---|---|
1603 | 1 /* xalloc.h -- malloc with out-of-memory checking |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
2 |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
3 Copyright (C) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, |
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
4 1999, 2000, 2003 Free Software Foundation, Inc. |
1603 | 5 |
6 This program is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 2, or (at your option) | |
9 any later version. | |
10 | |
11 This program is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with this program; if not, write to the Free Software Foundation, | |
18 Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ | |
19 | |
20 #ifndef XALLOC_H_ | |
21 # define XALLOC_H_ | |
22 | |
4347
df44e79ce676
.h files should stand alone, but we shouldn't include <sys/types.h>
Paul Eggert <eggert@cs.ucla.edu>
parents:
2951
diff
changeset
|
23 # include <stddef.h> |
df44e79ce676
.h files should stand alone, but we shouldn't include <sys/types.h>
Paul Eggert <eggert@cs.ucla.edu>
parents:
2951
diff
changeset
|
24 |
1958
3bf5a026bc95
(__attribute__): Protect against redefinition.
Jim Meyering <jim@meyering.net>
parents:
1955
diff
changeset
|
25 # ifndef __attribute__ |
1962
1f3b3ce10ab6
(__attribute__): Define to empty if GCC claims to
Jim Meyering <jim@meyering.net>
parents:
1958
diff
changeset
|
26 # if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__ |
1958
3bf5a026bc95
(__attribute__): Protect against redefinition.
Jim Meyering <jim@meyering.net>
parents:
1955
diff
changeset
|
27 # define __attribute__(x) |
3bf5a026bc95
(__attribute__): Protect against redefinition.
Jim Meyering <jim@meyering.net>
parents:
1955
diff
changeset
|
28 # endif |
1953 | 29 # endif |
30 | |
31 # ifndef ATTRIBUTE_NORETURN | |
32 # define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__)) | |
33 # endif | |
34 | |
1603 | 35 /* If this pointer is non-zero, run the specified function upon each |
1953 | 36 allocation failure. It is initialized to zero. */ |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
37 extern void (*xalloc_fail_func) (void); |
1070 | 38 |
1603 | 39 /* If XALLOC_FAIL_FUNC is undefined or a function that returns, this |
2811
a3217eb32838
(xalloc_msg_memory_exhausted): Now char const[],
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
40 message is output. It is translated via gettext. |
a3217eb32838
(xalloc_msg_memory_exhausted): Now char const[],
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
41 Its value is "memory exhausted". */ |
a3217eb32838
(xalloc_msg_memory_exhausted): Now char const[],
Jim Meyering <jim@meyering.net>
parents:
2807
diff
changeset
|
42 extern char const xalloc_msg_memory_exhausted[]; |
1070 | 43 |
1953 | 44 /* This function is always triggered when memory is exhausted. It is |
4473
fd6696a97000
Sync with coreutils xalloc.h, xmalloc.c, xmemcoll.h, xmemcoll.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
45 in charge of honoring the two previous items. It exits with status |
fd6696a97000
Sync with coreutils xalloc.h, xmalloc.c, xmemcoll.h, xmemcoll.c.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4397
diff
changeset
|
46 exit_failure (defined in exitfail.h). This is the |
1953 | 47 function to call when one wants the program to die because of a |
48 memory allocation failure. */ | |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
49 extern void xalloc_die (void) ATTRIBUTE_NORETURN; |
1953 | 50 |
4783
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
51 void *xmalloc (size_t s); |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
52 void *xnmalloc (size_t n, size_t s); |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
53 void *xzalloc (size_t s); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
54 void *xcalloc (size_t n, size_t s); |
4783
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
55 void *xrealloc (void *p, size_t s); |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
56 void *xnrealloc (void *p, size_t n, size_t s); |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
57 void *xclone (void const *p, size_t s); |
4397
c6450308f123
Assume C89, so PARAMS isn't needed.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4347
diff
changeset
|
58 char *xstrdup (const char *str); |
1603 | 59 |
4783
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
60 /* These macros are deprecated; they will go away soon, and are retained |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
61 temporarily only to ease conversion to the functions described above. */ |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
62 # define CCLONE(p, n) xclone (p, (n) * sizeof *(p)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
63 # define CLONE(p) xclone (p, sizeof *(p)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
64 # define NEW(type, var) type *var = xmalloc (sizeof (type)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
65 # define XCALLOC(type, n) xcalloc (n, sizeof (type)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
66 # define XMALLOC(type, n) xnmalloc (n, sizeof (type)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
67 # define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type)) |
d1dc5d9bf1ba
Revamp xalloc interface so that it can check for address arithmetic overflow.
Paul Eggert <eggert@cs.ucla.edu>
parents:
4473
diff
changeset
|
68 # define XFREE(p) free (p) |
1953 | 69 |
1603 | 70 #endif /* !XALLOC_H_ */ |