diff options
| author | WormHeamer | 2025-02-27 17:37:40 -0500 | 
|---|---|---|
| committer | WormHeamer | 2025-02-27 17:37:40 -0500 | 
| commit | bc2d3d1c59a521a6d0aea36a30f9e24b8288a1e5 (patch) | |
| tree | d1fce74e54b0b07c351718c4336bbf072223d53c | |
| parent | c762664ef5990c6e8684d5d8a34f811b18df0465 (diff) | |
use fprintf() + abort() instead of err()
| -rw-r--r-- | dynarr.h | 12 | 
1 files changed, 6 insertions, 6 deletions
| @@ -4,7 +4,6 @@  #include <stdlib.h>  #include <stdint.h>  #include <string.h> -#include <err.h>  #include "stdwrm.h" @@ -14,12 +13,13 @@ typedef struct { size_t count, capacity; } DynArrHeader;  #define DA_HEADER(da) ((DynArrHeader*)(da) - 1)  #define DA_INIT_CAP 16 -#define DA_INIT(da) do {\ -	char *da_init_ptr = ((char*)malloc(sizeof(DynArrHeader) + DA_INIT_CAP * sizeof(*da)));\ -	if (!da_init_ptr) err(1, "dynamic array allocation failed");\ +#define DA_INIT_SZ(da, cap) do {\ +	char *da_init_ptr = ((char*)malloc(sizeof(DynArrHeader) + cap * sizeof(*da)));\ +	if (!da_init_ptr) { fprintf(stderr, "dynamic array allocation failed\n"); abort(); }\  	da = (void *)(da_init_ptr + sizeof(DynArrHeader));\ -	*DA_HEADER(da) = (DynArrHeader) { 0, DA_INIT_CAP };\ +	*DA_HEADER(da) = (DynArrHeader) { 0, cap };\  } while(0) +#define DA_INIT(da) DA_INIT_SZ(da, DA_INIT_CAP)  #define DA_FREE(da)\  	free(DA_HEADER(da)) @@ -29,7 +29,7 @@ typedef struct { size_t count, capacity; } DynArrHeader;  	if (count >= DA_HEADER(da)->capacity) {\  		while (count >= DA_HEADER(da)->capacity) DA_HEADER(da)->capacity <<= 1;\  		char *da_fit_ptr = realloc(DA_HEADER(da), sizeof(DynArrHeader) + DA_HEADER(da)->capacity * sizeof(*da));\ -		if (!da_fit_ptr) err(1, "dynamic array reallocation failed");\ +		if (!da_fit_ptr) { fprintf(stderr, "dynamic array reallocation failed\n"); abort(); }\  		(da) = (void *)(da_fit_ptr + sizeof(DynArrHeader));\  	}\  } while(0) | 
