aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--c.lua11
-rw-r--r--src/config.c1
-rw-r--r--src/config.h2
-rw-r--r--src/io.c22
4 files changed, 20 insertions, 16 deletions
diff --git a/c.lua b/c.lua
index 45a531a..c90c8fe 100644
--- a/c.lua
+++ b/c.lua
@@ -1,10 +1,3 @@
require "llib"
-print(llib.crypto.spookyhash128_v1("meow"))
-print(llib.crypto.spookyhash128_v2("meow"))
-print(llib.crypto.spookyhash64_v1("meow"))
-print(llib.crypto.spookyhash64_v2("meow"))
-print(llib.crypto.spookyhash32_v1("meow"))
-print(llib.crypto.spookyhash32_v2("meow"))
-
-
-
+llib.config.set({file_chunksize = 2})
+print(llib.io.readfile("src/hash/md5.c"))
diff --git a/src/config.c b/src/config.c
index 46beca7..2fd4455 100644
--- a/src/config.c
+++ b/src/config.c
@@ -4,6 +4,7 @@
int _print_type = 0;
int _max_depth = 2;
int _start_nl_at = 3;
+int _file_malloc_chunk = 512;
int get_config_map(const char* key){
for(int i = 0; config_map[i].key != NULL; i++){
diff --git a/src/config.h b/src/config.h
index 1d45cad..15a4342 100644
--- a/src/config.h
+++ b/src/config.h
@@ -4,6 +4,7 @@
extern int _print_type;
extern int _max_depth;
extern int _start_nl_at;
+extern int _file_malloc_chunk;
struct str_to_int {
const char* key;
@@ -11,6 +12,7 @@ struct str_to_int {
};
static struct str_to_int config_map[] = {
+ {"file_chunksize", &_file_malloc_chunk},
{"print_type", &_print_type},
{"max_depth", &_max_depth},
{"start_nl_at", &_start_nl_at},
diff --git a/src/io.c b/src/io.c
index 9b84804..70771b6 100644
--- a/src/io.c
+++ b/src/io.c
@@ -1,3 +1,4 @@
+#include <unistd.h>
#include "io.h"
#include "stdlib.h"
#include "stdio.h"
@@ -10,18 +11,25 @@ int l_readfile(lua_State* L){
char* a = (char*)luaL_checklstring(L, 1, &len);
FILE *fp;
- const uint64_t chunk_iter = 512;
- uint64_t chunk = 512;
+ const uint64_t chunk_iter = _file_malloc_chunk;
+ uint64_t chunk = chunk_iter;
uint64_t count = 0;
- char* out = malloc(chunk);
-
+
+ if(access(a, F_OK)) {
+ p_fatal("file not found");
+ }
+ if(access(a, R_OK)){
+ p_fatal("missing permissions");
+ }
+
fp = fopen(a, "r");
-
+ char* out = malloc(chunk);
+
for(;;){
- char ch = fgetc(fp);
+ char ch = fgetc(fp);
if(ch==EOF) break;
- if(count > chunk){
+ if(count >= chunk){
chunk += chunk_iter;
out = realloc(out, chunk);
}