change get_binary to unsigned char

This commit is contained in:
Evan Burkey 2023-12-15 13:08:22 -08:00
parent d50611a198
commit 56f3a9b9bf
3 changed files with 5 additions and 5 deletions

View File

@ -25,7 +25,7 @@ Reads a file at `path` and returns the contents as a single string. The string i
the user is responsible for freeing it when finished. the user is responsible for freeing it when finished.
```c ```c
char *get_input(const char *path); unsigned char *get_input(const char *path);
/* Usage */ /* Usage */
char *str = get_input("/home/evan/textfile"); char *str = get_input("/home/evan/textfile");

View File

@ -3,7 +3,7 @@
#include <stdlib.h> #include <stdlib.h>
char *get_binary(const char *, size_t *fsz); unsigned char *get_binary(const char *, size_t *fsz);
char *get_input(const char *); char *get_input(const char *);

View File

@ -26,14 +26,14 @@ static FILE* open_file(const char *path, size_t *fsz) {
return fp; return fp;
} }
char *get_binary(const char *path, size_t *fsz) { unsigned char *get_binary(const char *path, size_t *fsz) {
FILE *fp = open_file(path, fsz); FILE *fp = open_file(path, fsz);
if (fp == NULL) { if (fp == NULL) {
return NULL; return NULL;
} }
char *buf = NULL; unsigned char *buf = NULL;
buf = malloc(*fsz); buf = (unsigned char*)malloc(sizeof(unsigned char) * (*fsz));
if (buf == NULL) { if (buf == NULL) {
fprintf(stderr, "Failed to malloc buf. Returning NULL\n"); fprintf(stderr, "Failed to malloc buf. Returning NULL\n");
fclose(fp); fclose(fp);