summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
author@syxhe <https://t.me/syxhe>2025-03-24 18:10:58 -0500
committer@syxhe <https://t.me/syxhe>2025-03-24 18:10:58 -0500
commita407458a893fd0716cfee564ad98756364c25a7a (patch)
treee2117ffeef747dd503c4b354e13c0ab34399d063 /src
parent3b5bf3b6ab23c6a5157919490cc07787614f95b8 (diff)
Change the name of readwholebuffer and writewholebuffer so that they won't autocomplete when typing "return"
Diffstat (limited to 'src')
-rw-r--r--src/ll.h5
-rw-r--r--src/shared.c12
-rw-r--r--src/shared.h8
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 @@
8////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*//* 8////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*//*
9// // 9// //
10// dlinkedlist functions should be considered X_ALLOC functions, as they call xcalloc to initialize new nodes. This is not // 10// dlinkedlist functions should be considered X_ALLOC functions, as they call xcalloc to initialize new nodes. This is not //
11// reflected in their naming, which could change later, but as of know it is something to keep in mind. This means ABSOLUETLY NO // 11// reflected in their naming, which could change later, but as of now it is something to keep in mind. This means ABSOLUETLY NO //
12// USE OF DLINKEDLIST FUNCTIONS INSIDE ENCRYPTION FUNCTIONS, OR ANYTHING THAT SHOULD BE CONSIDERED ATOMIC OR SEMI-ATOMIC. IF // 12// USE OF DLINKEDLIST FUNCTIONS INSIDE ENCRYPTION FUNCTIONS, OR ANYTHING THAT SHOULD BE CONSIDERED ATOMIC OR SEMI-ATOMIC. IF //
13// XCALLOC ERRORS FOR ANY REASON, AND YOU'RE DOING SOMETHING WITH THESE IN AN (SEMI)ATOMIC FUNCTION, YOU WILL BREAK SHIT // 13// XCALLOC ERRORS FOR ANY REASON, AND YOU'RE DOING SOMETHING WITH THESE IN AN (SEMI)ATOMIC FUNCTION, YOU WILL BREAK SHIT //
14// // 14// //
@@ -18,6 +18,9 @@
18// BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WA // 18// BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WARNING BIG WA //
19//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/ 19//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////*/
20 20
21/* TODO: Implement a way to register a set of alloc functions to a linked list so I can give it arenas for memory allocation
22// instead of just xcalloc */
23
21typedef int (*dll_freecb)(void*); 24typedef int (*dll_freecb)(void*);
22typedef struct dlinked dlinkedlist; 25typedef struct dlinked dlinkedlist;
23 26
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) {
22 return mem; 22 return mem;
23} 23}
24 24
25int readwholebuffer(char **str, unsigned long int initsize, int fd) { 25int rwbuf(char **str, unsigned long int initsize, int fd) {
26 // Try to read bytes from fd into str 26 // Try to read bytes from fd into str
27 // Bytes read == 0, return 0 27 // Bytes read == 0, return 0
28 // Bytes read < 0, free string, return -1; 28 // Bytes read < 0, free string, return -1;
29 // When string hits capacity, double the capacity, and reallocate the string 29 // When string hits capacity, double the capacity, and reallocate the string
30 30
31 const int ECODE = -100;
32
31 char *lstr = NULL, *tmp = NULL; 33 char *lstr = NULL, *tmp = NULL;
32 ssize_t bytesread = -1; 34 ssize_t bytesread = -1;
33 int csize = initsize, ccap = initsize; 35 int csize = initsize, ccap = initsize;
@@ -46,13 +48,13 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) {
46 48
47 free(lstr); 49 free(lstr);
48 lstr = NULL; // Need to set this because of the break 50 lstr = NULL; // Need to set this because of the break
49 bytesread = -100; 51 bytesread = ECODE;
50 break; 52 break;
51 } 53 }
52 lstr = tmp; 54 lstr = tmp;
53 } 55 }
54 } 56 }
55 if(bytesread < 0 && bytesread != -100) { 57 if(bytesread < 0 && bytesread != ECODE) {
56 if(___VXGG___VERBOSE_ERRORS___) 58 if(___VXGG___VERBOSE_ERRORS___)
57 error(0, errno, "Ran into a read() error"); 59 error(0, errno, "Ran into a read() error");
58 60
@@ -67,7 +69,7 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) {
67 error(0, errno, "Could not shrink lstr after reading buffer"); 69 error(0, errno, "Could not shrink lstr after reading buffer");
68 70
69 free(lstr); 71 free(lstr);
70 bytesread = -100; 72 bytesread = ECODE;
71 } 73 }
72 lstr = tmp; 74 lstr = tmp;
73 } 75 }
@@ -81,7 +83,7 @@ int readwholebuffer(char **str, unsigned long int initsize, int fd) {
81} 83}
82 84
83 85
84int writewholebuffer(int fd, const unsigned char *buf, int len) { 86int wwbuf(int fd, const unsigned char *buf, int len) {
85 int total = 0; 87 int total = 0;
86 int left = len; 88 int left = len;
87 int n; 89 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);
36void* xreallocarray(void *ptr, size_t nmemb, size_t size); 36void* xreallocarray(void *ptr, size_t nmemb, size_t size);
37 37
38// Read the entire contents of a file descriptor into a malloc()'ed buffer 38// Read the entire contents of a file descriptor into a malloc()'ed buffer
39int readwholebuffer(char **str, unsigned long int initsize, int fd); 39int rwbuf(char **str, unsigned long int initsize, int fd);
40 40
41// Write the entire contents of a buffer into a file descriptor 41// Write the entire contents of a buffer into a file descriptor
42int writewholebuffer(int fd, const unsigned char *buf, int len); 42int wwbuf(int fd, const unsigned char *buf, int len);
43 43
44// `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits on alloc error. 44// `dirname()` reimplementation that returns a malloc()'ed string. According to the `x___` naming scheme, exits/aborts on alloc error.
45// `___VXGG___XALLOC_EXIT_ON_ERROR___` influences whether `exit()` or `abort()` is called on error, and `___VXGG___VERBOSE_ERRORS___`
46// influences whether diagnostic error messages are printed
47char *xdirname(const char * const path); 45char *xdirname(const char * const path);
48 46
49#endif \ No newline at end of file 47#endif \ No newline at end of file