summaryrefslogtreecommitdiff
path: root/lib/xalloc.h
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2003-10-13 15:17:05 +0000
committerJim Meyering <jim@meyering.net>2003-10-13 15:17:05 +0000
commit7be8d88dd37266cb4b9865a251376e7bf687e662 (patch)
treed3096f87772ac09e05594cca39c094735f379b9b /lib/xalloc.h
parenta8e60e65f8d185f32f4d8d3832b69c4c0f5135ec (diff)
downloadcoreutils-7be8d88dd37266cb4b9865a251376e7bf687e662.tar.xz
Import latest version from gnulib.
Diffstat (limited to 'lib/xalloc.h')
-rw-r--r--lib/xalloc.h38
1 files changed, 15 insertions, 23 deletions
diff --git a/lib/xalloc.h b/lib/xalloc.h
index c6ca1174b..03c430699 100644
--- a/lib/xalloc.h
+++ b/lib/xalloc.h
@@ -48,31 +48,23 @@ extern char const xalloc_msg_memory_exhausted[];
memory allocation failure. */
extern void xalloc_die (void) ATTRIBUTE_NORETURN;
-void *xmalloc (size_t n);
+void *xmalloc (size_t s);
+void *xnmalloc (size_t n, size_t s);
+void *xzalloc (size_t s);
void *xcalloc (size_t n, size_t s);
-void *xrealloc (void *p, size_t n);
+void *xrealloc (void *p, size_t s);
+void *xnrealloc (void *p, size_t n, size_t s);
+void *xclone (void const *p, size_t s);
char *xstrdup (const char *str);
-# define XMALLOC(Type, N_items) xmalloc (sizeof (Type) * (N_items))
-# define XCALLOC(Type, N_items) xcalloc (sizeof (Type), N_items)
-# define XREALLOC(Ptr, Type, N_items) xrealloc (Ptr, sizeof (Type) * (N_items))
-
-/* Declare and alloc memory for VAR of type TYPE. */
-# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
-
-/* Free VAR only if non NULL. */
-# define XFREE(Var) \
- do { \
- if (Var) \
- free (Var); \
- } while (0)
-
-/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
-# define CCLONE(Src, Num) \
- (memcpy (xmalloc (sizeof *(Src) * (Num)), Src, sizeof *(Src) * (Num)))
-
-/* Return a malloc'ed copy of SRC. */
-# define CLONE(Src) CCLONE (Src, 1)
-
+/* These macros are deprecated; they will go away soon, and are retained
+ temporarily only to ease conversion to the functions described above. */
+# define CCLONE(p, n) xclone (p, (n) * sizeof *(p))
+# define CLONE(p) xclone (p, sizeof *(p))
+# define NEW(type, var) type *var = xmalloc (sizeof (type))
+# define XCALLOC(type, n) xcalloc (n, sizeof (type))
+# define XMALLOC(type, n) xnmalloc (n, sizeof (type))
+# define XREALLOC(p, type, n) xnrealloc (p, n, sizeof (type))
+# define XFREE(p) free (p)
#endif /* !XALLOC_H_ */