From a407458a893fd0716cfee564ad98756364c25a7a Mon Sep 17 00:00:00 2001 From: "@syxhe" Date: Mon, 24 Mar 2025 18:10:58 -0500 Subject: Change the name of readwholebuffer and writewholebuffer so that they won't autocomplete when typing "return" --- src/ll.h | 5 ++++- src/shared.c | 12 +++++++----- src/shared.h | 8 +++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/ll.h b/src/ll.h index 1f4b3b2..3d8ecc1 100644 --- a/src/ll.h +++ b/src/ll.h @@ -8,7 +8,7 @@ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*//* // // // dlinkedlist functions should be considered X_ALLOC functions, as they call xcalloc to initialize new nodes. This is not // -// reflected in their naming, which could change later, but as of know it is something to keep in mind. This means ABSOLUETLY NO // +// reflected in their naming, which could change later, but as of now it is something to keep in mind. This means ABSOLUETLY NO // // USE OF DLINKEDLIST FUNCTIONS INSIDE ENCRYPTION FUNCTIONS, OR ANYTHING THAT SHOULD BE CONSIDERED ATOMIC OR SEMI-ATOMIC. IF // // XCALLOC ERRORS FOR ANY REASON, AND YOU'RE DOING SOMETHING WITH THESE IN AN (SEMI)ATOMIC FUNCTION, YOU WILL BREAK SHIT // // // @@ -18,6 +18,9 @@ // BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WA // //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ +/* TODO: Implement a way to register a set of alloc functions to a linked list so I can give it arenas for memory allocation +// instead of just xcalloc */ + typedef int (*dll_freecb)(void*); typedef struct dlinked dlinkedlist; diff --git a/src/shared.c b/src/shared.c index 72ede56..cc11fe1 100644 --- a/src/shared.c +++ b/src/shared.c @@ -22,12 +22,14 @@ void* xreallocarray(void *ptr, size_t nmemb, size_t size) { return mem; } -int readwholebuffer(char **str, unsigned long int initsize, int fd) { +int rwbuf(char **str, unsigned long int initsize, int fd) { // Try to read bytes from fd into str // Bytes read == 0, return 0 // Bytes read < 0, free string, return -1; // When string hits capacity, double the capacity, and reallocate the string + const int ECODE = -100; + char *lstr = NULL, *tmp = NULL; ssize_t bytesread = -1; int csize = initsize, ccap = initsize; @@ -46,13 +48,13 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) { free(lstr); lstr = NULL; // Need to set this because of the break - bytesread = -100; + bytesread = ECODE; break; } lstr = tmp; } } - if(bytesread < 0 && bytesread != -100) { + if(bytesread < 0 && bytesread != ECODE) { if(___VXGG___VERBOSE_ERRORS___) error(0, errno, "Ran into a read() error"); @@ -67,7 +69,7 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) { error(0, errno, "Could not shrink lstr after reading buffer"); free(lstr); - bytesread = -100; + bytesread = ECODE; } lstr = tmp; } @@ -81,7 +83,7 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) { } -int writewholebuffer(int fd, const unsigned char *buf, int len) { +int wwbuf(int fd, const unsigned char *buf, int len) { int total = 0; int left = len; int n; diff --git a/src/shared.h b/src/shared.h index af6c56e..b9e7bcd 100644 --- a/src/shared.h +++ b/src/shared.h @@ -36,14 +36,12 @@ void* xcalloc(size_t nmemb, size_t size); void* xreallocarray(void *ptr, size_t nmemb, size_t size); // Read the entire contents of a file descriptor into a malloc()'ed buffer -int readwholebuffer(char **str, unsigned long int initsize, int fd); +int rwbuf(char **str, unsigned long int initsize, int fd); // Write the entire contents of a buffer into a file descriptor -int writewholebuffer(int fd, const unsigned char *buf, int len); +int wwbuf(int fd, const unsigned char *buf, int len); -// `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits on alloc error. -// `___VXGG___XALLOC_EXIT_ON_ERROR___` influences whether `exit()` or `abort()` is called on error, and `___VXGG___VERBOSE_ERRORS___` -// influences whether diagnostic error messages are printed +// `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits/aborts on alloc error. char *xdirname(const char * const path); #endif \ No newline at end of file -- cgit v1.2.3