changeset 63:67470b67e460

misc: remove unneeded code
author David Demelier <markand@malikania.fr>
date Thu, 18 Aug 2022 12:29:28 +0200
parents eaebcc612a0d
children 562372396019
files libsci/util.c libsci/util.h scictl/scictl.c sciworkerd/task.c
diffstat 4 files changed, 2 insertions(+), 105 deletions(-) [+]
line wrap: on
line diff
--- a/libsci/util.c	Thu Aug 18 12:18:12 2022 +0200
+++ b/libsci/util.c	Thu Aug 18 12:29:28 2022 +0200
@@ -31,17 +31,6 @@
 #include "util.h"
 
 void *
-util_malloc(size_t size)
-{
-	void *ret;
-
-	if (!(ret = malloc(size)))
-		util_die("abort: malloc: %s\n", strerror(errno));
-
-	return ret;
-}
-
-void *
 util_calloc(size_t n, size_t size)
 {
 	void *ret;
@@ -52,17 +41,6 @@
 	return ret;
 }
 
-void *
-util_realloc(void *ptr, size_t size)
-{
-	void *ret;
-
-	if (!(ret = realloc(ptr, size)) && size)
-		util_die("abort: realloc: %s\n", strerror(errno));
-
-	return ret;
-}
-
 char *
 util_strdup(const char *src)
 {
@@ -75,19 +53,6 @@
 }
 
 char *
-util_strndup(const char *src, size_t n)
-{
-	assert(src);
-
-	char *ret;
-
-	if (!(ret = strndup(src, n)))
-		util_die("abort: strndup: %s\n", strerror(errno));
-
-	return ret;
-}
-
-char *
 util_basename(const char *str)
 {
 	static char ret[PATH_MAX];
@@ -99,18 +64,6 @@
 	return ret;
 }
 
-char *
-util_dirname(const char *str)
-{
-	static char ret[PATH_MAX];
-	char tmp[PATH_MAX];
-
-	util_strlcpy(tmp, str, sizeof (tmp));
-	util_strlcpy(ret, dirname(tmp), sizeof (ret));
-
-	return ret;
-}
-
 FILE *
 util_open_memstream(char **out, size_t *outsz)
 {
--- a/libsci/util.h	Thu Aug 18 12:18:12 2022 +0200
+++ b/libsci/util.h	Thu Aug 18 12:29:28 2022 +0200
@@ -38,15 +38,6 @@
 #define UTIL_SIZE(x) (sizeof (x) / sizeof (x[0]))
 
 /**
- * Wrap malloc or exit with code 1.
- *
- * \param w the bytes to allocate
- * \return the pointer to the memory
- */
-void *
-util_malloc(size_t w);
-
-/**
  * Wrap calloc or exit with code 1.
  *
  * \param n the number of items
@@ -57,27 +48,6 @@
 util_calloc(size_t n, size_t w);
 
 /**
- * Wrap realloc or exit with code 1.
- *
- * \param ptr the old memory
- * \param w the bytes to allocate
- * \return the pointer to the memory
- */
-void *
-util_realloc(void *ptr, size_t w);
-
-/**
- * Wrap reallocarray or exit with code 1.
- *
- * \param ptr the old memory
- * \param n the number of items
- * \param w the bytes per item
- * \return the pointer to the memory
- */
-void *
-util_reallocarray(void *ptr, size_t n, size_t w);
-
-/**
  * Wrap strdup or exit with code 1.
  *
  * \pre str != NULL
@@ -88,17 +58,6 @@
 util_strdup(const char *str);
 
 /**
- * Wrap strndup or exit with code 1.
- *
- * \pre str != NULL
- * \param str the string to duplicate
- * \param n the maximum string to not exceed
- * \return the copied string
- */
-char *
-util_strndup(const char *str, size_t n);
-
-/**
  * Get the base name component from a path.
  *
  * \pre path != NULL
@@ -109,16 +68,6 @@
 util_basename(const char *path);
 
 /**
- * Get the directory name component from a path.
- *
- * \pre path != NULL
- * \param path the path to extract
- * \return a static thread local value containing the directory name
- */
-char *
-util_dirname(const char *path);
-
-/**
  * Wrap open_memstream or exit with code 1.
  *
  * \pre out != NULL
--- a/scictl/scictl.c	Thu Aug 18 12:18:12 2022 +0200
+++ b/scictl/scictl.c	Thu Aug 18 12:29:28 2022 +0200
@@ -76,8 +76,7 @@
 	else if (!(fp = fopen(path, "r")))
 		util_die("abort: %s: %s\n", path, strerror(errno));
 
-	if (!(str = open_memstream(&console, &consolesz)))
-		util_die("abort: open_memstream: %s\n", strerror(errno));
+	str = util_open_memstream(&console, &consolesz);
 
 	while ((nr = fread(buf, 1, sizeof (buf), fp)) > 0)
 		fwrite(buf, 1, nr, str);
--- a/sciworkerd/task.c	Thu Aug 18 12:18:12 2022 +0200
+++ b/sciworkerd/task.c	Thu Aug 18 12:29:28 2022 +0200
@@ -58,11 +58,7 @@
 	task->job_tag = util_strdup(tag);
 	task->pipe[0] = task->pipe[1] = -1;
 	task->child = -1;
-
-	if (!(task->fp = open_memstream(&task->console, &task->consolesz))) {
-		task_free(task);
-		return NULL;
-	}
+	task->fp = util_open_memstream(&task->console, &task->consolesz);
 
 	return task;
 }