diff options
| author | EuAndreh <eu@euandre.org> | 2025-01-12 00:14:03 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2025-01-12 14:27:57 -0300 |
| commit | 44d56f5311f98a8955c67638e7520963dbd4d845 (patch) | |
| tree | fbb2c58c79f1730ff62c83cef116fb5c0e035dfe /src/util.c | |
| parent | Replace src/config.h with <s.h>; incorporate changes from other projects (diff) | |
| download | pindaiba-44d56f5311f98a8955c67638e7520963dbd4d845.tar.gz pindaiba-44d56f5311f98a8955c67638e7520963dbd4d845.tar.xz | |
Revamp lib, simplify it a bit and address some FIXMEs
Diffstat (limited to '')
| -rw-r--r-- | src/util.c | 26 |
1 files changed, 5 insertions, 21 deletions
@@ -1,4 +1,4 @@ -#include "config.h" +#include <s.h> #include <errno.h> #include <stdio.h> @@ -11,26 +11,8 @@ -const size_t -NULL_TERMINATOR = sizeof((char)'\0'); - -const int -EXIT_USAGE = 2; - - - -void -freeit(const void **const ptr) { - if (ptr == NULL) { - return; - } - - free((void *)*ptr); - *ptr = NULL; -} - int -slurp(const char *const filename, char **out) { +slurp(const char *const filename, size_t *const outlen, char **out) { int rc = -1; FILE *file = NULL; @@ -73,6 +55,7 @@ slurp(const char *const filename, char **out) { } str[size] = '\0'; *out = str; + *outlen = size; rc = 0; out: @@ -84,7 +67,8 @@ out: } if (rc) { if (str != NULL) { - freeit((void *)&str); + free(str); + str = NULL; } } return rc; |
