From: Omar Polo Subject: [portable] get rid of compat/xmalloc.[ch] To: gameoftrees@openbsd.org Date: Sun, 26 Feb 2023 11:31:08 +0100 not used by anything, probably a leftover. ok? diff /home/op/w/got-portable commit - 415a43bb0c7491db8a907b4e5bbdf9894602d651 path + /home/op/w/got-portable blob - 4cb3fee954c0994f90c6ad916cce9abc291f8614 file + /dev/null --- compat/xmalloc.c +++ /dev/null @@ -1,185 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Author: Tatu Ylonen - * Copyright (c) 1995 Tatu Ylonen , 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 -#include -#include -#include -#include -#include - -#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; -} blob - 82a5624e6cff0daddb85ad48d75031abf9d728f0 file + /dev/null --- compat/xmalloc.h +++ /dev/null @@ -1,48 +0,0 @@ -/* $OpenBSD$ */ - -/* - * Author: Tatu Ylonen - * Copyright (c) 1995 Tatu Ylonen , 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 - -#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 */