From eee1fedc3a69e503fab74248937e35e71dee4992 Mon Sep 17 00:00:00 2001 From: Tomasz Kramkowski Date: Thu, 22 Dec 2016 16:31:28 +0100 Subject: util: remove unused functions Removed: xstrmalloc, xmalloc, xrealloc, xstrcut, szadd, szmul. --- util.c | 85 +++--------------------------------------------------------------- util.h | 6 ----- 2 files changed, 3 insertions(+), 88 deletions(-) diff --git a/util.c b/util.c index a8c3729..9f8e23e 100644 --- a/util.c +++ b/util.c @@ -15,23 +15,6 @@ * You should have received a copy of the GNU General Public License along * with this program; if not, write to the Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Some contents of this file (indicated below) are based on work covered by - * the following copyright and permission notice: - * - * Copyright (c) 2008 Otto Moerbeek - * - * Permission to use, copy, modify, and distribute this software for any - * purpose with or without fee is hereby granted, provided that the above - * copyright notice and this permission notice appear in all copies. - * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES - * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR - * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES - * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN - * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF - * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include @@ -42,80 +25,18 @@ #include #include "log.h" +#include "eprintf.h" #include "util.h" -/* szadd: checked size_t addition */ -size_t szadd(size_t a, size_t b) -{ - if (SIZE_MAX - a < b) - error(0, EMSG_SZOP); - - return a + b; -} - -/* szmul: checked size_t multiplication - * License information can be found at the top of this file */ -size_t szmul(size_t a, size_t b) -{ -#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof (size_t) * 4)) - if ((a >= MUL_NO_OVERFLOW || b >= MUL_NO_OVERFLOW) && - a > 0 && SIZE_MAX / a < b) - error(0, EMSG_SZOP); -#undef MUL_NO_OVERFLOW - - return a * b; -} - /* xstrmalloc: allocate for a string (+1) or exit with error */ void *xstrmalloc(size_t size) { size_t nsize; - nsize = size + 1; - if (nsize < size) + if (size == SIZE_MAX) error(0, EMSG_ALLOC); - return xmalloc(nsize); -} - -/* xstrdup: duplicae string or exit with error */ -char *xstrdup(const char *s) -{ - char *ret; - - assert(s); - - ret = xstrmalloc(strlen(s)); - strcpy(ret, s); - - return ret; -} - -/* xrealloc: reallocate or exit with error */ -void *xrealloc(void *p, size_t size) -{ - p = realloc(p, size); - if (!p) - error(errno, EMSG_ALLOC); - - return p; -} - -/* xmalloc: allocate or exit with error */ -void *xmalloc(size_t size) -{ - return xrealloc(NULL, size); -} - -/* xstrcut: cut out a bit of a string into a new string */ -char *xstrcut(const char *s, size_t offt, size_t len) -{ - char *ret; - - ret = xstrmalloc(len); - strncpy(ret, s + offt, len + 1); - - return ret; + return emalloc(nsize); } /* xstrcasecmp: case insensitive strcmp */ diff --git a/util.h b/util.h index 356366c..d1f459a 100644 --- a/util.h +++ b/util.h @@ -22,13 +22,7 @@ #include #include -size_t szadd(size_t a, size_t b); -size_t szmul(size_t a, size_t b); void *xstrmalloc(size_t size); -char *xstrdup(const char *s); -void *xmalloc(size_t size); -void *xrealloc(void *p, size_t size); -char *xstrcut(const char *s, size_t offt, size_t len); int xstrcasecmp(const char *s1, const char *s2); #endif /* UTIL_H */ -- cgit v1.2.3-54-g00ecf