commit d3f0cb406149f6e3cd79757097352e57977a3b84
parent 888ea50bde843a7f0d3b9b32e5e3cbed3a5f05ce
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Mon, 6 Jul 2020 13:02:36 -0500
removed unused utility functions
Diffstat:
M | util.c | | | 86 | ------------------------------------------------------------------------------- |
M | util.h | | | 12 | ------------ |
2 files changed, 0 insertions(+), 98 deletions(-)
diff --git a/util.c b/util.c
@@ -1,13 +1,8 @@
/* See LICENSE file for copyright and license details. */
-#include <errno.h>
-#include <limits.h>
#include <stdarg.h>
-#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <sys/types.h>
-#include <time.h>
#ifdef __OpenBSD__
#include <unistd.h>
@@ -81,84 +76,3 @@ eunveil(const char *path, const char *permissions)
}
#endif /* __OpenBSD__ */
}
-
-char *
-timestamp(time_t t, char buf[TIMESTAMP_LEN])
-{
- strftime(buf, TIMESTAMP_LEN, "%a, %d %b %Y %T GMT", gmtime(&t));
-
- return buf;
-}
-
-int
-esnprintf(char *str, size_t size, const char *fmt, ...)
-{
- va_list ap;
- int ret;
-
- va_start(ap, fmt);
- ret = vsnprintf(str, size, fmt, ap);
- va_end(ap);
-
- return (ret < 0 || (size_t)ret >= size);
-}
-
-#define INVALID 1
-#define TOOSMALL 2
-#define TOOLARGE 3
-
-long long
-strtonum(const char *numstr, long long minval, long long maxval,
- const char **errstrp)
-{
- long long ll = 0;
- int error = 0;
- char *ep;
- struct errval {
- const char *errstr;
- int err;
- } ev[4] = {
- { NULL, 0 },
- { "invalid", EINVAL },
- { "too small", ERANGE },
- { "too large", ERANGE },
- };
-
- ev[0].err = errno;
- errno = 0;
- if (minval > maxval) {
- error = INVALID;
- } else {
- ll = strtoll(numstr, &ep, 10);
- if (numstr == ep || *ep != '\0')
- error = INVALID;
- else if ((ll == LLONG_MIN && errno == ERANGE) || ll < minval)
- error = TOOSMALL;
- else if ((ll == LLONG_MAX && errno == ERANGE) || ll > maxval)
- error = TOOLARGE;
- }
- if (errstrp != NULL)
- *errstrp = ev[error].errstr;
- errno = ev[error].err;
- if (error)
- ll = 0;
-
- return ll;
-}
-
-/*
- * This is sqrt(SIZE_MAX+1), as s1*s2 <= SIZE_MAX
- * if both s1 < MUL_NO_OVERFLOW and s2 < MUL_NO_OVERFLOW
- */
-#define MUL_NO_OVERFLOW ((size_t)1 << (sizeof(size_t) * 4))
-
-void *
-reallocarray(void *optr, size_t nmemb, size_t size)
-{
- if ((nmemb >= MUL_NO_OVERFLOW || size >= MUL_NO_OVERFLOW) &&
- nmemb > 0 && SIZE_MAX / nmemb < size) {
- errno = ENOMEM;
- return NULL;
- }
- return realloc(optr, size * nmemb);
-}
diff --git a/util.h b/util.h
@@ -2,10 +2,6 @@
#ifndef UTIL_H
#define UTIL_H
-#include <regex.h>
-#include <stddef.h>
-#include <time.h>
-
#undef MIN
#define MIN(x,y) ((x) < (y) ? (x) : (y))
#undef MAX
@@ -21,12 +17,4 @@ void die(const char *, ...);
void epledge(const char *, const char *);
void eunveil(const char *, const char *);
-#define TIMESTAMP_LEN 30
-
-char *timestamp(time_t, char buf[TIMESTAMP_LEN]);
-int esnprintf(char *, size_t, const char *, ...);
-
-void *reallocarray(void *, size_t, size_t);
-long long strtonum(const char *, long long, long long, const char **);
-
#endif /* UTIL_H */