summaryrefslogtreecommitdiff
path: root/buffer.c
diff options
context:
space:
mode:
authorLeo Tenenbaum <pommicket@gmail.com>2020-12-03 11:07:04 -0500
committerLeo Tenenbaum <pommicket@gmail.com>2020-12-03 11:07:04 -0500
commitb2dea77f9698f06a8a9046f00ad00f4c3ebedfb0 (patch)
tree3fda1ba7d2c76a4af9282fd28d1b4ae639fa4669 /buffer.c
parent32b18a3e60b59957dd9dd237af9e2303aab93d3b (diff)
fix file loading on windows
Diffstat (limited to 'buffer.c')
-rw-r--r--buffer.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/buffer.c b/buffer.c
index a7b0c27..a78be8d 100644
--- a/buffer.c
+++ b/buffer.c
@@ -43,6 +43,8 @@ static Status buffer_line_append_char(Line *line, char32_t c) {
return true;
}
+// fp needs to be a binary file for this to work
+// (because of the way we're checking the size of the file)
Status buffer_load_file(TextBuffer *buffer, FILE *fp) {
assert(fp);
fseek(fp, 0, SEEK_END);
@@ -59,7 +61,8 @@ Status buffer_load_file(TextBuffer *buffer, FILE *fp) {
if (file_contents) {
buffer->lines = calloc(1, sizeof *buffer->lines); // first line
buffer->nlines = 1;
- if (fread(file_contents, 1, file_size, fp) == file_size) {
+ size_t bytes_read = fread(file_contents, 1, file_size, fp);
+ if (bytes_read == file_size) {
char32_t c = 0;
mbstate_t mbstate = {0};
for (u8 *p = file_contents, *end = p + file_size; p != end; ) {