aboutsummaryrefslogtreecommitdiff
path: root/src/common.cpp
diff options
context:
space:
mode:
authorkaiwu <kaiwu2004@gmail.com>2022-05-05 22:43:37 +0800
committerkaiwu <kaiwu2004@gmail.com>2022-05-05 22:43:37 +0800
commitb2af7ad35cc3610c2617ab288843de8d543fc7ed (patch)
treeb176b4bd85b39d8589dbbf0ae5ecf5fe5544884b /src/common.cpp
parente51ee4fea3a5a90004e671c525215b00ea2f9a63 (diff)
downloadadvent-of-code-b2af7ad35cc3610c2617ab288843de8d543fc7ed.tar.gz
advent-of-code-b2af7ad35cc3610c2617ab288843de8d543fc7ed.zip
assert return value
Diffstat (limited to 'src/common.cpp')
-rw-r--r--src/common.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/common.cpp b/src/common.cpp
index 73fa956..1e7984d 100644
--- a/src/common.cpp
+++ b/src/common.cpp
@@ -1,6 +1,7 @@
#include "common.h"
#include <fcntl.h>
#include <unistd.h>
+#include <assert.h>
static size_t file_size(FILE* fd, size_t s) {
char buf[1024];
@@ -20,8 +21,12 @@ line_view load_file(const char* path) {
return {nullptr, size_t(0)};
}
size_t size = file_size(fd, 0);
+ // printf("%s has size[%zu]\n", path, size);
fseek(fd, 0, SEEK_SET);
char* ptr = (char *) malloc(size);
+ size_t x = fread(ptr, sizeof(char), size, fd);
+ assert(x == size);
+ fclose(fd);
return {ptr, size};
}