Download raw body.
-portable: remove xmalloc compat code
xmalloc.c is not neccesary and can be removed.
There is only one user which calls xrecallocarray: ibuf_realloc().
We already provide recallocarray() in the compat layer so ibuf_realloc()
can simply call recallocarray() directly, as it does on OpenBSD.
ok?
diff --git a/compat/Makefile.am b/compat/Makefile.am
index a50e0102..e6e6105d 100644
--- a/compat/Makefile.am
+++ b/compat/Makefile.am
@@ -29,8 +29,7 @@ libopenbsd_compat_a_SOURCES = \
strnlen.c \
strsep.c \
strtonum.c \
- uuid.c \
- xmalloc.c
+ uuid.c
EXTRA_DIST = \
$(top_srcdir)/include/got_compat.h \
diff --git a/compat/imsg-buffer.c b/compat/imsg-buffer.c
index 37a41157..ce3ca9ba 100644
--- a/compat/imsg-buffer.c
+++ b/compat/imsg-buffer.c
@@ -27,7 +27,6 @@
#include <unistd.h>
#include "got_compat.h"
-#include "xmalloc.h"
static int ibuf_realloc(struct ibuf *, size_t);
static void ibuf_enqueue(struct msgbuf *, struct ibuf *);
@@ -78,7 +77,7 @@ ibuf_realloc(struct ibuf *buf, size_t len)
return (-1);
}
- b = xrecallocarray(buf->buf, buf->size, buf->wpos + len, 1);
+ b = recallocarray(buf->buf, buf->size, buf->wpos + len, 1);
if (b == NULL)
return (-1);
buf->buf = b;
diff --git a/compat/xmalloc.c b/compat/xmalloc.c
deleted file mode 100644
index 4cb3fee9..00000000
--- a/compat/xmalloc.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/* $OpenBSD$ */
-
-/*
- * Author: Tatu Ylonen <ylo@cs.hut.fi>
- * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
- * All rights reserved
- * Versions of malloc and friends that check their results, and never return
- * failure (they call fatalx if they encounter an error).
- *
- * As far as I am concerned, the code I have written for this software
- * can be used freely for any purpose. Any derived versions of this
- * software must be clearly marked as such, and if the derived work is
- * incompatible with the protocol description in the RFC file, it must be
- * called by a name other than "ssh" or "Secure Shell".
- */
-
-#include <errno.h>
-#include <limits.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "got_compat.h"
-
-#include "xmalloc.h"
-
-void *
-xmalloc(size_t size)
-{
- void *ptr;
-
- if (size == 0) {
- fprintf(stderr,"xmalloc: zero size");
- exit (1);
- }
- ptr = malloc(size);
- if (ptr == NULL) {
- fprintf(stderr, "xmalloc: allocating %zu bytes: %s",
- size, strerror(errno));
- exit (1);
- }
- return ptr;
-}
-
-void *
-xcalloc(size_t nmemb, size_t size)
-{
- void *ptr;
-
- if (size == 0 || nmemb == 0)
- fprintf(stderr,"xcalloc: zero size");
- ptr = calloc(nmemb, size);
- if (ptr == NULL) {
- fprintf(stderr, "xcalloc: allocating %zu * %zu bytes: %s",
- nmemb, size, strerror(errno));
- exit (1);
- }
- return ptr;
-}
-
-void *
-xrealloc(void *ptr, size_t size)
-{
- return xreallocarray(ptr, 1, size);
-}
-
-void *
-xreallocarray(void *ptr, size_t nmemb, size_t size)
-{
- void *new_ptr;
-
- if (nmemb == 0 || size == 0) {
- fprintf(stderr, "xreallocarray: zero size");
- exit (1);
- }
- new_ptr = reallocarray(ptr, nmemb, size);
- if (new_ptr == NULL) {
- fprintf(stderr, "xreallocarray: allocating %zu * %zu bytes: %s",
- nmemb, size, strerror(errno));
- exit (1);
- }
- return new_ptr;
-}
-
-void *
-xrecallocarray(void *ptr, size_t oldnmemb, size_t nmemb, size_t size)
-{
- void *new_ptr;
-
- if (nmemb == 0 || size == 0) {
- fprintf(stderr,"xrecallocarray: zero size");
- exit (1);
- }
- new_ptr = recallocarray(ptr, oldnmemb, nmemb, size);
- if (new_ptr == NULL) {
- fprintf(stderr,"xrecallocarray: allocating %zu * %zu bytes: %s",
- nmemb, size, strerror(errno));
- exit (1);
- }
- return new_ptr;
-}
-
-char *
-xstrdup(const char *str)
-{
- char *cp;
-
- if ((cp = strdup(str)) == NULL) {
- fprintf(stderr,"xstrdup: %s", strerror(errno));
- exit (1);
- }
- return cp;
-}
-
-char *
-xstrndup(const char *str, size_t maxlen)
-{
- char *cp;
-
- if ((cp = strndup(str, maxlen)) == NULL) {
- fprintf(stderr,"xstrndup: %s", strerror(errno));
- exit (1);
- }
- return cp;
-}
-
-int
-xasprintf(char **ret, const char *fmt, ...)
-{
- va_list ap;
- int i;
-
- va_start(ap, fmt);
- i = xvasprintf(ret, fmt, ap);
- va_end(ap);
-
- return i;
-}
-
-int
-xvasprintf(char **ret, const char *fmt, va_list ap)
-{
- int i;
-
- i = vasprintf(ret, fmt, ap);
-
- if (i == -1) {
- fprintf(stderr,"xasprintf: %s", strerror(errno));
- exit (1);
- }
-
- return i;
-}
-
-int
-xsnprintf(char *str, size_t len, const char *fmt, ...)
-{
- va_list ap;
- int i;
-
- va_start(ap, fmt);
- i = xvsnprintf(str, len, fmt, ap);
- va_end(ap);
-
- return i;
-}
-
-int
-xvsnprintf(char *str, size_t len, const char *fmt, va_list ap)
-{
- int i;
-
- if (len > INT_MAX)
- fprintf(stderr,"xsnprintf: len > INT_MAX");
-
- i = vsnprintf(str, len, fmt, ap);
-
- if (i < 0 || i >= (int)len) {
- fprintf(stderr,"xsnprintf: overflow");
- exit (1);
- }
-
- return i;
-}
diff --git a/compat/xmalloc.h b/compat/xmalloc.h
deleted file mode 100644
index 82a5624e..00000000
--- a/compat/xmalloc.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/* $OpenBSD$ */
-
-/*
- * Author: Tatu Ylonen <ylo@cs.hut.fi>
- * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
- * All rights reserved
- * Created: Mon Mar 20 22:09:17 1995 ylo
- *
- * Versions of malloc and friends that check their results, and never return
- * failure (they call fatal if they encounter an error).
- *
- * As far as I am concerned, the code I have written for this software
- * can be used freely for any purpose. Any derived versions of this
- * software must be clearly marked as such, and if the derived work is
- * incompatible with the protocol description in the RFC file, it must be
- * called by a name other than "ssh" or "Secure Shell".
- */
-
-#ifndef XMALLOC_H
-#define XMALLOC_H
-
-#include <stdarg.h>
-
-#if !defined(__bounded__)
-#define __bounded__(x, y, z)
-#endif
-
-void *xmalloc(size_t);
-void *xcalloc(size_t, size_t);
-void *xrealloc(void *, size_t);
-void *xreallocarray(void *, size_t, size_t);
-void *xrecallocarray(void *, size_t, size_t, size_t);
-char *xstrdup(const char *);
-char *xstrndup(const char *, size_t);
-int xasprintf(char **, const char *, ...)
- __attribute__((__format__ (printf, 2, 3)))
- __attribute__((__nonnull__ (2)));
-int xvasprintf(char **, const char *, va_list)
- __attribute__((__nonnull__ (2)));
-int xsnprintf(char *, size_t, const char *, ...)
- __attribute__((__format__ (printf, 3, 4)))
- __attribute__((__nonnull__ (3)))
- __attribute__((__bounded__ (__string__, 1, 2)));
-int xvsnprintf(char *, size_t, const char *, va_list)
- __attribute__((__nonnull__ (3)))
- __attribute__((__bounded__ (__string__, 1, 2)));
-
-#endif /* XMALLOC_H */
-portable: remove xmalloc compat code