summaryrefslogtreecommitdiffstats
path: root/xmalloc.c
diff options
context:
space:
mode:
authorpgen <p.gen.progs@gmail.com>2023-09-10 00:35:48 +0200
committerpgen <p.gen.progs@gmail.com>2023-09-11 14:15:32 +0200
commit36881ac8835674bf5ce0112f1c5bfa7d1b1e3f27 (patch)
tree97e706c87e9189c1896b5117578f112f8ce7484d /xmalloc.c
parentb4e826f3ce669758eb2847d5d7eb65ee2c4755d0 (diff)
Reformatting source code
Diffstat (limited to 'xmalloc.c')
-rw-r--r--xmalloc.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/xmalloc.c b/xmalloc.c
index cd2ffd6..e7f7896 100644
--- a/xmalloc.c
+++ b/xmalloc.c
@@ -29,7 +29,7 @@
#ifdef malloc
#undef malloc
-extern void * malloc(size_t);
+extern void *malloc(size_t);
void *
rpl_malloc(size_t size)
@@ -44,7 +44,7 @@ extern void *
realloc(void *, size_t);
void *
-rpl_realloc(void * ptr, size_t size)
+rpl_realloc(void *ptr, size_t size)
{
if (!size)
size++;
@@ -60,7 +60,7 @@ rpl_realloc(void * ptr, size_t size)
void *
xmalloc(size_t size)
{
- void * allocated;
+ void *allocated;
size_t real_size;
real_size = (size > 0) ? size : 1;
@@ -68,7 +68,8 @@ xmalloc(size_t size)
if (allocated == NULL)
{
fprintf(stderr,
- "Error: Insufficient memory (attempt to malloc %zu bytes)\n", size);
+ "Error: Insufficient memory (attempt to malloc %zu bytes)\n",
+ size);
exit(EXIT_FAILURE);
}
@@ -83,7 +84,7 @@ xmalloc(size_t size)
void *
xcalloc(size_t n, size_t size)
{
- void * allocated;
+ void *allocated;
n = (n > 0) ? n : 1;
size = (size > 0) ? size : 1;
@@ -91,7 +92,8 @@ xcalloc(size_t n, size_t size)
if (allocated == NULL)
{
fprintf(stderr,
- "Error: Insufficient memory (attempt to calloc %zu bytes)\n", size);
+ "Error: Insufficient memory (attempt to calloc %zu bytes)\n",
+ size);
exit(EXIT_FAILURE);
}
@@ -104,9 +106,9 @@ xcalloc(size_t n, size_t size)
/* Displays an error message and exits gracefully if an error occurs. */
/* ================================================================== */
void *
-xrealloc(void * p, size_t size)
+xrealloc(void *p, size_t size)
{
- void * allocated;
+ void *allocated;
allocated = realloc(p, size);
if (allocated == NULL && size > 0)
@@ -126,9 +128,9 @@ xrealloc(void * p, size_t size)
/* Displays an error message and exits gracefully if an error occurs. */
/* ================================================================== */
char *
-xstrdup(const char * str)
+xstrdup(const char *str)
{
- char * p;
+ char *p;
p = malloc(strlen(str) + 1);
@@ -149,9 +151,9 @@ xstrdup(const char * str)
/* Displays an error message and exits gracefully if an error occurs. */
/* ================================================================== */
char *
-xstrndup(const char * str, size_t len)
+xstrndup(const char *str, size_t len)
{
- char * p;
+ char *p;
size_t l;
p = memchr(str, '\0', len);