From 5431fec6726c18234c9c28b014cc6f18a0d79884 Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Fri, 6 Jun 2025 14:09:32 -0500 Subject: Style touchup --- src/shared.c | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'src/shared.c') diff --git a/src/shared.c b/src/shared.c index 1d5aa7f..e83261c 100644 --- a/src/shared.c +++ b/src/shared.c @@ -17,24 +17,23 @@ enum XALLOC_TYPE { }; void * xalloc(size_t nmemb, size_t size, enum XALLOC_TYPE actype, void *ptr) { - if(actype <= XALLOC_INVAL || actype >= XALLOC_2BIG) - RETURNWERR(EINVAL, NULL); + if(actype <= XALLOC_INVAL || actype >= XALLOC_2BIG) ERRRET(EINVAL, NULL); void *mem = NULL; switch(actype) { - case XALLOC_MALLOC: + case XALLOC_MALLOC: mem = malloc(nmemb * size); break; - case XALLOC_CALLOC: + case XALLOC_CALLOC: mem = calloc(nmemb, size); break; - case XALLOC_REALLOC: + case XALLOC_REALLOC: mem = realloc(ptr, nmemb * size); break; - - default: + + default: XALLOC_EXIT(" An unknown alloc type was passed, which shouldn't be possible", ); } @@ -61,7 +60,7 @@ int rwbuf(char **str, unsigned long int initsize, int fd) { // Bytes read == 0, return 0 // Bytes read < 0, free string, return -1; // When string hits capacity, double the capacity, and reallocate the string - + if(!str || initsize < 1) ERRRET(EINVAL, -1); const int ECODE = -100; char *lstr = NULL, *tmp = NULL; @@ -118,6 +117,8 @@ int rwbuf(char **str, unsigned long int initsize, int fd) { int wwbuf(int fd, const unsigned char *buf, int len) { + if(!buf || len <= 0) ERRRET(EINVAL, -1); + int total = 0; int left = len; int n = -1; @@ -225,7 +226,7 @@ char * xdirname(const char * const path) { int cleanup_init(cleanup *loc, fcallback callbacks[], void *arguments[], int size) { - if(!loc || !callbacks || !arguments || size <= 0) {errno = EINVAL; return -1;} + if(!loc || !callbacks || !arguments || size <= 0) ERRRET(EINVAL, -1); loc->callbacks = callbacks; loc->arguments = arguments; @@ -237,8 +238,8 @@ int cleanup_init(cleanup *loc, fcallback callbacks[], void *arguments[], int siz // registers if flag is NOT set int cleanup_register(cleanup *loc, fcallback cb, void *arg) { - if(!loc || !cb) {errno = EINVAL; return -1;} - if(loc->used >= loc->size || loc->used < 0) {errno = ENOMEM; return -1;} + if(!loc || !cb) ERRRET(EINVAL, -1); + if(loc->used >= loc->size || loc->used < 0) ERRRET(ENOMEM, -1); loc->callbacks[loc->used] = cb; loc->arguments[loc->used] = arg; @@ -248,20 +249,18 @@ int cleanup_register(cleanup *loc, fcallback cb, void *arg) { } int cleanup_cndregister(cleanup *loc, fcallback cb, void *arg, unsigned char flag) { - if(flag) - return 0; + if(flag) return 0; return cleanup_register(loc, cb, arg); } int cleanup_clear(cleanup *loc) { - if(!loc) {errno = EINVAL; return -1;} - + if(!loc) ERRRET(EINVAL, -1); loc->used = 0; return 0; } int cleanup_fire(cleanup *loc) { - if(!loc) {errno = EINVAL; return -1;} + if(!loc) ERRRET(EINVAL, -1); for(int i = (loc->used - 1); i >= 0; i--) { if(loc->callbacks[i] == NULL) { -- cgit v1.2.3