summaryrefslogtreecommitdiff
path: root/shared.h
diff options
context:
space:
mode:
authorkaa <kaa@disroot.org>2023-06-30 09:43:10 -0700
committerkaa <kaa@disroot.org>2023-06-30 09:43:10 -0700
commit67904a09bab959fdb27f7d237275097840b19f7b (patch)
treef1191cbb08de44a82c72b868a92db12c4c941890 /shared.h
parentd5ef3ff63d4aa30ba90b6c0302f9192497fc3194 (diff)
A tool for reading from files.json similar to ls.
Diffstat (limited to 'shared.h')
-rw-r--r--shared.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/shared.h b/shared.h
new file mode 100644
index 0000000..b4232ae
--- /dev/null
+++ b/shared.h
@@ -0,0 +1,22 @@
+static char *
+storeline(FILE *in, int *end, int *len, int guess)
+{
+ static char *line;
+ line = calloc(guess, sizeof(char));
+ int i = 0, buflen = guess;
+ char ch;
+ while ((ch = fgetc(in)) != EOF && ch != '\n') {
+ if (i == buflen - 1) {
+ buflen += guess;
+ line = realloc(line, buflen * sizeof(char));
+ }
+ line[i] = ch;
+ ++i;
+ }
+ line[i] = '\0';
+ *len = i;
+ if (ch == EOF)
+ *end = 1;
+
+ return line;
+}