aboutsummaryrefslogtreecommitdiff
path: root/src/lib/file.c
diff options
context:
space:
mode:
authorShav Kinderlehrer <[email protected]>2023-04-17 10:23:52 -0400
committerShav Kinderlehrer <[email protected]>2023-04-17 10:23:52 -0400
commita550c7f22985048a0089a529ca89061ab80daff2 (patch)
treeaddafd909c8ba041cf293fd144e5c9891c8952c9 /src/lib/file.c
parent6eadc6dd06dfd2fb1f61c4fd142811f10e4a4f51 (diff)
downloadlat-a550c7f22985048a0089a529ca89061ab80daff2.tar.gz
lat-a550c7f22985048a0089a529ca89061ab80daff2.zip
Add optional processing stagev0.7.0
Diffstat (limited to 'src/lib/file.c')
-rw-r--r--src/lib/file.c15
1 files changed, 9 insertions, 6 deletions
diff --git a/src/lib/file.c b/src/lib/file.c
index f1efa04..f8453d2 100644
--- a/src/lib/file.c
+++ b/src/lib/file.c
@@ -2,26 +2,29 @@
#include <stdlib.h>
#include <string.h>
-#include "file.h"
+#include "types.h"
#include "util.h"
struct filedata readfile(FILE *fp) {
struct filedata f;
f.lc = 0;
- f.len = 0;
+ f.buflen = 0;
f.binary = 0;
+ f.buf = NULL;
+ f.lines = NULL;
+
// expects to be at beginning of file
fseek(fp, 0, SEEK_END);
- f.len = ftell(fp);
+ f.buflen = ftell(fp);
fseek(fp, 0, SEEK_SET);
- f.buf = malloc(f.len);
+ f.buf = malloc(f.buflen);
if (f.buf == NULL)
die("malloc");
- if (fread(f.buf, f.len, 1, fp) < 0) {
+ if (fread(f.buf, f.buflen, 1, fp) < 0) {
die("fread");
}
@@ -29,7 +32,7 @@ struct filedata readfile(FILE *fp) {
// guess if printable
// from https://github.com/sharkdp/content_inspector/blob/master/src/lib.rs
- int testlen = f.len >= 64 ? 64 : f.len;
+ int testlen = f.buflen >= 64 ? 64 : f.buflen;
char *testbuf[testlen];
memcpy(testbuf, f.buf, testlen);